Rsync 服务

同步命令参数:

-v 详细模式输出,传输时的进度信息

-z 传输时进行压缩以提高传输效率

-a 递归模式保持所有文件属性。等同于-rtopPDl

-e 使用信道协议

服务端部署:

1关闭防火墙和selinux

2检查rsync 安装没有

[root@zabbixceshi /]# rpm -qa |grep rsync

rsync-3.0.6-12.el6.x86_64

3创建配置文件(默认没有)

Touch /etc/rsyncd.conf

uid = root

gid = root

use chroot = no

max connections = 0

pid file = /var/log/rsync/rsyncd.pid

lock file = /var/log/rsync/rsync.lock

log file = /var/log/rsync/rsyncd.log

strict modes =yes

[www]

path = /www/

ignore errors

read only = false

list = false

hosts allow = all

hosts deny = 172.25.0.0/24

auth users = backup

secrets file = /etc/rsyncd.passwd

4创建用户认证文件(虚拟用户名和密码)

Echo “back:123” >/etc/rsyncd.passwd

5给予600权限

Chmod 600 /etc/rsyncd.passwd

6启动服务

Rsync –daemon

7查看端口

[root@zabbixceshi /]# netstat -anpt |grep rsync

tcp        0      0 0.0.0.0:873                 0.0.0.0:*                   LISTEN      1302/rsync

tcp        0      0 :::873                      :::*                        LISTEN      1302/rsync

8建立共享的目录

mkdir /www

客服端配置

1 创建密码文件

Echo “123” >/etc/rsyncd.passwd

2 给予600 权限

Chmod 600 /etc/rsyncd.passwd

测试 :

3从服务端同步到客户端:
[root@rsync-c etc]# rsync -avz backup@192.168.199.235::www /tmp/  注:加 –password-file=/etc/rsyncd.passwd 可不用输密码

Password:

receiving incremental file list

./

aa

bb

cc.txt

sent 115 bytes  received 234 bytes  139.60 bytes/sec

total size is 0  speedup is 0.00

或者这样:

rsync -avz rsync://backup@192.168.199.235/www /tmp –password-file=/etc/rsyncd.passwd

从客户端同步到服务端

如果只同步目录里面内容/tmp/ 要加斜线,如果是目录不用加斜线/tmp 即可。

[root@rsync-c tmp]# rsync -avz /tmp/ backup@192.168.199.235::www  –password-file=/etc/rsyncd.passwd

sending incremental file list

yum.log

zabbix_agentd.log

zabbix_agentd.pid

.ICE-unix/

sent 1285 bytes  received 69 bytes  902.67 bytes/sec

total size is 5604  speedup is 4.14

或者:

[root@rsync-c tmp]# rsync -avz /tmp/ rsync://backup@192.168.199.235/www –password-file=/etc/rsyncd.passwd

使用ssh协议进行推送:

[root@rsync-c tmp]# rsync -avz -e ‘ssh -p 22’ /etc/hosts root@192.168.199.235:~

The authenticity of host ‘192.168.199.235 (192.168.199.235)’ can’t be established.

RSA key fingerprint is 0b:49:b6:27:2b:98:e4:b1:ed:42:77:7b:07:9a:42:0b.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added ‘192.168.199.235’ (RSA) to the list of known hosts.

root@192.168.199.235’s password:

sending incremental file list

hosts

sent 124 bytes  received 31 bytes  20.67 bytes/sec

total size is 158  speedup is 1.02

关闭rsync 服务

[root@rsync-s ~]# ps -ef |grep rsync

root       1373      1  0 14:05 ?        00:00:00 rsync –daemon

root       1610   1330  0 15:01 pts/0    00:00:00 grep rsync

[root@rsync-s ~]# pkill  rsync

[root@rsync-s ~]# ps -ef |grep rsync

root       1613   1330  0 15:01 pts/0    00:00:00 grep rsync

启动rsync服务

[root@rsync-s ~]# rsync –daemon

[root@rsync-s ~]# ps -ef |grep rsync

root       1615      1  0 15:02 ?        00:00:00 rsync –daemon

root       1617   1330  0 15:02 pts/0    00:00:00 grep rsync

–exclude 参数 排除文件

从客户端往服务端同步,排除客户端的文件

rsync -avz –exclude=aa  /tmp/ backup@192.168.199.235::www –password-file=/etc/rsyncd.passwd

排除多个文件

rsync -avz –exclude={aa,bb} /tmp/backup@192.168.199.235::www –password-file=/etc/rsyncd.passwd

或者

rsync -avz –exclude=aa –exclude=bb /tmp/  backup@192.168.199.235::www –password-file=/etc/rsyncd.passwd

排除多个不规律的文件

参数:–exclude-from=文件名

使用方法:把文件名写到一个文件中

[root@rsync-c tmp]# ll

总用量 4

-rw-r–r– 1 root root  0 7月  11 2016 aa

-rw-r–r– 1 root root  0 7月  11 2016 bb

