本文共 8495 字,大约阅读时间需要 28 分钟。
快速查询scp:/home : 表示将整个 /home 目录复制到目标目录
/home/ : 表示将 /home 目录中的所有内容复制到目标目录[OPTION...]参数 如: rsync -avzP apache@10.0.7.211::hadoop /backup
--exclude 指定排除不需要传输的文件(夹) (必须相对路径) --exclude='file' --exclude='file/123' --exclude-from=/exclude.list 指定排除不需要传输的文件列表 (绝对路径) 比如 我想避开log文件夹,list中的1文件夹,和fire打头的文件 那么/exclude.list 写为 log list/1 fire*
--include-from=/exclude.list 指定排除不需要传输的文件列表 (绝对路径)
(如果同时使用exclude和include,include命令在前) --files-from="includes。txt" 只同步指定的目录清单
一.本机不同目录进行同步 同步命令:
/home : 表示将整个 /home 目录复制到目标目录 /home/ : 表示将 /home 目录中的所有内容复制到目标目录
- 当路径中包含 单引号: 时,启功该模式
- 远程 Shell 方式(建议使用 ssh,用户验证由 ssh 负责) 不用创建rsync服务器、守护进程
- 即客户连接远程 rsync 服务器,用户验证由 rsync 服务器负责
[root@web1 ~]
# yum install rsync
[root@web1 ~]
# rpm -ql rsync 查看文件位置
/etc/xinetd
.d
/rsync
##基于xinetd的管理
/usr/bin/rsync
##rsync命令
/usr/share/doc/rsync-3
.0.6
/usr/share/doc/rsync-3
.0.6
/COPYING
/usr/share/doc/rsync-3
.0.6
/NEWS
…… | [root@node1 ~] # mkdir /etc/rsyncd ##创建配置目录 [root@node1 ~] # touch /etc/rsyncd/rsyncd.conf ## 创建主配置文件 [root@node1 ~] # touch /etc/rsyncd/rsyncd.secrets ## 创建用户密码文件 [root@node1 ~] # chmod 600 /etc/rsyncd/rsyncd.secrets ##修改文件权限 [root@node1 ~] # touch /etc/rsyncd/rsyncd.motd ## 创建定义服务器信息的 |
解析rsyncd.conf pid file = /var/run/rsyncd.pid #进程 pid 文件所在位置 port = 873 #指定监听端口,默认是873,可以自己指定 address = 192.168.1.171 #服务器监听的IP地址,可省略 uid = root #守护进程所属的uid,默认是nobody,可能会碰到文件或目录权限问题,此处偷懒用的 root gid = root #守护进程的gid #chroot,即改变程序执行时所参考的根目录位置,在传输文件之前,服务器守护程序在将chroot 到文件系统中的目录中 #这样做的好处是可能保护系统被安装漏洞侵袭的可能。缺点是需要超级用户权限。另外对符号链接文件,将会排除在外 #也就是说,你在 rsync服务器上,如果有符号链接,你在备份服务器上运行客户端的同步数据时,只会把符号链接名同步下来,并不会同步符号链接的内容 use chroot = yes read only = no #只读选择,只让客户端从服务器上读取文件 write only = yes #只写选择,只让客户端到服务器上写入 #允许访问的IP,可以指定单个IP,也可以指定整个网段,能提高安全性。 #格式是 ip 与 ip 之间、ip 和网段之间、网段和网段之间要用空格隔开; hosts allow = 192.168.1.0/255.255.255.0 10.0.1.0/255.255.255.0
max connections = 5 #客户端最多连接数 #当用户登录时会看到这个信息。比如显示当前时间、公告等 motd file = /etc/rsyncd/rsyncd.motd log file = /var/log/rsync.log #rsync 服务器的日志; transfer logging = yes #记录传输文件的日志 log format = %t %a %m %f %b #日志格式 syslog facility = local3 #日志级别 #通过该选项可以覆盖客户指定的IP超时时间。可以确保rsync服务器不会永远等待一个崩溃的客户端。 #超时单位为秒钟,0表示没有超时定义,这也是默认值。 #对于匿名rsync服务器来说,一个理想的数字是600。 timeout = 300 #模块定义 #主要是定义服务器哪个目录要被同步。 #每个模块都要以[name]形式。这个名字就是在 rsync 客户端看到的名字。 #但是服务器真正同步的数据是通过 path 指定的。可以依次创建多个模块。 #每个模块要指定认证用户、密码文件,但排除并不是必须的。 [ logs ] #模块名,以下配置都属于此模块 path = /var/log #文件目录所在位置 list = no #当查看服务器上提供了哪些目录时是否列出来,no比较安全 ignore errors #忽略I/O错误 #指定由空格或逗号分隔的用户名列表,只有这些用户才允许连接该模块。 #这里的用户和系统用户没有任何关系,是 rsyncd.secrets 中的用户名! #如果"auth users"被设置,那么客户端发出对该模块的连接请求 #以后会被rsync请求challenged进行验证身份。 #这里使用的 challenge/response 认证协议。 #用户的名和密码以明文方式存放在"secrets file"选项指定的文件中。 #默认情况下无需密码就可以连接模块(也就是匿名方式)。 auth users = zhangzk secrets file = /etc/rsyncd/rsyncd.secrets #密码文件 exclude = error_log httpd.pid #忽略的文件或目录 comment this is my log #本模块注释,可选
1.编辑配置rsyncd.conf pid file = /var/run/rsyncd.pid port = 873 uid = root gid = root use chroot = yes read only = no #write only = yes hosts allow = 10.0.7.211 hosts deny =* max connections = 5 motd file = /etc/rsyncd/rsyncd.motd log file = /var/log/rsync.log transfer logging = yes log format = %t %a %m %f %b syslog facility = local3 timeout = 300 [ logs ] path = /root/test/log list = no ignore errors auth users =lalala secrets file = /etc/rsyncd/rsyncd.secrets #exclude = comment this is my log
##定义第二个同步目录
path = /var/www/log
list=yes
ignore errors
auth users = apache ##必须在服务器上存在的真实的系统用户,多个用户以,号隔开
secrets file = /etc/rsyncd/rsyncd.secrets ##指定上述账号密码文件
comment = web log
exclude = data/ data1/ ##排除log下的data目录和data1目录
3.编辑服务器信息文件
设定rsyncd.motd 文件;
++++++++++++++++++++++++++++++++++++++++++++++ Welcome to use the mike.org.cn rsync services! 2017 ++++++++++++++++++++++++++++++++++++++++++++++
服务器端启动:
从远程服务器 同步到本地 强制性一致
# rsync -avzP --delete apache@110.0.7.211::hadoop /backup 这回我们引入一个 --delete 选项,表示服务器上的数据要与客户端完全一致,
如果 /backup目录中有服务器上不存在的文件,则删除。 最终目的是让 /backup 目录上的数据完全与服务器上保持一致;
用的时候要小心点,最好不要把已经有重要数所据的目录,当做本地更新目录,否则会把你的数据全部删除;
从远程服务器 同步到本地 自动脚本
# rsync -avzP --delete --password-file=/tmp/rsync.password apache@110.0.7.211::hadoop /backup
# touch /tmp/rsync.password# chmod 600 /tmp/rsync.password # echo "123456"> /tmp/rsync.password 注: 这样就不需要密码了;其实这是比较重要的,因为服务器通过crond 计划任务还是有必要的; rsync 客户端自动与服务器同步数据: 编辑crontab # crontab -e 加入如下代码: 10 0 * * * rsync -avzP --delete --password-file=/tmp/rsync.password apache@10.0.7.211::hadoop /tmp/hadoop/
转载地址:https://blog.csdn.net/zonghua521/article/details/78239413 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!