ServersMan(CentOS 6)に Django 環境を構築する(2) MySQLのインストール

前回(ServersMan(CentOS 6) に Django 環境を構築する(1) Python2.7のインストールまで) に続いて、、Django のバックエンドデータベースとして、MySQL 5.6 を利用することを前提に、MySQLのインストールを行う。

MySQLのダウンロード

Download MySQL Community Server のページを開く

mysql_inst01

ダウンロード対象にて、「Linux Generic」 を選択し、「Linux – Generic (glibc 2.5) (x86, 32-bit), RPM Bundle」のダウンロードボタンを押下。

mysql_inst02

Oracleのアカウントが無い場合、ここで作成を求められるので作成します。

あれば、ログインして次に進みます。

mysql_inst04

おおよそ 300MB のファイルをダウンロード

mysql_inst03

FTPサーバーの構築

MySQLのダウンロードには、上記の様な手順を踏むので、サーバー側で、wget によってファイルをダウンロードすることができません。

ので、PCでダウンロードしたファイルを、サーバーに送らなければいけないので、この機会にFTPサーバーも設定しておきます。

インストール

サーバーにログインして、

  1. # rpm -q vsftpd
  2. package vsftpd is not installed

念のため、インストールされているか確認する。。。されていない。

  1. # yum install -y vsftpd
  2. Loaded plugins: fastestmirror
  3. :
  4. Installed:
  5. vsftpd.i686 0:2.2.2-11.el6_4.1
  6.  
  7. Complete!

インストール完了

 

設定

/etc/vsftpd/vsftpd.conf を編集します。

匿名ログインを無効化

2行目をコメント化。

  1. # Allow anonymous FTP? (Beware - allowed by default if you comment this out).
  2. # anonymous_enable=YES

ログを出力

3行目のコメントを外す。

  1. # The name of log file when xferlog_enable=YES and xferlog_std_format=YES
  2. # WARNING - changing this filename affects /etc/logrotate.d/vsftpd.log
  3. xferlog_file=/var/log/xferlog

接続制限の設定

以下の様になっていることを確認

  1. tcp_wrappers=YES

/etc/hosts.allow の最終行に以下を追記(制限をかけるときはここで行う)

  1. #
  2. # hosts.allow This file contains access rules which are used to
  3. # allow or deny connections to network services that
  4. # either use the tcp_wrappers library or that have been
  5. # started through a tcp_wrappers-enabled xinetd.
  6. #
  7. # See 'man 5 hosts_options' and 'man 5 hosts_access'
  8. # for information on rule syntax.
  9. # See 'man tcpd' for information on tcp_wrappers
  10. #
  11. vsftpd : ALL : ALLOW

接続ユーザーの追加

基本的に、rootでは、FTPサーバーに接続できないため、ユーザーを追加する

非推奨だが、root でログインできる様にするためには、/etc/vsftpd/ftpusers、/etc/vsftpd/user_list の両方からroot 行をコメントアウトすることで可能

  1. # useradd xxxx
  2. # passwd xxxx
  3. # gpasswd -a xxx root

自動起動の設定

ランレベル 3 で自動起動するように設定する。(現状の確認から設定)

  1. # chkconfig --list vsftpd
  2. vsftpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
  3. # runlevel
  4. N 3
  5. # chkconfig --level 3 vsftpd on
  6. # chkconfig --list vsftpd
  7. vsftpd 0:off 1:off 2:off 3:on 4:off 5:off 6:off

起動

FTPサーバーを起動する。

  1. # /sbin/service vsftpd start
  2. Starting vsftpd for vsftpd: [ OK ]

これで、FTPでアップロードできる様になりますので、ダウンロードしたMySQLのインストールファイルを、サーバーに上げてください。

MySQLのインストール

