Chinaunix首页 | 论坛 | 博客
  • 博客访问: 145306
  • 博文数量: 29
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 368
  • 用 户 组: 普通用户
  • 注册时间: 2013-09-17 18:06
个人简介

一个直来直去的人,被生活折磨的弯弯曲曲。

文章分类

全部博文(29)

文章存档

2019年(1)

2017年(1)

2014年(13)

2013年(14)

我的朋友

分类: 服务器与存储

2013-10-08 16:40:30

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 /home/domains

上传:

# rsync -auzv --progress --delete --password-file=/etc/rsync.pas /home/domains/*

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

 

请注意这部分:

/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 /home/domains

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

本篇文章来源于 Linux公社网站()  原文链接:

阅读(696) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~