四,服务的启动
4.1 启动方式
分2中方式,daemon方式和xinetd方式
A、--daemon参数方式,是让rsync以服务器模式运行
#/usr/bin/rsync --daemon --config=/etc/rsyncd/rsyncd.conf #--config用于指定rsyncd.conf的位置,如果在/etc下可以不写
B xinet方式
1 修改 vim /etc/services 加入下面内容
rsync 873/tcp # rsync
rsync 873/udp # rsync
2 设定 /etc/xinetd.d/rsync, 简单例子如下:
# default: off
# description: The rsync server is a good addition to am 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
}
上述, 主要是要打开rsync這個daemon, 一旦有rsync client要连接時, xinetd会把它转介給 rsyncd(port 873)。然后service xinetd restart, 使上述设定生效.
4.2检测是否运行
1daemon模式下
方法1
[root@BackServer bin]# ./rsync --daemon
[root@BackServer bin]# netstat -ntlp | grep rsync
tcp 0 0 192.168.18.128:873 0.0.0.0:* LISTEN 6627/./rsync
方法2
[root@BackServer bin]# lsof -i:873
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
rsync 6627 root 4u IPv4 23126 0t0 TCP 192.168.18.128:rsync (LISTEN)
2 Xinetd模式下
方法1
[root@BackServer client]# netstat -ntlp | grep 873
tcp 0 0 :::873 :::* LISTEN 6567/xinetd
方法2
[root@BackServer client]# lsof -i:873
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
xinetd 6567 root 5u IPv6 22527 0t0 TCP *:rsync (LISTEN)
服务启动: service xinetd start
服务停止: service xiniet stop
注意:如果没有lsof和xinetd服务,通过yum安装即可。Yum –y install lsof xinetd
加入开机启动
[root@BackServer bin]# echo "/usr/bin/rsync --daemon" >> /etc/rc.local
五防火墙配置
rsync服务器和防火墙
Linux 防火墙是用iptables,所以我们至少在服务器端要让你所定义的rsync 服务器端口通过,客户端上也应该让通过。
#iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 873 -j ACCEPT
#iptables -L 查看一下防火墙是不是打开了 873端口
