首先准备两台centos服务器分别是服务器A和服务器B,最终实现效果是将A服务器的文件同步到服务器B上。
开始安装
下面是两台服务器共同的操作
首先打开防火墙的873端口,或直接关闭防火前:service iptables stop
安装rsync工具
yum install rsync
配置/etc/rsyncd.conf文件文件内容如下:(注意点:hosts allow: 192.168.1.2 这个ip要生成当前主机的真实ip)
- # /etc/rsyncd: configuration file for rsync daemon mode
- # See rsyncd.conf man page for more options.
- # configuration example:
- uid = 0
- gid = 0
- #use chroot = yes
- #list = yes
- #address = 192.161.1.1
- max connections = 10
- pid file = /var/run/rsyncd.pid
- log file = /var/log/rsyncd.log
- # exclude = lost+found/
- # transfer logging = yes
- # timeout = 900
- # ignore nonreadable = yes
- # dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2
- [data]
- path=/www/data/
- transfer logging = yes
- ignore errors
- read only = no
- list = no
- hosts allow = 192.168.1.1,192.168.1.2
- auth users = test
- secrets file = /etc/rsync.password
- # [ftp]
- # path = /home/ftp
- # comment = ftp export area
启动rsync服务
rsync --daemon
查看服务是否启动,rsync的默认端口是873
netstat -lnt
首先我们来设置好服务器B:
这里是创建rsync的password文件,内容为用户名:密码,为了安全起见,同时更改下文件权限:
跟着我们来设置好服务器A:
这里仅仅只需要密码,不需要用户了,免得要同步时还要手动互动
此时就可以在服务器A上面创建一个sh脚本来来执行同步了,也可以直接用此命令执行同步,写成sh脚本也只是为了加入定时任务