本測試須要3臺服務器,1,2,3bash
1.NFS客戶端,RSYNC客戶端服務器
2.NFS服務端,RSYNC客戶端,inotify軟件測試
3.NFS客戶端,RSYNC服務端ui
如下是各個服務器的安裝腳本:code
NFS客戶端orm
#!/bin/bash Path1=/data/a_w_lin Path2=/data/a_r_lin ### nfs rpcbind install ### yum -y install nfs-utils rpcbind &&\ rpm -qa nfs-utils rpcbind ### mkdir dir ### mkdir $Path1 -p mkdir $Path2 -p ### check nfs ### showmount -e 10.0.137.145 ### mount ### mount -t nfs 10.0.137.145:/data/w_shared $Path1 mount -t nfs 10.0.137.145:/data/r_shared $Path2 ### rc.local ### echo "mount -t nfs 10.0.137.145:/data/w_shared $Path1" >>/etc/rc.local echo "mount -t nfs 10.0.137.145:/data/r_shared $Path2" >>/etc/rc.local
NFS服務端server
#/bin/bash! ### nfs install ### yum -y install nfs-utils rpcbind rpm -qa nfs-utils rpcbind ### nfs start ### /etc/init.d/rpcbind start &&\ /etc/init.d/nfs start /usr/sbin/rpcinfo -p localhost ### mkdir dir ### mkdir /data/w_shared -p mkdir /data/r_shared -p chown -R nfsnobody.nfsnobody /data/w_shared chown -R nfsnobody.nfsnobody /data/r_shared ### nfs config ### echo "/data/w_shared 10.0.137.0/24(rw,sync)" >>/etc/exports echo "/data/r_shared 10.0.137.0/24(ro,sync)" >>/etc/exports ### nfs reload ### /etc/init.d/nfs reload showmount -e 127.0.0.1 ### chkconfig ### chkconfig rpcbind on chkconfig nfs on
RSYNC服務端ip
#!/bin/bash cat >>/etc/rsyncd.conf <<EOF #rsync_config____________________start #created bycarltonat 20180306 ##rsyncd.conf start## uid = rsync gid = rsync use chroot £»= no max connections = 200 timeout = 300 pid file = /var/run/rsyncd.pid lock file = /var/run/rsyncd.lock log file = /var/log/rsyncd.log [backup] path = /backup ignore errors read only = false list = false hosts allow = 10.0.137.0/24 hosts deny = 0.0.0.0/24 auth users = rsync_backup secrets file = /etc/rsync.password #rsync_config____________________start EOF useradd rsync -s /sbin/nologin -M rsync --daemon mkdir /backup chown rsync.rsync /backup cat >> /etc/rsync.password <<EOF rsync_backup:carlton EOF chmod 600 /etc/rsync.password echo "/usr/bin/rsync --daemon" >>/etc/rc.d/rc.local
RSYNC客戶端ci
#!/bin/bash echo "carlton" >/etc/rsync.password chmod 600 /etc/rsync.password
inotify安裝及配置rpc
#!/bin/bash ### instal inotify ### wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo yum -y install inotify-tools rpm -qa inotify-tools ### optimize ### echo 655350 >/proc/sys/fs/inotify/max_user_watches echo 655350 >/proc/sys/fs/inotify/max_queued_events
#!/bin/bash /usr/bin/inotifywait -mrq --format "%w%f" -e close_write,delete /data/w_shared \ |while read file do cd /data/w_shared rsync -az ./ rsync_backup@10.0.137.146::backup --password-file=/etc/rsync.password done
inotify加入到chkconfig --list 中
cat /etc/init.d/inotify #!/bin/bash #chkconfig: 2345 38 46 . /etc/init.d/functions if [ $# -ne 1 ];then usage: $0 {start|stop} exit 1 fi case "$1" in start) /bin/bash /server/scripts/inotify.time.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 "inotify service 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: $0 {start|stop} exit 1 esac