操作系統(tǒng):CentOS 7u3
源服務(wù)器:192.168.30.147
目標(biāo)服務(wù)器:192.168.30.148
目的:把源服務(wù)器上/home_test目錄實(shí)時(shí)同步到目標(biāo)服務(wù)器的/home_test下
首先關(guān)閉兩臺(tái)設(shè)備的selinux
臨時(shí)更改為setenforce 0,永久更改為修改/etc/sysconfig/selinux,將SELINUX=enforcing修改為SELINUX=diabled或者SELINUX=permissive
一、在目標(biāo)服務(wù)器安裝Rsync服務(wù)端(centos2)
安裝Rsync服務(wù)端軟件
rhel7:
#yum -y install rsync
創(chuàng)建rsyncd.conf配置文件
#vi /etc/rsyncd.conf #7上有默認(rèn)配置文件,rhel6上沒有默認(rèn)文件要自己創(chuàng)建配置文件,添加以下代碼
log file = /var/log/rsyncd.log
pidfile = /var/run/rsyncd.pid?
lock file = /var/run/rsync.lock?
secrets file = /etc/rsync.pass? #用戶認(rèn)證配置文件,里面保存用戶名稱和密碼,后面會(huì)創(chuàng)建這個(gè)文件
motd file = /etc/rsyncd.Motd? #rsync啟動(dòng)時(shí)歡迎信息頁面文件位置(文件內(nèi)容自定義)
[home_test] #同步模塊名稱
path = /home_test #rsync服務(wù)端數(shù)據(jù)目錄路徑
comment = home_test
uid = root
gid = root
port=873?
use chroot = no
read only = no?
list = no #不顯示rsync服務(wù)端資源列表
max connections = 200
timeout = 600?
auth users = user1 #執(zhí)行數(shù)據(jù)同步的用戶名,可以設(shè)置多個(gè),用英文狀態(tài)下逗號(hào)隔開
hosts allow = 192.168.30.147?#允許進(jìn)行數(shù)據(jù)同步的客戶端IP地址,可以設(shè)置多個(gè),用英文狀態(tài)下逗號(hào)隔開
hosts deny = *
創(chuàng)建用戶認(rèn)證文件
#vim /etc/rsync.pass
user1:123456 #格式,用戶名:密碼,可以設(shè)置多個(gè),每行一個(gè)用戶名:密碼,或者用echo"user1:123456" > /etc/rsync.pass
設(shè)置文件權(quán)限
chmod 600 /etc/rsyncd.conf #設(shè)置文件所有者讀取、寫入權(quán)限
chmod 600 /etc/rsync.pass #設(shè)置文件所有者讀取、寫入權(quán)限
mkdir /home_test
啟動(dòng)rsync
centos7 :
#systemctl restart rsyncd
centos 6:需要yum -y install xinetd服務(wù)
#/etc/init.d/xinetd start #啟動(dòng)
#service xinetd stop #停止
#service xinetd restart #重新啟動(dòng)
第二部分:在源服務(wù)器192.168.30.147上操作
一、安裝Rsync客戶端軟件
#yum install rsync
創(chuàng)建認(rèn)證密碼文件
#vim /etc/rsync.pass
123456 #密碼
chmod 600 /etc/rsync.pass #設(shè)置文件權(quán)限,只設(shè)置文件所有者具有讀取、寫入權(quán)限即可
mkdir /home_test/ceshi #在源服務(wù)器上創(chuàng)建測(cè)試文件夾,然后在源服務(wù)器運(yùn)行下面命令
rsync -avH –port=873 –progress –delete /home_test/ user1@192.168.36.82::home_test/ –password-file=/etc/rsync.pass
測(cè)試成功
更多關(guān)于云服務(wù)器,域名注冊(cè),虛擬主機(jī)的問題,請(qǐng)?jiān)L問西部數(shù)碼官網(wǎng):m.ps-sw.cn