一、服務(wù)器端(守護(hù)進(jìn)程):
1.1 配置rsyncd服務(wù)扎狱,并重啟服務(wù)和開(kāi)機(jī)自啟動(dòng)服務(wù)以及查看服務(wù)是否開(kāi)啟
1.1.1 先配置vim /etc/rsyncd.conf文件
##Rsync server
##created by oldboy 15:01 2009-6-5
##rsyncd.conf start##
fake super = yes
uid = rsync (uid指定rsync運(yùn)行的用戶侧到,虛擬用戶)
gid = rsync (gid指定rsync運(yùn)行的用戶,虛擬用戶)
use chroot = no
max connections = 2000(最大連接數(shù))
timeout = 600 (超時(shí)時(shí)間)
pid file = /var/run/rsyncd.pid(pid進(jìn)程號(hào))
lock file = /var/run/rsync.lock(鎖文件淤击,兩個(gè)窗口同時(shí)運(yùn)行yum)
log file = /var/log/rsyncd.log(日志匠抗,排錯(cuò)需要查看)
ignore errors
read only = false (關(guān)閉只讀)
list = false
#hosts allow = 10.0.0.0/24(白名單)
#hosts deny = 0.0.0.0/32(deny拒絕)
auth users = rsync_backup(指定認(rèn)證用戶,虛擬不存在)
secrets file = /etc/rsync.password(密碼文件)
#####################################
[data]
comment = www by old0boy 14:18 2012-1-13
path = /data (指定共享目錄)
#####################################
[backup](data模塊一般與目錄的名字相同)
comment = www by old0boy 14:18 2012-1-13
path = /backup (指定共享目錄)
1.1.2 配置完 /etc/rsyncd.conf文件后污抬,重啟服務(wù)
systemctl restart rsyncd (重啟服務(wù))
systemctl enable rsyncd (開(kāi)機(jī)自啟動(dòng)服務(wù))
1.1.3 查看是否啟動(dòng)和開(kāi)機(jī)自啟動(dòng)
[root@backup ~]# systemctl status rsyncd
● rsyncd.service - fast remote file copy program daemon
Loaded: loaded (/usr/lib/systemd/system/rsyncd.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2019-05-21 14:56:27 CST; 4h 36min ago
Main PID: 8891 (rsync)
CGroup: /system.slice/rsyncd.service
└─8891 /usr/bin/rsync --daemon --no-detach
May 21 14:56:27 backup systemd[1]: Stopped fast remote file copy program daemon.
May 21 14:56:27 backup systemd[1]: Started fast remote file copy program daemon.
[root@backup ~]# systemctl is-enabled rsyncd
enabled
1.1.4 查看進(jìn)程與端口是都開(kāi)啟
root@backup ~]# ps -ef |grep rsync
root 9749 1 0 16:12 ? 00:00:00 /usr/bin/rsync --daemon --no-detach
root 9751 9490 0 16:13 pts/1 00:00:00 grep --color=auto rsync
[root@backup ~]# ss -lntup|grep rsync
tcp LISTEN 0 5 *:873 *:* users:(("rsync",pid=9749,fd=3))
tcp LISTEN 0 5 :::873 :::* users:(("rsync",pid=9749,fd=5))
1.2 創(chuàng)建虛擬用戶rsync汞贸,創(chuàng)建backup塊目錄,并給backup目錄修改成rsync用戶主與用戶組
1.2.1 創(chuàng)建rsync虛擬用戶
[root@backup ~]# useradd -M -s /sbin/nologin rsync
1.2.2 創(chuàng)建backup塊目錄
[root@backup ~]# mkdir /backup
1.2.3給backup目錄修改成rsync用戶主與用戶組
[root@backup ~]# chown rsync.rsync /backup
1.3 創(chuàng)建密碼文件/etc/rsync.password,并寫(xiě)入密碼印机,然后授權(quán)600的權(quán)限
1.3.1 創(chuàng)建rsync.password文件矢腻,并寫(xiě)入密碼123456
[root@backup ~]# echo "rsync_backup:123456" >/etc/rsync.password
1.3.2 修改文件/etc/rsync.password的權(quán)限
[root@backup ~]# chmod 600 /etc/rsync.password
1.4 把/etc/hosts文件推到本地的backup塊目錄
[root@backup ~]# rsync -avz /etc/hosts rsync_backup@backup::backup
Password: (輸入/etc/rsync.password里的密碼)
sending incremental file list
hosts
sent 221 bytes received 49 bytes 108.00 bytes/sec
total size is 349 speedup is 1.29
二、客戶端(守護(hù)進(jìn)程):
2.1 創(chuàng)建密碼文件/etc/rsync.password,并寫(xiě)入密碼射赛,然后授權(quán)600的權(quán)限
2.1.1創(chuàng)建rsync.password文件多柑,并寫(xiě)入密碼123456
[root@nfs01 ~]# echo "123456" >/etc/rsync.password
2.1.2 修改文件/etc/rsync.password的權(quán)限
[root@nfs01 ~]# chmod 600 /etc/rsync.password
2.2 需要輸入密碼式的推送(把/etc/hosts 推送到服務(wù)器端的塊目錄data):
[root@nfs01 /]# rsync -avz /etc/hosts rsync_backup@10.0.0.41::data
Password:
sending incremental file list
hosts
sent 89 bytes received 49 bytes 55.20 bytes/sec
total size is 349 speedup is 2.53
2.3 不需要輸入密碼式的推送(把/etc/hosts 推送到服務(wù)器端的塊目錄data):
[root@nfs01 /]# rsync -avz /etc/hosts rsync_backup@10.0.0.41::data --password-file=/etc/rsync.password
sending incremental file list
sent 48 bytes received 20 bytes 136.00 bytes/sec
total size is 349 speedup is 5.13