yum install -y keepalived
Profile on nfs01
[root@nfs01 ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs { router_id nfs01 } vrrp_script check_data { script "/server/scripts/data.sh" interval 2 weight 60 } vrrp_instance oldboy { state MASTER interface eth1 virtual_router_id 51 priority 90 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 172.16.1.3/16 dev eth1 label eth1:1 } track_script { check_data } } [root@nfs01 ~]# cat /server/scripts/data.sh #!/bin/bash # File Name: data.sh # Author: su-lemon # Blog: https://lemonsu9.github.io/ # Mail: 1510973908@qq.com # Created Time:Wed 19 Sep 2018 11:53:29 PM CST # Description: This is a test script nfs_info=$(ps -ef|grep -c nfs) if [ $nfs_info -ge 4 ] then echo "nfs is start~" exit 0 else echo "nfs is stop~" exit 1 fi echo 'net.ipv4.ip_nonlocal_bind = 1' >>/etc/sysctl.conf sysctl -p /etc/init.d/keepalived start
Profile on rsync
[root@backup ~]# cat /etc/keepalived/keepalived.conf ! Configuration File for keepalived global_defs { router_id backup } vrrp_instance oldboy { state BACKUP interface eth1 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 172.16.1.3/16 dev eth1 label eth1:1 } }
Add a data module to the / etc/rsyncd.conf configuration file of backup, and change the uid gid to www
[root@backup ~]# cat /etc/rsyncd.conf uid = www gid = www use chroot = no max connections = 20 timeout = 300 pid file = /var/run/rsyncd.pid lock file = /var/run/rsync.lock log file = /var/log/rsyncd.log ignore errors read only = false list = false hosts allow = 172.16.1.0/24 hosts deny = 0.0.0.0/32 auth users = rsync_backup secrets file = /etc/rsync.password [backup] comment = "backup dir by oldboy" path = /backup [data] path = /data
Configuration file for nfs service
nfs01 is the same as backup
[root@nfs01 ~]# cat /etc/exports #share /data by su-lemon for share at 20180918 /data/www 172.16.1.0/24(rw,sync,no_all_squash,root_squash,anonuid=666,anongid=666) /data/blog 172.16.1.0/24(rw,sync,no_all_squash,root_squash,anonuid=666,anongid=666) /data/bbs 172.16.1.0/24(rw,sync,no_all_squash,root_squash,anonuid=666,anongid=666) [root@backup ~]# ll /data total 12 drwxrwxrwx 2 www www 4096 Sep 20 00:17 bbs drwxrwxrwx 2 www www 4096 Sep 20 00:17 blog drwxrwxrwx 2 www www 4096 Sep 20 00:17 www [root@nfs01 ~]# ll /data total 12 drwxrwxrwx 2 www www 4096 Sep 19 13:18 bbs drwxrwxrwx 2 www www 4096 Sep 19 13:18 blog drwxrwxrwx 2 www www 4096 Sep 19 13:18 www data Directory permission 777 belongs to group and primary www
Set the service to start automatically
chkconfig nfs on chkconfig keepalived on
Mount the upload directory of the website on the web server
[root@web01 ~]# ll /tmp total 964 -rw-r--r-- 1 root root 962858 Sep 18 11:22 bak.sql drwxr-xr-x 21 root root 4096 Sep 20 08:38 DedeCMS_bak drwxr-xr-x 11 root root 4096 Sep 20 08:44 Discuz_bak drwxr-xr-x 3 root root 4096 Sep 18 10:20 pear drwxr-xr-x 3 root root 4096 Sep 20 08:39 wordpress_bak drwxrwxrwx 3 www www 4096 Sep 19 11:44 www -rw-------. 1 root root 0 Sep 17 20:44 yum.log
Migrate data out (same as web 01,02,03)
[root@web01 ~]# mv /application/nginx/html/www/uploads/* /tmp/DedeCMS_bak/ [root@web01 ~]# mv /application/nginx/html/blog/wp-content/uploads/* /tmp/wordpress_bak/ [root@web01 ~]# mv /application/nginx/html/bbs/upload/data/attachment/* /tmp/Discuz_bak/
Mount (same as web 01,02,03)
[root@web01 ~]# mount -t nfs 172.16.1.3:/data/www /application/nginx/html/www/uploads/data/ [root@web01 ~]# mount -t nfs 172.16.1.3:/data/bbs /application/nginx/html/bbs/upload/data/attachment/ [root@web01 ~]# mount -t nfs 172.16.1.3:/data/blog /application/nginx/html/blog/wp-content/uploads/ [root@web01 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda3 48G 3.8G 42G 9% / tmpfs 190M 0 190M 0% /dev/shm /dev/sda1 190M 35M 146M 19% /boot 172.16.1.3:/data/www 48G 1.5G 44G 4% /application/nginx-1.14/html/www/uploads/data 172.16.1.3:/data/bbs 48G 1.5G 44G 4% /application/nginx-1.14/html/bbs/upload/data/attachment 172.16.1.3:/data/blog 48G 1.5G 44G 4% /application/nginx-1.14/html/blog/wp-content/uploads
Move the data back (web01), but only the data on web01 needs to be moved back, web02 web03 does not need to move the data back
[root@web01 wordpress_bak]# cp -r /tmp/wordpress_bak/* /application/nginx/html/blog/wp-content/uploads/ [root@web01 wordpress_bak]# cp -r /tmp/Discuz_bak/* /application/nginx/html/bbs/upload/data/attachment/ [root@web01 wordpress_bak]# cp -r /tmp/DedeCMS_bak/* /application/nginx/html/www/uploads/data/