MySQL5.7.20 グループレプリケーションでマルチマスターが実現できるバージョンのインストールだ。
グループレプリケーションは、MySQL5.7.17 から実装されている。
MHAも双方向レプリケーションもいろいろと問題があったが、その分グループレプリケーション+マルチマスターへの期待は大きいだろう。
CentOS6 でデフォルトでyum インストールできるバージョンのMySQL5.1とはちょっと違うセキュリティも含まれているので少々ややこしい面もあるが、それも含めて書いて行きたい。
サーバOSは、CentOS 7.3 である。
概要
手順は以下の通り。
1.mariadb-libsの削除
2.MySQL公式yumリポジトリの追加
3.MySQL5.7のインストール
4.MySQL5.7の自動起動登録
5.rootユーザの初期パスワード確認
6.mysql_secure_installationの実行
7./etc/my.cnfの設定追加
mariadb-libsの削除
CentOS7系ではデフォルトでMariaDBがインストールされているので、これを削除する。
データディレクトリ(/var/lib/mysql)もあれば削除しておく。
# yum remove mariadb-libs
# rm -rf /var/lib/mysql
|
MySQL公式yumリポジトリの追加
以下からRed Hat Enterprise Linux 7 用のyumリポジトリのrpmをダウンロードする。
https://dev.mysql.com/downloads/repo/yum/
2017/10/29現在の最新パッケージ
mysql57-community-release-el7-11.noarch.rpm
リポジトリの追加とMySQL情報の確認を行う。
# yum localinstall http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
# ls -al /etc/yum.repos.d/
合計 48
drwxr-xr-x. 2 root root 250 9月 10 23:30 .
drwxr-xr-x. 77 root root 8192 10月 28 03:58 ..
-rw-r--r--. 1 root root 1664 11月 30 2016 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 11月 30 2016 CentOS-CR.repo
-rw-r--r--. 1 root root 649 11月 30 2016 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 630 11月 30 2016 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 11月 30 2016 CentOS-Sources.repo
-rw-r--r--. 1 root root 2893 11月 30 2016 CentOS-Vault.repo
-rw-r--r--. 1 root root 314 11月 30 2016 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 1885 4月 27 2017 mysql-community-source.repo
-rw-r--r--. 1 root root 1838 4月 27 2017 mysql-community.repo
# yum info mysql-community-server
名前 : mysql-community-server
アーキテクチャー : x86_64
バージョン : 5.7.20
リリース : 1.el7
容量 : 164 M
リポジトリー : mysql57-community/x86_64
要約 : A very fast and reliable SQL database server
URL : http://www.mysql.com/
※以下省略
|
※グループレプリケーションは、MySQL5.7.17 から実装されている。
MySQL5.7のインストール
# yum install mysql-community-server
# mysqld --version
mysqld Ver 5.7.20 for Linux on x86_64 (MySQL Community Server (GPL))
|
MySQL5.7の自動起動登録
自動起動登録を行い、起動する。
# systemctl enable mysqld
# systemctl start mysqld
# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 日 2017-10-29 12:09:18 JST; 23min ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Main PID: 10755 (mysqld)
CGroup: /system.slice/mysqld.service
└─10755 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
10月 29 12:09:15 CentOS73 systemd[1]: Starting MySQL Server...
10月 29 12:09:18 CentOS73 systemd[1]: Started MySQL Server.
|
rootユーザの初期パスワード確認
MySQL5.7では、rootアカウントの初期パスワードが設定されている。
rootアカウントの初期パスワードは、ログファイル(/var/log/mysqld.log)に出力されている。
下記の赤文字部分が初期パスワードだ。
# grep password /var/log/mysqld.log
2017-10-29T10:25:52.159050Z 1 [Note] A temporary password is generated for root@localhost: Plk9tS3omI?#
|
mysql_secure_installationの実行
mysql_secure_installationで実施されるのは以下の通り。
・rootユーザのパスワード変更
・匿名ユーザの削除
・rootユーザのリモートログインの禁止
・testデータベースの削除
・権限テーブルの再読み込み
# mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root: ※ここでrootユーザの初期パスワードを入力
The existing password for the user account root has expired. Please set a new password.
New password: ※ここでrootユーザの新パスワードを入力
Re-enter new password: ※ここでrootユーザの新パスワードを入力
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.
Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : n ※またrootユーザのパスワードを変更するか聞かれるので、NoでOK
... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y ※匿名ユーザの削除、yを入力
Success.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y ※rootユーザのリモートログインの禁止、yを入力
Success.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y ※testデータベースの削除、yを入力
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y ※権限テーブルの再読み込みを実施、yを入力
Success.
All done!
|
/etc/my.cnfの設定追加
以下の設定を/etc/my.cnfの[mysqld]に追加する。
character-set-server = utf8
default_password_lifetime = 0
default_password_lifetime は、デフォルトのパスワード有効期間だ。
単位は日で、日数を指定する。
最後にパスワードが更新されてからこの日数が経つと、パスワードが無効になる。
MySQL4.7.10までは、この設定のデフォルト値は360で、360日経つとパスワードが無効になった。
MySQL4.7.11からは、この設定のデフォルト値は0となっており、日数は無制限となっている。
今さら設定値を0にすることはないのだが、念のため、明示的に0としておきたい。
このあたりは、好みの問題である。
Categories: MySQL