CentOS7にwordpressを導入しました。
Webサーバにnginx、DBはMariaDBを使用しています。さらに、これらの導入を自動化するため、ansibleを使用してみました。
ansibleのバージョン
# ansible --version
ansible 2.4.2.0
ansibleの設定
sshのパスワードは毎回入力する設定にしました。まず、バージョンの確認。
[root@localhost ~]# ansible --version
ansible 2.4.2.0
パスワードを聞くようにする。
vi /etc/ansible/ansible.cfg
「#ask_pass」と記述があるので、コメントを外します。
活用したplaybook
同じようなことを考えている人がいるようで、以下のplaybookを使用しました。ほんと、先人達の知恵に感謝です。
発生したエラーと対処
何度やってもMaiaDBが起動しないという事象がありました。「/var/log/messages」にはのようなログが出力されます
localhost systemd: Starting MariaDB database server...
localhost mariadb-prepare-db-dir: Database MariaDB is probably initialized in /var/lib/mysql already, nothing is done.
localhost mariadb-prepare-db-dir: If this is not the case, make sure the /var/lib/mysql is empty before running mariadb-prepare-db-dir.
localhost mysqld_safe: 180321 19:25:12 mysqld_safe Logging to '/var/log/mysqld.log'.
localhost mysqld_safe: 180321 19:25:12 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
localhost mysqld_safe: #007/usr/bin/mysqld_safe_helper: Can't create/write to file '/var/log/mysqld.log' (Errcode: 13)
localhost systemd: mariadb.service: main process exited, code=exited, status=1/FAILURE
localhost systemd: mariadb.service: control process exited, code=exited status=1
localhost systemd: Failed to start MariaDB database server.
localhost systemd: Unit mariadb.service entered failed state.
localhost systemd: mariadb.service failed.
この対処は以下を参考にしました。
具体的には、以下のコマンドで対応しました。
# chcon system_u:object_r:bin_t:s0 /usr/binmysqld_safe
毎回同じことをするのもなーと思ったので、playbookを書き換えました。
# vi /roles/mariadb/tasks/main.yml
MariaDBを起動する直前に以下を追加しました。
- name: change SELinux mysqld safe
shell: chcon system_u:object_r:bin_t:s0 /usr/bin/mysqld_safe
wordpress 4.9.4をダウンロードする
この記事を書いている時点の最新のwordpressをダウンロードするために、以下を書き換えました。
# vi group_vars/all
下のように、バージョンとチェックサムを書き換えました。
# Variables listed here are applicable to all host groups
wp_version: 4.9.4
wp_sha256sum: 871622ce9144184d9afe25dd6e970dc5c1fcd25ac1bc1050a920e492b897bb11.