Linux下配置rsync 同步数据

Linux下配置rsync 同步数据
说明:本配置为rpm包安装rsync
[root@Hammer home]# rpm -qa |grep rsync #检查系统是否安装了rsync软件包
rsync-2.6.8-3.1
[root@Hammer CentOS]# rpm -ivh rsync-2.6.8-3.1.i386.rpm # 如果没有安装则手动安装
[root@test rsync-3.0.4]# vim /etc/xinetd.d/rsync
1 配置rsync servervi /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
}
2 配置rsync自动启动
[root@test etc]# chkconfig rsync on
[root@test etc]# chkconfig rsync --list
rsync on
3 配置rsyncd.conf
[root@test etc]# vim rsyncd.conf
uid = root
gid = root
use chroot = no
max connections = 4
strict modes = yes
port = 873
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
[backup]
path = /srv
comment = This is test
auth users = scihoo
uid = root
gid = root
secrets file = /home/rsync.ps
read only = no
list = no
4 确保etc/services中rsync端口号正确
[root@test etc]# vim /etc/services
rsync 873/tcp # rsync
rsync 873/udp # rsync
5 配置rsync密码(在上边的配置文件中已经写好路径)/home/rsync.ps(名字随便写,只要和上边配置文件里的一致即可),格式
(一行一个用户)
[root@test etc]# vi /home/rsync.ps
scihoo(user):scihoo(pass)
6 配置rsync密码文件权限
[root@test home]# chown root.root rsync.ps
[root@test home]# chmod 600 rsync.ps
7 启动配置
[root@test home]# /etc/init.d/xinetd restart
Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]

或者:
启动rsync服务端(独立启动)
[root@test home]# /usr/bin/rsync --daemon

8 加入rc.local
在各种操作系统中,rc文件存放位置不尽相同,可以修改使系统启动时把rsync --daemon加载进去。
[root@test home]# vi /etc/rc.local
/usr/local/rsync –daemon #加入一行
9 检查rsync是否启动
[root@test home]# lsof -i :873
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
xinetd 4396 root 5u IPv4 633387 TCP *:rsync (LISTEN)
客户端配置
1 配置三个过程就可以了
1.1 设定密码文件
1.2 测试rsync执行指令
1.3 将rsync指令放入工作排程(crontab)
[root@aj1 home]# vi /etc/xinetd.d/rsync
# default: off
# description: The rsync server is a good addition to an ftp server, as it \
# allows crc checksumming etc.
service rsync
{
disable = no
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}
1.1 配置密码文件 (注:为了安全,设定密码档案的属性为:600。rsync.ps的密码一定要和Rsync Server密码设定案里的密
码一样)
[root@aj1 home]# vi rsync.ps
sciooo(pass)
[root@aj1 home]# chown root.root .rsync.ps # 注意必须给权限
[root@aj1 home]# chmod 600 .rsync.ps # 必须修改权限
1.2 从服务器上下载文件
[root@aj1 rsync-3.0.4]# rsync -avz --password-file=/home/rsync.ps [email protected]::backup /home/
从本地上传到服务器上去
[root@aj1 rsync-3.0.4]# rsync -avz --password-file=/home/rsync.ps /home [email protected]::backup
PDF created with pdfFactory Pro trial version www.pdffactory.com
1.3 将rsync指令放入工作排程(crontab)
现在可以把我们的备份工作置入排程了,假设每天凌晨1点开始备份工作:
[root@aj1 home]# crontab -e
0 1 * * * /usr/bin/rsync -az --password-file=/home/rsync.ps [email protected]::backup /home
2 重启动任务计划 crontab
[root@Hammer home]# /etc/init.d/crond restart # crond 就是crontab的启动进程
参看刚定的计划任务
[root@aj1 home]# crontab -l # 注意 是小写l 不是1
根据需要,可以参考下面的时间进行调整
配置文件 vi /etc/crontab
第1列分钟1~59
第2列小时1~23(0表示子夜)
第3列日1~31
第4列月1~12
第5列星期0~6(0表示星期天)
Rsync配置
vi /etc/rsyncd.conf (默认是没有的,可以手工创建)v#全局选项
strict modes =yes #是否检查口令文件的权限
port = 873 #默认端口873
log file = /var/log/rsyncd.log #日志记录文件
pid file = /usr/local/rsync/rsyncd.pid #运行进程的ID写到哪里

猜你喜欢

转载自blog.csdn.net/hewy0526/article/details/51470745
今日推荐