linux中在centos x64 6.8环境下部署rsync实现文件远程备份及同步,centosrsync


默认centos都有安装 如果没有可以先检查

rpm -qa rsync

yum install rsync

服务端部分(备份服务器)

1.写配置文件

vi /etc/rsyncd.conf

/etc/rsyncd: configuration file for rsync daemon mode

See rsyncd.conf man page for more options.

configuration example: uid = rsync gid = rsync

use chroot = yes

list = yes

address = 192.161.1.1 max connections = 10 pid file = /var/run/rsyncd.pid log file = /var/log/rsyncd.log

exclude = lost+found/

transfer logging = yes

timeout = 900

ignore nonreadable = yes

dont compress = .gz .tgz .zip .z .Z .rpm .deb .bz2 [data] path=/www/data/ transfer logging = yes ignore errors

read only = no list = no hosts allow = 192.168.1.1,192.168.1.2

auth users = test secrets file = /etc/rsync.password

[ftp]

path = /home/ftp

comment = ftp export area

注释:

uid = nobody

进行同步或者备份的用户,nobody 为任何用户

gid = nobody

进行备份的组,nobody为任意组

use chroot = no

如果”use chroot”指定为true,那么rsync在传输文件以前首先chroot到path参数所指定的目录下。这样做的原因是实现额外的安全防护,但是缺点是需要以root权限,并且不能备份指向外部的符号连接所指向的目录文件。默认情况下chroot值为true.但是这个一般不需要,我选择no或false

list = no

不允许列清单

max connections = 10

最大连接数

timeout = 600

覆盖客户指定的IP超时时间,也就是说rsync服务器不会永远等待一个崩溃的客户端。

pidfile = /var/run/rsyncd.pid

pid文件的存放位置

lock file = /var/run/rsync.lock

锁文件的存放位置

log file = /var/log/rsyncd.log

日志文件的存放位置

[data]

这里是认证模块名,即跟samba语法一样,是对外公布的名字

path = /www/data/

这里是参与同步的目录

ignore errors

可以忽略一些无关的IO错误

read only = no

允许可读可写

list = no

不允许列清单

hosts allow = 192.168.1.0/255.255.255.0

这里跟samba的语法是一样的,只允许192.168.21.0/24的网段进行同步,拒绝其它一切

auth users = test

认证的用户名

secrets file = /etc/rsyncd.password

密码文件存放地址

注意:

[backup] 认证模块名和 path = /www/backup/ 参与同步的目录

这里的path 大家要记好了,这里不要随便的一设置就直接完事,要知道这里是认证模块的,以后从客户机备份的数据会存储在这里。

auth users = redhat 认证的用户名

这个名字是服务器端实实在在存在用户,大家不要直接跟步骤走却忽略了这点。如果服务器端少了这个的话我估计你的数据同步就实现不了,大家要谨记。

2.创建用户

groupadd rsync

useradd rsync -g rsync

3.创建密码

echo "rsync:rsync666" > /etc/rsync.password

chmod 600 /etc/rsync.password

4.启动服务和开机自启动 开放端口 启动

rsync --daemon

自启动

vim /etc/rc.local

加入

/usr/bin/rsync --daemon

开放端口

iptables -A INPUT -p tcp --dport 873 -j ACCEPT

service iptables save

service iptables restart

5.设置备份目录权限

chown -R rsync:rsync /www/data/

客户端设置(上传服务器) =========================================== 6.设置密码 服务端设置的密码(sync666)

echo "rsync666" > /etc/rsync.password

chmod 600 /etc/rsync.password

7.编写上传脚本

vi /root/rsync.sh

#!/bin/bash rsync -avzP /www/data/ test@192.168.1.3::data --password-file=/etc/rsync.password

说明:

/www/data/ 为需要上传的目录

data 为服务端配置的 [data]选项

8.设置计划任务运行

crontab -e

加入

00 06 * * * /root/rsync.sh

定时为 每天 6点同步一次

相关内容