采用rsync實現兩臺solaris服務之間的文件同步

          目的:

          通過技術手段,保持服務器 A 中的某些目錄能夠定期同步到服務器 B 中。

          本文針對 Sun Solaris 5.9 版本,其他版本或其他 unix 服務器僅具有參考價值

          對于 Windows 服務器之間的文件同步,也可以采用 rsync ,但要使用 cwrsync 工具,請從 internet 上搜索資料。

          工具:

          rsync :在 unix 平臺下廣泛采用的同步軟件,免費使用,目前最新版本是 2.6.6

          crontab solaris 平臺上的定時任務管理器

          描述:

          rsync 同時安裝到 Server A Server B

          Server A 上, rsync 作為守護進程運行,通過配置,可以使得 Server A 上的某些目錄被 rsync 發布。

          Server B 上, rsync 作為命令行工具運行,可以從運行 rsync 守護進程的另一臺服務器( Server A )上將所發布的目錄同步到 Server B

          Server B 上配置定時任務,以便在指定的時間運行同步命令。

          步驟:

          1、 ? Server A Server B 上安裝 rsync 軟件:

          a) ???????? http://www.sunfreeware.com/programlistsparc9.html 上查找 rsync 的最新版本,從 http://ftp.saix.net/pub/solaris-freeware/sparc/5.9/ 上下載找到的文件。 目前的最新版本是 2.6.6 ,文件在本文所附的目錄中可以找到,名稱: rsync-2.6.6-sol9-sparc-local.gz

          b) ??????? 通過 ftp 命令將文件上傳到 Server A Server B ,在個人電腦的 DOS 命令行上執行命令如下:

          ftp 10.1.4.10?????????????????????????????? ???????????????????? # 通過 ftp 連接服務器 10.1.4.10

          bin???????????????????????????????????????????? ???????????????????? # 設定傳輸模式為二進制

          put rsync-2.6.6-sol9-sparc-local.gz????? ???????????????????? # 將本地的文件上傳到 10.1.4.10

          bye??????????????????????????????????????????? ???????????????????? # 退出 ftp 程序

          c) ??????? Server A Server B 上安裝 rsync ,命令非常簡單。在個人電腦的 DOS 命令行上執行下面的命令:

          telnet 10.1.4.10???????????????????????????????????????? ?????? # 連接到 10.1.4.10 的終端界面

          gzip -d rsync-2.6.6-sol9-sparc-local.gz??????? ?????? # 解壓縮 gz 文件

          pkgadd -d rsync-2.6.6-sol9-sparc-local.gz?? ?????? # 安裝 rsync ,遇到提問,按回車即可

          /usr/local/bin/rsync --version ??????????????????????????? # 驗證 rsync 安裝是否完成

          2、 ? Server A 上配置 rsync 服務

          a) ???????? 編輯 rsync 的配置文件, /etc/rsyncd.conf ,該文件在安裝之初是沒有的,需要自己建立。命令如下:

          vi /etc/rsyncd.conf ?????????????????????????????????????????? # 編輯 /etc/rsyncd.conf 文件

          文件內容如下:

          uid =? root????????????????????????????????????????????? # root 身份訪問文件目錄

          gid =? root????????????????????????????????????????????? # root 組身份訪問文件目錄

          use chroot = yes??????????????????????????????????????? # 可以使用 chroot

          max connections = 1????????????????????????????????? # 最大連接數

          syslog facility = local5??????????????????????????????

          pid file = /var/run/rsyncd.pid?????????????????????

          hosts allow = 10.1.4.13????????????????????????????? # 只允許 10.1.4.13 訪問

          [grpdomain1]?????????????????????????????????????????? # 這是一個發布項,可以發布多個

          ??????? path=/data/bea/user_projects/grpdomain1????????????????? # 發布的路徑

          ??????? read only=yes????????????????????????????????????????????????????????? # 只讀

          ??????? list = yes??????????????????????????????????????????????????????????????? # 允許列文件清單

          ??????? comment=CenGRP3.0,Sinopec Portal Web Server.????? # 描述信息

          文件在本文所附的目錄中可以找到,名稱: ServerA\rsyncd.conf

          [grpdomain1] 將作為其他服務器訪問 Server A rsync 發布目錄的一個發布名,這樣的小節可以根據需要存在多個。

          b) ??????? 以守護進程方式啟動 rsync 服務,命令如下:

          /usr/local/bin/rsync --daemon&

          c) ??????? 配置 rsync 自啟動

          vi /etc/rc3.d/S99Rsync? ??????????????????????????? # 編輯 /etc/rc3.d/S99Rsync

          chmod 700 /etc/rc3.d/S99Rsync ???????????????? # 設置文件可以被屬主( root )讀寫執行

          文件內容如下:

          /usr/local/bin/ rsync --daemon&

          文件在本文所附的目錄中可以找到,名稱: ServerA\S99Rsync

          d) ??????? 驗證服務

          登陸 Server B ,執行命令:

          /usr/local/bin/rsync -ztruvoglp --progress rsync://10.1.3.87

          grpdomain1????? CenGRP3.0,Sinopec Portal Web Server.????????????? # 執行結果

          列出了 Server A 上面發布的目錄的名稱,說明配置成功

          3、 ? Server B 上面設置自動獲取 Server A 上的文件

          a) ???????? 為了方便管理,把腳本文件放置在 Server B 上的特定目錄下,下面的命令建立目錄 /data/rsync

          mkdir /data/rsync

          b) ??????? 建立不同步文件的列表清單,清單文件名自己定義,該文件可選,如果不建立該文件,可以直接在后面步驟 C) 的腳本命令中使用參 --exclude 來直接指明。

          vi /data/rsync/grpdomain1_exclude_file.list

          文件每行表示一條,支持通配符,以發布項作為當前目錄,文件內容如下:

          grpdomain1.log*??? # 表示 /data/bea/user_projects/grpdomain1/grpdomain1.log* 不同步

          newgrplog???????????? # 表示 /data/bea/user_projects/grpdomain1/newgrp 目錄及子目錄

          home/logs

          applications/cenep/WEB-INF/log

          文件在本文所附的目錄中可以找到,名稱: ServerB\grpdomain1_exclude_file.list

          c) ??????? 建立同步腳本,可以根據需要建立多個腳本,每個腳本定義自己的調度計劃(見后)

          vi /data/rsync/rsync-grpdomain1.sh??????????????????? # 編輯文件

          chmod 700 /data/rsync/rsync-grpdomain1.sh???????????? # 設置文件為僅屬主可讀些執行

          文件內容如下,注意不要換行:

          /usr/local/bin/rsync –ztruvoglp --exclude-from=/data/rsync/grpdomain1_exclude_file.list --delete --progress rsync://10.1.4.10/grpdomain1 /data/bea/user_projects/grpdomain1

          參數說明:

          l ???????? --ztruvoglp ,表示的是壓縮傳輸、包含子目錄、保持相同的權限等,可不理會。

          l ???????? --exclude-from ,指明從那個文件讀取除外文件清單

          l ???????? --delete ,指明當文件被從 Server A 上刪除后,也在 Server B 上刪除

          l ???????? --progress ,是否在控制臺上顯示明細,如果在定時任務中運行,最好不增加該參數。

          l ???????? --exclude ,在命令行上直接指明那些文件不同步,格式 --exclude=”hgFF

          l ???????? rsync://10.1.4.10:873/grpdomain1 同布的源, 873 是缺省端口,可忽略

          l ???????? /data/bea/user_projects/grpdomain1 同步目的地

          d) ??????? 文件在本文所附的目錄中可以找到,名稱: ServerB\rsync-grpdomain1.sh

          e) ???????? 檢測腳本是否正確,直接執行命令: /data/rsync/rsync-grpdomain1.sh

          f) ???????? 設定每天 0 點執行同步命令,執行下面的命令

          crontab -e ??????????????????????????? # 編輯當前用戶的調度表

          顯示的是一個 vi 界面,文件的內容可能如下,其中黑體部分是我們添加的:

          #ident? "@(#)root?????? 1.20??? 01/11/06 SMI"

          #

          # The root crontab should be used to perform accounting data collection.

          #

          # The rtc command is run to adjust the real time clock if and when

          # daylight savings time changes.

          #

          10 3 * * * /usr/sbin/logadm

          15 3 * * 0 /usr/lib/fs/nfs/nfsfind

          1 2 * * * [ -x /usr/sbin/rtc ] && /usr/sbin/rtc -c > /dev/null 2>&1

          30 3 * * * [ -x /usr/lib/gss/gsscred_clean ] && /usr/lib/gss/gsscred_clean

          # 每天的晚上 24 點運行同步腳本 , 10 上的 grpdomain1 文件拷貝到本機

          0 0 * * * /data/rsync/rsync-grpdomain1.sh

          #10 3 * * * /usr/lib/krb5/kprop_script ___slave_kdcs___

          起作用的是 0 0 * * * /data/rsync/rsync-grpdomain1.sh 其中前面由空格間隔開的五項分別代表分鐘 小時 星期

          g)???????? 定時服務的啟動和停止:

          /etc/init.d/cron stop?????? ?????? ?????? ?????? # 停止定時服務

          /etc/init.d/cron start?????? ?????? ?????? ?????? # 啟動定時服務

          ?

          4、 ? 更多的文件目錄的同步之 ServerA 的操作

          a) ???????? 修改 ServerA /etc/rsyncd.conf ,增加新的描述,參見 [grpdomain1] 的描述

          b) ??????? 停止 Server A 上的 rsync 守候進程,命令:

          ps –ef|grep rsync?? ????????????? # 顯示 rsync 進程

          kill 888????????????????? ????????????? #888 要根據實際的進程號替換

          c) ??????? 重新啟動守候進程,執行:
          /usr/local/bin/rsync –daemon

          5、 ? 更多的文件目錄的同步之 ServerB 的操作,參見步驟 3

          參考資料:

          1、 ? rsync 資料同步 .mht???????

          2、 ? Cron 服務配置詳解 .mht

          posted on 2006-04-26 15:27 惡魔 閱讀(5140) 評論(1)  編輯  收藏 所屬分類: Sun Solaris

          評論

          # re: 采用rsync實現兩臺solaris服務之間的文件同步 2006-11-09 16:10 test[匿名]  回復  更多評論   

          文檔寫得非常清晰完整,非常感謝!
          主站蜘蛛池模板: 鄱阳县| 确山县| 海淀区| 汉沽区| 文登市| 区。| 鹤岗市| 西青区| 满城县| 兴国县| 咸阳市| 襄汾县| 中阳县| 内丘县| 手机| 安新县| 册亨县| 南投县| 塔城市| 永善县| 永清县| 东丰县| 娄底市| 连南| 玛多县| 普格县| 东源县| 兰西县| 永宁县| 响水县| 山丹县| 彭州市| 武冈市| 如皋市| 桑日县| 平遥县| 宿松县| 永顺县| 浏阳市| 鲁甸县| 迭部县|