【makuosanとは】
makuosan(まくおさん:通称「まくお」)は、複数のサーバへ同時にファイルを転
送するソフトウエアです。以下のような特徴があります。
・面倒な設定は不要
各サーバに常駐している「まくお」同士が、互いの存在を確認しあって自動的にサ
ーバリストを管理します。新しいサーバを増設する場合も、既設サーバの設定を一
切変更せずに転送対象へ追加することができます。また、正常稼働しているサーバ
のみをファイル転送の対象とするので、停止しているサーバのタイムアウトを待ち
つづけて処理が滞ることもありません。
・転送にかかる時間がサーバ台数に依存しない
サーバが増えても、転送にかかる時間はほとんどかわりません。10台のサーバに転
送しても、20台のサーバに転送しても、ほとんど同じ時間で完了します。ただし、
転送時間は一番応答が遅いサーバの性能に引っ張られるので、同程度のスペックの
サーバで構築された環境で利用することが望ましいです。
・すべてのサーバで同時にファイルが更新される
IPマルチキャストを使って全サーバへ同時にファイルを転送します。そのため、
「このサーバのファイルは更新されているけど、あのサーバのファイルはまだ更新
されていない」といったことがありません。
【インストール方法】
$ tar zxvf makuosan-x.x.x
$ cd makuosan-x.x.x
$ make
$ su -
# make install
【ファイル構成】
make installで以下のファイルがインストールされます。
/usr/local/sbin/makuosan # 「まくお」の本体(daemon)
/usr/local/bin/msync # コマンドラインプログラム
【起動と停止】
makuosan起動時には -b オプションでベースディレクトリを指定します。転送する
ファイルの指定は、ベースディレクトリからの相対パスとなります。
# makuosan -b /var/www -u www-data -g www-data
まくおを停止するには、killコマンドなどでSIGTERMを送ります。
# killall makuosan
【使用方法】
ファイルを転送するには「msyncコマンド」を使用します。
例1)ベースディレクトリ直下のindex.htmlを転送する(/var/www/index.html)
$ msync send index.html
例2)ベースディレクトリ以下のディレクトリツリーを全部転送する
$ msync send -r
例3)転送されるファイルを確認する(dry run)
$ msync send -r -n
【利用するメリット】
「まくお」は、ファイル転送の際にコマンドラインから転送先サーバを指定する
必要がありません。rsyncやscpのような、1対1の転送ツールは、必ず転送先を指定
する必要があります。
そのため、複数のサーバに対してファイルを転送したい場合、以下のようにサーバ
の数だけrsyncやscpを実行しなければいけません。
$ for h in host2 host3 host4 host5 host6;do rsync -aRv hogehoge $h:/;done
「まくお」では、makuosanが起動しているサーバ同士でファイルの転送をします。
したがって、転送したいサーバ全部でmakuosanを起動しておく必要はありますが、
そのかわり、ファイル転送は以下の例のように転送したいファイルやディレクトリ
を伝えるだけで済みます。
$ msync send -r hogehoge/
このコマンド一発で、「まくお」が稼働している全てのサーバに hogehoge/を転送す
ることができます。rsyncやscpを利用する場合と比べて、遥かにシンプルで簡単に転
送スクリプトを記述できると思います。
また「指定したサーバにだけ転送したい」というニーズのために、特定のサーバにだ
け転送するオプション(-t)も用意しています。
$ msync send -t host3 -r hogehoge/
ただし、この場合でも、host3では makuosanが動いている必要があります。尚、転送
可能なサーバの一覧は、以下のコマンドで確認することができます。
$ msync members
【簡単な使用例】
== ネットワーク構成 ==
host1のファイルを host2, host3, host4に転送します。
+-------+
| host2 |
+-------+
|
+-------+ +-----------+ +-------+
| host1 |-----| L2 SWITCH |-----| host3 |
+-------+ +-----------+ +-------+
|
+-------+
| host4 |
+-------+
== makuosanを起動する ==
host1:~# makuosan -b /var/www -u www-data -g www-data
host2:~# makuosan -b /var/www -u www-data -g www-data
host3:~# makuosan -b /var/www -u www-data -g www-data
host4:~# makuosan -b /var/www -u www-data -g www-data
== 転送するファイルを作る ==
host1の /var/www/ 以下にファイルを作ります。
host1:~# cd /var/www/
host1:/var/www# echo hoge > hoge.html
host1:/var/www# echo fuga > fuga.html
host1:/var/www# chown www-data:www-data hoge.html fuga.html
host1:/var/www# ls -la
total 16
drwxr-xr-x 3 root root 176 Oct 10 10:31 .
drwxr-xr-x 15 root root 360 Oct 9 04:52 ..
-rw-r--r-- 1 www-data www-data 5 Oct 10 10:31 fuga.html
-rw-r--r-- 1 www-data www-data 5 Oct 10 10:31 hoge.html
他のホストにはファイルはありません。
host2:/var/www# ls -la
total 16
drwxr-xr-x 3 root root 176 Oct 10 10:31 .
drwxr-xr-x 15 root root 360 Oct 9 04:52 ..
host3:/var/www# ls -la
total 16
drwxr-xr-x 3 root root 176 Oct 10 10:31 .
drwxr-xr-x 15 root root 360 Oct 9 04:52 ..
host4:/var/www# ls -la
total 16
drwxr-xr-x 3 root root 176 Oct 10 10:31 .
drwxr-xr-x 15 root root 360 Oct 9 04:52 ..
== ファイルを転送する ==
host1:~$ msync send -r
== 転送されたファイルを確認 ==
host2:/var/www# ls -la
total 16
drwxr-xr-x 3 root root 176 Oct 10 10:31 .
drwxr-xr-x 15 root root 360 Oct 9 04:52 ..
-rw-r--r-- 1 www-data www-data 5 Oct 10 10:31 fuga.html
-rw-r--r-- 1 www-data www-data 5 Oct 10 10:31 hoge.html
host3:/var/www# ls -la
total 16
drwxr-xr-x 3 root root 176 Oct 10 10:31 .
drwxr-xr-x 15 root root 360 Oct 9 04:52 ..
-rw-r--r-- 1 www-data www-data 5 Oct 10 10:31 fuga.html
-rw-r--r-- 1 www-data www-data 5 Oct 10 10:31 hoge.html
host4:/var/www# ls -la
total 16
drwxr-xr-x 3 root root 176 Oct 10 10:31 .
drwxr-xr-x 15 root root 360 Oct 9 04:52 ..
-rw-r--r-- 1 www-data www-data 5 Oct 10 10:31 fuga.html
-rw-r--r-- 1 www-data www-data 5 Oct 10 10:31 hoge.html