1. 程式人生 > >Rsync守護進程方式遠程部署

Rsync守護進程方式遠程部署

rsync 文件同步

2、Rsync守護進程方式遠程部署

以守護進程(Socket)的方式傳輸數據

操作系統:
[[email protected] ~]# cat /etc/redhat-release 
CentOS Linux release 7.3.1611 (Core) 
內核版本:
[[email protected] ~]# uname -r
3.10.0-514.el7.x86_64

主機網絡參數設置:

Hostname網卡eth0默認網關用途
node1192.168.1.71192.168.1.1rsync服務端
node2192.168.1.72192.168.1.1rsync客戶端
node3192.168.1.73192.168.1.1rsync客戶端

具體需求:

  要求在node1上以rsync守護進程的方式部署rsync服務,使得所有rsync節點客戶端主機,可以在rsync的server端拉去數據。   
1、安裝rsync
[[email protected] ~]# yum install -y rsync
[[email protected] ~]# rpm -q rsync
rsync-3.0.9-17.el7.x86_64
2、配置rsync
[[email protected] ~]# cat /etc/rsyncd.conf 
uid = rsync
gid = rsync
use chroot = no  #囚牢
max connections = 200
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log

[cce]
path = /data/
ignore errors         #遇到錯誤自動忽略
read only = false  #可寫
list = false             #不允許列出
hosts allow = 192.168.1.0/24   #允許同步的網段
hosts deny = 0.0.0.0/32           #拒絕的網段
auth users = caichangen         #虛擬用戶
secrets file = /etc/rsync.passw #虛擬用戶的密碼據通過rsync的方式備份到數據備份服務器node1上。
3、配置rsync訪問用戶的賬號密碼
[[email protected]
/* */ ~]# echo "caichangen:caichangen" > /etc/rsync.passwd [[email protected] ~]# chmod 600 /etc/rsync.passwd 4、創建專屬用戶、目錄並授權、啟動 [[email protected] ~]# useradd -r rsync [[email protected] ~]# mkdir /data [[email protected] ~]# chown rsync:rsync /data/ [[email protected]
*/ ~]# systemctl start rsyncd 5、客戶端 [[email protected] ~]# yum install -y rsync 6、配置客戶端在訪問服務端需要用到的密碼 [[email protected] ~]# echo "caichangen" > /etc/rsync.passwd [[email protected] ~]# chmod 600 /etc/rsync.passwd 7、測試拉取數據到rsync服務端 語法:rsync -avz [email protected]_IP::Rsync_object_name local_dir [[email protected] ~]# rsync -avz --password-file=/etc/rsync.passwd [email protected]::cce /tmp/ receiving incremental file list ./ fstab sent 81 bytes received 482 bytes 375.33 bytes/sec total size is 552 speedup is 0.98 [[email protected] ~]# ls -l /tmp/ total 4 -rw-r--r--. 1 997 995 552 May 13 15:47 fstab 8、測試推送數據到服務端 [[email protected] ~]# mkdir test [[email protected] ~]# touch test/{a..g} [[email protected] ~]# rsync -avz --password-file=/etc/rsync.passwd /root/test/ [email protected]::cce sending incremental file list ./ a b c d e f g sent 323 bytes received 144 bytes 934.00 bytes/sec total size is 0 speedup is 0.00 9、查看數據是否推送成功 [[email protected] ~]# ls /data/ a b c d e f fstab g rc.local 10、使用rsync協議來推送 [[email protected] ~]# rsync -avz --password-file=/etc/rsync.passwd rsync:[email protected]/cce /tmp/ receiving incremental file list ./ a b c d e f g sent 195 bytes received 451 bytes 1292.00 bytes/sec total size is 1025 speedup is 1.59 11、使用rsync協議來拉取數據 [[email protected] ~]# mkdir test [[email protected] ~]# touch test/{1..10} [[email protected] ~]# rsync -avz --password-file=/etc/rsync.passwd /root/test/ rsync:[email protected]/cce sending incremental file list ./ 1 10 2 3 4 5 6 7 8 9 sent 450 bytes received 201 bytes 434.00 bytes/sec total size is 0 speedup is 0.00

本文出自 “Char” 博客,請務必保留此出處http://charcce.blog.51cto.com/4255555/1926333

Rsync守護進程方式遠程部署