前言:本章主要講解實現快速、安全、高效的異地備份
實驗環境:服務端A 192.168.1.10 客戶端B 192.168.1.20
一,安裝rsync yum -y install rsync*
新建配置文件 vi /etc/rsyncd.conf
uid = nobody
gid = nobody
use chroot = yes
address = 192.168.1.10
port 873
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
hosts allow = 192.168.1.0/24
[yy]
path = /var/www/html
comment = ccccccccccccc
read only = yes
dont compress = *.gz *.bz2
auth users =bin
secrets file = /etc/rsyncd_users.db
注意:如果採用匿名同步的方式,只要將其中的auth users和secrets file配置記錄去掉就可以了。
二,創建密碼認證文件 vi /etc/rsyncd_users.db
bin:123
保存退出
修改密碼文件權限 chmod 600 /etc/rsyncd_users.db
三,啓動rsync rsync --daemon ps -ef | grep rsync 查看進程。
如若想要結束進程 kill 進程號 殺掉
1,使用rsync 本地備份 將文件 /etc/fastab 備份到 /tmp下
rsync -rl /etc/fastab /tmp/
2,使用遠程備份 使用客戶端, 首先配置服務端防火牆 iptables -I INPUT -p tcp --dport 873 -j ACCEPT
service iptables save 保存防火牆
四,客戶端配置
1,創建測試目錄 mkdir /rsync
2.同步rsync共享目錄
# rsync [email protected]::yy //瀏覽共享
vim /root/rsync_pass //設定密碼文件
123 //只需寫登錄用戶密碼,要與服務器端設置密碼一致
chmod 600 /root/rsync_pass //不修改權限會報錯
rsync -az --password-file=/root/rsync_pass [email protected]::yy /rsync //同步
3.將rsync放入crontab計劃任務,每天同步一次
#crontab -e
0 5 * * * /usr/bin/rsync -a --password-file=/root/rsync_pass [email protected]::yy /rsync