兩臺centos 6.3 64位服務器 ip地址分別爲 192.168.1.97,192.168.1.96
其中 192.168.1.97作爲rsync服務端,192.168.1.96作爲客戶端
【服務端設置】
注意:關閉防火牆和selinux的設置
service iptables stop(臨時關閉防火牆)
1.查看是否安裝rsync
rpm -qa rsync (或者 yum list installed | grep rsync )
2.若沒有安裝rsync
yum -y install rsync
3.創建rsync配置文件
vi /etc/rsyncd.conf
uid = nobody (任何用戶)
gid = nobody (任何組)
user chroot = no (不允許列清單)
max connections = 200 (最大連接數)
timeout = 600 (超時時間)
pid file =/var/run/rsyncd.pid (PID文件存放的位置)
lock file = /var/run/rsyncd.lock(鎖文件的存放位置)
log file = /var/log/rsyncd.log (日誌文件位置)
hosts allow = 192.168.1.96 (允許連接的IP)
hosts deny = * (其餘全部拒絕)
[log] (認證模塊,就是對外公佈的名字)
# sync of dir path
path = /www/web/ (同步目錄)
Miss I/O errors (忽略一些無關的I/O錯誤)
ignore errors = yes (忽略一些無關的I/O錯誤)
read only = no (只允許讀和寫)
list = no (表示不允許列表清單)
hosts allow = 192.168.1.96 (只允許指定IP同步,拒絕其他一切連接)
hosts deny = *
# use username
auth users= andy (認證的用戶名)
# password file
secrets file=/etc/rsyncd.password (密碼文件存放位置)
4.啓動rsync,可通過xinetd來控制,所以我們先需要安裝xinetd
yum -y install xinetd
5、對rsync進行修改,我們先編輯rsync相關的文件/etc/xinetd.d/rsync
service rsync
{
disable = no
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}
這裏主要降disable=yes 改爲 no。
重啓xinetd服務
service xinetd restart
6.創建同步目錄
mkdir -p /www/web
chmod -R 777 /www/web
echo "andy:andy" < /etc/rsyncd.password (用戶名:密碼 要求是系統中存在的用戶)
chmod 600 /etc/rsyncd.password
7、開啓防火牆tcp 873端口(Rsync默認端口)
vi /etc/sysconfig/iptables #編輯防火牆配置文件
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 873 -j ACCEPT
:wq! #保存
service iptables restart #最後重啓防火牆使配置生效
【客戶端設置】
1.查看是否安裝rsync
rpm -qa rsync (或者 yum list installed | grep rsync )
2.若沒有安裝rsync
yum -y install rsync
3.創建存放服務器端用戶密碼的文件
echo "andy" < /etc/rsyncd.password (這裏指需要密碼,不需要寫用戶名)
chmod 600 /etc/rsyncd.password
4.進行同步
rsync -vzrtopg --delete /home/andy/logs [email protected]::log --password-file=/etc/rsyncd.password
(delete後面是要同步的文件路徑 ::後面是在rsyncd.conf文件中設置的模塊名稱)
常見故障解決思路:
1.查看文件權限,服務器端和客戶端一致
2.查看客戶端是否提供正確的密碼或服務器端的用戶和密碼是否無誤。
3.查看模塊名稱是否正確
4.服務端是否啓動