Linux rsync服务配置及使用
1.安装rsync服务
yum install -y rsync
2.修改配置文件 /etc/xinetd.d/rsync 将disable=yes 改为no 开启服务
service rsync
{
disable = no
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}
3.创建服务器配置文件 /etc/rsyncd.conf
全局参数
uid = root //运行RSYNC守护进程的用户
gid = root //运行RSYNC守护进程的组
use chroot = no //不使用chroot
max connections = 4 // 最大连接数为4
timeout = 600 //超时时间
strict modes =yes //是否检查口令文件的权限
port = 873 //默认端口873
pid file = /var/run/rsyncd.pid //pid文件的存放位置
lock file = /var/run/rsync.lock //锁文件的存放位置
log file = /var/log/rsyncd.log //日志记录文件的存放位置模块参数
[backup] //这里是认证的模块名,在client端需要指定
path = /home/backup/ //需要备份的目录,不可缺少!
comment = This is a test //这个模块的注释信息
ignore errors //可以忽略一些无关的IO错误
read only = yes // 只读
#list = no //不允许列文件
auth users = wj //认证的用户名,如果没有这行则表明是匿名,此用户与系统无关
secrets file = /etc/rsync.pas //密码和用户名对比表,密码文件自己生成
hosts allow = 192.168.1.1,10.10.10.10 //允许主机
hosts deny = 0.0.0.0/0 //禁止主机
#transfer logging = yes
4.创建认证文件/etc/rsyncd.passwd
每行 ---- 账号:密码 这里账号要和上面一样
5.修改权限
chmod 600 /etc/rsyncd.passwd
6.修改iptables配置
/etc/sysconfig/iptables中加入一行
7.启动服务
/usr/bin/rsync --daemon
开机启动将该命令加入到 /etc/rc.local
8.配置客户端
1)yum install -y rsync
2)touch /etc/rsyncd.conf
3) touch /etc/rsyncd.passwd
4)echo "123" >> /etc/rsyncd.passwd #将之前设置的密码加入进去,为了不用输入密码
5)chmod 600 /etc/rsyncd.passwd
6)/usr/bin/rsync --daemon
9.使用方式
客户端上传文件到服务端:
rsync -avz /backup/ rsync://[email protected]/rsync --password-file=/etc/rsyncd.passwd
/backup/: 要推送的文件目录
rsync:上面设置的 账号名
192.168.0.112: 服务端ip
rsync: rsync用户
/etc/rsyncd.passwd: 设置的密码文件
上传的路径为rsync用户设置的path路径
客户端从服务端下载文件:
rsync -avz rsync://[email protected]/rsync /backup/ --password-file=/etc/rsyncd.passwd
就是上面/backup/ 与rsync://[email protected]/rsync换位置
文件拷贝
SRC="/apps/tdms_data/upload/doc/"
DES="/apps/myfiles"
rsync -avzrP ${SRC}* ${DES}