-rw-r–r– 1 root root  0 7月  11 2016 cc

-rw-r–r– 1 root root  0 7月  11 2016 jin

-rw-r–r– 1 root root 13 7月   8 16:11 li.log

-rw-r–r– 1 root root  0 7月   8 16:09 xx

[root@rsync-c tmp]# cat li.log  注意:文件中每行后面不能有空格

aa

bb

jin

cc

[root@rsync-c tmp]# rsync -avz –exclude-from=li.log /tmp/ backup@192.168.199.235::www –password-file=/etc/rsyncd.passwd

sending incremental file list

./

li.log

xx

sent 174 bytes  received 50 bytes  149.33 bytes/sec

total size is 13  speedup is 0.06

服务端排除 参数:

再配置文件中加参数,重启服务。

Exclude=aa bb 空格隔开

如果是目录中文件格式如下:

Exclude=aa bb test/test.txt

本文转自无形于有形  51CTO博客,原文链接:http://blog.51cto.com/jinchuang/1844408,如需转载请自行联系原作者

centos 6.5 安装rsync相关推荐

  1. linux手动安装rsync_在Linux/Unix上安装rsync并通过示例的方式介绍使用rsync命令

    本文介绍Rsync的功能,在Linux/Unix系统上安装rsync的方法,并通过示例的方式介绍使用rsync命令的方法. Rsync介绍及其功能 在rsync的手册页中,Rsync是一种快速且极其通 ...

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

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

  3. CentOS 6.3下rsync服务器的安装与配置[转]

    CentOS 6.3下rsync服务器的安装与配置 一.rsync 简介 Rsync(remote synchronize)是一个远程数据同步工具,可通过LAN/WAN快速同步多台主机间的文件,也可以 ...

  4. Centos 7 全网备份Rsync

    ==========运维之路 环境如下 [root@Centos ~]# cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core) [r ...

  5. Mongodb学习(安装篇): 在centos下的安装

    安装篇 ###下载解压文件 [root@192 lamp]# wget http://fastdl.mongodb.org/linux/mongodb-linux-i686- 2.2.2.tgz ## ...

  6. 虚拟机安装rsync服务器配置,虚拟机安装rsync服务器配置

    虚拟机安装rsync服务器配置 内容精选 换一换 在分布式HA部署场景下,ASCS主备节点通过共享盘实现数据同步.本章节指导用户将ASCS主节点的数据盘绑定给ASCS备节点并为ASCS主备节点绑定浮动 ...

  7. 如何在CentOS 7上安装Percona XtraDB集群

    原作者:Muhammad Arul  转载&翻译来源:https://www.howtoforge.com/tutorial/how-to-install-percona-xtradb-clu ...

  8. vertica 数据库 linux,CentOS 7下安装vertica记录

    CentOS 7下安装vertica记录 1.    安装好centeros 并更新 Centeros安装就不说了,安装完之后联网环境下 yum update.更新下,使得那些包都是新的.(要想用中文 ...

  9. centos 7 Docker 安装及配置镜像加速

    centos 7 Docker 安装及配置镜像加速 文章目录 centos 7 Docker 安装及配置镜像加速 Docker 版本 基于 `CentOS `安装 `Docker` 引擎 系统要求 卸 ...

最新文章

  1. DEV控件自定义排序实现
  2. 洛谷 2680 (NOIp2015) 运输计划
  3. 底层知识学习记录目录表
  4. Thinkphp5 还有这种操作?
  5. 17--合并两个有序数组
  6. iOS应用图片命名规则
  7. Python学习笔记——for循环和range函数
  8. Java有了synchronized,为什么还要提供Lock
  9. linux tomcat重启 报错,Linux启动Tomcat或停止Tomcat的错误解决方案
  10. Windows内核基础之权限级别
  11. 一个留美女博士的七年
  12. Java怎么除以2_哪个更好的选项用于将整数除以2?
  13. C#实现时间戳与标准时间的互转学习通http://www.bdgxy.com/
  14. Quorum NWR
  15. Ubuntu20.4.4离线安装无线网卡驱动
  16. 北京市2012年职工平均月工资5223元
  17. 睿呈时代与袋鼠云签署战略合作协议,携手助推传统行业数字化转型
  18. 微信公众号开发 接口配置信息 配置失败
  19. 史上最完美的 Typora 教程
  20. 日志系统新贵 Loki,确实比笨重的ELK轻

热门文章

  1. Python:日志模块logging的应用
  2. Silverlight(CodeNameWPF/E) Features一览表
  3. react项目中遇到的坑
  4. Linux下安装和配置JDK与Tomcat(升级版)
  5. 【结构型】Bridge模式
  6. iptables的应用
  7. Python--day47--mysql索引类型介绍
  8. 一次 Java 内存泄漏排查过程,涨姿势
  9. Elasticsearch Java Low Level REST Client(读取响应)
  10. Linux Linux程序练习九