rsync [選項(xiàng)] 原始位置 目標(biāo)位置
[root@rsyncd ~]# rpm -q rsync
rsync-3.0.9-18.el7.x86_64
[root@rsyncd ~]# vim /etc/rsyncd.conf
uid = nobody //匿名用戶
gid = nobody
use chroot = yes //禁錮家目錄
pid file = /var/run/rsyncd.pid //pid文件路徑
address = 192.168.144.128 //配置監(jiān)聽(tīng)地址
port = 873 //端口號(hào)
log file = /var/log/rsyncd.log //日志文件路徑
hosts allow = 192.168.144.0/24 //允許地址段訪問(wèn)
dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2 //不需要壓縮的類型
[wwwroot] //共享模塊名
path = /var/www/html //共享文件路徑
comment = www.kgc.com //定義名稱
read only = yes //只讀權(quán)限
auth users = backuper //身份驗(yàn)證用戶名
secrets file = /etc/rsyncd_users.db //密碼文件
:wq
[root@rsyncd ~]# vim /etc/rsyncd_users.db //創(chuàng)建密碼文件
backuper:123123 //編輯用戶名:密碼
:wq
[root@rsyncd ~]# chmod 600 /etc/rsyncd_users.db //更改權(quán)限
[root@rsyncd ~]# rsync --daemon //開(kāi)啟rsync服務(wù)
[root@rsyncd ~]# netstat -ntap | grep rsync //查看端口
tcp 0 0 192.168.144.128:873 0.0.0.0:* LISTEN 36346/rsync
[root@rsyncd ~]# systemctl stop firewalld.service //關(guān)閉防火墻
[root@rsyncd ~]# setenforce 0
[root@rsyncd ~]# yum install httpd -y //安裝httpd服務(wù)
[root@rsyncd ~]# cd /var/www/html/
[root@rsyncd html]# echo "this is test web" > index.html //編輯網(wǎng)頁(yè)信息
[root@rsyncd html]# cd ../
[root@rsyncd www]# chmod 777 html/ //放開(kāi)目錄權(quán)限,方便用戶操作
[root@client ~]# systemctl stop firewalld.service //關(guān)閉防火墻
[root@client ~]# setenforce 0 //關(guān)閉selinux
[root@client ~]# rpm -q rsync //檢查是否安裝rsync服務(wù)
rsync-3.0.9-18.el7.x86_64
[root@client ~]# yum install httpd -y //安裝httpd服務(wù)
[root@client ~]# cd /var/www/
[root@client www]# chmod 777 html/ //放開(kāi)目錄權(quán)限
[root@client www]# rsync -avz backuper@192.168.144.128::wwwroot /var/www/html //拉取共享模塊
Password: //輸入密碼
[root@client www]# cat html/index.html //查看是否同步信息
this is test web
[root@client www]# rm -rf html/index.html
[root@client www]# vim /etc/server.pass //創(chuàng)建本地的密碼文件
123123
[root@client www]# chmod 600 /etc/server.pass //更改權(quán)限
[root@client www]# rsync -avz --delete --password-file=/etc/server.pass backuper@192.168.144.128::wwwroot /var/www/html/ //指定本地密碼文件,刪除目標(biāo)位置有而原始位置沒(méi)有的文件,實(shí)現(xiàn)免交互
[root@client www]# vim /etc/sysctl.conf //修改內(nèi)核參數(shù)文件
fs.inotify.max_queued_events = 16384 //隊(duì)列
fs.inotify.max_user_instances = 1024 //每個(gè)隊(duì)列中的實(shí)例數(shù)
fs.inotify.max_user_watches = 1048576 //每個(gè)實(shí)例中的文件數(shù)
[root@client www]# sysctl -p ##加載
[root@client www]# mount.cifs //192.168.100.8/LNMP-C7 /mnt/ //掛載
Password for root@//192.168.100.3/LNMP-C7:
[root@client www]# cd /mnt/
[root@client mnt]# tar zxvf inotify-tools-3.14.tar.gz -C /opt/ //解壓inotify到/opt下
[root@client mnt]# cd /opt/
[root@client opt]# cd inotify-tools-3.14/
[root@client inotify-tools-3.14]# yum install gcc gcc-c++ make -y //安裝環(huán)境
[root@client inotify-tools-3.14]# ./configure //配置
[root@client inotify-tools-3.14]# make && make install //編譯安裝
[root@client inotify-tools-3.14]# inotifywait -mrq -e modify,create,move,delete /var/www/html/ //啟動(dòng)監(jiān)控
[root@client ~]# cd /var/www/html/
[root@client html]# touch abc
[root@client html]# rm -rf abc
/var/www/html/ CREATE abc
/var/www/html/ DELETE abc //顯示監(jiān)控信息
[root@client inotify-tools-3.14]# cd /opt/
[root@client opt]# vim inotify.sh
#!/bin/bash
INOTIFY_CMD="inotifywait -mrq -e modify,create,move,delete /var/www/html/"
RSYNC_CMD="rsync -avz --delete --password-file=/etc/server.pass /var/www/html/ backuper@192.168.144.128::wwwroot/"
$INOTIFY_CMD | while read DIRECTORY EVENT FILE
do
if [ $(pgrep rsync | wc -l) -le 0 ]; then
$RSYNC_CMD
fi
done
[root@client opt]# chmod +x inotify.sh //添加執(zhí)行權(quán)限
[root@rsyncd www]# vim /etc/rsyncd.conf
read only = no //關(guān)閉只讀權(quán)限
[root@rsyncd www]# netstat -natp | grep rsync
tcp 0 0 192.168.144.128:873 0.0.0.0:* LISTEN 36346/rsync
[root@rsyncd www]# kill -9 36346 //關(guān)閉服務(wù)
[root@rsyncd www]# netstat -natp | grep rsync
[root@rsyncd www]# rm -rf /var/run/rsyncd.pid //刪除pid文件
[root@rsyncd www]# rsync --daemon //重新開(kāi)啟rsync服務(wù)
[root@client opt]# ./inotify.sh
[root@client html]# echo "this is test" > test.txt //添加文本
[root@client opt]# ./inotify.sh
sending incremental file list
./
rsync: failed to set times on "/." (in wwwroot): Operation not permitted (1)
test.txt
sent 121 bytes received 30 bytes 302.00 bytes/sec
total size is 30 speedup is 0.20
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1052) [sender=3.0.9]
sending incremental file list
sent 66 bytes received 8 bytes 148.00 bytes/sec
total size is 30 speedup is 0.41
[root@rsyncd www]# cd html/
[root@rsyncd html]# ls
index.html test.txt //實(shí)現(xiàn)同步
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
在孟村等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場(chǎng)前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都網(wǎng)站設(shè)計(jì)、網(wǎng)站建設(shè) 網(wǎng)站設(shè)計(jì)制作定制網(wǎng)站開(kāi)發(fā),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站建設(shè),營(yíng)銷型網(wǎng)站,外貿(mào)營(yíng)銷網(wǎng)站建設(shè),孟村網(wǎng)站建設(shè)費(fèi)用合理。