Due to the company's recent business requirements to build a set of services specific requirements such as:
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/80/14/wKiom1c2mXDAecrxAAEM4w1pCJ0525.png "title=" nb% Qz7d%%zfqv[{i) 5p6b (g.png "alt=" Wkiom1c2mxdaecrxaaem4w1pcj0525.png "/>
1. Basic Backup Requirements
known 3 server host names are a (WEB01),B (Backup) ,C (nfs01), respectively
Requirements : 0 points per night on the b Web server A a to package backup system configuration files, website program directory and visit
ask the log and push backup on server b b by means of the C rsync command (backup ideas can be first locally by date
package, and then push to the backup server b b ).
The specific requirements are as follows:
1) The backup directory for both Web server A and backup server B must be/backup.
2) The system configuration files to be backed up include, but are not limited to:
A. the configuration file for the scheduled task Service (/var/spool/cron/root).
B. Boot -up configuration file (/etc/rc.local).
C. directory of daily Scripts (/server/scripts).
D. firewall iptables configuration file (/etc/sysconfig/iptables).
E. What else do you need to back up when you think about it?
3) The WEB Server site Directory is assumed to be (/var/html/www).
4) Web server A Access log path assumed to be (/app/logs)
5) The Web server retains the packaged 7 days of backup data ( local retention cannot be more than 7 days, because too many hard drives are full )
6) back up server b B, keep all copies of the data for every Monday, and keep the other 6 6 months A copy of the data.
7) Backup server B on the backup data server to the IP for the directory to save the backup, the files backed up by the time name
Save.
Special note: In the work of the site is a website production environment of the whole network backup project a small simulation, very meaningful.
2, the entire backup logical structure of this project, such as:
Special Note:
1) The leadership at work is likely not to tell you how to do it, only to ask for, for example: Xiao Cui,WEB Server is very important,
Please back up your data on another server (regular backup).
2) Logical architecture diagram more unlikely to be the leader to draw for you, but you understand the meaning of the leader, and then you think back to the side
case, and finally, a blueprint you made before the implementation.
3, need to ensure that the backup data as complete as possible, on the backup server to check the backup data, the success of the backup and failure results
The information is sent to the system administrator's mailbox.
(iii) back end of the site cluster NFS shared storage setup and optimization solutions
1. Configure NFS services:
Requirements:
1) share/data/w_shared and /data/r_shared two file directories on NFS server C (NFS01), allowing NFS
Client read-only from a (WEB01),B (Backup) when a shared directory is mounted on a (WEB01), B (Backup),respectively
/data/r_shared, can write /data/w_shared.
2) mount point on NFS client A (WEB01) is/data/b_w(write),/data/b_r(read),
mount point on NFS client B (Backup) for/data/w_ your name in English (written),/data/r_ your name in English
(read).
3) create arbitrary files from NFS writable mount point directory on NFS client B (Backup) from NFS client A (WEB01)
You can delete this created file, or vice versa.
4) Question and answer: how do I optimize services for NFS ?
2, the entire backup logical structure of this project (red dashed part):
(iv) address the backend of the site cluster NFS shared storage single point for real-time data synchronization
1, real-time data synchronization requirements:
when users write data to NFS server C (nfs01) through the Web server , they are also copied to the backup server
B (Backup)
do a full network backup first doRsyncServiceService SideBackupBuild Command
Cat >/etc/rsyncd.conf <<eof
#Rsync Server
UID = rsync
GID = rsync
Use chroot = no
Max connections = 2000
Timeout = 600
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 = by Oldboy 28qi Liangye
Path =/backup
[Nfsbackup]
Path =/nfsbackup
Eof
Useradd-s/sbin/nologin-m rsync
Mkdir/backup
Mkdir/nfsbackup
Chown–r Rsync.rsync/nfsbackup
Chown-r Rsync.rsync/backup
echo "Rsync_backup:oldboy" >/etc/rsync.password
Chmod600/etc/rsync.password
Rsync--daemon
lsof-i:873
echo "/usr/bin/rsync--daemon" >>/etc/rc.local
Customer Service SideNFS Wed01Build Command
echo "Oldboy" >/etc/rsync.password
chmod 600/etc/rsync.password
Mkdir/backup
TOUCH/BACKUP/STU{1..5}
Rsync-avz/backup/[email Protected]::backup--password-file=/etc/rsync.password
Full Network backupWedClient side Script
CD/&&\
ip= ' Ifconfig eth1|awk-f "[:]+" ' Nr==2{print $4} '
mkdir/backup/$ip-P
Tar zcfh/backup/$ip/bak_$ (date+%f_%w). tar.gz var/www/html app/logs var/spool/cron/root etc/rc.local etc/sysconfig/ Iptables server/scripts &&\
find/backup/$ip-type f-name "*$ (date +%f_%w). tar.gz" |xargs md5sum >/backup/$ip/flag_$ (date+%f_%w). txt &&\
Rsync-av/backup/[email protected]::backup/--password-file=/etc/rsync.password
find/backup/$ip-type f-mtime +7-name "*.tar.gz" |xargs rm–fr
Full-network backup serviceBackupScript
lang=en
flag_num=/tmp/check_$ (date +%f). txt
find/backup/-type f-name "flag_$ (date +%f_%w). txt" |xargs md5sum-c|grep failed&> $flag _num
If [' Cat $flag _num|wc-l '-gt 0];then
Mail-s "$ (date +%f\%T) backup is fail!!" [Email protected]< $flag _num
Else
echo "Backup is OK" |mail-s "$ (date +%f\%T) backup issuccessful" [email protected]
Fi
#find/backup/172.16.1.31/-type f-mtime-7 \! -name "bak*_6.tar.gz" |xargs rm–fr
because we're going to receive mail from the server, so we're going to/etc/mail.rcAdd a configuration file below
Set [email protected] smtp=smtp.163.comsmtp-auth-user=15855557337 smtp-auth-password=cai1234 Smtp-auth=login
2. ConfigurationNfsServiceNfsService-Side Build command
Yum Install nfs-utils Rpcbind–y
Mkdir/data/w_share-p
Mkdir/data/r_share-p
echo "/DATA/W_SHARE172.16.1.0/24 (Rw,sync)" >>/etc/exports
echo "/data/r_share 172.16.1.0/24 (ro,sync)" >>/etc/exports
Chown-r nfsnobody:nfsnobody/data&&\
Chown-r nfsnobody:nfsnobody/data/r_share/
Chown-r Nfsnobody:nfsnobody/data/w_share
/etc/init.d/rpcbind restart
/etc/init.d/rpcbind restart
/etc/init.d/nfs restart
/etc/init.d/nfs restart
NfsMountWed01Customer service side build command
Yum Install nfs-utils rpcbind-y
/etc/init.d/rpcbind restart
/etc/init.d/rpcbind restart
/etc/init.d/nfs restart
/etc/init.d/nfs restart
SHOWMOUNT-E 172.16.1.31
Mkdir/data/w_caizhiliang–p
Mkdir/data/r_caizhiliang–p
Mount-t NFS 172.16.1.31:/data/w_share/data/w_caizhiliang
Mount-t Nfs172.16.1.31:/data/r_share/data/r_caizhiliang
echo "/usr/bin/mount-t NFS 172.16.1.31:/data/r_share/data/r_caizhiliang" >>/etc/rc.loca
echo "/usr/bin/mount-t NFS 172.16.1.31:/data/w_share/data/w_caizhiliang" >>/etc/rc.loca
NfsgMountBackupCustomer service side build command
Yum Install nfs-utils rpcbind-y
/etc/init.d/rpcbind restart
/etc/init.d/rpcbind restart
/etc/init.d/nfs restart
/etc/init.d/nfs restart
SHOWMOUNT-E 172.16.1.31
Mkdir/data/d_w–p
Mkdir/data/d_r–p
Mount-t NFS 172.16.1.31:/data/w_share/data/d_w
Mount-t NFS 172.16.1.31:/data/r_share/data/d_r
echo "/usr/bin/mount-t NFS 172.16.1.31:/data/r_share/data/d_r" >>/etc/rc.loca
echo "/usr/bin/mount-t NFS 172.16.1.31:/data/w_share/data/d_w" >>/etc/rc.loca
Real-time backupINotifyinstallationin theNfsinstalled on the server
Wget-o/etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo&&\
Yum Install Inotify-tools–y
Real-time backup scripts
#!/bin/bash
Path=/data
ip=172.16.1.41
/usr/bin/inotifywait-mrq--format '%w%f '-e close_write,delete $Path \
|while Read File
Do
if [-F $file];then
Rsync-az $file--delete [email protected] $Ip:: Nfsbackup--password-file=/etc/rsync.password
Else
CD $Path &&\
Rsync-az./--delete [email protected] $Ip:: Nfsbackup--password-file=/etc/rsync.password
fi
Done
Real-time backup boot command
Chkconfig--add SYNCD
Chkconfig SYNCD on
Vim/etc/init.d/syncd
Vim/etc/init.d/rsyncd
[Email protected] scripts]# CAT/ETC/INIT.D/SYNCD
#!/bin/bash
#chkconfig: 2345 38 46
################################################
. /etc/init.d/functions
If [$#-ne 1];then
Usage: $ {start|stop}
Exit 1
Fi
Case "$" in
Start
/bin/bash/server/scripts/shishibeifen.sh&
Echo $$ >/var/run/inotify.pid
If [' Ps-ef|grep inotify|wc-l '-gt 2];then
Action "INotify service is started"/bin/true
Else
Action "Inotif Yservice is started"/bin/false
Fi
;;
Stop
Kill-9 ' Cat/var/run/inotify.pid ' >/dev/null 2>&1
Pkill inotifywait
Sleep 2
If [' Ps-ef|grep inotify|grep-v grep|wc-l '-eq 0];then
Action "INotify service is stopped"/bin/true
Else
Action "INotify service is stopped"/bin/false
Fi
;;
*)
Usage: $ {start|stop}
Exit 1
Esac
Rsync+inotify Real-time Backup plus NFS Mount combat