一、服務端(192.168.8.81):
- 安裝軟件: yum -y install rsync
- 創建需同步的目錄: mkdir -p /home/root/rsync
- 編輯配置文件:vim /etc/rsyncd.conf motd file = /etc/rsyncd.motd transfer logging = yes log file = /var/log/rsyncd.log port = 873 address = 192.168.8.81 uid = root gid = root use chroot = no read only = no max connections = 10 [common] comment = rsync lee path = /home/lee/rsync/ ignore errors auth users = lee secrets file = /etc/rsyncd.secrets hosts allow = 192.168.8.0/255.255.255.0 hosts deny = * list = false
- 創建用戶密碼: echo "root:123456" > /etc/rsyncd.secrets chmod 600 /etc/rsyncd.secrets
- 配置防火牆規則: iptables -I INPUT -p tcp --dport 873 -j ACCEPT
- 啓動服務:
rsync --daemon echo "rsync --daemon" >> /etc/rc.local
二、客戶端(192.168.8.82):
- 安裝軟件: yum -y install rsync
- 創建需同步的目錄: mkdir -p /home/root/rsync
- 創建密碼文件(免輸入密碼): echo "123456" > /root/passwd chmod 600 /root/passwd
- 拉取(在客戶端(192.168.8.82)): rsync -avz --password-file=/root/passwd [email protected]::common /home/root/rsync/
- 推送(在服務端(192.168.8.81)): rsync -avz --password-file=/root/passwd /home/root/rsync/ [email protected]::common
三、實現定時自動同步
創建一個需要定時執行的腳本文件,如:rsyncd.sh腳本:vi /etc/rsyncd.sh
(路徑自己設置的),在此腳本中添加如下內容
設置腳本執行的時間:crontab –e,添加如下內容