您好,登錄后才能下訂單哦!
[root@backup nfsbackup]# uname -a
Linux backup 2.6.32-696.el6.x86_64 #1 SMP Tue Mar21 19:29:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
iptables的狀態(tài)
[root@backup nfsbackup]# /etc/init.d/iptables status
iptables: Firewall is not running.
XElinux的狀態(tài)
[root@backup nfsbackup]# getenforce
Disabled
查看rsync服務(wù)是否啟動(dòng)
[root@backup nfsbackup]# ss -lntup|grep"rsync"
tcp LISTEN 0 5 :::873 :::* users:(("rsync",1294,5))
tcp LISTEN 0 5 *:873 *:* users:(("rsync",1294,3))
查看推送的目錄是模塊nfsbackup
[nfsbackup]
path = /nfsbackup/
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
[root@nfs01 ~]# uname -a
Linux nfs01 2.6.32-696.el6.x86_64 #1 SMP Tue Mar 2119:29:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
iptables狀態(tài)
[root@nfs01 ~]# /etc/init.d/iptables status
iptables: Firewall is not running.
XElinux狀態(tài)
[root@nfs01 ~]# getenforce
Disabled
我們使用的共享目錄是nfsbackup
[root@nfs01 ~]# showmount -e
Export list for nfs01:
/app/r 172.16.1.0/24
/app/w 172.16.1.0/24
/data 10.0.0.0/24
/www 172.16.1.0/24
/nfsbackup 172.16.1.0/24
查看是否有inotify,如果沒(méi)有下載
[root@nfs01 ~]# rpm -qa inotify-tools
inotify-tools-3.14-1.el6.x86_64
下載方法
yum install inotify-tools -y
注: inotify-tools屬于epel源.
查看epel
[root@nfs01 ~]# yum repolist
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
* base:mirrors.aliyun.com
* epel:mirrors.aliyun.com
* extras:mirrors.aliyun.com
* updates:mirrors.aliyun.com
repo id repo name status
base CentOS-6 - Base - mirrors.aliyun.com 6,706
epel Extra Packages for Enterprise Linux6 - x86_64 12,350
extras CentOS-6 - Extras - mirrors.aliyun.com 45
updates CentOS-6 - Updates - mirrors.aliyun.com 383
repolist: 19,484
更換方法(更換為阿里的源)
###更換系統(tǒng)默認(rèn)的yum源為國(guó)內(nèi)
http://mirrors.aliyun.com/
mv /etc/yum.repos.d/CentOS-Base.repo/etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repohttp://mirrors.aliyun.com/repo/Centos-6.repo
##擴(kuò)展的yum源-補(bǔ)充
epel源-fedora
wget -O /etc/yum.repos.d/epel.repohttp://mirrors.aliyun.com/repo/epel-6.repo
一步完成:
mv /etc/yum.repos.d/CentOS-Base.repo/etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repohttp://mirrors.aliyun.com/repo/Centos-6.repo
wget -O /etc/yum.repos.d/epel.repohttp://mirrors.aliyun.com/repo/epel-6.repo
我們的目標(biāo)是每當(dāng)nfs端的/nfsbackup有文件或目錄變化就向backup端的女方是backup模塊推送,保持實(shí)時(shí)更新.
1,利用inotify監(jiān)控/nfsbackup中目錄和文件的變化
2,利用while循環(huán)把/nfsbackup中目錄和文件的變化,推送到backup服務(wù)器的nfsbackup模塊中
vim watch.sh
#!/bin/bash
IP=`hostname -i`
NFSBP=/nfsbackup/
###監(jiān)控/nfsbackup的變化,并交給while進(jìn)行逐行執(zhí)行
inotifywait -mrq $NFSBP --format "%w%f" -e create,delete,close_write,moved_to|while read line
do
rsync-aLz --delete $NFSBP rsync_backup@172.16.1.41::nfsbackup/$IP/--password-file=/etc/rsync.password
###推送$line文件到172.16.1.41下的nfsbackup中
done
窗口1, [root@nfs01 scripts]#/bin/bash /server/scripts/watch.sh
窗口2,[root@nfs01 nfsbackup]#touch {1..4}.log
[root@nfs01 nfsbackup]# echo "偉大" >a.txt
窗口3, [root@backup nfsbackup]#ll 172.16.1.31/
total 0
-rw-r--r-- 1 rsync rsync 0 Jun 28 16:381.log
-rw-r--r-- 1 rsync rsync 0 Jun 28 16:382.log
-rw-r--r-- 1 rsync rsync 0 Jun 28 16:383.log
-rw-r--r-- 1 rsync rsync 0 Jun 28 16:384.log
[root@backup nfsbackup]# ll 172.16.1.31/
total 4
-rw-r--r-- 1 rsync rsync 0 Jun 28 16:381.log
-rw-r--r-- 1 rsync rsync 0 Jun 28 16:38 2.log
-rw-r--r-- 1 rsync rsync 0 Jun 28 16:383.log
-rw-r--r-- 1 rsync rsync 0 Jun 28 16:384.log
-rw-r--r-- 1 rsync rsync 7 Jun 28 16:40a.txt
[root@backup nfsbackup]# cat172.16.1.31/a.txt
偉大
echo '/bin/bash /server/scripts/watch.sh &'>>/etc/rc.local
查看
[root@nfs01 scripts]# tail -1 /etc/rc.local
/bin/bash /server/scripts/watch.sh &
注:&是在后臺(tái)執(zhí)行的意思.
[root@nfs01 scripts]# jobs
[1]+ Running /bin/bash/server/scripts/watch.sh &
[root@nfs01 nfsbackup]# jobs -p 查看后臺(tái)命令的進(jìn)程號(hào)
3362
[root@nfs01 nfsbackup]# kill 3362 刪除這個(gè)進(jìn)程號(hào)的進(jìn)程
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。