国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 服務器 > Web服務器 > 正文

CentOS5 + rsync 同步2臺服務器的文件

2024-09-01 13:45:48
字體:
供稿:網(wǎng)友
Always use rsync over ssh

Since rsync does not provide any security while transferring data it is recommended that you use rsync over ssh . This allows a secure remote connection. Now let us see some examples of rsync.

rsync command common options
  • --delete : delete files that don't exist on sender (system)
  • -v : Verbose (try -vv for more detailed information)
  • -e "ssh options" : specify the ssh as remote shell
  • -a : archive mode
  • -r : recurse into directories
  • -z : compress file data
  • Task : Copy file from a local computer to a remote server

    Copy file from /www/backup.tar.gz to a remote server called openbsd.nixcraft.in

    $ rsync -v -e ssh /www/backup.tar.gz jerry@openbsd.nixcraft.in:~

    Output:

    Password: sent 19099 bytes received 36 bytes 1093.43 bytes/sec total size is 19014 speedup is 0.99

    Please note that symbol ~ indicate the users home directory (/home/jerry).

    Task : Copy file from a remote server to a local computer

    Copy file /home/jerry/webroot.txt from a remote server openbsd.nixcraft.in to a local computer /tmp directory:

    $ rsync -v -e ssh jerry@openbsd.nixcraft.in:~/webroot.txt /tmp

    Password

    Task: Synchronize a local directory with a remote directory

    $ rsync -r -a -v -e "ssh -l jerry" --delete openbsd.nixcraft.in:/webroot/ /local/webroot

    Task: Synchronize a remote directory with a local directory

    $ rsync -r -a -v -e "ssh -l jerry" --delete /local/webroot openbsd.nixcraft.in:/webroot

    Task: Synchronize a local directory with a remote rsync server

    $ rsync -r -a -v --delete rsync://rsync.nixcraft.in/cvs /home/cvs

    Task: Mirror a directory between my "old" and "new" web server/ftp

    You can mirror a directory between my "old" (my.old.server.com) and "new" web server with the command (assuming that ssh keys are set for password less authentication)

    $ rsync -zavrR --delete --links --rsh="ssh -l vivek" my.old.server.com:/home/lighttpd /home/lighttpd

    ===================================================

    當需要把服務器上的文件復制到另外的機器上,可用rsync來同步文件。

    一、服務器端配置:
    # yum -y install xinetd

    # vi /etc/xinetd.d/rsync
    將如下代碼

    復制代碼 代碼如下:


    service rsync
    {
    disable = yes
    socket_type = stream
    wait = no
    user = root
    server = /usr/bin/rsync
    server_args = –daemon
    log_on_failure += USERID
    }


    中的 disable = yes 改成 disable = no

    然后啟動 xinetd

    復制代碼 代碼如下:


    # /etc/init.d/xinetd start


    注意:如果服務器上裝有防火墻記得要打開端口,默認端口是873

    復制代碼 代碼如下:


    # telnet 127.0.0.1 873


    Trying 127.0.0.1...
    telnet: connect to address 127.0.0.1: Connection refused
    # iptables -A INPUT -s 192.168.0.0/255.255.255.0 -p tcp -m tcp --dport 873 -j ACCEPT
    # iptables -A INPUT -p tcp -m tcp --dport 873 -j DROP

    # vi /etc/rsyncd.conf

    復制代碼 代碼如下:


    [backup]
    path = /www
    auth users = admin
    uid = root
    gid = root
    secrets file = /etc/rsyncd.secrets
    read only = no


    [服務器代號]
    path = 備份文件路徑
    auth users = 授權帳號
    uid = 執(zhí)行時的uid
    gid = 執(zhí)行時的gid
    secrets file = 密碼文件位置
    read only = 是否只讀

    # vi /etc/rsyncd.secrets

    復制代碼 代碼如下:


    admin:1234 #用戶名:密碼


    給文件正確的權限
    # chown root:root /etc/rsyncd.secrets
    # chmod 600 /etc/rsyncd.secrets

    二、client 端進行同步
    客戶端默認好像已經(jīng)裝了rsync,沒有的話裝下:
    # yum -y install rsync

    執(zhí)行異步同步操作:

    /usr/bin/rsync -avz –progress  admin@192.168.1.105::backup /www

    同步命令說明:

    1 顯示目錄內(nèi)容

    命令
    ——
    a) rsync
    b) rsync -r
    c) rsync jack@192.168.0.1::
    d) rsync ssh_user@192.168.0.1:

    命令說明
    ———
    a) 顯示目錄內(nèi)容(第一層)
    b) 遞歸顯示目錄內(nèi)容
    c) 顯示遠程主機目錄內(nèi)容
    *注1:端口模式, 基于rsync用戶的身份驗證
    *注2:rsync server上的目錄必須具有xx7的權限.
    d) 查看遠程主機目錄內(nèi)容
    *注1:remote shell模式, 通過ssh連接的基于系統(tǒng)本地用戶的身份驗證
    *注2:這里只使用了一個冒號(:),同時用戶名是遠程主機的ssh 用戶,密碼也是ssh用戶對應的密碼。
    *注3:使用””,則列出文件夾本身的信息。若要列出文件夾內(nèi)容,應使用”/”。

    參數(shù)說明
    ———
    -r 對目錄進行遞歸操作

    2 本地目錄之間同步

    命令
    ——
    a) rsync -av –progress / *** 注意(/) ***
    b) rsync -av –progress
    c) rsync -avu –progress –delete /
    d) rsync -av –progress –temp-dir=/tmp /

    命令說明
    ———
    a) 同步src-dir目錄下所有文件到dst-dir目錄下
    b) 同步src-dir目錄下所有文件到dst-dir/src-dir目錄下
    c) 對src-dir目錄內(nèi)容向dst-dir目錄下進行差異更新,有增加/更新則添加替換,有減少則對其刪減
    d) 比a)多了–temp-dir=/tmp,即指定/tmp為臨時交換區(qū),這樣可以避免因目標目錄空間不夠引起的無法同步文件的錯誤。

    參數(shù)說明
    ———
    -a 相當于 -rlptgoD 的集合
    -u 等同于 –update,在目標文件比源文件新的情況下不更新
    -v 顯示同步的文件
    –progress 顯示文件同步時的百分比進度、傳輸速率
    –delete 刪除目標目錄中多于源目錄的文件

    3 異地主機之間同步
    命令
    ——
    a) rsync -avz –progress jack@192.168.0.1::/
    b) rsync -avz –progress jack@192.168.0.1::/ –password-file=/home/jack/rsync.jack
    c) rsync -avuz –progress –delete jack@192.168.0.1::/ –password-file=/home/jack/rsync.jack
    d) rsync -avz –progress jack@192.168.0.1::/

    命令說明
    ———
    a) 同步本地目錄的內(nèi)容到遠程主機192.168.0.1的目錄下,jack是rsync數(shù)據(jù)庫用戶(參見3. /etc/rsync.secrets)
    b) 通過自動讀取用戶密碼而實現(xiàn)非交互登錄文件同步
    c) 較b)多了-u和–delete
    d) 同步遠程主機內(nèi)容到本地目錄

    發(fā)表評論 共有條評論
    用戶名: 密碼:
    驗證碼: 匿名發(fā)表
    主站蜘蛛池模板: 会东县| 江陵县| 常德市| 马山县| 建德市| 枝江市| 津南区| 贵州省| 祥云县| 杨浦区| 江孜县| 德兴市| 乐平市| 天峨县| 礼泉县| 襄垣县| 中超| 昭苏县| 阿瓦提县| 游戏| 兖州市| 明光市| 广灵县| 陆良县| 双城市| 张家川| 军事| 中牟县| 乐山市| 临夏县| 南康市| 新巴尔虎左旗| 洪湖市| 永昌县| 东乡族自治县| 青阳县| 芒康县| 张家港市| 如皋市| 都安| 孝感市|