ファイルの解凍をすると、いくつかのRPMファイルが展開される。

  1. # tar xvf MySQL-5.6.14-1.linux_glibc2.5.i386.rpm-bundle.tar
  2. MySQL-shared-5.6.14-1.linux_glibc2.5.i386.rpm
  3. MySQL-embedded-5.6.14-1.linux_glibc2.5.i386.rpm
  4. MySQL-server-5.6.14-1.linux_glibc2.5.i386.rpm
  5. MySQL-shared-compat-5.6.14-1.linux_glibc2.5.i386.rpm
  6. MySQL-devel-5.6.14-1.linux_glibc2.5.i386.rpm
  7. MySQL-test-5.6.14-1.linux_glibc2.5.i386.rpm
  8. MySQL-client-5.6.14-1.linux_glibc2.5.i386.rpm
  • 標準の最低限のインストールには、サーバーとクライアント RPM をインストールする
  • RPM はまた MySQL サーバーを運用するためのユーザー mysql (存在しない場合) のログインアカウントが作成されます
  • 開発用のヘッダー(devel)もDjangoで必要になるのでインストールする
  • サーバーのインストール時に、rootパスワードの情報が表示されるので、見過ごさない
  1. # rpm -ivh MySQL-shared-5.6.14-1.linux_glibc2.5.i386.rpm
  1. # rpm -ivh MySQL-shared-compat-5.6.14-1.linux_glibc2.5.i386.rpm
  1. # rpm -ivh MySQL-server-5.6.14-1.linux_glibc2.5.i386.rpm
  2. error: Failed dependencies:
  3. libaio.so.1 is needed by MySQL-server-5.6.14-1.linux_glibc2.5.i386
  4. libaio.so.1(LIBAIO_0.1) is needed by MySQL-server-5.6.14-1.linux_glibc2.5.i386
  5. libaio.so.1(LIBAIO_0.4) is needed by MySQL-server-5.6.14-1.linux_glibc2.5.i386

libaio が無いとエラーになる場合、インストールして再実行

  1. # yum install libaio
  2. # rpm -ivh MySQL-server-5.6.14-1.linux_glibc2.5.i386.rpm

このとき、初期パスワードに関する情報が出力されるので、忘れずに確認すること!

root ユーザー用のランダムパスワードが設定されて、/root/.mysql_secret にそのパスワードが記述されたようだ。

  1. A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
  2. You will find that password in '/root/.mysql_secret'.
  1. # rpm -ivh MySQL-client-5.6.14-1.linux_glibc2.5.i386.rpm
  1. # rpm -ivh MySQL-devel-5.6.14-1.linux_glibc2.5.i386.rpm

MySQLの起動と停止

起動と停止を行ってみる。

起動

  1. # /sbin/service mysql start
  2. Starting MySQL.. SUCCESS!

停止

  1. # /sbin/service mysql stop
  2. Shutting down MySQL.. SUCCESS!

ランレベル 3 で自動起動される様に設定されたか確認

  1. # chkconfig | grep "mysql"
  2. mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off

ルートパスワードの変更

初期設定されたパスワードを確認する

  1. # cat /root/.mysql_secret
  2. # The random password set for the root user at Mon Oct 14 23:19:35 2013 (local time): xsHn1DXH

MySQLにログイン(上記手順で起動させておく)

mysql -u root -p でログインすると、パスワードの入力を求められるので、上記で確認したパスワードを入力すると、mysqlのプロンプトが表示される。

  1. # mysql -u root -p
  2. Enter password:
  3. Welcome to the MySQL monitor. Commands end with ; or \g.
  4. Your MySQL connection id is 2
  5. Server version: 5.6.14
  6.  
  7. Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
  8.  
  9. Oracle is a registered trademark of Oracle Corporation and/or its
  10. affiliates. Other names may be trademarks of their respective
  11. owners.
  12.  
  13. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  14.  
  15. mysql>

パスワードを変更する

  1. mysql> set password for 'root'@'localhost' = password('xxxxxxxx');
  2. Query OK, 0 rows affected (0.00 sec)

以上で、MySQLのインストールまで完了!

次は、Djangoのインストール

Follow me!

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です