install
Server side
Install software:
yum -y install rsync
To create a directory to synchronize:
mkdir -p /data
Edit the configuration file: vim /etc/rsyncd.conf
motd file = /etc/rsyncd.motd transfer logging = yes log file = /var/log/rsyncd.log #Log storage path port = 873 #Port number address = 192.168.0.37 #IP address uid = root #User name used gid = root #Password used 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 #Allowed address segments hosts deny = * list = false UID = 0 GID = 0
Create user password:
echo "simops:123456" > /etc/rsyncd.secrets chmod 600 /etc/rsyncd.secrets
To create a prompt file:
echo "rsync simops" > /etc/rsyncd.motd
To configure firewall rules and turn off SElinux:
iptables -I INPUT -p tcp --dport 873 -j ACCEPT setenforce 0 #Temporarily shut down SElinux
Start service:
rsync --daemon echo "rsync --daemon" >> /etc/rc.local
II. Client (192.168.0.17):
Install software:
yum -y install rsync
To create a directory to synchronize:
mkdir -p /data
Create password file (password free):
echo "123456" > /root/passwd chmod 600 /root/passwd
Pull:
rsync -avz --password-file=/root/passwd simops@192.168.0.37::common /data/
Push
rsync -avz --password-file=/root/passwd /data simops@192.168.0.37::common
Encounter problems
1. Error is reported after the push command is executed
rsync -avz --password-file=/root/passwd lee@192.168.0.37::common /home/lee/rsync/ rsync lee @ERROR: invalid uid root #User name used rsync error: error starting client-server protocol (code 5) at main.c(1648) [Receiver=3.1.2]
Solution add the following two lines to the rsyncd.conf file to solve the problem
UID = 0 GID = 0
2. The server has no permission to synchronize the directory
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]
Solution: the server-side synchronization directory does not have permission. The default user of cwrsync is Svcwrsync. Add user Svcwrsync permission for synchronization directory
3. selinux is not closed
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]
This problem seems to have been synced, but it was not synced when I went to check it
Check the selinux problem in detail, and close it