henniu

[安装帮助] linux下rsync同步文件

1. 安装rsync

    yum install rsync 

2. #touch /etc/rsyncd.conf  #创建rsyncd.conf,这是rsync服务器的配置文件。

  #touch /etc/rsyncd.secrets  #创建rsyncd.secrets ,这是用户密码文件。
  #chmod 600 /etc/rsyncd/rsyncd.secrets  #将rsyncd.secrets这个密码文件的文件属性设为root拥有, 且权限要设为600, 否则无法备份成功!
  #touch /etc/rsyncd.motd 

3. rsync.conf配置文件


# Distributed under the terms of the GNU General Public License v2

# Minimal configuration file for rsync daemon

# See rsync(1) and rsyncd.conf(5) man pages for help

# This line is required by the /etc/init.d/rsyncd script

pid file = /var/run/rsyncd.pid

port = 873

#服务端IP

address = xxx.xxx.xxx.xxx

#uid = nobody

#gid = nobody

uid = root

gid = root

use chroot = yes

read only = yes

#limit access to private LANs

#允许的客户端IP

hosts allow=xxx.xxx.xxx.xxx

hosts deny=*

max connections = 5

#欢迎信息文件路径

motd file = /etc/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

#模块

[henniufiles]

path = /mnt/www/henniu110.com/files

list=yes

ignore errors

auth users = root

secrets file = /etc/rsyncd.secrets

comment = This is RHEL 4 data

exclude = easylife/ samba/  


4. 修改文件属性

chown root.root /etc/rsyncd.secrets  #修改属主

chmod 600 /etc/rsyncd.secrets     #修改权限   


5. 编辑欢迎信息

vi /etc/rsyncd.motd

输入:

++++++++++++++++++++++++++++++++++++++++++++++
   欢迎光临<很牛小说网-www.henniu110.com> rsync services!
++++++++++++++++++++++++++++++++++++++++++++++ 


6. 设置服务端防火墙

两种方法:

    a) service iptables stop

    b) iptables -A INPUT -p tcp -m state --state NEW  -m tcp --dport 873 -j ACCEPT


7. 在客户端同步服务端内容

 新建密码文件touch password.pwd

 在文件中输入密码

 设置文件属性chmod 600 password.pwd    (必须设置, 否则无法同步)

 rsync -zrtopg --progress --delete --password-file=/data/www/password.pwd root@103.241.51.27::henniufiles /data/www/henniu110.com


#1楼
发帖时间:2014-4-12   |   查看数:0   |   回复数:1
shao
弄了半天不知所云,用下面莫名好使
rsync 同步 拉文件  
旧vps:
rsync --daemon  
新vps:
rsync -rp --ignore-existing root@xxx.xxx.xxx.xxx:/data/txt /data/txt
2015-1-31 #2楼
游客组