概要
- ansibleを使い、centos7にMySQL5.7をインストール
- ansibleでservice startを行ったがエラー
- この原因の調査と対応について
現象
ansibleのPlaybookは下記のように記載していた。
- name: install mysqld
yum:
name: "{{ item }}"
enablerepo: mysql57-community
disablerepo: mysql56-community
state: present
with_items:
- mysql-community-server
- mysql-community-client
- mysql-community-common
- mysql-community-libs
- mysql-community-libs-compat
- name: mysqld start
# enable serve chkconfig
service: name=mysqld state=started enabled=on
しかし、mysqldをstartさせる所でエラー
TASK: [mysqld start] **********************************************************
failed: [192.168.33.12] => {"failed": true}
msg: Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
FATAL: all hosts have already failed -- aborting
ゲストOSに入って直接やってみる。
[root@localhost ~]# service mysql start
Redirecting to /bin/systemctl start mysql.service
Failed to start mysql.service: Unit mysql.service failed to load: No such file or directory.
やはりダメ。
/var/log/mysqld.log
を見てみる
2016-09-05T22:57:33.447887Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2016-09-05T22:57:33.448064Z 0 [Note] InnoDB: Buffer pool(s) load completed at 160906 0:57:33
2016-09-05T22:57:33.450290Z 0 [ERROR] /usr/sbin/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 2 - No such file or directory)
2016-09-05T22:57:33.450317Z 0 [ERROR] Can't start server: can't create PID file: No such file or directory
どうやら/var/run/mysqld/mysqld.pid
というファイルを作成することができずに怒られてるようだ。
そもそも/var/run/mysqld/
というディレクトリがなかったので、このディレクトリを作り、
パーミッションの設定をmysqlにしてあげた。
[root@localhost ~]# mkdir /var/run/mysqld
[root@localhost ~]# chown mysql.mysql /var/run/mysqld
[root@localhost ~]# service mysqld start
Starting mysqld (via systemctl): [ OK ]
お、行けた
一応ansibleでも起動出来るか確認
TASK: [mysqld start] **********************************************************
ok: [192.168.33.12]
大丈夫。
まとめ
- なぜか構築したゲストOSに
/var/run/mysqld
ディレクトリがなかったため、自作して解決 - 本来はどこかのタイミングでこのディレクトリが作られる気がするが、それが作られなかった理由は謎のまま