服务器列表
# 1 主
192.168.199.230
# 2 从
192.168.199.183
192.168.199.105
第一步、分别配置好SSH免登陆
参考:点这里
第二步、分别装好 rsync
yum -y install rsync
第三步、设置 2从 服务器的 rsync.conf
vim /etc/rsyncd.conf
rsyncd.conf 文件内容中原有内容全部注释,然后在文件中追加以下内容,记得替换其中 hosts allow 后面的IP地址。
# 全局信息
uid = root
gid = root
log file = /var/log/rsyncd.log
[wwwroot]
# 文件目录
path = /home/wwwroot
# 允许IP
hosts allow = 192.168.199.230 192.168.199.105
# 禁止IP,不包括允许IP
hosts deny = *
# 是否显示目录
list = true
# 是否只读
read only = false
第四步、开启 2从 服务器的 rsync 服务
/usr/bin/rsync --daemon
第五步、在 1主 服务器 上安装相关应用
yum -y install lua lua-devel
rpm -iUvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-9.noarch.rpm
yum -y install lsyncd
第六步、在 1主 服务器 上配置 lsyncd
vim /etc/lsyncd.conf
原有内容通过 -- 两个减号注释掉,settings 中是全局配置,servers 中是2从服务器的IP地址,随后通过一个for循环针对2从服务器配置rsync信息
-- 基本设置
settings{
statusFile = "/var/log/lsyncd/lsyncd.log",
statusInterval = 1
}
-- 服务器
servers = {
"192.168.199.183",
"192.168.199.105"
}
for _, server in ipairs(servers) do
sync{
default.rsyncssh,
source="/root/iguoji/",
host=server,
targetdir="/home/wwwroot/",
delay = 0,
rsync = {
binary = "/usr/bin/rsync",
compress = true,
archive = true,
verbose = true,
--rsh = "/usr/bin/shh -p 22 -o StrichHostKeyChecking=no"
}
}
end
第七步、开启 1主 服务器的 lsyncd 服务
systemctl start lsyncd.service
第八步、测试是否同步
在主服务器的 /root/iguoji/ 文件夹中创建文件1
touch 1
随后在两个从服务器的 /home/wwwroot/ 文件夹中查看变化
[root@localhost wwwroot]# la
总用量 0
drwxr-xr-x. 2 root root 97 7月 11 11:14 ./
-rw-r--r--. 1 root root 0 7月 11 10:57 9
-rw-r--r--. 1 root root 0 7月 11 10:57 10
-rw-r--r--. 1 root root 0 7月 11 10:55 8
-rw-r--r--. 1 root root 0 7月 11 10:55 7
-rw-r--r--. 1 root root 0 7月 11 10:55 6
-rw-r--r--. 1 root root 0 7月 11 10:55 5
-rw-r--r--. 1 root root 0 7月 11 10:54 4
-rw-r--r--. 1 root root 0 7月 11 10:53 3
-rw-r--r--. 1 root root 0 7月 11 10:52 2
-rw-r--r--. 1 root root 0 7月 11 10:45 1
drwxr-xr-x. 3 root root 21 7月 11 10:10 ../
作者:我来自塘湖
链接:https://www.jianshu.com/p/fa7d1bf28ef0
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。