Linux - LAMP + DNS + NFS + RSYNC
在前面实验已经做了关于LAMP + DNS + NFS,现在在此基础上再做NFS备份机制
1> 在NFS主机配置基于rsync daemon 实现 sersync
323 wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/sersync/sersync2.5.4_64bit_binary_stable_final.tar.gz 324 tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz 325 cp -a GNU-Linux-x86 /usr/local/sersync 326 echo 'PATH=/usr/local/sersync:$PATH' > /etc/profile.d/sersync.sh 327 source /etc/profile.d/sersync.sh 329 cp /usr/local/sersync/confxml.xml{,.bak} 330 vim /usr/local/sersync/confxml.xml (高亮部分重点观察) <inotify> <delete start="true"/> <createFolder start="true"/> <createFile start="false"/> <closeWrite start="true"/> <moveFrom start="true"/> <moveTo start="true"/> <attrib start="true"/> <modify start="false"/> </inotify> <sersync> <localpath watch="/data/wordpress/wp-content"> <remote ip="10.0.0.10" name="backup/"/>
<rsync>
<commonParams params="-artuz"/>
<auth start="true" users="rsyncuser" passwordfile="/etc/rsync.pas"/>
[23:50:23 root@nfs wp-content]#cat /etc/rsync.pas 123456
# chmon 600 防止其他用户看到密码 [23:50:26 root@nfs wp-content]#ll -a /etc/rsync.pas -rw------- 1 root root 7 Jul 5 22:36 /etc/rsync.pas
2> 备份主机配置
[23:20:59 root@centos8 ~]#yum -y install rsync-daemon [23:44:52 root@centos8 backup]#cat /etc/rsyncd.conf # /etc/rsyncd: configuration file for rsync daemon mode # See rsyncd.conf man page for more options. # configuration example: # uid = nobody # gid = nobody # use chroot = yes # max connections = 4 # pid file = /var/run/rsyncd.pid # exclude = lost+found/ # transfer logging = yes # timeout = 900 # ignore nonreadable = yes # dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2 # [ftp] # path = /home/ftp # comment = ftp export area # uid = root gid = root max connections = 0 ignore errors exclude = lost+found/ log file = /var/log/rsyncd.log pid file = /var/run/rsyncd.pid lock file = /var/run/rsyncd.lock reverse lookup = no [backup] -> 这里即上面NFS主机xml配置文件remote的name path = /data/backup/ ->真实路径 comment = backup dir read only = no auth users = rsyncuser -> 访问者 secrets file = /etc/rsync.pas ->访问密码
[23:53:45 root@centos8 backup]#cat /etc/rsync.pas
rsyncuser:123456
[23:55:36 root@centos8 backup]#ll -a /etc/rsync.pas
-rw------- 1 root root 17 Jul 5 23:42 /etc/rsync.pas
[23:30:03 root@centos8 ~]#systemctl enable --now rsyncd.service
Created symlink /etc/systemd/system/multi-user.target.wants/rsyncd.service → /usr/lib/systemd/system/rsyncd.service.
[23:43:06 root@centos8 backup]#systemctl restart rsyncd
[23:43:19 root@centos8 backup]#ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 5 0.0.0.0:873 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 5 [::]:873 [::]:*
LISTEN 0 128 [::]:22 [::]:*
开始测试
[23:46:55 root@nfs wp-content]#sersync2 -dro /usr/local/sersync/confxml.xml set the system param execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events parse the command param option: -d run as a daemon option: -r rsync all the local files to the remote servers before the sersync work option: -o config xml name: /usr/local/sersync/confxml.xml daemon thread num: 10 parse xml config file host ip : localhost host port: 8008 daemon start,sersync run behind the console use rsync password-file : user is rsyncuser passwordfile is /etc/rsync.pas config xml parse success please set /etc/rsyncd.conf max connections=0 Manually sersync working thread 12 = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads) Max threads numbers is: 22 = 12(Thread pool nums) + 10(Sub threads) please according your cpu ,use -n param to adjust the cpu rate ------------------------------------------ rsync the directory recursivly to the remote servers once working please wait... execute command: cd /data/wordpress/wp-content && rsync -artuz -R --delete ./ rsyncuser@10.0.0.10::backup/ --password-file=/etc/rsync.pas >/dev/null 2>&1 run the sersync: watch path is: /data/wordpress/wp-content [23:47:13 root@nfs wp-content]#touch 10.txt [23:47:20 root@nfs wp-content]# [23:47:20 root@nfs wp-content]#touch 11.txt [23:58:29 root@nfs wp-content]#ll /data/wordpress/wp-content/ total 8 -rw-r--r-- 1 root root 0 Jul 5 23:47 10.txt -rw-r--r-- 1 root root 0 Jul 5 23:47 11.txt -rw-r--r-- 1 root root 0 Jul 5 22:27 1.txt -rw-r--r-- 1 root root 0 Jul 5 22:30 3.txt -rw-r--r-- 1 root root 28 Jan 9 2012 index.php drwxr-xr-x 4 root root 4096 Jun 15 21:00 languages drwxr-xr-x 3 root root 55 Jun 15 21:00 plugins -rw-r--r-- 1 root root 0 Jul 5 22:37 test.txt drwxr-xr-x 5 root root 88 Jun 15 21:00 themes === 备份机 Every 0.5s: ls -l /data/backup/ centos8.3: Mon Jul 5 23:59:33 2021 total 12 -rw-r--r-- 1 root root 0 Jul 5 23:47 10.txt -rw-r--r-- 1 root root 0 Jul 5 23:47 11.txt -rw-r--r-- 1 root root 0 Jul 5 23:32 1.txt -rw-r--r-- 1 root root 0 Jul 5 22:30 3.txt -rw-r--r-- 1 root root 28 Jan 9 2012 index.php drwxr-xr-x 4 root root 4096 Jun 15 21:00 languages drwxr-xr-x 3 root root 55 Jun 15 21:00 plugins -rw-r--r-- 1 root root 0 Jul 5 22:37 test.txt drwxr-xr-x 5 root root 88 Jun 15 21:00 themes

浙公网安备 33010602011771号