Centos 7 全网备份Rsync

本文详细介绍了如何在CentOS 7环境下部署Rsync服务,包括服务端和客户端的配置过程。从软件安装、配置文件编辑、安全设置到服务启动及验证,提供了完整的步骤说明。

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

==========运维之路

  • 环境如下
[root@Centos ~]# cat /etc/redhat-release 
CentOS Linux release 7.5.1804 (Core) 
[root@Centos ~]# systemctl status firewalld.service 
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)
[root@Centos ~]# getenforce 
Disabled
# 服务端 IP:10.0.0.100
# 客户端 IP:10.0.0.101
Rsync 服务端部署
  • 检测软件是否安装
[root@Centos ~]# rpm -qa|grep rsync
rsync-3.1.2-4.el7.x86_64
  • 编写服务配置文件
[root@Centos ~]# vi /etc/rsyncd.conf
#rsync_config
##rsyncd.conf start##

uid = root                                   # 指定该模块以指定的 UID 传输文件
gid = root                                   # 指定该模块以指定的 GID 传输文件
use chroot = false
# 若为 true,则 rsync 在传输文件之前首先 chroot 到 path 参数所指定的目录下。
# 这样做的原因是实现额外的安全防护,但是缺点是需要 root 权限,并且不能备份指向 path 外部的符号连接所指向的目录文件                           
max connections = 200                        # 指定该模块的最大并发连接数量
timeout = 300                                # 指定客户端连接超时时间
pid file = /var/run/rsyncd.pid               # 指定守护进程将其 PID 写入的文件
lock file = /var/run/rsync.lock              # 指定支持 max connections 参数的锁文件
log file = /var/log/rsyncd.log               # 指定 rsync 守护进程的日志文件
ignore errors                                
# 指定在 rsync 服务器上运行 delete 操作时是否忽略 I/O 错误。一般来说 rsync 在出现 I/O 错误时
# 将跳过 –delete 操作,以防止因为暂时的资源不足或其它 I/O 错误导致的严重问题
read only = false                            # 客户端只读,ture 为开启只读模式
list = false                                 
# 指定当客户请求列出可以使用的模块列表时,该模块是否应该被列出。如果设置该选项为 false,可以创建隐藏的模块
hosts allow = 10.0.0.101                     # IP 白名单
auth users = rsync_backup                    # 指定允许连接该模块的用户
secrets file = /etc/rsync.password           # 指定用户与密码的验证文件
[backup]                                     # 连接模块
path = /backup                               # 该模块的存储路径
  • 添加进程管理用户
[root@Centos ~]# useradd rsync -s /sbin/nologin -M
  • 创建程序所需目录
# 创建数据备份目录
[root@Centos ~]# mkdir -p /backup
# 授权数据备份目录
[root@Centos ~]# chown -R rsync.rsync /backup/
[root@Centos ~]# ll -d /backup/
drwxr-xr-x 2 rsync rsync 6 Sep 11 18:21 /backup/
  • 进行安全相关配置
# 创建文件认证信息
[root@Centos ~]# echo "rsync_backup:123456" >/etc/rsync.password
# 修改认证文件权限
[root@Centos ~]# chmod 600 /etc/rsync.password
[root@Centos ~]# ll -d /etc/rsync.password
-rw------- 1 root root 20 Sep 11 18:26 /etc/rsync.password
  • 运行程序服务进程
# 启动rsync程序守护进程
[root@Centos ~]# rsync --daemon
# 停止rsync程序守护进程
[root@Centos ~]# killall rsync
# 加入开机自启动
[root@Centos ~]# echo 'rsync --daemon' >>/etc/rc.d/rc.local
[root@Centos ~]# chmod +x /etc/rc.d/rc.local
[root@Centos rc.d]# ll -d /etc/rc.d/rc.local
-rwxr-xr-x. 1 root root 488 Sep 12 17:22 /etc/rc.d/rc.local
  • 检查服务是否启动
[root@Centos ~]# ps -ef|grep rsync
root      16632      1  0 18:55 ?        00:00:00 rsync --daemon
root      16634   1176  0 18:56 pts/0    00:00:00 grep --color=auto rsync
[root@Centos ~]# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:873             0.0.0.0:*               LISTEN      16632/rsync
Rsync 客户端部署
  • 检测软件是否安装
[root@Centos ~]# rpm -qa|grep rsync
rsync-3.1.2-4.el7.x86_64
  • 进行安全相关配置
# 创建文件认证信息
[root@Centos ~]# echo "123456" >/etc/rsync.password
# 修改认证文件权限
[root@Centos ~]# chmod 600 /etc/rsync.password
[root@Centos ~]# ll -d /etc/rsync.password
-rw------- 1 root root 20 Sep 11 18:26 /etc/rsync.password
  • 进行服务应用设置
# 确认备份数据传输,采用免密钥进行传输
[root@Centos ~]# rsync -avzP /etc/hosts rsync_backup@10.0.0.100::backup --password-file=/etc/rsync.password
sending incremental file list
hosts
            158 100%    0.00kB/s    0:00:00 (xfr#1, to-chk=0/1)

sent 140 bytes  received 43 bytes  33.27 bytes/sec
total size is 158  speedup is 0.86
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值