CentOS5 + rsync 同步2臺(tái)服務(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
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:
Password
Task: Synchronize a local directory with a remote directory
Task: Synchronize a remote directory with a local directory
Task: Synchronize a local directory with a remote rsync server
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)
===================================================
當(dāng)需要把服務(wù)器上的文件復(fù)制到另外的機(jī)器上,可用rsync來同步文件。
一、服務(wù)器端配置:
# 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
然后啟動(dòng) xinetd
# /etc/init.d/xinetd start
注意:如果服務(wù)器上裝有防火墻記得要打開端口,默認(rèn)端口是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
[服務(wù)器代號(hào)]
path = 備份文件路徑
auth users = 授權(quán)帳號(hào)
uid = 執(zhí)行時(shí)的uid
gid = 執(zhí)行時(shí)的gid
secrets file = 密碼文件位置
read only = 是否只讀
# vi /etc/rsyncd.secrets
admin:1234 #用戶名:密碼
給文件正確的權(quán)限
# chown root:root /etc/rsyncd.secrets
# chmod 600 /etc/rsyncd.secrets
二、client 端進(jìn)行同步
客戶端默認(rèn)好像已經(jīng)裝了rsync,沒有的話裝下:
# yum -y install rsync
執(zhí)行異步同步操作:
同步命令說明:
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) 顯示遠(yuǎn)程主機(jī)目錄內(nèi)容
*注1:端口模式, 基于rsync用戶的身份驗(yàn)證
*注2:rsync server上的目錄必須具有xx7的權(quán)限.
d) 查看遠(yuǎn)程主機(jī)目錄內(nèi)容
*注1:remote shell模式, 通過ssh連接的基于系統(tǒng)本地用戶的身份驗(yàn)證
*注2:這里只使用了一個(gè)冒號(hào)(:),同時(shí)用戶名是遠(yuǎn)程主機(jī)的ssh 用戶,密碼也是ssh用戶對(duì)應(yīng)的密碼。
*注3:使用””,則列出文件夾本身的信息。若要列出文件夾內(nèi)容,應(yīng)使用”/”。
參數(shù)說明
———
-r 對(duì)目錄進(jìn)行遞歸操作
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) 對(duì)src-dir目錄內(nèi)容向dst-dir目錄下進(jìn)行差異更新,有增加/更新則添加替換,有減少則對(duì)其刪減
d) 比a)多了–temp-dir=/tmp,即指定/tmp為臨時(shí)交換區(qū),這樣可以避免因目標(biāo)目錄空間不夠引起的無法同步文件的錯(cuò)誤。
參數(shù)說明
———
-a 相當(dāng)于 -rlptgoD 的集合
-u 等同于 –update,在目標(biāo)文件比源文件新的情況下不更新
-v 顯示同步的文件
–progress 顯示文件同步時(shí)的百分比進(jìn)度、傳輸速率
–delete 刪除目標(biāo)目錄中多于源目錄的文件
3 異地主機(jī)之間同步
命令
——
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)容到遠(yuǎn)程主機(jī)192.168.0.1的目錄下,jack是rsync數(shù)據(jù)庫用戶(參見3. /etc/rsync.secrets)
b) 通過自動(dòng)讀取用戶密碼而實(shí)現(xiàn)非交互登錄文件同步
c) 較b)多了-u和–delete
d) 同步遠(yuǎn)程主機(jī)內(nèi)容到本地目錄
- CentOS6.5平臺(tái)上rsync服務(wù)器安裝配置方法簡(jiǎn)述
- CentOS6.5環(huán)境下使用rsync增量同步備份文件的方法
- CentOS Rsync服務(wù)端與Windows cwRsync客戶端實(shí)現(xiàn)數(shù)據(jù)同步配置方法
- CentOS 6.3 Rsync客戶端與Win2003 cwRsyncServer服務(wù)端實(shí)現(xiàn)數(shù)據(jù)同步
- Centos rsync文件同步配置步驟分享
- centos下mysql主從同步快速設(shè)置步驟分享
- Mysql 主從數(shù)據(jù)庫同步(centos篇)
- CentOS服務(wù)器平臺(tái)搭建mysql主從復(fù)制與讀寫分離的方法
- CentOS6.5系統(tǒng)簡(jiǎn)單安裝與配置Nginx服務(wù)器的方法
- CentOS平臺(tái)實(shí)現(xiàn)搭建rsync遠(yuǎn)程同步服務(wù)器的方法
相關(guān)文章
CentOS6 配置Nginx,MySql,php-fpm開機(jī)啟動(dòng)的方法
這篇文章主要介紹了CentOS6 配置Nginx,MySql,php-fpm開機(jī)啟動(dòng)的方法的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-10-10
Linux工具之Nethogs按進(jìn)程監(jiān)控網(wǎng)絡(luò)帶寬的安裝部署
NetHogs是一個(gè)小型的net top工具,不像大多數(shù)工具那樣拖慢每個(gè)協(xié)議或者是每個(gè)子網(wǎng)的速度而是按照進(jìn)程進(jìn)行帶寬分組,這篇文章主要介紹了Linux工具Nethogs按進(jìn)程監(jiān)控網(wǎng)絡(luò)帶寬,值得收藏,需要的朋友可以參考下2019-07-07
Linux使用nload監(jiān)控網(wǎng)絡(luò)流量的方法
Linux 中的 nload 命令是一個(gè)用于實(shí)時(shí)監(jiān)控網(wǎng)絡(luò)流量的工具,它提供了傳入和傳出流量的可視化表示,幫助用戶一目了然地了解網(wǎng)絡(luò)活動(dòng),本文給大家介紹了Linux使用nload監(jiān)控網(wǎng)絡(luò)流量的方法,需要的朋友可以參考下2025-02-02
Linux下Redis設(shè)置密碼及開機(jī)自啟動(dòng)
這篇文章主要介紹了Linux下Redis設(shè)置密碼及開機(jī)自啟動(dòng)的相關(guān)資料,需要的朋友可以參考下2016-12-12

