rsync 常用维护

本文详细介绍了如何在CentOS7系统中安装Rsync,包括环境确认、设置rsyncd服务开机启动、配置同步目录以及处理常见的错误如主机解析失败和权限问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

修订记录

序号修订内容时间
1新增20240202

零 摘要

本文主要介绍rysnc 安装及常用维护

一 环境信息

[root@2023001 rc.d]# rsync --version
rsync  version 3.1.2  protocol version 31

[root@2023001 rc.d]# cat /etc/centos-release
CentOS Linux release 7.9.2009 (Core)
[root@2023001 rc.d]#

二 常用维护

2.1 开启

2.1.1 方法一 (推荐)


[root@2023001 rc.d]# systemctl start rsyncd.service
[root@2023001 rc.d]# systemctl status rsyncd.service
● rsyncd.service - fast remote file copy program daemon
   Loaded: loaded (/usr/lib/systemd/system/rsyncd.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2024-02-02 11:11:22 CST; 6s ago
 Main PID: 32043 (rsync)
    Tasks: 1
   Memory: 192.0K
   CGroup: /system.slice/rsyncd.service
           └─32043 /usr/bin/rsync --daemon --no-detach

Feb 02 11:11:22 2023001 systemd[1]: Started fast remote file copy program daemon.
Feb 02 11:11:22 2023001 rsyncd[32043]: rsyncd version 3.1.2 starting, listening on port 873
[root@2023001 rc.d]#

2.1.2 方法二

/usr/bin/rsync --daemon

2.2 配置开机启动

若果您使用ssh协议传输数据,是不需要开启rsync 服务的,
此处是使用rsync 协议传输。

2.2.1 方法一 推荐使用

[root@2023001 ~]# systemctl enable rsyncd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.

2.2.2 方法二

在rc.local 增加/usr/bin/rsync --daemon 即可。

先备份rc.local,
然后添加
最后重启机器验证


[root@2023001 rc.d]# pwd
/etc/rc.d
[root@2023001 rc.d]# cp rc.local rc.local.bak.20240202
[root@2023001 rc.d]# vim rc.local
[root@2023001 rc.d]#

[root@2023001 rc.d]# cat rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
/bin/bash  /usr/bin/linux_yun_hids.sh
#/bin/bash  /usr/bin/autoyum.sh
[ -f /usr/local/gse/gse_install.sh ] && /bin/bash /usr/local/gse/gse_install.sh >/var/log/gse_install.log 2>&1
[ -x /usr/local/gse/agent/bin/gsectl ] && /usr/local/gse/agent/bin/gsectl start
/usr/bin/rsync --daemon
[root@2023001 rc.d]#

2.3 配置同步目录

rsync 默认配置文件在/etc/rsyncd.conf,默认没有配置同步目录

2.3.1 新增同步目录

首先备份配置文件

cp rsyncd.conf rsyncd.conf.bak.orig

新增配置:

[root@2023001 etc]# cat rsyncd.conf
# /etc/rsyncd: configuration file for rsync daemon mode

# See rsyncd.conf man page for more options.

# configuration example:

# uid = nobody
# gid = nobody
# use chroot = yes
# max connections = 4
# pid file = /var/run/rsyncd.pid
# exclude = lost+found/
# transfer logging = yes
# timeout = 900
# ignore nonreadable = yes
# dont compress   = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2

# [ftp]
#        path = /home/ftp
#        comment = ftp export area
#
 [mirrors]
       path = /mirrordata/mirrors
       comment = mirros data area

[root@2023001 etc]#

2.3.2 验证

[mirrors@client test]$ rsync  rsync://rsyncserverip:/mirrors
drwxr-xr-x             66 2024/02/02 09:50:59 .
drwxr-xr-x             54 2024/01/26 15:05:46 centos-vault
drwxrwxr-x          4,096 2024/02/02 14:19:33 epel
drwxr-xr-x             34 2024/01/24 20:52:02 log
drwxr-xr-x             37 2024/02/02 09:50:59 openeuler

2.3 include 参数使用示例

2.3.1 只同步某个目录下一个子目录

比如/openeuler/ 目录下 子目录 openEuler-22.03-LTS-SP3 下所有内容
在这里插入图片描述

rsync -avzP  --bwlimit=30720 --timeout=120 --contimeout=120 --include="openEuler-22.03-LTS-SP3/" --include="openEuler-22.03-LTS-SP3/***"  --exclude="*" --exclude="*/" rsync://mirrors.tuna.tsinghua.edu.cn/openeuler/ /data/mirrors/openeuler/ 

参数说明:

–include=“openEuler-22.03-LTS-SP3/” 同步该目录名
–include=“openEuler-22.03-LTS-SP3/*" 同步该目录下所有内容
–exclude="
" 不同步openeuler下所有文件
–exclude="
/” 不同步openeuler下所有目录

三个星号官网解释:https://download.samba.org/pub/rsync/rsync.1
a trailing *** in the pattern is a shorthand that allows you to match a directory and all its contents using a single rule. For example, specifying “dir_name/*" will match both the “dir_name” directory (as if “dir_name/” had been specified) and everything in the directory (as if "dir_name/” had been specified).

三 常用排错

3.1 Could not resolve hostname rysnc: Name or service not known

解决办法通 3.2

3.2 error unknown module

分析:rsync 默认走ssh 协议,且默认配置文件里没有配置同步目录
当我们使用rsync 协议同步文件时,必须配置同步目录 具体可参考2.3 配置同步目录

 [mirrors]
       path = /mirrordata/mirrors
       comment = mirros data area

3.3 Permission denied (13)

详细报错
receiving file list … done
rsync: send_files failed to open “/centos-vault/7.9.2009/updates/Source/SPackages/.thunderbird-78.10.0-1.el7.centos.plus.src.rpm.DhAOHI” (in mirrors): Permission denied (13)
IO error encountered – skipping file deletion

原因:rsync 服务端 文件权限问题

当前rsync 服务端 目录权限mirrors:mirrorgroup

[root@2023001 mirrordata]# ll
total 0
drwxr-xr-x 6 mirrors mirrorgroup 66 Feb  2 09:50 mirrors
drwxr-xr-x 3 mirrors mirrorgroup 61 Feb  2 15:08 soft
[root@2023001 mirrordata]#

修改/etc/rsyncd.conf

 uid = mirrors
 gid = mirrorgroup

重启服务

[root@2023001 ~]# systemctl restart rsyncd

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值