linux rsync 指定使用者名稱和密碼的方式同步
rsync 客戶端 172.17.0.29
rsync 服務端 --daemon 方式執行 172.17.0.31 備份端
以下首先說明服務端的安裝情況:
1 檢查是否安裝rsync
rpm -qa rsync
rsync-3.0.6-12.el6.x86_64 如果沒有安裝進行yum 安裝即可
yum install -y rsync
yum install -y xinetd
/etc/init.d/xinetd status
/etc/init.d/xinetd restart
2 useradd rsync -s /sbin/nologin -M
mkdir /backup
chown rsync.rsync /backup
3 編寫rsync daemon 配置檔案/etc/rsyncd.conf
##rsyncd.conf start###工作中指定使用者(需要指定使用者)
uid = rsync
gid = rsync
use chroot = no
max connections = 200
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
【backup】指定模組
path = /backup
read only = false
list = false
hosts allow = 172.17.0.29/32 允許的地址連線
hosts deny = 0.0.0.0/32 拒絕的地址連線
auth users = rsync_backup #虛擬使用者名稱
secrets file = /etc/rsync.password #對應的密碼
rsync_config_______________end
[backup01] #注意這裡指定模組的方式方法,因為在客戶端需要指定這個地方,否則導致同步 失敗的奇葩現象
path = /backup01
4 建立上述配置中指定的虛擬賬號和密碼:
echo "rsync_backup:123456">/etc/rsync.password
chmod 600 /etc/rsync.password # 注意許可權
[[email protected] backup01]# cat /etc/rsync.password
rsync_backup:123456
5 啟動服務
rsync --daemon
[[email protected] backup01]# cat /etc/rc.local 追加開機啟動
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
/usr/local/mfs/sbin/mfsmaster start
rsync --daemon
which rsync
也可以echo "/etc/bin/rsync --daemon" >> /etc/rc.local
[[email protected] ~]# ps -ef |grep rsync
root 1432 1 0 16:57 ? 00:00:00 rsync --daemon
[[email protected] ~]# ss -tnlp | grep rsync 檢視873 存在873埠
LISTEN 0 5 :::873 :::* users:(("rsync",1432,5))
LISTEN 0 5 *:873 *:* users:(("rsync",1432,3)
[[email protected] /]# rsync -avz disk.txt [email protected]::backup/ --password-file=/etc/rsync.password
rsync: failed to connect to 172.17.0.16: No route to host (113)
rsync error: error in socket IO (code 10) at clientserver.c(124) [sender=3.0.6]
You have new mail in /var/spool/mail/root
出現錯誤的方法:
檢查伺服器的埠netstat –tunlp,遠端telnet測試。
可能因為客戶端或者服務端的防火牆開啟 導致無法通訊,可以設定規則放行 rsync(873埠) 或者直接關閉防火牆。
6 客戶端的安裝方法:
echo "123456" > /etc/rsync.password # 這裡只填寫密碼即可
chmod 600 /etc/rsync.password # 注意許可權 (這一步不配置出現password file must not be other-accessible
continuing without password file
Password:
@ERROR: auth failed on module backup
rsync error: error starting client-server protocol (code 5) at main.c(1503) [sender=3.0.6])
rsync -avz moosefs-3.0.81-1.tar.gz [email protected]::backup01 --password-file=/etc/rsync.password # 目錄同步並指定相應的密碼檔案
rsync -avzp --delete /data [email protected]::backup01 --password-file=/etc/rsync.password
注意:這裡/data 目錄的區別
/data 同步目錄
/data/ 同步目錄下的檔案
/data/* 同步目錄下的檔案
[[email protected] /]# scp -r /data/ [email protected]:/backup2016/ 複製目錄
scp -r /data/* [email protected]:/backup2016/ 複製目錄下的檔案