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

相关文章
|
5天前
|
缓存 Ubuntu Linux
Linux中yum、rpm、apt-get、wget的区别,yum、rpm、apt-get常用命令,CentOS、Ubuntu中安装wget
通过本文,我们详细了解了 `yum`、`rpm`、`apt-get`和 `wget`的区别、常用命令以及在CentOS和Ubuntu中安装 `wget`的方法。`yum`和 `apt-get`是高层次的包管理器,分别用于RPM系和Debian系发行版,能够自动解决依赖问题;而 `rpm`是低层次的包管理工具,适合处理单个包;`wget`则是一个功能强大的下载工具,适用于各种下载任务。在实际使用中,根据系统类型和任务需求选择合适的工具,可以大大提高工作效率和系统管理的便利性。
54 25
|
15天前
|
监控 Linux PHP
【02】客户端服务端C语言-go语言-web端PHP语言整合内容发布-优雅草网络设备监控系统-2月12日优雅草简化Centos stream8安装zabbix7教程-本搭建教程非docker搭建教程-优雅草solution
【02】客户端服务端C语言-go语言-web端PHP语言整合内容发布-优雅草网络设备监控系统-2月12日优雅草简化Centos stream8安装zabbix7教程-本搭建教程非docker搭建教程-优雅草solution
65 20
|
1月前
|
存储 分布式计算 Hadoop
Centos7.9安装kerberos
Centos7.9安装kerberos
86 25
|
1月前
|
存储 Shell 网络安全
Centos7.9安装openldap
Centos7.9安装openldap
58 16
|
1月前
|
数据可视化 Linux 应用服务中间件
Centos7.9安装phpldapadmin
Centos7.9安装phpldapadmin
62 15
|
1月前
|
网络协议 Java 应用服务中间件
centos7环境下tomcat8的安装与配置
本文介绍了在Linux环境下安装和配置Tomcat 8的详细步骤。首先,通过无网络条件下的文件交互软件(如Xftp 6或MobaXterm)下载并解压Tomcat安装包至指定路径,启动Tomcat服务并测试访问。接着,修改Tomcat端口号以避免冲突,并部署Java Web应用项目至Tomcat服务器。最后,调整Linux防火墙规则,确保外部可以正常访问部署的应用。关键步骤包括关闭或配置防火墙、添加必要的端口规则,确保Tomcat服务稳定运行。
|
3月前
|
SQL 存储 Linux
从配置源到数据库初始化一步步教你在CentOS 7.9上安装SQL Server 2019
【11月更文挑战第16天】本文介绍了在 CentOS 7.9 上安装 SQL Server 2019 的详细步骤,包括配置系统源、安装 SQL Server 2019 软件包以及数据库初始化,确保 SQL Server 正常运行。
168 4
|
4月前
|
Linux 网络安全 数据安全/隐私保护
Linux系统之Centos7安装cockpit图形管理界面
【10月更文挑战第12天】Linux系统之Centos7安装cockpit图形管理界面
187 1
Linux系统之Centos7安装cockpit图形管理界面
|
3月前
|
SQL 存储 Linux
从配置源到数据库初始化一步步教你在CentOS 7.9上安装SQL Server 2019
【11月更文挑战第8天】本文介绍了在 CentOS 7.9 上安装 SQL Server 2019 的详细步骤,包括系统准备、配置安装源、安装 SQL Server 软件包、运行安装程序、初始化数据库以及配置远程连接。通过这些步骤,您可以顺利地在 CentOS 系统上部署和使用 SQL Server 2019。
178 1
|
3月前
|
SQL 存储 Linux
从配置源到数据库初始化一步步教你在CentOS 7.9上安装SQL Server 2019
【11月更文挑战第7天】本文介绍了在 CentOS 7.9 上安装 SQL Server 2019 的详细步骤,包括系统要求检查与准备、配置安装源、安装 SQL Server 2019、配置 SQL Server 以及数据库初始化(可选)。通过这些步骤,你可以成功安装并初步配置 SQL Server 2019,进行简单的数据库操作。
108 1

热门文章

最新文章