LoginSignup
3
6

More than 5 years have passed since last update.

Lsyncdを使用したフォルダReplication[片側同期]

Last updated at Posted at 2016-01-27

EC2間のSSHについては別途記述し追加予定
ここにリンクを挿入予定

インスタンス間でSSH通信が可能になっている状態からお話をスタートします。

lsyncdを導入します。
 動きとしては、lsyncdで変更を検知し、rsyncが勝手に走る(rsyncはいじらない)みたいです。
 僕の理解です。間違ってたらごめんなさい。

今回はMASTER→SLAVEの片側構成です。

lsyncdをインストールします。

yum install -y lsyncd

インストールすると設定ファイルが 作成されます
/etc/lsyncd.conf

sudo cp /etc/lsyncd.conf /etc/lsyncd.conf.old
sudo vim /etc/lsyncd.conf
lsyncd.conf
--
-- Simple example for default rsync, but executing moves through on the target.
--
-- For more examples, see /usr/share/doc/lsyncd*/examples/
--
-- sync{default.rsyncssh, source="/var/www/html", host="localhost", targetdir="/tmp/htmlcopy/"}

settings{
        insist = true,
        statusFile = "/tmp/lsyncd.stat",
        logfile = "/var/log/lsyncd/lsyncd.log",
        statusInterval = 1,
}

sync {
   default.rsync,
   source = "/var/www/html/",
   target = "hogehoge-user@ipaddr:/var/www/hogehoge/",
   exclude={"/除外フォルダ/","/除外フォルダ/"},
   rsync = {
      archive = true
   },
}

lsyncdをスタートし、起動時に自動起動するように設定します。

/etc/init.d/lsyncd start
chkconfig lsyncd --on


注意

  • 同期先Serverにおいて、同期先のフォルダがSSHしてくるユーザー(この場合だとhogehoge-user)が所有しているフォルダになっていないと同期できない(書き込み、削除ができないため)
  • SSHで通信するためPort22開けておかないと書き込みできない
  • ユーザーはSSHで作成したユーザーを使用する。
  • 除外設定を書く際、途中で改行後の空白とか入るとだめ。

http://www.shift-the-oracle.com/linux/utility/lsyncd-local.html
http://qiita.com/bezeklik/items/22e791df7187958d76c1
http://dev.blog.fairway.ne.jp/%E3%80%90%E5%82%99%E5%BF%98%E9%8C%B2%E3%80%91lsyncd%E3%81%AE%E4%BD%BF%E3%81%84%E6%96%B9-ssh%E7%B7%A8/

3
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
6