rsync同步文件
負責發起rsync同步操作的客戶機稱為發起端,而負責響應來自客戶機的為同步源。再同步過程中,同步源負責提供文檔的原始位置,而發起端對該位置具有讀取權限,最後同步到本地
系統:centos7.5
##註釋
#systemctl stop firewalld --關閉防火墻
1.
#yum -y install rsync
2.
#useradd -s /sbin/nologin -M rsync
#id rsync
3.
#vim /etc/rsyncd.conf
uid = rsync
gid = rsync
use chroot = yes
auth users = leshan
pid file = /var/run/rsyncd.pid
log file = /var/log/rsyncd.log
secrets file = /etc/rsyncpw
hosts allow = 10.41.104.0/24
#exclude = lost+found/
transfer logging = yes
max connections = 1
timeout = 900
ignore nonreadable = yes
[backup]
path = /root/backup
comment = backup test
read only = no
list = false
4.密碼文件
#echo "leshan:123" > /etc/rsyncpw
#cat /etc/rsyncpw
#chmod 600 /etc/rsyncpw
#ll /etc/rsyncpw
-rw------- 1 root root 11 8月 31 11:04 /etc/rsyncpw
5.啟動服務
#systemctl restart rsyncd.service ## 很多人用這個rsync --daemon
#netstat -ntlp | grep rsync
#lsof -i:873 ##rsync的端口為873
6.配置 rsync 客戶端(密碼)
#rsync -av [email protected]::backup /root/rsync
Password:
。。。。。。
5.1 免密
#echo "123" > /etc/rsyncpw ##只要密碼就行,密碼文件放在哪裏都行
#cat /etc/rsyncpw
123
#chmod 600 /etc/rsyncpw
#rsync -avz --delete --password-file=/etc/rsyncpw [email protected]::backup /root/rsync
##這樣就不用輸入密碼,用crontab自動備份很是方便;
#rsync -v 10.41.104.5:: ##查看rsync服務器同步路徑名
rsync同步文件