centos 6.5 安装rsync

前端之家收集整理的这篇文章主要介绍了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 -avzbackup@192.168.199.235::www /tmp/注:加�password-file=/etc/rsyncd.passwd 可不用输密码

Password:

receiving incremental file list

./

aa

bb

cc.txt

sent 115 bytesreceived 234 bytes139.60 bytes/sec

total size is 0speedup 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 bytesreceived 69 bytes902.67 bytes/sec

total size is 5604speedup 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/hostsroot@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 bytesreceived 31 bytes20.67 bytes/sec

total size is 158speedup is 1.02

关闭rsync服务

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

root 1373 10 14:05 ? 00:00:00 rsync �daemon

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

[root@rsync-s ~]# pkillrsync

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

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

启动rsync服务

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

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

root 1615 10 15:02 ? 00:00:00 rsync �daemon

root 1617 13300 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 root0 7月11 2016 aa

-rw-r�r� 1 root root0 7月11 2016 bb

-rw-r�r� 1 root root0 7月11 2016 cc

-rw-r�r� 1 root root0 7月11 2016 jin

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

-rw-r�r� 1 root root0 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 bytesreceived 50 bytes149.33 bytes/sec

total size is 13speedup is 0.06

服务端排除 参数:

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

Exclude=aa bb空格隔开

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

Exclude=aa bb test/test.txt

原文链接:https://www.f2er.com/centos/380956.html

猜你在找的CentOS相关文章