很多时候,在我们管理多机器集群时,需要让成千上万台机器实现数据同步,如果采用人工维护,几乎是不可能的事情。幸运的是,我们有十分强大的工具,
lsyncd
和rsync
,接下来,就介绍下如何利用lsyncd和rsync实现文件的实时同步。
服务器
安装lsyncd
yum install -y lsync
配置lsyncd
默认安装配置文件地址是/etc/lsyncd.conf
settings {
logfile = "/var/log/lsyncd/lsyncd.log",
statusFile = "/var/log/lsyncd/lsyncd.status"
}
sync {
default.rsync,
source = "/test/git/shortUrl",
target = "root@10.129.31.72::share"
}
启动lsyncd
配置结束后,在命令行运行如下命令,即可完成lsync的启动。lsyncd -pidfile /var/run/lsyncd.pid /etc/lsyncd.conf
客户端
安装rsync
yum install -y rsync
配置rsync
默认安装配置文件地址是/etc/rsyncd.conf
uid = root
gid = root
use chroot = no
max connections = 4
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
[share]
path = /test/git/shortUrl
comment = My Share Documents
read only = false
hosts allow = 10.129.31.78
启动rsync
配置结束后,在命令行运行如下命令,即可完成rsync的启动。rsync --daemon
基本的介绍就到这里,大家赶快动手试下吧。