您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
rsync [选项] 原始位置 目标位置
[root@rsyncd ~]# rpm -q rsync
rsync-3.0.9-18.el7.x86_64
[root@rsyncd ~]# vim /etc/rsyncd.conf
uid = nobody //匿名用户
gid = nobody
use chroot = yes //禁锢家目录
pid file = /var/run/rsyncd.pid //pid文件路径
address = 192.168.144.128 //配置监听地址
port = 873 //端口号
log file = /var/log/rsyncd.log //日志文件路径
hosts allow = 192.168.144.0/24 //允许地址段访问
dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2 //不需要压缩的类型
[wwwroot] //共享模块名
path = /var/www/html //共享文件路径
comment = www.kgc.com //定义名称
read only = yes //只读权限
auth users = backuper //身份验证用户名
secrets file = /etc/rsyncd_users.db //密码文件
:wq
[root@rsyncd ~]# vim /etc/rsyncd_users.db //创建密码文件
backuper:123123 //编辑用户名:密码
:wq
[root@rsyncd ~]# chmod 600 /etc/rsyncd_users.db //更改权限
[root@rsyncd ~]# rsync --daemon //开启rsync服务
[root@rsyncd ~]# netstat -ntap | grep rsync //查看端口
tcp 0 0 192.168.144.128:873 0.0.0.0:* LISTEN 36346/rsync
[root@rsyncd ~]# systemctl stop firewalld.service //关闭防火墙
[root@rsyncd ~]# setenforce 0
[root@rsyncd ~]# yum install httpd -y //安装httpd服务
[root@rsyncd ~]# cd /var/www/html/
[root@rsyncd html]# echo "this is test web" > index.html //编辑网页信息
[root@rsyncd html]# cd ../
[root@rsyncd www]# chmod 777 html/ //放开目录权限,方便用户操作
[root@client ~]# systemctl stop firewalld.service //关闭防火墙
[root@client ~]# setenforce 0 //关闭selinux
[root@client ~]# rpm -q rsync //检查是否安装rsync服务
rsync-3.0.9-18.el7.x86_64
[root@client ~]# yum install httpd -y //安装httpd服务
[root@client ~]# cd /var/www/
[root@client www]# chmod 777 html/ //放开目录权限
[root@client www]# rsync -avz backuper@192.168.144.128::wwwroot /var/www/html //拉取共享模块
Password: //输入密码
[root@client www]# cat html/index.html //查看是否同步信息
this is test web
[root@client www]# rm -rf html/index.html
[root@client www]# vim /etc/server.pass //创建本地的密码文件
123123
[root@client www]# chmod 600 /etc/server.pass //更改权限
[root@client www]# rsync -avz --delete --password-file=/etc/server.pass backuper@192.168.144.128::wwwroot /var/www/html/ //指定本地密码文件,删除目标位置有而原始位置没有的文件,实现免交互
[root@client www]# vim /etc/sysctl.conf //修改内核参数文件
fs.inotify.max_queued_events = 16384 //队列
fs.inotify.max_user_instances = 1024 //每个队列中的实例数
fs.inotify.max_user_watches = 1048576 //每个实例中的文件数
[root@client www]# sysctl -p ##加载
[root@client www]# mount.cifs //192.168.100.8/LNMP-C7 /mnt/ //挂载
Password for root@//192.168.100.3/LNMP-C7:
[root@client www]# cd /mnt/
[root@client mnt]# tar zxvf inotify-tools-3.14.tar.gz -C /opt/ //解压inotify到/opt下
[root@client mnt]# cd /opt/
[root@client opt]# cd inotify-tools-3.14/
[root@client inotify-tools-3.14]# yum install gcc gcc-c++ make -y //安装环境
[root@client inotify-tools-3.14]# ./configure //配置
[root@client inotify-tools-3.14]# make && make install //编译安装
[root@client inotify-tools-3.14]# inotifywait -mrq -e modify,create,move,delete /var/www/html/ //启动监控
[root@client ~]# cd /var/www/html/
[root@client html]# touch abc
[root@client html]# rm -rf abc
/var/www/html/ CREATE abc
/var/www/html/ DELETE abc //显示监控信息
[root@client inotify-tools-3.14]# cd /opt/
[root@client opt]# vim inotify.sh
#!/bin/bash
INOTIFY_CMD="inotifywait -mrq -e modify,create,move,delete /var/www/html/"
RSYNC_CMD="rsync -avz --delete --password-file=/etc/server.pass /var/www/html/ backuper@192.168.144.128::wwwroot/"
$INOTIFY_CMD | while read DIRECTORY EVENT FILE
do
if [ $(pgrep rsync | wc -l) -le 0 ]; then
$RSYNC_CMD
fi
done
[root@client opt]# chmod +x inotify.sh //添加执行权限
[root@rsyncd www]# vim /etc/rsyncd.conf
read only = no //关闭只读权限
[root@rsyncd www]# netstat -natp | grep rsync
tcp 0 0 192.168.144.128:873 0.0.0.0:* LISTEN 36346/rsync
[root@rsyncd www]# kill -9 36346 //关闭服务
[root@rsyncd www]# netstat -natp | grep rsync
[root@rsyncd www]# rm -rf /var/run/rsyncd.pid //删除pid文件
[root@rsyncd www]# rsync --daemon //重新开启rsync服务
[root@client opt]# ./inotify.sh
[root@client html]# echo "this is test" > test.txt //添加文本
[root@client opt]# ./inotify.sh
sending incremental file list
./
rsync: failed to set times on "/." (in wwwroot): Operation not permitted (1)
test.txt
sent 121 bytes received 30 bytes 302.00 bytes/sec
total size is 30 speedup is 0.20
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1052) [sender=3.0.9]
sending incremental file list
sent 66 bytes received 8 bytes 148.00 bytes/sec
total size is 30 speedup is 0.41
[root@rsyncd www]# cd html/
[root@rsyncd html]# ls
index.html test.txt //实现同步
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。