<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] ## 服務器角色: NFS服務器,sersync服務端.rsync客戶端 NFS備份服務器,rsync的服務端 ## sersync下載地址: ``` https://code.google.com/archive/p/sersync/downloads ``` ## 部署計劃 - NFS服務器創建好對應的用戶www - NFS備份服務器端安裝配置rsync服務端 - 創建相應的備份目錄,手動測試rsync是否可以正常傳輸 - NFS服務器配置sersync配置文件,多目錄傳輸 - 啟動sersync,測試是否可以正常運行 - 手動寫入文件,測試是否可以傳輸,目錄權限是否正確 - 測試控制傳輸速率 - 測試軟鏈接是否正常傳輸 ## 部署過程 ### NFS服務器端 ### 創建用戶 ``` [root@nfs-194 ~]# useradd www -M [root@nfs-194~]# id www uid=1001(www) gid=1001(www) groups=1001(www) ``` ### 創建目錄 ``` [root@nfs-194 ~]# mkdir -p /data/{www,bbs} [root@nfs-194 ~]# chown -R www:www /data/ [root@nfs-194 ~]# ls -lh /data/ total 8.0K drwxr-xr-x 2 www www 4.0K Mar 19 11:53 bbs drwxr-xr-x 2 www www 4.0K Mar 19 11:53 www ``` ### 配置rsync服務端 查看rsync版本 ``` [root@nfs-194 ~]# rsync --version rsync version 3.1.1 protocol version 31 ``` ### 創建rsync配置文件 注意, 把下面的注釋去掉,不然可能會報錯 ``` [root@nfs-194 ~]# vim /etc/rsyncd.conf [root@nfs-194 ~]# cat /etc/rsyncd.conf uid = www #rsync使用的用戶 gid = www #rsync使用的用戶組 use chroot = yes #如果需要把軟鏈接也一起傳輸,則必須要配置為true,默認為no max connections = 200 #設置最大連接數,默認為0,負值為關閉這個模塊 timeout = 300 #默認為0,建議為300-600(5-10)分鐘 pid file = /var/run/rsyncd.pid #pid文件 lock file = /var/run/rsync.lock #lock鎖 log file = /var/log/rsyncd.log #log文件 ignore errors #忽略I/O錯誤 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.passwd #用于密碼認證的文件,里面有同步用戶名和密碼,客戶端只需要密碼即可 [www] #備份模塊,可以制定不同的備份目錄,客戶端可以指定不同的模塊 path = /data/www #www模塊的備份目錄 [bbs] #bbs備份模塊 path = /data/bbs #bbs備份模塊的備份目錄 ``` ### 創建rsync密碼文件并更改權限 ``` [root@nfs-194 ~]# vim /etc/rsync.passwd [root@nfs-194 ~]# cat /etc/rsync.passwd rsync_backup:vim26 [root@nfs-194 ~]# chmod 600 /etc/rsync.passwd [root@nfs-194 ~]# ls -lh /etc/rsync.passwd -rw------- 1 root root 19 Mar 19 12:02 /etc/rsync.passwd ``` ### 使rsync以deamon模式啟動 ``` [root@nfs-194 ~]# /etc/init.d/rsync start [ ok ] Starting rsync (via systemctl): rsync.service. [root@nfs-88 ~]# ps -ef|grep rsync root 924 1 0 12:04 ? 00:00:00 /usr/bin/rsync --daemon --no-detach root 943 786 0 12:04 pts/0 00:00:00 grep rsync ``` ### NFS備份服務器端 ### 查看rsync版本 ``` [root@nfs-88 ~]# rsync --version rsync version 3.1.1 protocol version 31 ``` ### 創建用戶和目錄 ``` [root@nfs-88 ~]# useradd www -M [root@nfs-88 ~]# id www uid=1001(www) gid=1001(www) groups=1001(www) [root@nfs-88 ~]# mkdir -p /data/{www,bbs} [root@nfs-88 ~]# chown -R www:www /data/ [root@nfs-88 ~]# ls -lh /data/ total 8.0K drwxr-xr-x 2 www www 4.0K Mar 19 12:06 bbs drwxr-xr-x 2 www www 4.0K Mar 19 12:06 www ``` ### 創建rsync密碼文件 ``` [root@nfs-88 ~]# vim /etc/rsync.passwd [root@nfs-88 ~]# cat /etc/rsync.passwd vim26 [root@nfs-88 ~]# chmod 600 /etc/rsync.passwd [root@nfs-88 ~]# ls -lh /etc/rsync.passwd -rw------- 1 root root 6 Mar 19 12:07 /etc/rsync.passwd ``` ##NFS服務端測試 ### 創建測試文件 ``` [root@nfs-88 ~]# cd /data/www/ [root@nfs-88 www]# echo "88www" > 88www.txt [root@nfs-88 www]# cat 88www.txt 194www [root@nfs-88 www]# ls -lh total 0 -rw-r--r-- 1 root root 0 Mar 19 12:21 88www.txt ``` ### 測試傳輸www ``` [root@nfs-88 www]# rsync -avzP --password-file=/etc/rsync.passwd /data/www/ rsync_backup@172.16.1.194::www sending incremental file list ./ 88www.txt 0 100% 0.00kB/s 0:00:00 (xfr#1, to-chk=0/2) rsync: chgrp ".88www.txt.RYv0pa" (in www) failed: Operation not permitted (1) sent 126 bytes received 128 bytes 508.00 bytes/sec total size is 0 speedup is 0.00 rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1183) [sender=3.1.1] ``` 結果顯示失敗,因為88www.txt的權限是root, 我們修改一下權限在測試一下 ``` [root@nfs-88 www]# chown www:www 88www.txt [root@nfs-88 www]# ls -lh 88www.txt -rw-r--r-- 1 www www 0 Mar 19 12:21 88www.txt [root@nfs-88 www]# rsync -avzP --password-file=/etc/rsync.passwd /data/www/ rsync_backup@172.16.1.194::www sending incremental file list ./ 88www.txt 0 100% 0.00kB/s 0:00:00 (xfr#1, to-chk=0/2) sent 124 bytes received 46 bytes 340.00 bytes/sec total size is 0 speedup is 0.00 ``` 這一次沒有提示失敗,然后查看一下NFS備份端有沒有文件生成 ``` [root@nfs-194 www]# ls -lh total 4.0K -rw-r--r-- 1 www www 6 Mar 19 12:26 88www.txt [root@nfs-194 www]# cat 88www.txt 88www ``` ### 測試傳輸bbs www測試沒有問題,我們再測試傳輸一下bbs,步驟和上面一樣 ``` [root@nfs-88 ~]# cd /data/bbs/ [root@nfs-88 bbs]# echo "88bbs" > 88bbs.txt [root@nfs-88 bbs]# cat 88bbs.txt 88bbs [root@nfs-88 bbs]# chown -R www:www 88bbs.txt [root@nfs-88 bbs]# ls -lh total 4.0K -rw-r--r-- 1 www www 6 Mar 19 12:53 88bbs.txt [root@nfs-88 bbs]# rsync -avzP --password-file=/etc/rsync.passwd /data/bbs/ rsync_backup@172.16.1.194::bbs sending incremental file list ./ 88bbs.txt 6 100% 0.00kB/s 0:00:00 (xfr#1, to-chk=0/2) sent 131 bytes received 46 bytes 354.00 bytes/sec total size is 6 speedup is 0.03 ``` ### NFS備份端查看 ``` [root@nfs-194 ~]# cd /data/bbs/ [root@nfs-194 bbs]# ls -lh total 4.0K -rw-r--r-- 1 www www 6 Mar 19 12:53 88bbs.txt [root@nfs-194 bbs]# cat 88bbs.txt 88bbs ``` ## NFS服務器部署sersync 下載地址 ``` https://code.google.com/archive/p/sersync/downloads ``` 解壓安裝 ``` [root@nfs-88 ~]# cd /opt/ [root@nfs-88 opt]# wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/sersync/sersync2.5.4_64bit_binary_stable_final.tar.gz [root@nfs-88 opt]# ls -lh total 712K -rw-r--r-- 1 root root 711K Jan 24 2016 sersync2.5.4_64bit_binary_stable_final.tar.gz [root@nfs-88 opt]# tar zxf sersync2.5.4_64bit_binary_stable_final.tar.gz [root@nfs-88 opt]# ls -lh total 716K drwxr-xr-x 2 root root 4.0K Oct 26 2011 GNU-Linux-x86 -rw-r--r-- 1 root root 711K Jan 24 2016 sersync2.5.4_64bit_binary_stable_final.tar.gz [root@nfs-88 opt]# mv GNU-Linux-x86/ sersync [root@nfs-88 opt]# ls -lh total 716K drwxr-xr-x 2 root root 4.0K Oct 26 2011 sersync -rw-r--r-- 1 root root 711K Jan 24 2016 sersync2.5.4_64bit_binary_stable_final.tar.gz [root@nfs-88 opt]# tree sersync sersync ├── confxml.xml └── sersync2 ``` ### 規范目錄結構 ``` [root@nfs-88 sersync]# cd /opt/sersync/ [root@nfs-88 sersync]# ls confxml.xml sersync2 [root@nfs-88 sersync]# mkdir {bin,conf,logs} [root@nfs-88 sersync]# tree . ├── bin ├── conf ├── confxml.xml ├── logs └── sersync2 [root@nfs-88 sersync]# mv confxml.xml conf [root@nfs-88 sersync]# mv sersync2 bin/sersync [root@nfs-88 sersync]# tree . ├── bin │?? └── sersync ├── conf │?? └── confxml.xml └── logs ``` ### 備份配置文件 ``` [root@nfs-88 sersync]# cp conf/confxml.xml conf/confxml.xml.bak [root@nfs-88 sersync]# cd conf/ [root@nfs-88 conf]# ls confxml.xml confxml.xml.bak ``` ### 修改配置文件內容,這里只貼出主要的配置 每個備份模塊都要有自己的一個單獨的配置文件,不然同步的時候可能會出現問題 ``` [root@nfs-88 conf]# cat -n bbs_confxml.xml 1 <?xml version="1.0" encoding="ISO-8859-1"?> 2 <head version="2.5"> 3 <host hostip="localhost" port="8008"></host> 4 <debug start="false"/> 5 <fileSystem xfs="false"/> 6 <filter start="false"> 7 <exclude expression="(.*)\.svn"></exclude> 8 <exclude expression="(.*)\.gz"></exclude> 9 <exclude expression="^info/*"></exclude> 10 <exclude expression="^static/*"></exclude> 11 </filter> 12 <inotify> 13 <delete start="true"/> 14 <createFolder start="true"/> 15 <createFile start="false"/> 16 <closeWrite start="true"/> 17 <moveFrom start="true"/> 18 <moveTo start="true"/> 19 <attrib start="false"/> 20 <modify start="false"/> 21 </inotify> 22 23 <sersync> 24 <localpath watch="/data/bbs"> 25 <remote ip="172.16.1.194" name="bbs"/> 26 </localpath> 27 <rsync> 28 <commonParams params="-artuz"/> 29 <auth start="true" users="rsync_backup" passwordfile="/etc/rsync.passwd"/> 30 <userDefinedPort start="false" port="874"/><!-- port=874 --> 31 <timeout start="false" time="100"/><!-- timeout=100 --> 32 <ssh start="false"/> 33 </rsync> 34 <failLog path="/opt/sersync/logs/bbs_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once--> ``` ### 寫入環境變量 ``` [root@nfs-88 conf]# echo 'export PATH=/opt/sersync/bin:$PATH'>>/etc/profile [root@nfs-88 conf]# tail -1 /etc/profile export PATH=/opt/sersync/bin:$PATH [root@nfs-88 conf]# source /etc/profile [root@nfs-88 conf]# which sersync /opt/sersync/bin/sersync ``` ### 測試傳輸 在測試之前我們先在多創建一些目錄,測試一下第一次傳輸會不會完全同步一次 ``` [root@nfs-88 conf]# cd /data/www/ [root@nfs-88 www]# ls 88www.txt [root@nfs-88 www]# [root@nfs-88 www]# for i in $(seq 1 1000);do echo "${i}_www" > www_${i}.txt;done; [root@nfs-88 www]# ls 88www.txt www_1.txt www_300.txt www_401.txt www_502.txt www_603.txt www_704.txt www_805.txt www_906.txt www_1000.txt www_200.txt www_301.txt www_402.txt www_503.txt www_604.txt www_705.txt www_806.txt www_907.txt www_100.txt www_201.txt www_302.txt www_403.txt www_504.txt www_605.txt www_706.txt www_807.txt www_908.txt www_101.txt www_202.txt www_303.txt www_404.txt www_505.txt www_606.txt www_707.txt www_808.txt www_909.txt www_102.txt www_203.txt www_304.txt www_405.txt www_506.txt www_607.txt www_708.txt www_809.txt www_90.txt www_103.txt www_204.txt www_305.txt www_406.txt www_507.txt www_608.txt www_709.txt www_80.txt www_910.txt www_104.txt www_205.txt www_306.txt www_407.txt www_508.txt www_609.txt www_70.txt www_810.txt www_911.txt ======================================== ``` 然后使用rsync傳輸,啟動后的界面.這里沒有使用-d命令,而是前臺啟動.方便我們排錯 ``` [root@nfs-88 www]# sersync -r -o /opt/sersync/conf/www_confxml.xml set the system param execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events parse the command param option: -r rsync all the local files to the remote servers before the sersync work option: -o config xml name: /opt/sersync/conf/www_confxml.xml daemon thread num: 10 parse xml config file host ip : localhost host port: 8008 use rsync password-file : user is rsync_backup passwordfile is /etc/rsync.passwd config xml parse success please set /etc/rsyncd.conf max connections=0 Manually sersync working thread 12 = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads) Max threads numbers is: 22 = 12(Thread pool nums) + 10(Sub threads) please according your cpu ,use -n param to adjust the cpu rate ------------------------------------------ rsync the directory recursivly to the remote servers once working please wait... execute command: cd /data/www && rsync -artuz -R --delete ./ rsync_backup@172.16.1.194::www --password-file=/etc/rsync.passwd >/dev/null 2>&1 run the sersync: watch path is: /data/www ``` 查看194的www目錄,發現已經同步過來了 ``` [root@nfs-194 ~]# cd /data/www/ [root@nfs-194 www]# ls 88www.txt www_1.txt www_300.txt www_401.txt www_502.txt www_603.txt www_704.txt www_805.txt www_906.txt www_1000.txt www_200.txt www_301.txt www_402.txt www_503.txt www_604.txt www_705.txt www_806.txt www_907.txt www_100.txt www_201.txt www_302.txt www_403.txt www_504.txt www_605.txt www_706.txt www_807.txt www_908.txt www_101.txt www_202.txt www_303.txt www_404.txt www_505.txt www_606.txt www_707.txt www_808.txt www_909.txt www_102.txt www_203.txt www_304.txt www_405.txt www_506.txt www_607.txt www_708.txt www_809.txt www_90.txt www_103.txt www_204.txt www_305.txt www_406.txt www_507.txt www_608.txt www_709.txt www_80.txt www_910.txt www_104.txt www_205.txt www_306.txt www_407.txt www_508.txt www_609.txt www_70.txt www_810.txt www_911.txt www_105.txt www_206.txt www_307.txt www_408.txt www_509.txt www_60.txt www_710.txt www_811.txt www_912.txt ``` 然后我們測試一下新增文件會不會同步過來,保持sersync的前端窗口,然后新開一個窗口 這里我們在88上進行了創建文件夾并移動文件的操作 ``` [root@nfs-88 www]# mkdir www_test [root@nfs-88 www]# mv *.txt www_test/ [root@nfs-88 www]# ls -lh total 36K drwxr-xr-x 2 root root 36K Mar 19 13:49 www_test ``` 在194服務器上觀察發現也相應的執行了創建和移動的操作,只不過速度不是即使完成的,之所以會這樣是因為每個文件的變化都是由inotify監控的,所以相當于記錄了每個文件的移動位置而不是執行shell命令. ``` [root@nfs-194 www]# ls|wc -l 473 [root@nfs-194 www]# ls|wc -l 460 [root@nfs-194 www]# ls|wc -l 442 [root@nfs-194 www]# ls|wc -l 423 [root@nfs-194 www]# ls|wc -l 406 [root@nfs-194 www]# ls|wc -l 390 [root@nfs-194 www]# ls|wc -l 43 [root@nfs-194 www]# ls|wc -l 24 [root@nfs-194 www]# ls|wc -l 1 [root@nfs-194 www]# ls -lh total 36K drwx------ 2 www www 36K Mar 19 13:49 www_test ``` ### 一致性同步測試 通過觀察前臺啟動的日志輸出我們可以看到rsync默認是帶有--delete也就是完全同步的參數的 ``` execute command: cd /data/www && rsync -artuz -R --delete ./ rsync_backup@172.16.1.194::www --password-file=/etc/rsync.passwd >/dev/null 2>&1 ``` 所以備份的目錄會強制和對端的NFS保持一直. 這里我們假如在備份端創建一個文件或目錄,然后在服務端創建文件,看會不會把備份端的給刪掉 備份端 ``` [root@nfs-194 www]# touch www_194.txt [root@nfs-194 www]# ls -lh total 36K -rw-r--r-- 1 root root 0 Mar 19 13:56 www_194.txt drwx------ 2 www www 36K Mar 19 13:49 www_test ``` 服務端 ``` [root@nfs-88 www]# touch www_88.txt [root@nfs-88 www]# ls -lh total 36K -rw-r--r-- 1 root root 0 Mar 19 13:57 www_88.txt drwxr-xr-x 2 root root 36K Mar 19 13:49 www_test ``` 再次查看備份端,發現并沒有被刪掉 ``` [root@nfs-194 www]# ls -lh total 36K -rw-r--r-- 1 root root 0 Mar 19 13:56 www_194.txt -rw------- 1 www www 0 Mar 19 13:57 www_88.txt drwx------ 2 www www 36K Mar 19 13:49 www_test ``` 然后我們在服務端手動刪掉剛才創建的文件 ``` [root@nfs-88 www]# rm www_88.txt rm: remove regular empty file ‘www_88.txt’? y [root@nfs-88 www]# ls -lh total 36K drwxr-xr-x 2 root root 36K Mar 19 13:49 www_test ``` 再次查看備份端,發現被刪掉了. ``` [root@nfs-194 www]# ls -lh total 36K -rw-r--r-- 1 root root 0 Mar 19 13:56 www_194.txt drwx------ 2 www www 36K Mar 19 13:49 www_test ``` 結論猜測. 為什么手動在194上創建的目錄沒有觸發刪除條件呢? 是因為rsync啟動的時候會全部掃描一次需要備份的目錄的文件列表. 然后同步完成后的更改就由inotify負責記錄. 而我們手動創建的目錄是在sersync啟動之后創建的,所以rsync啟動時的文件列表里并沒有這個文件 其次,inotify只負責記錄服務端的更改,所以inotify里也沒有我們要記錄的文件列表 猜測 加入重新啟動一次sersync,重新觸發一次--delete可能會刪掉 猜測驗證 重啟sersyc ``` [root@nfs-88 www]# sersync -r -o /opt/sersync/conf/www_confxml.xml set the system param execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events parse the command param option: -r rsync all the local files to the remote servers before the sersync work option: -o config xml name: /opt/sersync/conf/www_confxml.xml daemon thread num: 10 parse xml config file host ip : localhost host port: 8008 use rsync password-file : user is rsync_backup passwordfile is /etc/rsync.passwd config xml parse success please set /etc/rsyncd.conf max connections=0 Manually sersync working thread 12 = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads) Max threads numbers is: 22 = 12(Thread pool nums) + 10(Sub threads) please according your cpu ,use -n param to adjust the cpu rate ------------------------------------------ rsync the directory recursivly to the remote servers once working please wait... execute command: cd /data/www && rsync -artuz -R --delete ./ rsync_backup@172.16.1.194::www --password-file=/etc/rsync.passwd >/dev/null 2>&1 run the sersync: watch path is: /data/www ^C [root@nfs-88 www]# sersync -r -o /opt/sersync/conf/www_confxml.xml set the system param execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events parse the command param option: -r rsync all the local files to the remote servers before the sersync work option: -o config xml name: /opt/sersync/conf/www_confxml.xml daemon thread num: 10 parse xml config file host ip : localhost host port: 8008 use rsync password-file : user is rsync_backup passwordfile is /etc/rsync.passwd config xml parse success please set /etc/rsyncd.conf max connections=0 Manually sersync working thread 12 = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads) Max threads numbers is: 22 = 12(Thread pool nums) + 10(Sub threads) please according your cpu ,use -n param to adjust the cpu rate ------------------------------------------ rsync the directory recursivly to the remote servers once working please wait... execute command: cd /data/www && rsync -artuz -R --delete ./ rsync_backup@172.16.1.194::www --password-file=/etc/rsync.passwd >/dev/null 2>&1 run the sersync: watch path is: /data/www ``` 然后觀察備份端的目錄變化,可以發現原來手動創建的文件已經被刪除了.驗證了我們的結論是正確的 ``` [root@nfs-194 www]# ls -lh total 36K -rw-r--r-- 1 root root 0 Mar 19 13:56 www_194.txt drwx------ 2 www www 36K Mar 19 13:49 www_test [root@nfs-194 www]# ls -lh total 36K drwx------ 2 www www 36K Mar 19 13:49 www_test ``` 上面這種情況是因為我們啟動sersyc的時候使用了-r選項,也就是說啟動的時候會先完整同步一次 Sersync同步參數說明 ``` Sersync參數說明 -r -r參數作用是在開啟實時監控之前對主服務器目錄與遠程目標機目錄進行一次整體同步,如果需要將sersync運行前,主服務器目錄下已經存在的所有文件或目錄全部同步到遠端,則需要指定-r參數運行sersync,將本地與遠程整體同步一次**。說明:如果設置了過濾器,即在xml配置文件中,filter為true,則暫時不能使用-r參數進行整體同步。** –o confxml.xml 不指定-o參數時,sersync可執行文件目錄下的默認配置文件confxml.xml,如果需要使用其他的配置文件,可以使用-o參數指定其他配置文件,通過-o參數,我們可以指定多個不同的配置文件,從而實現sersync多進行多實例的數據同步。 –n number -n參數為指定默認的線程池的現充總數。 ``` ### 對比sersync不同的啟動參數 使用-r ``` [root@nfs-88 www]# sersync -r -o /opt/sersync/conf/www_confxml.xml set the system param execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events parse the command param option: -r rsync all the local files to the remote servers before the sersync work option: -o config xml name: /opt/sersync/conf/www_confxml.xml daemon thread num: 10 parse xml config file host ip : localhost host port: 8008 use rsync password-file : user is rsync_backup passwordfile is /etc/rsync.passwd config xml parse success please set /etc/rsyncd.conf max connections=0 Manually sersync working thread 12 = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads) Max threads numbers is: 22 = 12(Thread pool nums) + 10(Sub threads) please according your cpu ,use -n param to adjust the cpu rate ------------------------------------------ rsync the directory recursivly to the remote servers once working please wait... execute command: cd /data/www && rsync -artuz -R --delete ./ rsync_backup@172.16.1.194::www --password-file=/etc/rsync.passwd >/dev/null 2>&1 run the sersync: watch path is: /data/www ``` 不使用-r ``` [root@nfs-88 www]# sersync -o /opt/sersync/conf/www_confxml.xml set the system param execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events parse the command param option: -o config xml name: /opt/sersync/conf/www_confxml.xml daemon thread num: 10 parse xml config file host ip : localhost host port: 8008 use rsync password-file : user is rsync_backup passwordfile is /etc/rsync.passwd config xml parse success please set /etc/rsyncd.conf max connections=0 Manually sersync working thread 12 = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads) Max threads numbers is: 22 = 12(Thread pool nums) + 10(Sub threads) please according your cpu ,use -n param to adjust the cpu rate run the sersync: watch path is: /data/www ``` 可見使用-r則在啟動sersync前執行了一條--delete的語句 ``` rsync the directory recursivly to the remote servers once working please wait... execute command: cd /data/www && rsync -artuz -R --delete ./ rsync_backup@172.16.1.194::www --password-file=/etc/rsync.passwd >/dev/null 2>&1 run the sersync: ``` ### 測試軟鏈接 由于我們的rsync服務端配置文件里的use chroot 設置了no.默認是不會 測試 1.在88服務端創建軟鏈接,然后查看194會不會同步創建 ``` [root@nfs-88 www]# ls -lh total 36K lrwxrwxrwx 1 root root 9 Mar 19 14:23 www_ln -> www_test/ drwxr-xr-x 2 root root 36K Mar 19 13:49 www_test ``` 查看194的www目錄會發現,雖然已經創建了,也顯示是軟鏈接,但是鏈接的目標目錄位置不對,由于不存在這個目錄,所以也就就不去 ``` [root@nfs-194 www]# ls -lh total 36K lrwxrwxrwx 1 www www 24 Mar 19 14:24 www_ln -> /rsyncd-munged/www_test/ drwx------ 2 www www 36K Mar 19 13:49 www_test [root@nfs-194 www]# cd www_ln -bash: cd: www_ln: No such file or directory ``` 更改rsync的配置文件,設置use chroot = yes.然后重啟rsync,在重新傳輸一次 ``` [root@nfs-194 www]# vim /etc/rsyncd.conf [root@nfs-194 www]# grep "chroot" /etc/rsyncd.conf use chroot = yes [root@nfs-194 www]# /etc/init.d/rsync restart [ ok ] Restarting rsync (via systemctl): rsync.service. [root@nfs-194 www]# ps -ef|grep rsync root 5491 1 0 14:28 ? 00:00:00 /usr/bin/rsync --daemon --no-detach root 5510 785 0 14:28 pts/0 00:00:00 grep rsync ``` 重啟sersync, 重新同步一次 然后在觀察一次備份服務器的www目錄,發現已經修改過來了,并且可以正常進入 ``` [root@nfs-194 www]# ls -lh total 36K lrwxrwxrwx 1 www www 9 Mar 19 14:28 www_ln -> www_test/ drwx------ 2 www www 36K Mar 19 13:49 www_test [root@nfs-194 www]# cd www_ln [root@nfs-194 www_ln]# ls -lh |wc -l 1002 ``` 結論: 通過修改rsync的use chroot = yes選項可以同步并保留正確的軟鏈接目錄屬性 ### 控制傳輸速率 如果傳輸的文件太多,而服務器本身也提供業務,如果全部給rsync用來同步傳輸文件可能會使網卡占滿, 所以這里我們可以通過rsync的參數--bwlimit來控制傳輸速率,由于我們使用了sersync, 所以我們就嘗試在sersync的配置文件里修改參數 ``` [root@nfs-88 www]# cat -n /opt/sersync/conf/www_confxml.xml 28 <commonParams params="-artuz --bwlimit=10240"/> ``` 這里配置文件里的rsync區塊內我們添加了rsync控制速率的參數,然后重啟sersync,查看是否生效 ``` [root@nfs-88 www]# sersync -r -o /opt/sersync/conf/www_confxml.xml set the system param execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events parse the command param option: -r rsync all the local files to the remote servers before the sersync work option: -o config xml name: /opt/sersync/conf/www_confxml.xml daemon thread num: 10 parse xml config file host ip : localhost host port: 8008 use rsync password-file : user is rsync_backup passwordfile is /etc/rsync.passwd config xml parse success please set /etc/rsyncd.conf max connections=0 Manually sersync working thread 12 = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads) Max threads numbers is: 22 = 12(Thread pool nums) + 10(Sub threads) please according your cpu ,use -n param to adjust the cpu rate ------------------------------------------ rsync the directory recursivly to the remote servers once working please wait... execute command: cd /data/www && rsync -artuz --bwlimit=10240 -R --delete ./ rsync_backup@172.16.1.194::www --password-file=/etc/rsync.passwd >/dev/null 2>&1 run the sersync: watch path is: /data/www ``` 可見,日志輸出里是是已經添加了控制速率的命令,但是我們并不知道有沒有生效,所以我們上傳一個大文件,然后測試 ``` execute command: cd /data/www && rsync -artuz --bwlimit=10240 -R --delete ./ rsync_backup@172.16.1.194::www --password-file=/etc/rsync.passwd >/dev/null 2>&1 ``` 為了不影響傳輸實驗,我們先停掉sersync服務,然后上傳一個上G的文件,然后使用iftop命令查看網卡流量 安裝iftop ``` [root@nfs-88 www]# apt-get install iftop ``` 上傳大鏡像 ``` [root@nfs-88 www]# ls -lh total 4.1G -rw-r--r-- 1 root root 4.1G Mar 19 14:52 CentOS-7-x86_64-DVD-1511.iso lrwxrwxrwx 1 root root 9 Mar 19 14:23 www_ln -> www_test/ drwxr-xr-x 2 root root 36K Mar 19 13:49 www_test drwxr-xr-x 2 root root 4.0K Mar 19 14:37 www_test2 ``` 重新啟動sersync ``` [root@nfs-88 www]# /opt/sersync/bin/sersync -r -o /opt/sersync/conf/www_confxml.xml set the system param execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events parse the command param option: -r rsync all the local files to the remote servers before the sersync work option: -o config xml name: /opt/sersync/conf/www_confxml.xml daemon thread num: 10 parse xml config file host ip : localhost host port: 8008 use rsync password-file : user is rsync_backup passwordfile is /etc/rsync.passwd config xml parse success please set /etc/rsyncd.conf max connections=0 Manually sersync working thread 12 = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads) Max threads numbers is: 22 = 12(Thread pool nums) + 10(Sub threads) please according your cpu ,use -n param to adjust the cpu rate ------------------------------------------ rsync the directory recursivly to the remote servers once working please wait... execute command: cd /data/www && rsync -artuz --bwlimit=10240 -R --delete ./ rsync_backup@172.16.1.194::www --password-file=/etc/rsync.passwd >/dev/null 2>&1 ``` 新窗口啟動iftop,監聽內網網卡eth1,使用-B顯示M單位 ![](https://box.kancloud.cn/4bb9befd8511f39cc0e613dfdda38e45_1977x1045.png) 可以看到右下角的rates控制在了9M左右, 沒有超過我們限制的10M,也就是說控制傳輸速率的限制是生效的. 為了對比測試,現在刪掉控制速率的參數,然后再測試一下 首先刪掉備份端的鏡像,然后去掉速率參數重新測試一下 刪掉控制速率的參數,然后重新啟動sersync ``` [root@nfs-88 www]# /opt/sersync/bin/sersync -r -o /opt/sersync/conf/www_confxml.xml set the system param execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events parse the command param option: -r rsync all the local files to the remote servers before the sersync work option: -o config xml name: /opt/sersync/conf/www_confxml.xml daemon thread num: 10 parse xml config file host ip : localhost host port: 8008 use rsync password-file : user is rsync_backup passwordfile is /etc/rsync.passwd config xml parse success please set /etc/rsyncd.conf max connections=0 Manually sersync working thread 12 = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads) Max threads numbers is: 22 = 12(Thread pool nums) + 10(Sub threads) please according your cpu ,use -n param to adjust the cpu rate ------------------------------------------ rsync the directory recursivly to the remote servers once working please wait... execute command: cd /data/www && rsync -artuz -R --delete ./ rsync_backup@172.16.1.194::www --password-file=/etc/rsync.passwd >/dev/null 2>&1 ``` 然后iftop查看網卡發現rates速率顯示的是22M,可見傳輸速率是沒有限制的. ![](https://box.kancloud.cn/329b2b81144ae6cac592a55e5fc55d22_1977x1045.png) ### 使用supervision管理sersync進程 ``` root@nfs-88:~# cat /etc/supervisor/conf.d/program.conf [program:bbs] command = /opt/sersync/bin/sersync -r -o /opt/sersync/conf/bbs_confxml.xml -n 5 autostart = true startsecs = 5 autorestart = true startretries = 3 user = root redirect_stderr = true stdout_logfile_maxbytes = 20MB stdout_logfile_backups = 20 stdout_logfile = /opt/sersync/logs/bbs_sersync.log ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看