2020-02-04-rsync服务端

查看rsycn安装包

[root@bakcup ~]# rpm -qa rsync
rsync-3.0.6-12.el6.x86_64

生成rsyncd.conf配置文件

[root@bakcup ~]# ls -l /etc/rsyncd.conf
ls: cannot access /etc/rsyncd.conf: No such file or directory
[root@bakcup ~]# vim /etc/rsyncd.conf
##rsyncd.conf start##
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
[backup]  #<==模块名称,需要中括号,名称没有特殊要求
path = /backup #<==在这个模块中,daemon使用的文件系统或目录,目录权限要和配置文件中的权限一致
ignore errors
read only = false
list = false
hosts allow = 172.16.1.0/24  #<==指定可以联系的客户端主机名或ip
hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync.password
#rsync_ config_end
~                                                                               
~                                                                                                                                                            
~                                                                               
~                                                                               
"/etc/rsyncd.conf" [New] 19L, 398C written                    
[root@bakcup ~]# cat /etc/rsyncd.conf
##rsyncd.conf start##
uid = rsync
gid = rsync
use chroot = no
max connections = 200
  meout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log 
[backup] 
path = /backup
ignore errors
read only = false
list = false
hosts allow = 172.16.1.0/24
hosts deny = 0.0.0.0/32 
auth users = rsync_backup
secrets file = /etc/rsync.password
#rsync_ config_end

添加rsync服务的用户,管理本地目录

[root@bakcup ~]# id rsync
id: rsync: No such user
[root@bakcup ~]# useradd rsync -s /sbin/nologin -M 
[root@bakcup ~]# tail -1 /etc/passwd
rsync:x:501:501::/home/rsync:/sbin/nologin

启动rsync服务并检查

[root@bakcup ~]# rsync --daemon
[root@bakcup ~]# ps -ef|grep rsync|grep -v grep
root       4214      1  0 00:13 ?        00:00:00 rsync --daemon

创建共享的目录并授权rsync服务管理

[root@bakcup ~]# mkdir /backup
[root@bakcup ~]# ls -ld /backup/
drwxr-xr-x 2 root root 4096 Feb  4 00:15 /backup/
[root@bakcup ~]# chown rsync.rsync /backup/
[root@bakcup ~]# ls -ld /backup/           
drwxr-xr-x 2 rsync rsync 4096 Feb  4 00:15 /backup/

根据rsync.conf的auth users配置账户,远程连续的,并生成密码文件

[root@bakcup ~]# ll /etc/rsync.password
ls: cannot access /etc/rsync.password: No such file or directory
[root@bakcup ~]# vim /etc/rsync.password   #<==或者用 echo "rsync_backup:oldboy" >/etc/rsync.password
rsync_backup:oldboy
~                                                                               
~                                                                                                                                                    
~                                                                                                                                                            
~                                                                               
~                                                                               
~                                                                               
"/etc/rsync.password" [New] 1L, 21C written                   
[root@bakcup ~]# cat /etc/rsync.password
rsync_backup:oldboy                         
[root@bakcup ~]# cat /etc/rsync.password
rsync_backup:oldboy #<==为同步传输用的虚拟账号,仅为rsync的账号,不需要是系统账号。后面的oldboy是密码,不超过8位,账号和密码用冒号分割
[root@bakcup ~]# ls /etc/rsync.password -l
-rw-r--r-- 1 root root 20 Feb  4 00:22 /etc/rsync.password

为密码文件配置权限

[root@bakcup ~]# chmod 600 /etc/rsync.password 
[root@bakcup ~]# ls /etc/rsync.password -l     
-rw------- 1 root root 20 Feb  4 00:22 /etc/rsync.password
[root@bakcup ~]# lsof -i :873  #<==根据端口找出服务名
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
rsync   4214 root    4u  IPv6  19781      0t0  TCP *:rsync (LISTEN)
rsync   4214 root    5u  IPv4  19782      0t0  TCP *:rsync (LISTEN)
[root@bakcup ~]# netstat -lntup|grep 873
tcp        0      0 0.0.0.0:873                 0.0.0.0:*                   LIS 
tcp        0      0 :::873                      :::*                        LIS 

加入开机自启动

[root@bakcup ~]# echo "/usr/bin/rsync --daemon" >>/etc/rc.local   
[root@bakcup ~]# tail -1 /etc/rc.local
/usr/bin/rsync --daemon

排错日志

[root@bakcup ~]# tail /var/log/rsyncd.log

你可能感兴趣的:(2020-02-04-rsync服务端)