Linux 搭建 rsync 后台服务

步骤1: 安装:yum install rsync -y

步骤2:编辑 /etc/rsyncd.conf   

特别注意:

1、这是安装后默认带的,如果你其他另建一个,默认先搜索到这个位置配置文件

2、配置文件内,参数后不要带注释, 例如“ uid = root #这是啥啥啥    ”   这种可能产生意想不到错误效果

pid file = /var/run/rsyncd.pid #进程 pid 文件所在位置
port = 873 #指定监听端口,默认是873,可以自己指定
#address =  #服务器监听的IP地址,可省略

uid = root
gid = root

#chroot,即改变程序执行时所参考的根目录位置,在传输文件之前,服务器守护程序在将chroot 到文
件系统中的目录中
#这样做的好处是可能保护系统被安装漏洞侵袭的可能。缺点是需要超级用户权限。另外对符号链接文>件,将会排除在外
#也就是说,你在 rsync服务器上,如果有符号链接,你在备份服务器上运行客户端的同步数据时,只>会把符号链接名同步下来,并不会同步符号链接的内容
use chroot = no

read only = no
write only = no

#允许访问的IP,可以指定单个IP,也可以指定整个网段,能提高安全性。格式是 ip 与 ip 之间、ip 和网段之间、网段和网段之间要用空格隔开;
#hosts allow = 192.168.1.0/255.255.255.0 10.0.1.0/255.255.255.0 
hosts allow= *
max connections = 4

#当用户登录时会看到这个信息。比如显示当前时间、公告等
motd file = /etc/rsyncd/rsyncd.motd

log file = /var/log/rsync.log
transfer logging = yes
log format = %t %a %m %f %b
syslog facility = local3

#通过该选项可以覆盖客户指定的IP超时时间。可以确保rsync服务器不会永远等待一个崩溃的客户端。
超时单位为秒钟,0表示没有超时定义,这也是默认值。对于匿名rsync服务器来说,一个理想的数字是
600。
timeout = 600

#模块定义
#主要是定义服务器哪个目录要被同步。
#每个模块都要以[name]形式。这个名字就是在 rsync 客户端看到的名字。
#但是服务器真正同步的数据是通过 path 指定的。可以依次创建多个模块。
#每个模块要指定认证用户、密码文件,但排除并不是必须的。
[hybackup]
path=/data/synology/
list=true
ignore errors
#指定由空格或逗号分隔的用户名列表,只有这些用户才允许连接该模块。这里的用户和系统用户没有>任何关系,是 rsyncd.secrets 中的用户名!
#如果"auth users"被设置,那么客户端发出对该模块的连接请求以后会被rsync请求challenged进行验
证身份。
#这里使用的 challenge/response 认证协议。
#用户的名和密码以明文方式存放在"secrets file"选项指定的文件中。默认情况下无需密码就可以连>接模块(也就是匿名方式)。
auth users=rsyncuser
secrets file=/etc/rsyncd/rsyncd.secrets
exclude=error_log httpd.pid
comment this is my log

步骤3:生成一些必要文件,配置文件中提及

1、密码认证文件:内容是 rsync 登录的用户名密码,格式  <用户名>:<密码> 一行一个用户。 注意需要将权限修改为 600 

chmod 600 /etc/rsyncd/rsyncd.secrets

2、登录欢迎提示文件:/etc/rsyncd/rsyncd.motd 内容随意

3、当然你模块指定的路径,必须事先建立存在

步骤4:生成 systemctl 服务文件 

vim /etc/systemd/system/rsync.service 
[Unit]
Description=fast remote file copy program daemon
ConditionPathExists=/etc/rsyncd.conf

[Service]
EnvironmentFile=/etc/sysconfig/rsyncd
ExecStart=/usr/bin/rsync --daemon --no-detach "$OPTIONS"

[Install]
WantedBy=multi-user.target

最后启动服务 

 

posted on 2022-10-27 09:22  震撼起飞  阅读(246)  评论(0编辑  收藏  举报

导航