本文共 1905 字,大约阅读时间需要 6 分钟。
停止并禁用防火墙:
systemctl stop firewalldsystemctl disable firewalldsetenforce 0
安装并配置rsync:
yum -y install rsync
配置rsyncd.conf:
vim /etc/rsyncd.confuid = rootgid = rootuse chroot = yesaddress = 192.168.0.10port 873log file = /var/log/rsyncd.logpid file = /var/run/rsyncd.pidhosts allow = 192.168.0.0/24[wwwroot]path = /var/www/htmlcomment = Document Root of www.example.comread only = yesdont compress = *.gz *.bz2 *.tgz *.zip *.rar *.zauth users = foxsecrets file = /etc/rsyncd_users.db
创建并设置用户文件:
echo "fox:123456" > /etc/rsyncd_users.dbchmod 600 /etc/rsyncd_users.db
启动rsync服务:
rsync --daemonnetstat -natp | grep rsyncmkdir -p /var/www/htmlcd /var/www/htmltouch dog.htmlcat.htmls
停止并禁用防火墙:
systemctl stop firewalldsystemctl disable firewalldsetenforce 0
安装rsync并创建目录:
yum install -y rsyncmkdir /slavechmod 777 /slave
创建密钥文件并设置权限:
echo "123456" > /etc/server.passchmod 600 /etc/server.pass
使用rsync同步数据:
rsync -az --delete --password-file=/etc/server.pass fox@192.168.0.10::wwwroot /slave
echo "fs.inotify.max_queued_events = 32768 fs.inotify.max_user_instances = 1024 fs.inotify.max_user_watches = 1048576" > /etc/sysctl.confsysctl -p
wget -P /opt https://nchc.dl.sourceforge.net/project/inotify-tools/inotify-tools/3.13/inotify-tools-3.13.tar.gzcd /opttar -zxvf inotify-tools-3.13.tar.gzcd /opt/inotify-tools-3.13./configuremake -j 4make install
vim /opt/inotify.sh#!/bin/bashINOTIFY_CMD="inotifywait -mrq -e create,delete,move,modify,attrib /slave"RSYNC_CMD="rsync -azH --delete --password-file=/etc/server.pass /slave fox@192.168.0.10::wwwroot"# ...
chmod +x inotify.sh./inotify.sh &
创建文件:
cd /slavetouch fox.htmlrm -rf dog.htmls
查看同步日志:
tail -f /var/log/rsyncd.log
@ERROR: auth failed on module wwwroot
检查用户名和密码是否一致。
转载地址:http://jpwaz.baihongyu.com/