centos 6.5 安装rsync

简介:

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,如需转载请自行联系原作者

相关文章
|
7天前
|
Linux 网络安全 开发工具
Centos6.5安装并配置Telnet服务
该内容是一个关于如何安装配置Telnet服务的教程。首先,通过yum安装vim、xinetd、telnet和telnet-server。接着,修改/etc/xinetd.d/telnet配置文件,将disable改为no,并设置访问限制(如限定特定网段和时间)。关闭防火墙,重启服务。创建测试用户后,分别使用CentOS和Windows的Telnet客户端进行连接测试,显示成功,实验完成。
17 1
|
2天前
|
NoSQL Linux 网络安全
【专栏】如何在 RHEL 8 或者 CentOS 8 上安装 MongoDB?
【4月更文挑战第28天】本文档介绍了如何在RHEL或CentOS 8上安装MongoDB,包括环境准备(系统更新、依赖安装、硬件需求和sudo用户)、导入MongoDB GPG公钥、创建Yum仓库、安装MongoDB社区版,以及后续的基本配置和验证(启动服务、防火墙设置和连接验证)。通过这些步骤,用户可以顺利安装并运行MongoDB,以处理非结构化数据和扩展技术栈。
|
2天前
|
安全 Linux 网络安全
【专栏】如何进行 CentOS 8 最小安装
【4月更文挑战第28天】本文介绍了如何进行CentOS 8的最小安装,包括准备工作(确认硬件兼容性、下载ISO镜像、制作启动盘及备份数据)和安装步骤(选择语言、最小环境、网络设置、安全策略、分区、用户设置及开始安装)。安装后需进行基础配置,如系统更新、SELinux设置、防火墙配置、安装必要软件包和服务优化。最小安装提供了一个精简高效的环境,便于用户根据需求自定义和管理服务器。
|
3天前
|
存储 Linux 持续交付
【docker】CentOS 7上安装Docker的详细过程
【docker】CentOS 7上安装Docker的详细过程
|
5天前
|
安全 关系型数据库 Linux
centos7_安装mysql8(局域网访问navicat连接)
centos7_安装mysql8(局域网访问navicat连接)
12 1
|
5天前
|
Linux 云计算 Perl
centos7_安装虚拟机工具
centos7_安装虚拟机工具
15 0
|
5天前
|
网络协议 Java 应用服务中间件
记录_centos7离线环境和虚拟机共享文件安装jdk和tomcat(配置环境变量)
记录_centos7离线环境和虚拟机共享文件安装jdk和tomcat(配置环境变量)
6 0
|
6天前
|
存储 Unix Linux
|
6天前
|
Shell
CentOS6.5自动化安装LAMP脚本
CentOS6.5自动化安装LAMP脚本
|
6天前
|
Linux
centos 6.5安装yum
centos 6.5安装yum
34 0

热门文章

最新文章