环境部署
源机:192.168.31.140
目标机:192.168.31.130
源机配置
基于rsync的lsyncd 自动同步,rsync的配置省略
安装lsyncd
rpm -ivh lsyncd-2.1.5-1.x86_64.rpm
配置文件:/usr/local/lsyncd/etc/lsyncd.conf
日志文件:/usr/local/lsyncd/logs/lsyncd.log
状态文件(由程序自动生成):/usr/local/lsyncd/logs/lsyncd.status
配置lsyncd
[root@baseos-1_192.168.31.140 ~]# vim /usr/local/lsyncd/etc/lsyncd.conf
settings {
logfile = "/usr/local/lsyncd/logs/lsyncd.log",
statusFile = "/usr/local/lsyncd/logs/lsyncd.status",
maxDelays = 100,
delay = 5,
exitcodes = {[0] = "ok", [1] = "again", [2] = "die"},
maxProcesses = 5,
statusInterval = 5
}
sync {
default.rsync,
source = "/tmp/src_src",
target = "sync_user@192.168.31.130::sync_data",
exclude = { ".*", "*.tmp", "*.bak" },
delete = true,
rsync = {
compress = false,
archive = true,
verbose = false,
timeout = 3600,
password_file = "/usr/local/lsyncd/etc/rsync1.pass"
}
}
sync {
default.rsync,
source = "/tmp/sync",
target = "sync_user2@192.168.31.130::data_backup",
exclude = { ".*", "*.tmp", "*.bak" },
delete = true,
rsync = {
compress = false,
archive = true,
verbose = false,
timeout = 3600,
password_file = "/usr/local/lsyncd/etc/rsync2.pass"
}
}
# 配置认证密码,要求密码权限为400,否则rsync无法正常同步。
[root@baseos-1_192.168.31.140 ~]# cat /usr/local/lsyncd/etc/rsync.pass
123456sync
[root@baseos-1_192.168.31.140 ~]# cat /usr/local/lsyncd/etc/rsync2.pass
654321sync
目标机配置
[root@baseos-2_192.168.31.130 ~]# vim /etc/rsyncd.conf
uid=root
gid=root
max connections=10
log file=/var/log/rsyncd.log
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsyncd.lock
[sync_data]
comment=backup data
path=/tmp/src_dist
read only=no
exclude=test
auth users=sync_user
secrets file=/etc/rsyncd.passwd
[data_backup]
comment=backup data
path=/tmp/sync
read only=no
auth users=sync_user2
secrets file=/etc/rsyncd.passwd
# 配置认证用户和密码
[root@baseos-2_192.168.31.130 ~]# vim /etc/rsyncd.passwd
sync_user:123456sync
sync_user2:654321sync
启动lsyncd服务
[root@baseos-1_192.168.31.140 ~]# /etc/init.d/lsyncd start
Starting lsyncd: [ OK ]
[root@baseos-1_192.168.31.140 ~]# cat /usr/local/lsyncd/logs/lsyncd.log
Tue Jun 27 14:09:09 2017 Normal: recursive startup rsync: /tmp/src_src/ -> sync_user@192.168.31.130::sync_data/ excluding
.*
*.tmp
*.bak
Tue Jun 27 14:09:09 2017 Normal: recursive startup rsync: /tmp/sync/ -> sync_user2@192.168.31.130::data_backup/ excluding
.*
*.tmp
*.bak
Tue Jun 27 14:09:09 2017 Normal: Startup of "/tmp/src_src/" finished.
cannot delete non-empty directory: frontends/php/local
cannot delete non-empty directory: frontends/php/local
cannot delete non-empty directory: frontends/php/include
cannot delete non-empty directory: frontends/php/include
cannot delete non-empty directory: frontends/php/conf
cannot delete non-empty directory: frontends/php/conf
cannot delete non-empty directory: frontends/php/app
cannot delete non-empty directory: frontends/php/app
cannot delete non-empty directory: frontends/php
cannot delete non-empty directory: frontends/php
cannot delete non-empty directory: frontends
Tue Jun 27 14:09:10 2017 Normal: Startup of "/tmp/sync/" finished.
Tue Jun 27 14:10:19 2017 Normal: Calling rsync with filter-list of new/modified files/dirs
/anaconda-ks.cfg
/
/install.log
/install.log.syslog
/ip_name_list.txt
/mysql_login
/name_list.txt
/nginx_reload
/nginx_start
/php_reload
/php_start
/redis6000.login
/redis6000.start
/redis6000.stop
/redis6001.login
/redis6001.start
/redis6001.stop
Tue Jun 27 14:10:20 2017 Normal: Finished a list after exitcode: 0
Tue Jun 27 14:20:09 2017 Normal: --- TERM signal, fading ---
Tue Jun 27 14:22:45 2017 Normal: recursive startup rsync: /tmp/src_src/ -> sync_user@192.168.31.130::sync_data/ excluding
.*
*.tmp
*.bak
Tue Jun 27 14:22:45 2017 Normal: recursive startup rsync: /tmp/sync/ -> sync_user2@192.168.31.130::data_backup/ excluding
.*
*.tmp
*.bak
Tue Jun 27 14:22:46 2017 Normal: Startup of "/tmp/sync/" finished.
Tue Jun 27 14:22:46 2017 Normal: Startup of "/tmp/src_src/" finished.