微信搜索superit|邀请体验:大数据, 数据管理、OLAP分析与可视化平台 | 赞助作者:赞助作者

rsync 守护进程模式

linux aide_941 10℃

5.20笔记整理 rsync 守护进程模式

Rsync daemon (rsyncd)

Daemon为守护进程,rsyncd运行在服务器端

服务器端操作:

1. 添加虚拟用户

[root@backup ~]# useradd  -s  /sbin/nologin  -M rsync
2. 创建共享目录/data 修改所有者

[root@guanggege ~]# mkdir  -p  /data
[root@guanggege ~]# chown  rsync.rsync  /data
[root@guanggege ~]# ll  -d  /data
drwxr-xr-x 2 rsync rsync 6 May  5 18:33 /data
[root@guanggege ~]#
3. 创建密码文件,修改权限为600(密码文件都为600)

[root@guanggege ~]# echo  'rsync_backup:123456' >/etc/rsync.password
[root@guanggege ~]# chmod  600  /etc/rsync.password
[root@guanggege ~]# ll /etc/rsync.password
-rw------- 1 root root 20 May 21 09:44 /etc/rsync.password
[root@guanggege ~]# cat  /etc/rsync.password
rsync_backup:123456
[root@guanggege ~]#
4. 修改rsync配置文件 /etc/rsync.conf

[root@guanggege ~]# vim  /etc/rsyncd.conf 
#Rsync server
##created by oldboy 15:01 2009-6-5
###rsyncd.conf start##
fake super = yes
uid = rsync 
gid = rsync 
use chroot = no
max connections = 2000
timeout = 600
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors
read only = false
list = false
##hosts allow = 10.0.0.0/24
##hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync.password
######################################
[data]
comment = www by old0boy 14:18 2012-1-13
path = /data
rsync配置文件下各行含义
5. 启动rsync服务端(rsyncd或rsyncd.service)

启动

[root@guanggege ~]# systemctl  restart  rsyncd
[root@guanggege ~]#

检查进程

[root@guanggege ~]# ps  -ef |grep  rsync
root       7514      1  0 09:51 ?        00:00:00 /usr/bin/rsync --daemon --no-detach
root       7516   7391  0 09:52 pts/0    00:00:00 grep --color=auto rsync
[root@guanggege ~]#

检查端口

[root@guanggege ~]# ss  -lntup |grep  rsync
tcp    LISTEN     0      5         *:873                   *:*                   users:(("rsync",pid=7514,fd=3))
tcp    LISTEN     0      5        :::873                  :::*                   users:(("rsync",pid=7514,fd=5))
[root@guanggege ~]#
6. 检查rsync服务端是否能用(自我检查)

[root@backup ~]# rsync  -avz  /etc/hosts  rsync_backup@172.16.1.41::data
Password: 
sending incremental file list
hosts

sent 89 bytes  received 49 bytes  30.67 bytes/sec
total size is 349  speedup is 2.53
[root@backup ~]#
7. 排查故障流程
看日志

[root@backup ~]# tail  -f  /var/log/rsyncd.log 
2019/05/20 20:56:10 [8609] receiving file list
2019/05/20 20:56:10 [8609] sent 48 bytes  received 263 bytes  total size 234
2019/05/20 21:02:45 [8419] sent 0 bytes  received 0 bytes  total size 0
2019/05/21 09:58:01 [7857] params.c:Parameter() - Ignoring badly formed line in config file: ignore er
看配置文件是否有错误

Rsync客户端操作:

1. 创建密码文件(只需要密码即可),并改权限为600

[root@guanggege ~]# echo  123456 >/etc/rsync.password
[root@guanggege ~]# chmod  600  /etc/rsync.password
[root@guanggege ~]# ll  /etc/rsync.password
-rw------- 1 root root 7 May 21 10:01 /etc/rsync.password
[root@guanggege ~]# cat  /etc/rsync.password
123456
[root@guanggege ~]#
2. 检查

[root@nfs01 ~]# rsync  -avz  /etc/hostname  rsync_backup@172.16.1.41::data  --password-file /etc/rsync.passwd
sending incremental file list

sent 51 bytes  received 20 bytes  47.33 bytes/sec
total size is 6  speedup is 0.08
[root@nfs01 ~]#

Rsync多模块

新建一个目录 /backup

[root@backup ~]# mkdir  -p  /backup
[root@backup ~]#
修改rsync配置文件,添加/backup模块

[root@backup ~]# vim  /etc/rsyncd.conf 
#Rsync server
#created by oldboy 15:01 2009-6-5
##rsyncd.conf start##
fake super = yes
uid = rsync
gid = rsync
use chroot = no
max connections = 2000
timeout = 600
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors
read only = false
list = false
#hosts allow = 10.0.0.0/24
#hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync.password
#####################################
[data]
comment = www by old0boy 14:18 2012-1-13
path = /data
#####################################
[backup]
comment = www by old0boy 14:18 2012-1-13
path = /backup

多个模块对应多个目录,每添加一个目录需要再添加模块

转载请注明:SuperIT » rsync 守护进程模式

喜欢 (1)or分享 (0)