Rsync(remote synchronize)是一个远程数据同步工具,简要的概括就是主机于主机之间的文件目录数据的一个同步。下面就是rsync服务器的搭建过程。

   系统环境

  平台:Centos 6.5

  rsync版本:rsync-3.0.6-12.el6.x86_64

  rsync服务器:172.23.216.86

  rsync客户端:172.23.216.87

  

 服务端安装rsync服务

  1.检查rsync是否已经安装,若已安装,使用rpm -e 命令卸载。

[root@021rjsh216087s ~]# rpm -qa|grep rsync
rsync-3.0.-.el6.x86_64

  2.安装这里我们选择yum安装。

yum -y install rsync

  3.安装完成后,我们要在/etc目录下创建并编辑这三个文件。

[root@021rjsh216086s run]# ll /etc/rsyncd*
-rw-r--r-- root root Jan : /etc/rsyncd.conf        --配置文件
-rw-r--r-- root root Jan : /etc/rsyncd.motd         --欢迎文件(不重要)
-rw------- root root Jan : /etc/rsyncd.password      --用户的密码文件

   4.修改/etc/rsyncd.conf 文件

#This is rsync conf######
uid = root #必须是系统的用户,可以不是root
gid = root                #必须是系统用用户,可以不是root
max connections =
timeout =
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
motd file = /etc/rsyncd.motd      
[hellowhome]               #同步的模块的名称
path = /home/hello            #模块的家目录,
read only = false              #true表示只读,false表示非只读
list = yes                  
hosts allow = *               #允许访问的ip
hosts deny = 10.10.10.10         #拒绝访问的ip
auth users = hello            #访问的用户(可以不是系统用户) 
secrets file = /etc/rsyncd.password   #密码文件
exclude = www/ xxx/            #这是除了home目录的下www 跟xxx目录
comment = ...Hello..            #欢迎内容

注意:在搭建服务时,要把注释删除,或者另起一行,因为当有些配置项(auth users...)后面有空格,rsync会无法使用,这种空格问题很隐蔽,很难发现,所以要避免。

 5.修改/etc/rsyncd.password 文件,修改完成之后,要把文件权限赋成600,否则无法访问。

hello:123456         #格式【用户名(auth users):密码】
[root@021rjsh216086s run]# chmod  /etc/rsyncd.password
[root@021rjsh216086s run]# ll /etc/rsyncd.password
-rw------- root root Jan : /etc/rsyncd.password

 6.启动rsync 服务。

rsync --daemon --config=/etc/rsyncd.conf                #启动服务
cat /var/run/rsyncd.pid|xargs kill -9 && rm -rf /var/run/rsyncd.pid #停止服务

  7.查看873端口是否成功启动

[root@021rjsh216086s run]#  netstat -an | grep 873                #查873端口状态
tcp 0.0.0.0: 0.0.0.0:* LISTEN
tcp ::: :::* LISTEN
[root@021rjsh216086s run]# lsof -i tcp:873 #根据端口查服务
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
rsync root 4u IPv4 0t0 TCP *:rsync (LISTEN)
rsync root 5u IPv6 0t0 TCP *:rsync (LISTEN)

 客户端操作

  服务端装完之后,在客户端也需要进行一些配置。

  1.先用yum装一下rsync这个软件。

yum -y install rsync

  2.测试一下是否成功

[root@021rjsh216087s ~]# rsync -avz -P hello@172.23.216.86::
*****************************************
* *
* Rsync *
* *
* *
***************************************** hellohome loading...Hello..

  3.列出服务器上的文件信息

