Attention : Amazon Linux 2 がリリースされており、この記事は古くなっています。
前回に引き続きAmazon Linuxにミドルウェアを入れていきます。
今回はMariaDBです。
ここで、どうしてひとつのインスタンスに何でも入れてしまうのか、ElasticsearchとWebとDBは分けた方がいいんではないかという声も聞こえてきそうですが、経費節減のためです。
それだけです。
自社サービスなので。
インストール
パッケージの確認
$ yum list | grep mariadb mariadb-connector-java.noarch 1.3.6-1.5.amzn1 amzn-main
パッケージないです・・・ないんです。
前回褒めたのは取り消しです。
MySQLだと、今回は5.7じゃないとダメなんですが、どうでしょうか。
$ yum list | grep mysql57 mysql57.x86_64 5.7.18-2.3.amzn1 amzn-main mysql57-common.i686 5.7.18-2.3.amzn1 amzn-main mysql57-common.x86_64 5.7.18-2.3.amzn1 amzn-main mysql57-devel.x86_64 5.7.18-2.3.amzn1 amzn-main mysql57-embedded.x86_64 5.7.18-2.3.amzn1 amzn-main mysql57-embedded-devel.x86_64 5.7.18-2.3.amzn1 amzn-main mysql57-errmsg.x86_64 5.7.18-2.3.amzn1 amzn-main mysql57-libs.i686 5.7.18-2.3.amzn1 amzn-main mysql57-libs.x86_64 5.7.18-2.3.amzn1 amzn-main mysql57-server.x86_64 5.7.18-2.3.amzn1 amzn-main mysql57-test.x86_64 5.7.18-2.3.amzn1 amzn-main
オープンソースをないがしろにするOracleはイヤだったんですけど・・・
rpmを落としてくればMariaDBもインストールできそうですが、何かあった時にデータベースに手間を取られたくないので、素直にMySQLをインストールします。
$ sudo yum -y install mysql57 mysql57-server Loaded plugins: priorities, update-motd, upgrade-helper amzn-main | 2.1 kB 00:00:00 amzn-updates | 2.5 kB 00:00:00 Resolving Dependencies --> Running transaction check ---> Package mysql57.x86_64 0:5.7.18-2.3.amzn1 will be installed 中略 Installed: mysql57.x86_64 0:5.7.18-2.3.amzn1 mysql57-server.x86_64 0:5.7.18-2.3.amzn1 Dependency Installed: mysql-config.x86_64 0:5.5.57-1.18.amzn1 mysql57-common.x86_64 0:5.7.18-2.3.amzn1 mysql57-errmsg.x86_64 0:5.7.18-2.3.amzn1 Complete!
先にログファイルサイズinnodb_log_file_size
の設定などを行ってから起動します。
先に起動してしまうと、デフォルトのサイズで作成されるログファイルと異なるためにエラーになって起動できません。
停止してログファイルを削除するなどの手間が発生してしまいます。
さて、その他含めてどのようにチューニングするかはここには記述しません。
詳細に調査された方の記事などがインターネットにたくさんありますので、参考になさってください。
/etc/my.cnfを編集したら、MySQLを起動します。
$ sudo service mysqld start Initializing MySQL database 2017-10-25T07:58:57.101242Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 100 100 2017-10-25T07:58:59.603967Z 0 [Warning] InnoDB: New log files created, LSN=45790 2017-10-25T07:58:59.852002Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2017-10-25T07:58:59.917021Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 5bf69048-b95a-11e7-a979-06b2989d6876. 2017-10-25T07:58:59.919227Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2017-10-25T07:59:00.809568Z 0 [Warning] CA certificate ca.pem is self signed. 2017-10-25T07:59:00.840083Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option. Starting mysqld: [ OK ]
最終的に起動しましたが、いくつかワーニングが出ています。
エラー対応
行番号3
TIMESTAMP with implicit DEFAULT value is deprecated. Please use –explicit_defaults_for_timestamp server option (see documentation for more details).
TIMESTAMPの暗黙的なデフォルト値は非推奨だと教えてくれています。
正直なところ、何もそのような設定をしていないので、デフォルトでそのデフォルト値を設定しないようにしてほしい。
explicit_defaults_for_timestampを使えとのことなので、
explicit_defaults_for_timestamp = true
とmy.cnfに記述した。
行番号10までは初回起動でいろいろないから作りました、というお知らせのようです。
行番号11
rootユーザーのパスワードが設定されていない、と怒られています。
initialize-insecureオプションをオフにしろとのことですが、この見慣れないオプションは何でしょうか?
どうやら初期化コマンド実行時のオプションのようです。
参考:MySQL 5.7.6でデータベースの初期化が変わる mysql_install_dbからmysqld –initialize
initialize-insecureを使わなければいいんでしょ、ということで初期化を実行しようと思ったけれどもう起動している。
その辺のところの確認や、設定変更もしているので再起動してみる。
$ sudo service mysqld restart Stopping mysqld: [ OK ] Starting mysqld: [ OK ]
文句のつけどころは無いようです。
MySQLのrootパスワードを設定しておきます。
参考:MySQL 5.7でrootユーザのパスワードを再設定
$ mysql -u root mysql> use mysql Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> UPDATE user SET authentication_string=password('設定するパスワード') WHERE user='root'; Query OK, 1 row affected, 1 warning (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 1 mysql> flush privileges; mysql> quit Bye
ログイン確認
$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 Server version: 5.7.18 MySQL Community Server (GPL) Copyright (c) 2000, 2017, 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>
無事ログインできました。
インストール関連はここまで。