rsync 服务标准配置(将 / home/coremail 目录同步至备机的 / tmp/123 目录下)
一, 服务端 / 数据源
开启 rsync 服务
1, 确保系统内安装了 xinetd 服务
2, 修改配置, 启动 rsync 服务
VIM /etc/xinetd.d/rsync
将
disable=yes
修改为
disable=no
保存退出
重启 xinetd
service xinetd restart
3, 确认服务在监听
- [[email protected] coremail]# netstat -anop |grep 873
- tcp 0 0 :::873 :::* LISTEN 22406/xinetd off (0.00/0/0)
4, 添加 /etc/rsyncd.conf 配置文件
- [[email protected] coremail]# cat /etc/rsyncd.conf
- read only = yes
- uid = coremail
- gid = coremail
- max connections = 5
- hosts allow = 192.168.213.129
- use chroot = no
- log file = /var/log/rsyncd.log
- pid file = /var/run/rsyncd.pid
- [data]
- path = /home/coremail/
- auth users = test
- secrets file =/etc/rsyncd.secrets
- [[email protected] coremail]# ll /etc/rsyncd.conf
-rw-r--r-- 1 root root 270 3 月 25 18:49 /etc/rsyncd.conf
[[email protected] coremail]#
以上配置定义了要同步的数据目录, 以及 rsync 中的虚拟同步账号 test, test 的密码文件路径.
hosts allow 为允许连接的客户端 ip
5, 添加账号密码文件 / etc/rsyncd.secrets
- [[email protected] coremail]# cat /etc/rsyncd.secrets
- test:12345
- [[email protected] coremail]# ll /etc/rsyncd.secrets
-rw------- 1 root root 11 3 月 25 16:52 /etc/rsyncd.secrets
[[email protected] coremail]#
/etc/rsyncd.secrets 的权限必须是 600, test 的密码是 12345
二, 客户端配置
1, 客户端需要将服务端的虚拟账号 test 密码配置到本地
- [email protected] var]#
- [[email protected] var]# cat /etc/rsyncd.secrets
- 12345
- [[email protected] var]#
- [[email protected] var]# ll /etc/rsyncd.secrets
-rw------- 1 root root 6 3 月 25 16:59 /etc/rsyncd.secrets
[[email protected] var]#
/etc/rsyncd.secrets 的权限必须是 600
2, 执行命令同步
rsync -av --delete --password-file=/etc/rsyncd.secrets [email protected]::data /tmp/123
获取本地的密码文件, 来进行同步, 将服务端的 [data] 下配置的目录同步到本地的 / tmp/123 目录下
rsync -av --delete --password-file=/etc/rsyncd.secrets --exclude=var/backup/ [email protected]::data /tmp/123
同步整个数据目录, 排除掉 / home/coremail/var/backup, 配置中的 var/backup / 是一个相对路径, 取决于 [data] 下的配置路径
3, 设置计划周期即可实现
来源: http://www.bubuko.com/infodetail-3156772.html