{"id":7762,"date":"2018-10-08T13:16:06","date_gmt":"2018-10-08T05:16:06","guid":{"rendered":"http:\/\/rmohan.com\/?p=7762"},"modified":"2018-10-08T13:16:06","modified_gmt":"2018-10-08T05:16:06","slug":"centos-7-deploys-rsync-backup-server","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=7762","title":{"rendered":"CentOS 7 deploys rsync backup server"},"content":{"rendered":"<p>1.1 rsync (official address http:\/\/wwww.samba.org\/ftp\/rsync\/rsync.html)<\/p>\n<p>A remote data synchronization tool that quickly synchronizes files between multiple hosts over a LAN\/WAN. Rsync uses the so-called &#8220;rsync algorithm&#8221; to synchronize files between two local and remote hosts. This algorithm only transfers different parts of two files, rather than transmitting them all at once, so the speed is quite fast.<\/p>\n<p>1.2rsync backup mode<\/p>\n<p>1) Local data backup method<\/p>\n<p>Rsync parameter The data to be backed up where the backup data is saved<\/p>\n<p>2) Remote backup mode<\/p>\n<p>Pull:rsync [OPTION&#8230;] [USER@]HOST:SRC&#8230; [DEST]<br \/>\nWhat is the rsync parameter to pull data from the corresponding host to pull data to save the local path<br \/>\nPush:rsync [OPTION&#8230;] SRC &#8230; [USER@]HOST:DEST<br \/>\nrsync where the local data is pushed by the local host data<\/p>\n<p>3) Daemon process<\/p>\n<p>Pull:rsync [OPTION&#8230;] [USER@]HOST::SRC&#8230; [DEST]<br \/>\nrsync parameter authenticates the user to pull data from the corresponding host. Pull data to save the local path<br \/>\nPush:rsync [OPTION&#8230;] SRC &#8230; [USER@]HOST::DEST<br \/>\nrsync parameter authenticates the location where the user will push the local host data for push data<\/p>\n<p>2. Environmental preparation<\/p>\n<p>[root@backup ~]# cat \/etc\/RedHat-release<br \/>\nCentOS Linux release 7.2.1511 (Core)<br \/>\n[root@backup ~]# uname -r<br \/>\n3.10.0-327.el7.x86_64<br \/>\n[root@backup ~]# getenforce<br \/>\nDisabled<br \/>\n[root@backup ~]# systemctl status firewalld.service<br \/>\n? firewalld.service &#8211; firewalld &#8211; dynamic firewall daemon<br \/>\nLoaded: loaded (\/usr\/lib\/systemd\/system\/firewalld.service; disabled; vendor preset: enabled)<br \/>\nActive: inactive (dead)<br \/>\n[root@backup ~]# ifconfig<br \/>\neth0: flags=4163&lt;UP,BROADCAST,RUNNING,MULTICAST&gt; mtu 1500<br \/>\ninet 10.0.0.41 netmask 255.255.255.0 broadcast 10.0.0.255<br \/>\ninet6 fe80::20c:29ff:fe40:1a4e prefixlen 64 scopeid 0x20&lt;link&gt;<br \/>\nether 00:0c:29:40:1a:4e txqueuelen 1000 (Ethernet)<br \/>\nRX packets 1607 bytes 355312 (346.9 KiB)<br \/>\nRX errors 0 dropped 0 overruns 0 frame 0<br \/>\nTX packets 358 bytes 47574 (46.4 KiB)<br \/>\nTX errors 0 dropped 0 overruns 0 carrier 0 collisions 0<br \/>\neth1: flags=4163&lt;UP,BROADCAST,RUNNING,MULTICAST&gt; mtu 1500<br \/>\ninet 172.16.1.41 netmask 255.255.255.0 broadcast 172.16.1.255<br \/>\ninet6 fe80::20c:29ff:fe40:1a58 prefixlen 64 scopeid 0x20&lt;link&gt;<br \/>\nether 00:0c:29:40:1a:58 txqueuelen 1000 (Ethernet)<br \/>\nRX packets 0 bytes 0 (0.0 B)<br \/>\nRX errors 0 dropped 0 overruns 0 frame 0<br \/>\nTX packets 23 bytes 1698 (1.6 KiB)<br \/>\nTX errors 0 dropped 0 overruns 0 carrier 0 collisions 0<br \/>\nlo: flags=73&lt;UP,LOOPBACK,RUNNING&gt; mtu 65536<br \/>\ninet 127.0.0.1 netmask 255.0.0.0<br \/>\ninet6 ::1 prefixlen 128 scopeid 0x10&lt;host&gt;<br \/>\nloop txqueuelen 0 (Local Loopback)<br \/>\nRX packets 0 bytes 0 (0.0 B)<br \/>\nRX errors 0 dropped 0 overruns 0 frame 0<br \/>\nTX packets 0 bytes 0 (0.0 B)<br \/>\nTX errors 0 dropped 0 overruns 0 carrier 0 collisions 03.??rsync???????<\/p>\n<p>3.1 Check if rsync is installed<\/p>\n<p>[root@backup ~]# rpm -qa rsync<\/p>\n<p>rsync-3.0.9-17.el7.x86_64<\/p>\n<p>3.2 Writing rsync configuration files<\/p>\n<p>[root@backup ~]# cat \/etc\/rsyncd.conf<br \/>\n#rsync_config<br \/>\n#created by fengyu 2018-3-16<br \/>\nuid = rsync Operator<br \/>\ngid = rsync User group<br \/>\nuse chroot = no Related security<br \/>\nmax connections = 200 Maximum number of connections<br \/>\ntimeout = 300 Timeout<br \/>\npid file = \/var\/run\/rsyncd.pid The process number file corresponding to the process<br \/>\nlock file = \/var\/run\/rsyncd.log lock file<br \/>\nlog file = \/var\/log\/rsyncd.log log file<br \/>\n[backup] module Name<br \/>\npath = \/backup module location<br \/>\nignore errors ignore error program<br \/>\nread only = false read only<br \/>\nlist = false list of<br \/>\nhosts allowed = 172.16.1.01\/24 network segment allowed accesses<br \/>\ndeny = 0.0.0.0\/32 network forbidden to access segment<br \/>\nAuth users = rsync_backup User that does not exist, only used for authentication<br \/>\nsecrets file = \/etc\/rsync.password There is no key file when the user authenticates<\/p>\n<p>3.3 Create an administrative user<\/p>\n<p>[root@backup ~]# useradd -s \/sbin\/nologin -M rsync<\/p>\n<p>3.4 Creating an Authentication User Password File<\/p>\n<p>[root@backup ~]# echo &#8220;rsync_backup:123456&#8221; &gt; \/etc\/rsync.password<br \/>\n[root@backup ~]# chmod 600 \/etc\/rsync.password<\/p>\n<p>3.5 Create a backup directory<\/p>\n<p>[root@backup ~]# mkdir \/backup<br \/>\n[root@backup ~]# chown -R rsync.rsync \/backup\/<\/p>\n<p>3.6 start daemon<\/p>\n<p>[root@backup ~]# rsync &#8211;daemon<br \/>\n[root@backup ~]# netstat -lntup | grep rsync<br \/>\ntcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 3286\/rsync<br \/>\ntcp6 0 0 :::873 :::* LISTEN 3286\/rsync<\/p>\n<p>4. Configure the rsync daemon client (here, the NFS storage server is used as an example. In the work, the rsync server and the NFS server are matched with each other)<\/p>\n<p>4.1 Creating a Password Authentication File<\/p>\n<p>[root@nfs01 ~]# echo &#8220;123456&#8221; &gt; \/etc\/rsync.password<\/p>\n<p>[root@nfs01 ~]# chmod 600 \/etc\/rsync.password<\/p>\n<p>4.2 Writing real-time monitoring push scripts<\/p>\n<p>[root@nfs01 backup]# cat \/server\/scripts\/inotify.sh<br \/>\n#!bin\/bash<br \/>\ninotifywait -mrq &#8211;format &#8220;%w%f&#8221; -e create,close_write,delete,moved_to \/data\/|\\<br \/>\nwhile read fy<br \/>\ndo<br \/>\nrsync -az \/data\/ &#8211;delete rsync_backup@172.16.1.41::backup &#8211;password-file=\/etc\/rsync.password<br \/>\ndone<\/p>\n<p>4.3 Put the script execution command into the \/etc\/rc.local directory (under the CentOS 7 system, you need to execute the permissions in the \/etc\/rc.local directory)<\/p>\n<p>[root@nfs01 ~]# echo &#8220;\/usr\/bin\/sh \/server\/scripts\/inotify.sh&#8221; &gt;&gt; \/etc\/rc.local<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1.1 rsync (official address http:\/\/wwww.samba.org\/ftp\/rsync\/rsync.html)<\/p>\n<p>A remote data synchronization tool that quickly synchronizes files between multiple hosts over a LAN\/WAN. Rsync uses the so-called &#8220;rsync algorithm&#8221; to synchronize files between two local and remote hosts. This algorithm only transfers different parts of two files, rather than transmitting them all at once, so the speed is [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7762"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7762"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7762\/revisions"}],"predecessor-version":[{"id":7763,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7762\/revisions\/7763"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7762"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7762"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7762"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}