0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

amazon linux2023で複数ディレクトリで、双方向同期をする方法

Posted at

概要

諸事情で急遽同期設定の検証を行うことになりました。
(同期設定すらしたことなかったのでかなりしんどかったです。)

手順を忘れないために書き残します。
今回は、EC2でサーバーを2つ用意しこの2つで同期をします。

前提条件

  • lsyncdインストール済

利用するツール

①lsyncd

  • 指定したディレクトリの監視を行う、変更が発生した際rsyncを動かす

②rsync

  • 設定されたサーバーに対し、同期を行う

③amazon linux2023

  • AWSが提供しているLinux

検証に利用するサーバー情報

web01

  • プライベートIP 10.0.2.11

web02

  • プライベートIP 10.0.2.22

同期させるディレクトリ

  • /var/www/test1
  • /var/www/test2

同期設定を行う際、プライベートIPを利用するのでIPに注意すること

手順

rsync.confに以下を追記する

uid = root
gid = root
read only = no
log file = /var/log/rsync/rsyncd.log
pid file = /var/log/rsync/rsyncd.pid
port = 873
 
[var-www-test1]
path = /var/www/test1
hosts allow = 10.0.2.22
read only = false
 
[var-www-test2]
path = /var/www/test2
hosts allow = 10.0.2.22
read only = false

lsyncd.confに以下を記載する

settings {
    logfile    = "/var/log/lsyncd/lsyncd.log",
    statusFile = "/var/log/lsyncd/lsyncd.status",
    statusInterval = 1,
}
 
sync {
    default.rsync,
    source = "/var/www/test1",
    target = "10.0.2.22::var-www-test1",
    init = false,
    rsync = {
        archive = true,
        links = true,
        update = true,
        verbose = false
    }
}
 
sync {
    default.rsync,
    source = "/var/www/test2",
    target = "10.0.2.22::var-www-test2",
    init = false,
    rsync = {
        archive = true,
        links = true,
        update = true,
        verbose = false
    }
}

上記にはweb01側のファイルになります。
web02側にはweb01のIPにした内容を記載してください。

ログ用のディレクトリとファイルを作成する

mkdir /var/log/lsyncd
touch /var/log/lsyncd/lsyncd.log
touch /var/log/lsyncd/lsyncd.status

同期するディレクトリの作成

mkdir /var/www/test1
mkdir /var/www/test2
  • この状態で、lsyncdをリスタートする

まとめ

これで同期するようになりました。
初めて同期設定をしたので、最初わけがわからず困惑しました。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?