修订记录
序号 | 修订内容 | 时间 |
---|---|---|
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