[root@021rjsh216087s ~]# rsync -a hello@172.23.216.86::hellohome       #hello为auth users,hellohome为模块名字,密码在/etc/rsyncd.password中,列出的信息是/home/hello下的内容
*****************************************
* *
* Rsync *
* *
* *
***************************************** Password:
drwx------ // :: .
-rw-r--r-- // :: .bash_logout
-rw-r--r-- // :: .bash_profile
-rw-r--r-- // :: .bashrc
-rw-r--r-- // :: rsyncd.conf
drwxr-xr-x // :: .gnome2
drwxr-xr-x // :: .mozilla
drwxr-xr-x // :: .mozilla/extensions
drwxr-xr-x // :: .mozilla/plugins
drwxr-xr-x // :: newdir
drwxr-xr-x // :: newdir/test
drwxr-xr-x // :: newdir/test/newdir

  4.下载服务器上的文件

[root@021rjsh216087s ~]# rsync -avzP hello@172.23.216.86::hellohome/newdir /tmp/tmp    #将hello用户家目录下的newdir文件夹拷贝到 本地/tmp/tmp 文件夹下
Password:
receiving incremental file list
created directory /tmp/tmp
newdir/
newdir/test/
newdir/test/newdir/ sent bytes received bytes 194.00 bytes/sec
total size is speedup is 0.00
[root@021rjsh216087s ~]# ll /tmp/tmp #查看下载的内容
total
drwxr-xr-x Jan : newdir

  5.上传文件到服务器

[root@021rjsh216087s ~]# rsync -avzP /tmp/abc  hello@172.23.216.86::hellohome     # 将本地tmp/abc文件下的内容上传到hello用户的家目录下

注意:在上传时,若写成【 /tmp/abc 】,上传的是tmp目录下的abc文件夹,连abc一同上传;

            若写成【 /tmp/abc/ 】,上传的是tmp目录下的abc目录下的内容,abc这个文件夹不会上传。下载时情况也一样。

  

 6.客户端配置密码文件登录

  在客户端上的新建一个密码文件/etc/rsyncd.password,在文件内只写登录用户(auth users)的密码,例如用户hello,其密码是123,那么只在文件中写123.

[root@021rjsh216087s ~]# chmod  /etc/rsyncd.password            #也要将密码文件的权限赋成600,要不会失败
[root@021rjsh216087s ~]# ll /etc/rsyncd.password
-rw------- root root Jan : /etc/rsyncd.password

之后,再用rsync时,加上--password-file=/etc/rsyncd.password,就可以不用输入密码登录了。

[root@021rjsh216087s ~]# rsync -avzP --password-file=/etc/rsyncd.password hello@172.23.216.86::hellohome/newdir /tmp/tmp 

receiving incremental file list

sent  bytes  received  bytes  311.33 bytes/sec
total size is speedup is 0.00

至此,算是完成。

参考文档:rsync服务与搭建详解

        Rsync的文件同步实现

     CentOS 6.3下rsync服务器的安装与配置

       rsync关于auth failed on module xxx的解决方法

     rsync入门

