美文网首页
第35课 rsync守护进程服务 2019-05-20

第35课 rsync守护进程服务 2019-05-20

作者: 苏水的北 | 来源:发表于2019-05-21 14:43 被阅读0次

一、服务器端(守护进程):

1.1 配置rsyncd服务,并重启服务和开机自启动服务以及查看服务是否开启

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运行的用户,虚拟用户)
gid = rsync  (gid指定rsync运行的用户,虚拟用户)

use chroot = no
max connections = 2000(最大连接数)
timeout = 600 (超时时间)
pid file = /var/run/rsyncd.pid(pid进程号)
lock file = /var/run/rsync.lock(锁文件,两个窗口同时运行yum)
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(deny拒绝)
auth users = rsync_backup(指定认证用户,虚拟不存在)
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文件后,重启服务

systemctl restart  rsyncd (重启服务)

systemctl  enable rsyncd     (开机自启动服务)

1.1.3 查看是否启动和开机自启动

[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 查看进程与端口是都开启

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 创建虚拟用户rsync,创建backup块目录,并给backup目录修改成rsync用户主与用户组

1.2.1 创建rsync虚拟用户

[root@backup ~]#    useradd  -M -s /sbin/nologin  rsync

1.2.2 创建backup块目录

[root@backup ~]#    mkdir  /backup

1.2.3给backup目录修改成rsync用户主与用户组

[root@backup ~]# chown  rsync.rsync  /backup
1.3 创建密码文件/etc/rsync.password,并写入密码,然后授权600的权限

1.3.1 创建rsync.password文件,并写入密码123456

[root@backup ~]# echo "rsync_backup:123456" >/etc/rsync.password

1.3.2 修改文件/etc/rsync.password的权限

[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

二、客户端(守护进程):

2.1 创建密码文件/etc/rsync.password,并写入密码,然后授权600的权限

2.1.1创建rsync.password文件,并写入密码123456

[root@nfs01 ~]# echo "123456" >/etc/rsync.password

2.1.2 修改文件/etc/rsync.password的权限

[root@nfs01 ~]# chmod  600  /etc/rsync.password
2.2 需要输入密码式的推送(把/etc/hosts 推送到服务器端的块目录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 推送到服务器端的块目录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

相关文章

网友评论

      本文标题:第35课 rsync守护进程服务 2019-05-20

      本文链接:https://www.haomeiwen.com/subject/svkdzqtx.html