手机版
你好,游客 登录 注册
背景:
阅读新闻

CentOS 6.3下rsync笔记

[日期:2013-06-07] 来源:Linux社区  作者:Linux [字体:大 中 小]

rsync是linux下的文件同步服务,功能简单来说就是服务端打开873端口,客户端连接这个端口,并对服务器端配置的目录进行同步,可以理解为客户端比对服务器端资源后,对增量或者差异的数据进行增删改操作,功能支持上传或下载比对,也就是远程数据比对本地数据而后对远程数据进行增删改操作,以及本地数据比对远程数据然后对本地数据进行增删改操作。

CentOS6.3下默认已经安装,只需保证依赖服务xinetd开启即可。 

环境搭建: 

注:首先关闭selinux与iptables

# vi /etc/sysconfig/selinux

---------

SELINUX=disabled

---------

# setenforce 0

# service iptables stop

 

配置分为2个部分

 

server端:

 

1.安装rsync(centos6.3默认已安装)

# yum install rsync -y

# yum install xinetd -y

 

2.启动rsync依赖服务

# /etc/init.d/xinetd start

# chkconfig xinetd on

 

3.配置/etc/rsyncd.conf

----------------------

uid = root

gid = root

use chroot = no

max connections = 10

strict modes = yes

port = 873

address = 172.24.40.30

[mail]

path = /home/domains/

comment = mirror for extmail

ignore errors

read only = no

list = no

auth users = user

secrets file = /etc/rsync.pas

hosts allow = 172.24.40.50

hosts deny = 0.0.0.0/0

pid file = /var/run/rsyncd.pid

lock file = /var/run/rsync.lock

log file = /var/log/rsyncd.log

--------------------------

# 表示可写

read only = no

# 端口

port = 873

 

4.配置/etc/rsync.pas

在服务器端,必须加入登陆名和密码,在client上,只需要输入密码

# vi /etc/rsync.pas

----------------

user:123456

---------------

并给与相关权限(重要,必须是600)

# chmod 600 /etc/rsync.pas

 

5.配置/etc/rsync.motd

# vi /etc/rsyncd.motd

welcome to use the rsync services!

 

6.启动rsync

# rsync --daemon --config=/etc/rsyncd.conf

 

client端:

 

1.安装rsync(centos6.3默认已安装)

# yum install rsync -y

# yum install xinetd -y

 

2.启动rsync依赖服务

# /etc/init.d/xinetd start

# chkconfig xinetd on

 

3.客户端必须配置密码文件

# vi /etc/rsync.pas

------------------------

123456

----------------------

并给与相关权限(重要,必须是600)

# chmod 600 /etc/rsync.pas

 

4.然后在客户端输入命令同步:

下载:

# rsync -auzv --progress --delete --password-file=/etc/rsync.pas user@172.24.40.30::mail /home/domains

上传:

# rsync -auzv --progress --delete --password-file=/etc/rsync.pas /home/domains/* user@172.24.40.30::mail

注:后面加 --port 873 可添加端口号信息,若在配置文件中自定义端口,这里需要加--port参数。

 

请注意这部分:

user@172.24.40.30::mail /home/domains

----------------

user对应server端配置文件的auth users = user

和server端/etc/rsync.pas内用户名:密码(user:123456)

172.24.40.30对应服务端IP地址

mail对应server端配置文件的[mail]

/home/domains表示client端同步server端数据后数据保存在client端目录的路径

@与::均起到字符连接功能

----------------

 

5.定时计划任务:

在crontab中增加一条命令,设置每分钟自动执行一次。

# crontab -e

----------------------

* * * * * /usr/bin/rsync -auzv --progress --delete --password-file=/etc/rsync.pas user@172.24.40.30::mail /home/domains

---------------------

linux
相关资讯       rsync 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款