欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

CentOS5 + rsync 同步2臺服務(wù)器的文件

 更新時間:2010年12月05日 12:16:07   作者:  
CentOS 5 + rsync 同步2臺服務(wù)器的文件,需要服務(wù)器同步的朋友可以參考下。

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

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

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

一、服務(wù)器端配置:
# yum -y install xinetd

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

復(fù)制代碼 代碼如下:

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

復(fù)制代碼 代碼如下:

# /etc/init.d/xinetd start

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

復(fù)制代碼 代碼如下:

# 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

復(fù)制代碼 代碼如下:

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

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

# vi /etc/rsyncd.secrets

復(fù)制代碼 代碼如下:

admin:1234 #用戶名:密碼

給文件正確的權(quán)限
# 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的權(quán)限.
d) 查看遠程主機目錄內(nèi)容
*注1:remote shell模式, 通過ssh連接的基于系統(tǒng)本地用戶的身份驗證
*注2:這里只使用了一個冒號(:),同時用戶名是遠程主機的ssh 用戶,密碼也是ssh用戶對應(yīng)的密碼。
*注3:使用””,則列出文件夾本身的信息。若要列出文件夾內(nèi)容,應(yīng)使用”/”。

參數(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)容到本地目錄

相關(guān)文章

  • apache虛擬主機的配置指南

    apache虛擬主機的配置指南

    本文介紹了apache虛擬主機的配置的方法,要配置apache的虛擬主機,我們需要分以下幾步進行:檢查apache虛擬主機模塊,開啟apache虛擬主機功能,httpd-vhosts.conf文件詳解,根據(jù)IP配置虛擬主機,根據(jù)端口配置虛擬主機,根據(jù)域名配置虛擬主機,有需要的小伙伴參考下
    2015-01-01
  • 基于linux程序中段的學習總結(jié)詳解

    基于linux程序中段的學習總結(jié)詳解

    本篇文章是對linux程序中段的學習進行了詳細的總結(jié)與分析,需要的朋友參考下
    2013-05-05
  • linux命令:echo使用解讀

    linux命令:echo使用解讀

    這篇文章主要介紹了linux命令之關(guān)于echo的使用,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-04-04
  • Apache?APISIX?Dashboard?未授權(quán)訪問漏洞分析(CVE-2021-45232)

    Apache?APISIX?Dashboard?未授權(quán)訪問漏洞分析(CVE-2021-45232)

    Apache?APISIX?是一個動態(tài)、實時、高性能的?API?網(wǎng)關(guān),?提供負載均衡、動態(tài)上游、灰度發(fā)布、服務(wù)熔斷、身份認證、可觀測性等豐富的流量管理功能,這篇文章主要介紹了Apache?APISIX?Dashboard?未授權(quán)訪問漏洞(CVE-2021-45232),需要的朋友可以參考下
    2023-03-03
  • 80端口被system占用導致Apache無法啟動的解決方法

    80端口被system占用導致Apache無法啟動的解決方法

    本文給大家介紹80端口被system占用導致Apache無法啟動的解決方法,非常不錯,一起看看吧
    2016-12-12
  • centos 7中設(shè)置tomcat 7為系統(tǒng)服務(wù)的方法詳解

    centos 7中設(shè)置tomcat 7為系統(tǒng)服務(wù)的方法詳解

    這篇文章主要給大家介紹了關(guān)于在centos 7中設(shè)置tomcat 7為系統(tǒng)服務(wù)的相關(guān)資料,文中介紹的非常詳細,對大家具有一定的參考學習價值,需要的朋友們下面來跟著小編一起學習學習吧。
    2017-06-06
  • Linux目錄切換實現(xiàn)代碼案例

    Linux目錄切換實現(xiàn)代碼案例

    這篇文章主要介紹了Linux目錄切換實現(xiàn)代碼案例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-09-09
  • LNMP服務(wù)器環(huán)境配置 (linux+nginx+mysql+php)

    LNMP服務(wù)器環(huán)境配置 (linux+nginx+mysql+php)

    在高并發(fā)連接的情況下,Nginx是Apache服務(wù)器不錯的替代品。Nginx同時也可以作為7層負載均衡服務(wù)器來使用。Nginx 0.8.46 + PHP 5.2.14 (FastCGI) 可以承受3萬以上的并發(fā)連接數(shù),相當于同等環(huán)境下Apache的10倍
    2014-07-07
  • Apache Ant自動化腳本入門教程及常用命令介紹

    Apache Ant自動化腳本入門教程及常用命令介紹

    這篇文章主要介紹了Apache Ant自動化腳本入門教程及常用命令介紹的相關(guān)資料,需要的朋友可以參考下
    2016-06-06
  • CentOS 最新版本git的安裝教程

    CentOS 最新版本git的安裝教程

    本文主要給大家介紹了CentOS 最新版本git的安裝教程,非常不錯,具有參考借鑒價值,感興趣的朋友一起看看吧
    2016-11-11

最新評論