Rsync architecture and rsync Architecture
1.1 rsync server configuration
1.1.1 view the server rsync version
1.1.2 after the rsync program is installed by default, the main configuration file of rsync is not automatically created and needs to be created manually. The main configuration file is "/etc/rsyncd. conf, create the file and insert the following content:
1 # Rsync server 2 # create by zhurui 18:15 2016-3-1 3 # rsyncd. conf start #4 uid = rsync 5 gid = rsync 6 use chroot = no 7 max connections = 2000 // client connection count 8 timeout = 600 // connection timeout 9 pid file =/var /run/rsyncd. pid // 10 lock file =/var/run/rsyncd. lock11 log file =/var/log/rsyncd. log12 ignore errors13 read only = false14 list = false15 hosts allow = 192.168.1.0/2416 hosts deny = 0.0.0.0/3217 auth users = rsync_backup // authorized remote connection user 18 secrets file =/etc/ rsync. password // 19 ############################## ################ 20 [backup] 21 comment = backup by zhurui 2016-3-122 path =/backup
1.1.2 start the service
1 [root @ backup ~] # Rsync -- daemon // start service 2 [root @ backup ~] # Ps-ef | grep rsync | grep-v grep // view rsync process 3 root 2764 1 0? 00:00:00 rsync -- daemon 4 [root @ backup ~] # Netstat-lntup | grep rsync // check whether the port corresponding to rsync is up. 5 tcp 0 0 0.0.0.0: 873 0.0.0.0: * LISTEN 2764/rsync 6 tcp 0 0 ::: 873 ::: * LISTEN 2764/rsync 7 [root @ backup ~] # Lsof-I: 873 8 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME 9 rsync 2764 root 3u IPv4 16218 0t0 TCP *: rsync (LISTEN) 10 rsync 2764 root 5u IPv6 16219 0t0 TCP *: rsync (LISTEN)
1.1.3 create virtual users supporting rsync
1 [root@backup ~]# useradd rsync -s /sbin/nologin 2 [root@backup ~]# id rsync3 uid=500(rsync) gid=500(rsync) groups=500(rsync)4 [root@backup ~]#
1.1.4 create the bakcup directory and change the directory user to rsync.
1 [root@backup ~]# mkdir /backup2 [root@backup ~]# ls -ld /backup/3 drwxr-xr-x. 2 root root 4096 Dec 2 14:48 /backup/4 [root@backup ~]# chown -R rsync /backup/5 [root@backup ~]# ls -ld /backup/ 6 drwxr-xr-x. 2 rsync root 4096 Dec 2 14:48 /backup/
1.1.5 configure the user name and password for client login, and change the File Permission for storing the password to 600
1 [root @ backup ~] # Echo "rsync_backup: zhurui">/etc/rsync. password // configure the client logon user and password 2 [root @ backup ~] # Cat/etc/rsync. password 3 rsync_backup: zhurui4 [root @ backup ~] # Ll/etc/rsync. password 5-rw-r --. 1 root 20 Dec 2/etc/rsync. password6 [root @ backup ~] # Chmod 600/etc/rsync. password // modify the/etc/rsync. password File to 600. Only root access is allowed. [root @ backup ~] # Ll/etc/rsync. password 8-rw -------. 1 root 20 Dec 2 :01/etc/rsync. password
1.1.6 Add "rsync -- daemon" to auto-start
1 [root@backup ~]# echo "rsync --daemon" >>/etc/rc.local
1.1.7 synchronization Security Optimization
1 [root @ backup ~] # Lsof-I: 873 // check whether port 873 is up 2 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME3 rsync 2764 root 3u IPv4 16218 0t0 TCP *: rsync (LISTEN) 4 rsync 2764 root 5u IPv6 16219 0t0 TCP *: rsync (LISTEN) 5 [root @ backup ~] # Pkill rsync // kill process 6 [root @ backup ~] # Lsof-I: 8737 [root @ backup ~] # Rsync -- daemon -- adress = 192.168.1.17 // bind the specified IP Address: 192.168.1.17 to provide service 8 [root @ backup ~] # Netstat-lntup | grep rsync9 tcp 0 0 192.168.1.17: 873 0.0.0.0: * LISTEN 3039/rsync
2.1 rsync client Configuration
2.1.1 create a password file
1 [root@lamp01 tmp]# echo "zhurui" >>/etc/rsync.password2 [root@lamp01 tmp]# cat /etc/rsync.password 3 zhurui4 [root@lamp01 tmp]# ll /etc/rsync.password 5 -rw-r--r--. 1 root root 7 Jan 31 03:49 /etc/rsync.password6 [root@lamp01 tmp]# chmod 600 /etc/rsync.password 7 [root@lamp01 tmp]# ll /etc/rsync.password 8 -rw-------. 1 root root 7 Jan 31 03:49 /etc/rsync.password
2.1.2 back up all files in the/tmp/directory to the/backup/directory
1 [root @ lamp01 tmp] # rsync-avz/tmp/rsync_backup@192.168.1.17: backup -- password-file =/etc/rsync. password // push backup 2 sending incremental file list 3. /4 a 5 B 6 c 7 d 8 e 9 f10 g11 h12 hosts13 i14 j15 k16 l17 m18 n19 o20 p21-q22 r23 s24 t25 u26 v27 w28 x29 y30 z31. ICE-unix/32 ssh-pAPHMU3586/33 ssh-pAPHMU3586/agent.358634 35 sent 1412 bytes encoded ed 535 bytes 299.54 bytes/sec36 total size is 193 speedup is 0.10
2.1.3 verify files under the server/backup/directory
1 [root@backup backup]# ll 2 total 8 3 -rw-r--r--. 1 rsync rsync 0 Dec 2 15:50 a 4 -rw-r--r--. 1 rsync rsync 0 Jan 30 2016 b 5 -rw-r--r--. 1 rsync rsync 0 Jan 30 2016 c 6 -rw-r--r--. 1 rsync rsync 0 Jan 30 2016 d 7 -rw-r--r--. 1 rsync rsync 0 Jan 30 2016 e 8 -rw-r--r--. 1 rsync rsync 0 Jan 30 2016 f 9 -rw-r--r--. 1 rsync rsync 0 Jan 30 2016 g10 -rw-r--r--. 1 rsync rsync 0 Jan 30 2016 h11 -rw-r--r--. 1 rsync rsync 193 Jan 30 2016 hosts12 -rw-r--r--. 1 rsync rsync 0 Jan 30 2016 i13 -rw-r--r--. 1 rsync rsync 0 Jan 30 2016 j14 -rw-r--r--. 1 rsync rsync 0 Jan 30 2016 k15 -rw-r--r--. 1 rsync rsync 0 Jan 30 2016 l16 -rw-r--r--. 1 rsync rsync 0 Jan 30 2016 m17 -rw-r--r--. 1 rsync rsync 0 Jan 30 2016 n18 -rw-r--r--. 1 rsync rsync 0 Jan 30 2016 o19 -rw-r--r--. 1 rsync rsync 0 Jan 30 2016 p20 -rw-r--r--. 1 rsync rsync 0 Jan 30 2016 q21 -rw-r--r--. 1 rsync rsync 0 Jan 30 2016 r22 -rw-r--r--. 1 rsync rsync 0 Jan 30 2016 s23 drwx------. 2 rsync rsync 4096 Jan 30 2016 ssh-pAPHMU358624 -rw-r--r--. 1 rsync rsync 0 Jan 30 2016 t25 -rw-r--r--. 1 rsync rsync 0 Jan 30 2016 u26 -rw-r--r--. 1 rsync rsync 0 Jan 30 2016 v27 -rw-r--r--. 1 rsync rsync 0 Jan 30 2016 w28 -rw-r--r--. 1 rsync rsync 0 Jan 30 2016 x29 -rw-r--r--. 1 rsync rsync 0 Jan 30 2016 y30 -rw-r--r--. 1 rsync rsync 0 Jan 30 2016 z