環境:
操作系統:CentOS 7u3
源服務器:192.168.30.147
目標服務器:192.168.30.148
目的:把源服務器上/home_test目錄實時同步到目標服務器的/home_test下
首先關閉兩臺設備的selinux
臨時更改爲setenforce 0,永久更改爲修改/etc/sysconfig/selinux,將SELINUX=enforcing修改爲SELINUX=diabled或者SELINUX=permissive
一、在目標服務器安裝Rsync服務端(centos2)
安裝Rsync服務端軟件
rhel7:
#yum -y install rsync
創建rsyncd.conf配置文件
#vi /etc/rsyncd.conf #7上有默認配置文件,rhel6上沒有默認文件要自己創建配置文件,添加以下代碼
log file = /var/log/rsyncd.log
pidfile = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
secrets file = /etc/rsync.pass #用戶認證配置文件,裏面保存用戶名稱和密碼,後面會創建這個文件
motd file = /etc/rsyncd.Motd #rsync啓動時歡迎信息頁面文件位置(文件內容自定義)
[home_test] #同步模塊名稱
path = /home_test #rsync服務端數據目錄路徑
comment = home_test
uid = root
gid = root
port=873
use chroot = no
read only = no
list = no #不顯示rsync服務端資源列表
max connections = 200
timeout = 600
auth users = user1 #執行數據同步的用戶名,可以設置多個,用英文狀態下逗號隔開
hosts allow = 192.168.30.147 #允許進行數據同步的客戶端IP地址,可以設置多個,用英文狀態下逗號隔開
hosts deny = *
創建用戶認證文件
#vim /etc/rsync.pass
user1:123456 #格式,用戶名:密碼,可以設置多個,每行一個用戶名:密碼,或者用echo"user1:123456" > /etc/rsync.pass
設置文件權限
chmod 600 /etc/rsyncd.conf #設置文件所有者讀取、寫入權限
chmod 600 /etc/rsync.pass #設置文件所有者讀取、寫入權限
mkdir /home_test
啓動rsync
centos7 :
#systemctl restart rsyncd
centos 6:需要yum -y install xinetd服務
#/etc/init.d/xinetd start #啓動
#service xinetd stop #停止
#service xinetd restart #重新啓動
第二部分:在源服務器192.168.30.147上操作
一、安裝Rsync客戶端軟件
#yum install rsync
創建認證密碼文件
#vim /etc/rsync.pass
123456 #密碼
chmod 600 /etc/rsync.pass #設置文件權限,只設置文件所有者具有讀取、寫入權限即可
mkdir /home_test/ceshi #在源服務器上創建測試文件夾,然後在源服務器運行下面命令
rsync -avH --port=873 --progress --delete /home_test/ [email protected]::home_test/ --password-file=/etc/rsync.pass
測試成功