使用 rsync 在两台 Centos 服务器间同步多个文件夹,并配置定时任务,实现自动同步。
环境
主服务器:10.0.204.75
备份服务器:10.0.204.64
主服务器和备份服务器安装 rsync
软件:
1 | yum -y install rsync |
服务端配置
在主服务器 10.0.204.75
上进行服务器端的配置,rsync
服务端安装完成之后是没有生成 rsync.conf
文件的,需要手动在 /etc
目录下创建 rsyncd.conf
配置文件。
1 | vim /etc/rsyncd.conf |
服务端 rsyncd.conf
配置文件示例:
1 | # global setting |
配置同步的用户名和密码:
1 | # touch /etc/rsyncd.secrets |
启动 rsync
,并设置为开机启动:
1 | # /usr/bin/rsync --daemon |
客户端配置
在备份服务器 10.0.204.64
上生成与服务端对应密码配置文件,注意这里只需要服务器 rsyncd.secrets
中的密码。
1 | # touch /etc/rsyncd.secrets |
在备份服务器端执行同步命令:
1 |
|
建立定时任务:
1 | # crontab -e |