rsync服务器的搭建的更多相关文章

  1. Rsync 服务器搭建

    Rsync简介 rsync 是一个 Unix 系统下的文件同步和传输工具. 它具备以下特性: 1. 能更新整个目录和树和文件系统 2. 有选择性的保持符号链链.硬链接.文件属于.权限.设备以及时间 等 ...

  2. 搭建Rsync服务器

    部署Rsync服务器需要创建至少 一个配置文件,默认在系统中并不存在Rsync配置文件,对于服务器而言,配置文件创建完成后,使用守护进程模式启动rsync程序即可. 使用Centos 系统安装 部署R ...

  3. Linux-Rsync服务器/客户端搭建实战

    一.需求 每晚汇总各机器的操作日志,同步到主服务器进行日志分析. 二.基础知识 rsync 分为服务器端.客户端,服务器端搭建比客户端辛苦一些(也是很简单). rsync 服务器是指以 deamon ...

  4. [Linux]Linux下rsync服务器和客户端配置

    一.rsync简介 Rsync(remote sync)是UNIX及类UNIX平台下一款神奇的数据镜像备份软件,它不像FTP或其他文件传输服务那样需要进行全备份,Rsync可以根据数据的变化进行差异( ...

  5. 4、nfs服务器的搭建

    4.1.nfs服务介绍: samba服务器一般互联网企业不会使用 nfs服务的端口是不固定的,需要先启动rpc服务对nfs服务端口进行注册 4.2.安装nfs: rpm -qa nfs-utils r ...

  6. 在MAC服务器上搭建docker-registry(转)

    在MAC服务器上搭建docker-registry 2014-03-14      0个评论    来源:在MAC服务器上搭建docker-registry   收藏    我要投稿 本文介绍如何在M ...

  7. LNAMP服务器环境搭建(手动编译安装)

    LNAMP服务器环境搭建(手动编译安装) 一.准备材料 阿里云主机一台,操作系统CentOS 6.5 64位 lnamp.zip包(包含搭建环境所需要的所有软件) http://123.56.144. ...

  8. 在Ubuntu14.04系统POWER8服务器上搭建Docker Registry服务

    本文描述了如何在POWER8服务器上搭建一个本地化的Docker镜像仓库,主要涉及镜像制作,Docker Registry服务启动等.希望能够对在非X86服务器上搭建Docker仓库的同学提供参考. ...

  9. 【转载】CentOS 6.3下rsync服务器的安装与配置

    一.rsync 简介 Rsync(remote synchronize)是一个远程数据同步工具,可通过LAN/WAN快速同步多台主机间的文件,也可以使用 Rsync 同步本地硬盘中的不同目录. Rsy ...

随机推荐

  1. Ubuntu配置完全教程

    前言 最近将旧电脑换成了Ubuntu系统,在网上找了许多优化和配置教程,今天整理一份完整的教程给大家分享 系统清理 卸载LibreOffice libreoffice事ubuntu自带的开源offic ...

  2. IntelliJ IDEA(一) :安装

    前言 我是从eclipse转IDEA的,对于习惯了eclipse快捷键的我来说,转IDEA开始很不习惯,IDEA快捷键多,组合多,记不住,虽然可以设置使用eclipse的快捷键,但是总感觉怪怪的.开始 ...

  3. 前端自动化测试漫长路之——Selenium初探

    引言 最近想解决前端开发或测试中的两个问题:一是界面UI的布局适配,能否在测试的过程中,通过命令操作真机打开相应页面然后截屏,通过对图片识别分类,发现有问题的图片,然后及时修复:二是页面性能分析,很多 ...

  4. 整理下git常用命令

    Git工作示意图 一.新建代码库 ::在当前目录新建一个Git代码库git init::新建一个目录,将其初始化为Git代码库git init [project-name]::下载一个项目和它的整个代 ...

  5. 如何在PHP7中安装mysql的扩展

    相对与PHP5,PHP7的最大变化之一是移除了mysql扩展,推荐使用mysqli或者pdo_mysql,实际上在PHP5.5开始,PHP就着手开始准备弃用mysql扩展,如果你使用mysql扩展,可 ...

  6. LeetCode :My solution N-Queens

    N-Queens Total Accepted: 15603 Total Submissions: 60198My Submissions The n-queens puzzle is the pro ...

  7. Spring Cache简单介绍和使用

    Spring Cache 缓存是实际工作中非经常常使用的一种提高性能的方法, 我们会在很多场景下来使用缓存. 本文通过一个简单的样例进行展开,通过对照我们原来的自己定义缓存和 spring 的基于凝视 ...

  8. "Insufficient RAM for Flash Algorithms"出错原因及解决方式

    "Insufficient RAM for Flash Algorithms"错误通常会有一个"cannot load flash programming algorit ...

  9. break and continue

    public class HelloWorld { public static void main(String[] args) { int sum = 0; for (int i = 1; i &l ...

  10. jquery 自定义选择器

    // HTML 代码 <body> <div id="divid1" class="divclass">白色</div> & ...