Installation Environment
Backup server: CentOS7, IP: 192.168.1.100
Backup Client: CentOS7, IP: 192.168.1.200
Rsync server-side service deployment
1, installation package
# yum –y install rsync
2, create a server configuration file
# vim /etc/rsyncd.conf uid = rsync gid = rsync use chroot = no max connections = 2000 timeout = 600 ignore errors = yes pid file = /var/run/rsyncd.pid log file = /var/log/rsyncd.log lock file = /var/run/rsyncd.lock [backup] path = /backup/data #服务器端的存储目录 read only = no write only = no hosts allow = 192.168.0.0/16 hosts deny = * list = false auth users = server1-200 secrets file = /etc/rsync.password
3. Create a user name rsync
# useradd -M -s /sbin/nologin rsync
4. Create a backup directory, modify directory permissions
# mkdir /backup
# chown -R rsync /backup
5, create a password file, and modify permissions
Echo # " server1-200 : 123456"> /etc/rsync.password # Note: server1-200 user name, password is 123456
# chmod 600 /etc/rsync.password
6, start the service
# systemctl start rsyncd
Note: After starting the service opens tcp: 873 port
Client Configuration inotify
1, installation package
# yum –y install rsync
2, compile and install inotify
1 , source package download the inotify -tools- 3.14 . The tar .gz 2 , decompression: # the tar zxf the inotify-Tools- 3.14 . The tar .gz . 3 , compiler installation (requires GCC) # CD the inotify -tools- 3.14 . # / Configure = --prefix / usr / local / the inotify-Tools- 3.14 # the make & the make the install . 4 , create a soft link # LN -s / usr / local / Tools- the inotify- 3.14 / / usr / local / inotify- Tools . 5 , modified environment variables # echo 'PATH=/usr/local/inotify-tools/bin:$PATH' > /etc/profile.d/inotify.sh # source /etc/profile.d/inotify.sh
3, automatic client detection script
Vim /script/backup.sh # ################################## #! / Bin / bash SRC = '/ Data /' # client needs to back up the original path DEST = ' server1 -200 @ :: 192.168.1.100 backup ' # server1-200 backup server to the location is the user name, backup is a module configuration file to the server name inotifywait -mrq --timefmt '% Y-% m- % d% H:% M' --format '% T% w% f' -e create, delete, moved_to, close_write, attrib $ {SRC} | while the DIR the FILE DATE the TIME Read; do FILEPATH the DIR = $ {$}} {the FILE the rsync --delete -AZ---password = File / etc / rsync.password $ $ the SRC DEST && echo "At the TIME $ {$ {ON} } DATE, File $ FILEPATH WAS backuped up Via rsync ">> /var/log/changelist.log DONE
4, start the service script
# chmod +x /script/backup.sh
Nohup /script/backup.sh & #> / dev / null & # into the background