安裝軟件:linux
yum -y install rsync
建立需同步的目錄:vim
mkdir -p /data
編輯配置文件:vim /etc/rsyncd.conf服務器
motd file = /etc/rsyncd.motd transfer logging = yes log file = /var/log/rsyncd.log #日誌存放路徑 port = 873 #端口號 address = 192.168.0.37 #IP地址 uid = root #使用的用戶名 gid = root #使用的密碼 use chroot = no read only = no max connections = 10 [common] comment = rsync lee path = /data ignore errors auth users = simops secrets file = /etc/rsyncd.secrets hosts allow = 192.168.0.0/255.255.255.0 #容許訪問的地址段 hosts deny = * list = false UID = 0 GID = 0
建立用戶密碼:tcp
echo "simops:123456" > /etc/rsyncd.secrets chmod 600 /etc/rsyncd.secrets
建立提示信息文件:ui
echo "rsync simops" > /etc/rsyncd.motd
配置防火牆規則和關閉SElinux:日誌
iptables -I INPUT -p tcp --dport 873 -j ACCEPT setenforce 0 #臨時關閉SElinux
啓動服務:code
rsync --daemon echo "rsync --daemon" >> /etc/rc.local
安裝軟件:server
yum -y install rsync
建立需同步的目錄:ip
mkdir -p /data
建立密碼文件(免輸入密碼):rem
echo "123456" > /root/passwd chmod 600 /root/passwd
拉取:
rsync -avz --password-file=/root/passwd simops@192.168.0.37::common /data/
推送
rsync -avz --password-file=/root/passwd /data simops@192.168.0.37::common
一、執行推送命令以後報錯
rsync -avz --password-file=/root/passwd lee@192.168.0.37::common /home/lee/rsync/ rsync lee @ERROR: invalid uid root #使用的用戶名 rsync error: error starting client-server protocol (code 5) at main.c(1648) [Receiver=3.1.2]
解決方案在rsyncd.conf文件中添加下面兩行便可解決問題
UID = 0 GID = 0
二、服務器端同步目錄沒有權限
rsync -avz --password-file=/root/passwd simops@192.168.0.37::common /home/lee/rsync/ rsync lee @ERROR: chdir failed rsync error: error starting client-server protocol (code 5) at main.c(1648) [Receiver=3.1.2]
解決方案:服務器端同步目錄沒有權限,cwrsync默認用戶是Svcwrsync。爲同步目錄添加用戶Svcwrsync權限
三、沒有關閉selinux
rsync -avz --password-file=/root/passwd simops@192.168.0.37::common /data/ rsync lee receiving incremental file list rsync: opendir "." (in common) failed: Permission denied (13) sent 20 bytes received 108 bytes 256.00 bytes/sec total size is 0 speedup is 0.00 rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1650) [generator=3.1.2]
這個問題看似已經同步但是去查看的時候沒有同步過來 細細的檢查了一下是selinux問題,關閉以後就能夠了