ServersMan(CentOS 6)に Django 環境を構築する(2) MySQLのインストール
前回(ServersMan(CentOS 6) に Django 環境を構築する(1) Python2.7のインストールまで) に続いて、、Django のバックエンドデータベースとして、MySQL 5.6 を利用することを前提に、MySQLのインストールを行う。
MySQLのダウンロード
Download MySQL Community Server のページを開く
ダウンロード対象にて、「Linux Generic」 を選択し、「Linux – Generic (glibc 2.5) (x86, 32-bit), RPM Bundle」のダウンロードボタンを押下。
Oracleのアカウントが無い場合、ここで作成を求められるので作成します。
あれば、ログインして次に進みます。
おおよそ 300MB のファイルをダウンロード
FTPサーバーの構築
MySQLのダウンロードには、上記の様な手順を踏むので、サーバー側で、wget によってファイルをダウンロードすることができません。
ので、PCでダウンロードしたファイルを、サーバーに送らなければいけないので、この機会にFTPサーバーも設定しておきます。
インストール
サーバーにログインして、
- # rpm -q vsftpd
- package vsftpd is not installed
念のため、インストールされているか確認する。。。されていない。
- # yum install -y vsftpd
- Loaded plugins: fastestmirror
- :
- Installed:
- vsftpd.i686 0:2.2.2-11.el6_4.1
- Complete!
インストール完了
設定
/etc/vsftpd/vsftpd.conf を編集します。
匿名ログインを無効化
2行目をコメント化。
- # Allow anonymous FTP? (Beware - allowed by default if you comment this out).
- # anonymous_enable=YES
ログを出力
3行目のコメントを外す。
- # The name of log file when xferlog_enable=YES and xferlog_std_format=YES
- # WARNING - changing this filename affects /etc/logrotate.d/vsftpd.log
- xferlog_file=/var/log/xferlog
接続制限の設定
以下の様になっていることを確認
- tcp_wrappers=YES
/etc/hosts.allow の最終行に以下を追記(制限をかけるときはここで行う)
- #
- # hosts.allow This file contains access rules which are used to
- # allow or deny connections to network services that
- # either use the tcp_wrappers library or that have been
- # started through a tcp_wrappers-enabled xinetd.
- #
- # See 'man 5 hosts_options' and 'man 5 hosts_access'
- # for information on rule syntax.
- # See 'man tcpd' for information on tcp_wrappers
- #
- vsftpd : ALL : ALLOW
接続ユーザーの追加
基本的に、rootでは、FTPサーバーに接続できないため、ユーザーを追加する
非推奨だが、root でログインできる様にするためには、/etc/vsftpd/ftpusers、/etc/vsftpd/user_list の両方からroot 行をコメントアウトすることで可能
- # useradd xxxx
- # passwd xxxx
- # gpasswd -a xxx root
自動起動の設定
ランレベル 3 で自動起動するように設定する。(現状の確認から設定)
- # chkconfig --list vsftpd
- vsftpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
- # runlevel
- N 3
- # chkconfig --level 3 vsftpd on
- # chkconfig --list vsftpd
- vsftpd 0:off 1:off 2:off 3:on 4:off 5:off 6:off
起動
FTPサーバーを起動する。
- # /sbin/service vsftpd start
- Starting vsftpd for vsftpd: [ OK ]
これで、FTPでアップロードできる様になりますので、ダウンロードしたMySQLのインストールファイルを、サーバーに上げてください。
MySQLのインストール
ファイルの解凍をすると、いくつかのRPMファイルが展開される。
- # tar xvf MySQL-5.6.14-1.linux_glibc2.5.i386.rpm-bundle.tar
- MySQL-shared-5.6.14-1.linux_glibc2.5.i386.rpm
- MySQL-embedded-5.6.14-1.linux_glibc2.5.i386.rpm
- MySQL-server-5.6.14-1.linux_glibc2.5.i386.rpm
- MySQL-shared-compat-5.6.14-1.linux_glibc2.5.i386.rpm
- MySQL-devel-5.6.14-1.linux_glibc2.5.i386.rpm
- MySQL-test-5.6.14-1.linux_glibc2.5.i386.rpm
- MySQL-client-5.6.14-1.linux_glibc2.5.i386.rpm
- 標準の最低限のインストールには、サーバーとクライアント RPM をインストールする
- RPM はまた MySQL サーバーを運用するためのユーザー mysql (存在しない場合) のログインアカウントが作成されます
- 開発用のヘッダー(devel)もDjangoで必要になるのでインストールする
- サーバーのインストール時に、rootパスワードの情報が表示されるので、見過ごさない
- # rpm -ivh MySQL-shared-5.6.14-1.linux_glibc2.5.i386.rpm
- # rpm -ivh MySQL-shared-compat-5.6.14-1.linux_glibc2.5.i386.rpm
- # rpm -ivh MySQL-server-5.6.14-1.linux_glibc2.5.i386.rpm
- error: Failed dependencies:
- libaio.so.1 is needed by MySQL-server-5.6.14-1.linux_glibc2.5.i386
- libaio.so.1(LIBAIO_0.1) is needed by MySQL-server-5.6.14-1.linux_glibc2.5.i386
- libaio.so.1(LIBAIO_0.4) is needed by MySQL-server-5.6.14-1.linux_glibc2.5.i386
libaio が無いとエラーになる場合、インストールして再実行
- # yum install libaio
- # rpm -ivh MySQL-server-5.6.14-1.linux_glibc2.5.i386.rpm
このとき、初期パスワードに関する情報が出力されるので、忘れずに確認すること!
root ユーザー用のランダムパスワードが設定されて、/root/.mysql_secret にそのパスワードが記述されたようだ。
- A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
- You will find that password in '/root/.mysql_secret'.
- # rpm -ivh MySQL-client-5.6.14-1.linux_glibc2.5.i386.rpm
- # rpm -ivh MySQL-devel-5.6.14-1.linux_glibc2.5.i386.rpm
MySQLの起動と停止
起動と停止を行ってみる。
起動
- # /sbin/service mysql start
- Starting MySQL.. SUCCESS!
停止
- # /sbin/service mysql stop
- Shutting down MySQL.. SUCCESS!
ランレベル 3 で自動起動される様に設定されたか確認
- # chkconfig | grep "mysql"
- mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
ルートパスワードの変更
初期設定されたパスワードを確認する
- # cat /root/.mysql_secret
- # 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のプロンプトが表示される。
- # mysql -u root -p
- Enter password:
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 2
- Server version: 5.6.14
- Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
- Oracle is a registered trademark of Oracle Corporation and/or its
- affiliates. Other names may be trademarks of their respective
- owners.
- Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
- mysql>
パスワードを変更する
- mysql> set password for 'root'@'localhost' = password('xxxxxxxx');
- Query OK, 0 rows affected (0.00 sec)
以上で、MySQLのインストールまで完了!