要求:配置针对单一ip的免认证 rsync 服务,环境为 centos 6.5,需要关闭 SELINUX
安装
yum install -y xinetd rsync
检查 iptables 需要使 873 端口通行
配置 xinetd
vim /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
flags = IPv4
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}
配置 rsync 配置文件
vim /etc/rsyncd.conf
max connections = 5 log file = /var/log/rsync.log uid = nobody gid = nobody [web] path = /home/ftpuser1 read only = false hosts allow = 192.168.1.1
重启 xinetd
上面访问的路径就为 rsync -av 192.168.x.x::web .
参考:
如果不使用 xinetd 来做守护。创建如下目录和文件
/etc/rsyncd
├── rsyncd.conf
└── rsyncd.secrets
查看 rsyncd.conf
pid file = /var/run/rsyncd.pid port = 873 address = 192.168.1.123 uid = root gid = root use chroot = yes read only = no hosts allow=192.168.1.0/255.255.255.0 hosts deny=* max connections = 10 motd file = /etc/rsyncd/rsyncd.motd log format = %t %a %m %f %b syslog facility = local3 timeout = 300 [bbs] path = /data/www/bbs list=yes ignore errors auth users = my_name secrets file = /etc/rsyncd/rsyncd.secrets comment = blog
查看 rsyncd.secrets
my_name:mypass
之后要想传文件到 192.168.1.123 的 /data/www/bbs 下
客户端创建文件 /etc/sersync/rsync_password
写入
mypass
权限为 0400
执行
rsync -a -R --delete ./ --include=bbbb --exclude=* [email protected]::bbs --password-file=/etc/sersync/rsync_password
关于权限问题而不成功参考:
http://superuser.com/questions/243656/how-to-configure-and-use-rsyncd
rsyncd 的 init 文件
#! /bin/bash
#
# chkconfig: 2345 50 50
# description: The rsync daemon
#pidfile: /var/run/rsyncd.pid
# source function library
. /etc/rc.d/init.d/functions
PROG='/usr/bin/rsync'
BASE=${0##*/}
# The config file must contain following line:
# pid file = /var/run/rsync.pid
OPTIONS="--daemon --config=/etc/rsyncd/rsyncd.conf"
case "$1" in
start)
echo -n $"Starting $BASE: "
daemon $PROG $OPTIONS
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$BASE
echo
;;
stop)
echo -n $"Shutting down $BASE: "
killproc $PROG
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$BASE
echo
;;
restart|force-reload)
$0 stop
sleep 1
$0 start
;;
status)
status $PROG
;;
*)
echo "Usage: $0 {start|stop|restart|status|force-reload}" >&2
exit 1
;;
esac
Leave a Reply