一、环境
系统:CentOS6.4x64最小化安装
rsync-1:192.168.3.50
rsync-2:192.168.3.52
二、安装rsync
卸载原有的rsync软件包
[[email protected] ~]# rpm -e `rpm -qa |grep rsync`
下载最新的rsync安装包,并安装
[[email protected] ~]# wget http://pkgs.repoforge.org/rsync/rsync-3.1.1-1.el6.rfx.x86_64.rpm [[email protected] ~]# rpm -ivh rsync-3.1.1-1.el6.rfx.x86_64.rpm warning: rsync-3.1.1-1.el6.rfx.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 6b8d79e6: NOKEY Preparing... ########################################### [100%] 1:rsync ########################################### [100%]
场景:从rsync-1直接推送文件到rsync-2的/root目录下
#查看rsync-2的/root目录下的文件 [[email protected] ~]# ll /root/ total 56 -rw-------. 1 root root 2790 May 4 13:49 anaconda-ks.cfg -rw-r--r--. 1 root root 3305 May 4 13:49 cobbler.ks -rw-r--r--. 1 root root 20504 May 4 13:49 install.log -rw-r--r--. 1 root root 5882 May 4 13:48 install.log.syslog -rw-r--r--. 1 root root 2241 May 4 13:49 ks-post.log -rw-r--r--. 1 root root 1 May 4 13:49 ks-post-nochroot.log -rw-r--r--. 1 root root 978 May 4 13:45 ks-pre.log #在rsync-1上直接推送文件到rsync-2上 [[email protected] ~]# rsync -avz rsync-3.1.1-1.el6.rfx.x86_64.rpm 192.168.3.52:/root [email protected]‘s password: sending incremental file list rsync-3.1.1-1.el6.rfx.x86_64.rpm sent 409,478 bytes received 35 bytes 117,003.71 bytes/sec total size is 413,760 speedup is 1.01 #在rsync-2上查看结果 [[email protected] ~]# ll /root/ total 464 -rw-------. 1 root root 2790 May 4 13:49 anaconda-ks.cfg -rw-r--r--. 1 root root 3305 May 4 13:49 cobbler.ks -rw-r--r--. 1 root root 20504 May 4 13:49 install.log -rw-r--r--. 1 root root 5882 May 4 13:48 install.log.syslog -rw-r--r--. 1 root root 2241 May 4 13:49 ks-post.log -rw-r--r--. 1 root root 1 May 4 13:49 ks-post-nochroot.log -rw-r--r--. 1 root root 978 May 4 13:45 ks-pre.log -rw-r--r-- 1 root root 413760 Jun 23 2014 rsync-3.1.1-1.el6.rfx.x86_64.rpm
三、配置rsync服务
配置rsync已xinetd方式运行
[[email protected] ~]# yum install xinetd -y #修改/etc/xinetd.d/rsync [[email protected] ~]# vim /etc/xinetd.d/rsync service rsync { disable = no ##将yes改成no socket_type = stream wait = no user = root server = /usr/bin/rsync server_args = --daemon log_on_failure += USERID } #启动xinetd服务 [[email protected] ~]# service xinetd start Starting xinetd: [ OK ] #rsync默认的监听端口是873,查看873号端口是否启动 [[email protected] ~]# netstat -anpt Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1244/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1321/master tcp 0 52 192.168.3.50:22 192.168.3.2:17985 ESTABLISHED 1812/sshd tcp 0 0 :::22 :::* LISTEN 1244/sshd tcp 0 0 ::1:25 :::* LISTEN 1321/master tcp 0 0 :::873 :::* LISTEN 1957/xinetd
添加防火墙规则,放行873端口
[[email protected] ~]# iptables -I INPUT -p tcp --dport 873 -j ACCEPT [[email protected] ~]# iptables -I INPUT -p udp --dport 873 -j ACCEPT [[email protected] ~]# service iptables save iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ] [[email protected] ~]# iptables -L -n |grep 873 ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:873 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:873
创建rsync服务目录和配置文件
#创建rsync服务目录 [[email protected] ~]# mkdir /etc/rsyncd # 创建配置文件 [[email protected] ~]# touch /etc/rsyncd/rsyncd.conf # 创建密码文件 [[email protected] ~]# touch /etc/rsyncd/rsyncd.secrets #权限修改 [[email protected] ~]# chown root:root /etc/rsyncd/rsyncd.passwd [[email protected] ~]# chmod 600 /etc/rsyncd/rsyncd.secrets
创建用户和密码
[[email protected] ~]# echo "rsync:test" >>/etc/rsyncd/rsyncd.secrets
创建rsync配置文件
[[email protected] ~]# vim /etc/rsyncd/rsyncd.conf # GLOBAL OPTIONS uid = root gid = root use chroot = no read only = yes #limit access to private LANs hosts allow=192.168.3.0/255.255.0.0 hosts deny=* max connections = 5 pid file = /var/run/rsyncd.pid secrets file = /etc/rsyncd/rsyncd.secrets #lock file = /var/run/rsync.lock motd file = /etc/rsyncd/rsyncd.motd #This will give you a separate log file log file = /var/log/rsync.log #This will log every file transferred - up to 85,000+ per user, per sync transfer logging = yes log format = %t %a %m %f %b syslog facility = local3 timeout = 300 # MODULE OPTIONS [test] path = /data/test list=yes ignore errors auth users = rsync comment = welcome to rsync server
编辑xinetd的rsync配置文件,添加配置文件路径
#添加rsync的配置文件路径 [[email protected] ~]# vim /etc/xinetd.d/rsync service rsync { disable = no socket_type = stream wait = no user = root server = /usr/bin/rsync server_args = --daemon --config=/etc/rsyncd/rsyncd.conf #添加配置文件路径 log_on_failure += USERID } [[email protected] ~]# service xinetd restart Stopping xinetd: [ OK ] Starting xinetd: [ OK ] [[email protected] ~]# netstat -anpt |grep 873 tcp 0 0 :::873 :::* LISTEN 2045/xinetd
在客户端rsync-2上查看rsync-1提供了哪些数据服务
[[email protected] ~]# rsync --list-only [email protected]:: test welcome to rsync server #现已有一个名为test的数据服务 #将test同步到本地的/root目录下
时间: 2024-10-07 20:53:00