您好,登錄后才能下訂單哦!
[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的狀態
[root@backup nfsbackup]# /etc/init.d/iptables status
iptables: Firewall is not running.
XElinux的狀態
[root@backup nfsbackup]# getenforce
Disabled
查看rsync服務是否啟動
[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狀態
[root@nfs01 ~]# /etc/init.d/iptables status
iptables: Firewall is not running.
XElinux狀態
[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,如果沒有下載
[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
更換方法(更換為阿里的源)
###更換系統默認的yum源為國內
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
##擴展的yum源-補充
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
我們的目標是每當nfs端的/nfsbackup有文件或目錄變化就向backup端的女方是backup模塊推送,保持實時更新.
1,利用inotify監控/nfsbackup中目錄和文件的變化
2,利用while循環把/nfsbackup中目錄和文件的變化,推送到backup服務器的nfsbackup模塊中
vim watch.sh
#!/bin/bash
IP=`hostname -i`
NFSBP=/nfsbackup/
###監控/nfsbackup的變化,并交給while進行逐行執行
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 &
注:&是在后臺執行的意思.
[root@nfs01 scripts]# jobs
[1]+ Running /bin/bash/server/scripts/watch.sh &
[root@nfs01 nfsbackup]# jobs -p 查看后臺命令的進程號
3362
[root@nfs01 nfsbackup]# kill 3362 刪除這個進程號的進程
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。