两台centos 6.3 64位服务器 ip地址分别为 192.168.1.97,192.168.1.96
其中 192.168.1.97作为rsync服务端,192.168.1.96作为客户端
【服务端设置】
注意:关闭防火墙和selinux的设置
service iptables stop(临时关闭防火墙)
1.查看是否安装rsync
rpm -qa rsync (或者 yum list installed | grep rsync )
2.若没有安装rsync
yum -y install rsync
3.创建rsync配置文件
vi /etc/rsyncd.conf
uid = nobody (任何用户)
gid = nobody (任何组)
user chroot = no (不允许列清单)
max connections = 200 (最大连接数)
timeout = 600 (超时时间)
pid file =/var/run/rsyncd.pid (PID文件存放的位置)
lock file = /var/run/rsyncd.lock(锁文件的存放位置)
log file = /var/log/rsyncd.log (日志文件位置)
hosts allow = 192.168.1.96 (允许连接的IP)
hosts deny = * (其余全部拒绝)
[log] (认证模块,就是对外公布的名字)
# sync of dir path
path = /www/web/ (同步目录)
Miss I/O errors (忽略一些无关的I/O错误)
ignore errors = yes (忽略一些无关的I/O错误)
read only = no (只允许读和写)
list = no (表示不允许列表清单)
hosts allow = 192.168.1.96 (只允许指定IP同步,拒绝其他一切连接)
hosts deny = *
# use username
auth users= andy (认证的用户名)
# password file
secrets file=/etc/rsyncd.password (密码文件存放位置)
4.启动rsync,可通过xinetd来控制,所以我们先需要安装xinetd
yum -y install xinetd
5、对rsync进行修改,我们先编辑rsync相关的文件/etc/xinetd.d/rsync
service rsync
{
disable = no
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}
这里主要降disable=yes 改为 no。
重启xinetd服务
service xinetd restart
6.创建同步目录
mkdir -p /www/web
chmod -R 777 /www/web
echo "andy:andy" < /etc/rsyncd.password (用户名:密码 要求是系统中存在的用户)
chmod 600 /etc/rsyncd.password
7、开启防火墙tcp 873端口(Rsync默认端口)
vi /etc/sysconfig/iptables #编辑防火墙配置文件
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 873 -j ACCEPT
:wq! #保存
service iptables restart #最后重启防火墙使配置生效
【客户端设置】
1.查看是否安装rsync
rpm -qa rsync (或者 yum list installed | grep rsync )
2.若没有安装rsync
yum -y install rsync
3.创建存放服务器端用户密码的文件
echo "andy" < /etc/rsyncd.password (这里指需要密码,不需要写用户名)
chmod 600 /etc/rsyncd.password
4.进行同步
rsync -vzrtopg --delete /home/andy/logs [email protected]::log --password-file=/etc/rsyncd.password
(delete后面是要同步的文件路径 ::后面是在rsyncd.conf文件中设置的模块名称)
常见故障解决思路:
1.查看文件权限,服务器端和客户端一致
2.查看客户端是否提供正确的密码或服务器端的用户和密码是否无误。
3.查看模块名称是否正确
4.服务端是否启动