さて現在、Wordpressのバックエンドの一般設定で、Wordpressアドレス(こちらのアドレスは、管理者がWordpressのダッシュボードにログインするためのアドレス)を「http://vubuntu01.it-ishin.com」、サイトアドレス(インターネット上のユーザーがサイトを見るためのアドレス)を「http://ubuntu03.it-ishin.com」にしています。同じにした場合、バックエンドにログインすることが出来なくなる(IDとPasswordがマッチしないといって、怒られます)可能性が高いからです。
また、Wordpressアプリケーション・サーバーを如何にして「そっくりさん」にするかも、大きな課題です。投稿記事や各種の設定はMySQLデータベースで共有できるのですが、テーマとかプラグインはphp/css/jsなどの静的ファイルであり、これらをすべてのバックエンド・サーバーで同一化しないといけないと思っておりますので。
それで、同期の方策として考えたのは、同期の定番ソフトrsyncを使うことです。バックエンドのWordpressアプリケーション・サーバーのうち、1台をPrimary Serverと定め、管理者がアクセスするのはこのPrimary Serverとしておき、Wordpressのダッシュボードで記事の投稿、プラグインやテーマの設定などのサイト管理を行う。そのうえで、rsyncを使って、他のバックエンドのWordpressアプリケーション・サーバーとの同期を取る、というものです。
作業手順としては、
【2】Wordpress管理のためのSSHサーバー(vu01.it-ishin.com=192.168.1.101)の設定
まずは、鍵認証を使い、パスフレーズ入力なしに他のバックエンドサーバー(仮想サーバーのホスト名+ドメイン名とIPアドレスはvu02.it-ishin192.com=192.168.1.102、vu03.it-ishin.com=192.168.1.103)にログインできるようにするSSHサーバーの設定です。これについては、「SSHサーバー」のカテゴリに投稿しました。次をページをご覧下さい。http://www2.it-ishin.com/2014/07/11/905.html。
【3】同期ソフトrsyncを使い仮想サーバーを同期させる設定
仮想ホストvu01の/var/www/html/wordpres以下のディレクトリと、Ubuntu14.04LTS付属のKVMで作成した仮想ホストvu02、vu03の/var/www/html/wordpresse以下のディレクトリと同期させるための簡単なシェルスクリプトもどきを下記のように作成します。
#!/bin/bash rsync -aur --delete 192.168.1.101:/var/www/ /var/www/
rsyncにはたくさんのオプションがあります。
このスクリプトモドキに実行可能のオプションを付けて、ユーザーのホームディレクトリのbinに配置し、vu02, vu03でクーロンを使います。crontab -eで編集ができますが、最初はnanoかtiny vimとか編集用にどのエディタを使うかを聞いてきます。
# Edit this file to introduce tasks to be run by cron. # # Each task to run has to be defined through a single line # indicating with different fields when the task will be run # and what command to run for the task # # To define the time you can provide concrete values for # minute (m), hour (h), day of month (dom), month (mon), # and day of week (dow) or use '*' in these fields (for 'any').# # Notice that tasks will be started based on the cron's system # daemon's notion of time and timezones. # # Output of the crontab jobs (including errors) is sent through # email to the user the crontab file belongs to (unless redirected). # # For example, you can run a backup of all your user accounts # at 5 a.m every week with: # 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/ # # For more information see the manual pages of crontab(5) and cron(8) # # m h dom mon dow command 00 * * * * /home/michiaki/bin/synchro.sh 10 * * * * /home/michiaki/bin/synchro.sh 20 * * * * /home/michiaki/bin/synchro.sh 30 * * * * /home/michiaki/bin/synchro.sh 40 * * * * /home/michiaki/bin/synchro.sh 50 * * * * /home/michiaki/bin/synchro.sh
設定した内容は上記です。
【4】後記
この設定でそっくりさんが出来るかどうか、確認してみます。間違いがあれば、訂正します。上記はロードバランサーを使ったテストモデルです。実稼働させる場合は、
などが必要になると思います。
※【追記】
WordPressの場合、rsyncでテーマやプラグインのファイル自体は同期できますがプラグインの場合、「有効化」という作業が必要になります。これについては、プラグインの有効化を強制するプラグインがあるとのことです。次のサイトに紹介されています。http://dogmap.jp/2012/08/25/must-use-plugins/comment-page-1/。折をみて、確かめて見ます。