环境都是在Ubuntu中
一般情况下 ubuntu默认安装了rsync服务的 我们只需要开启就OK了

# 安装 rsync
sudo vim /etc/default/rsync (如果不存在则需要安装) 安装命令 sudo apt-get install rsync
RSYNC_ENABLE=true   #false改true
#配置 rsync
sudo cp /usr/share/doc/rsync/examples/rsyncd.conf /etc   #已默认安装的软件,默认不启动的似乎都要这么做
sudo vim /etc/rsyncd.conf
 # sample rsyncd.conf configuration file

# GLOBAL OPTIONS

#motd file=/etc/motd
log file=/var/log/rsyncd
# for pid file, do not use /var/run/rsync.pid if
# you are going to run rsync out of the init.d script.
 pid file=/var/run/rsyncd.pid
syslog facility=daemon
#socket options=

# MODULE OPTIONS

[my_rsync_bk] #名字可以任意命名,只要客户端的rsync命令一致

        comment = public archive
        path = /home/rsync_bk                             #指定路径,如果没有这个目录自己建。
        use chroot = no
#       max connections=10
        lock file = /var/lock/rsyncd
# the default for read only is yes...
        read only = yes
        list = yes
        uid = nobody
        gid = nogroup
#       exclude = 
#       exclude from = 
#       include =
#       include from =
        auth users = liu_rsync              #rsync连接时的用户名,要和客户端rsync的命令一致
        secrets file = /etc/rsyncd.secrets #这里是保存密码的地方,如果屏蔽掉就不用密码了
        strict modes = yes
        hosts allow = 192.168.64.145 #运行的客户端ip
#       hosts deny =
        ignore errors = yes
        ignore nonreadable = yes
        transfer logging = yes
        log format = %t: host %h (%a) %o %f (%l bytes). Total %b bytes.
        timeout = 600
        refuse options = checksum dry-run
        dont compress = *.gz *.tgz *.zip *.z *.rpm *.deb *.iso *.bz2 *.tbz
日志格式选项列表:

%h: 远程主机名
%a: 远程IP地址
%l: 文件长度字符数
%p: 该次rsync会话的进程id
%o: 操作类型:"send"或"recv"、”del.”
%f: 文件名
%P: 模块路径
%m: 模块名
%t: 当前时间
%u: 认证的用户名(匿名时是null)
%b: 实际传输的字节数
%c: 当发送文件时,该字段记录该文件的校验码
#创建密码
sudo vim /etc/rsyncd.secrets
内容为 用户名:密码
最后修改日期: 2023-02-02

作者

留言

撰写回覆或留言