一、rsync服务端安装
1、查看rsync安装包
# rpm -qa rsync
rsync-3.0.6-12.el6.x86_64
2、安装rsync
系统默认都会安装rsync软件包的,如果查看发现没有安装,执行yum安装即可
# yum install rsync -y
3、添加rsync服务的用户,管理本地目录的
# useradd -s /sbin/nologin -M rsync
# id rsync
4、生成rsyncd.conf配置文件
复制代码
# cat /etc/rsyncd.conf
#rsync_config______________________start
#created by oldboy 15:00 2016-11-15
##rsyncd.conf start##
uid = rsync # 用户 远端的命令使用rsync访问共享目录
gid = rsync # 用户组
use chroot = no # 安全相关
max connections = 200 # 最大连接数
timeout = 300 # 超时时间
pid file = /var/run/rsyncd.pid # 进程对应的进程号文件
lock file = /var/run/rsyncd.lock # 锁文件
log file = /var/log/rsyncd.log # 日志文件
ignore errors # 忽略错误
read only = false # 可写
list = false # 不能列表
hosts allow = 172.16.1.0/24 # 允许连接的服务器
hosts deny = 0.0.0.0/32 # 后勤组连接的服务器
auth users = rsync_backup # 虚拟用户
secrets file = /etc/rsync.password # 虚拟用户对应的用户和密码文件
[backup] # 模块名称
path = /backup # 服务端提供访问的目录
[nfsbackup]
path = /nfsbackup
#rsync_config______________________end
复制代码
5、根据rsyncd.conf的auth users配置帐户,远程连接的,并根据secrets file 参数生成密码文件。
# echo "rsync_backup:hkrt" > /etc/rsync.password
# cat /etc/rsync.password
rsync_backup:hkrt
6、为密码文件配置权限
# chmod 600 /etc/rsync.password
# ls -l /etc/rsync.password
-rw------- 1 root root 20 Nov 15 23:35 /etc/rsync.password
7、创建共享目录并授权rsync服务管理
# mkdir /backup -p
# chown -R rsync.rsync /backup
8、启动rsync服务并检查
# rsync --daemon
# ps -ef | grep rsync|grep -v grep
# lsof -i:873
9、加入开机自启动
# echo "/usr/bin/rsync --daemon" >> /etc/rc.local
# tail -1 /etc/rc.local
二、rsync客户端
1、查看rsync安装包
# rpm -qa rsync
rsync-3.0.6-12.el6.x86_64
2、安装rsync
系统默认都会安装rsync软件包的,如果查看发现没有安装,执行yum安装即可
# yum install rsync -y
3、添加rsync服务的用户,管理本地目录的
# useradd -s /sbin/nologin -M rsync
# id rsync
4、生成连接服务器需要的密码文件
# echo "hkrt" > /etc/rsync.password
# cat /etc/rsync.password
hkrt
5、为密码文件配置权限
# chmod 600 /etc/rsync.password
# ls -1 /etc/rsync.password
-rw------- 1 root root 7 Nov 15 23:48 /etc/rsync.password
6、同步文件语法
基于rsync daemon同步语法:
拉取: rsync [OPTION...] [USER@]HOST::SRC... [DEST]
rsync [OPTION...] rsync://[USER@]HOST[:PORT]/SRC... [DEST]
推送: rsync [OPTION...] SRC... [USER@]HOST::DEST
rsync [OPTION...] SRC... rsync://[USER@]HOST[:PORT]/DEST
7、测试手动推送是否正常
复制代码
[root@nfs01 backup]# pwd
/backup
[root@nfs01 backup]# ls
a.txt c.txt e.txt g.txt i.txt k.txt m.txt o.txt q.txt s.txt u.txt w.txt y