2019年6月30日 ⋅ 浏览量: 3
web1=172.16.1.10
web2=172.16.1.11
#!/bin/bash
# --------------------------------------------------
#Author: 晴天
#Email: admin@attacker.club
#website: http://attacker.club
# --------------------------------------------------
yum install git -y
git clone https://github.com/wsgzao/sersync.git
cd sersync
function install_rsync()
{
tar zxvf rsync-3.1.1.tar.gz
cd rsync-3.1.1
./configure
make && make install
cd ..
rm rsync-3.1.1 -rf
}
function install_inotify()
{
tar zxvf inotify-tools-3.14.tar.gz
cd inotify-tools-3.14
./configure --prefix=/local/local/inotify
make && make install
cd ..
rm inotify-tools-3.14 -rf
}
function install_sersync()
{
tar zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz
mv GNU-Linux-x86/ /usr/local/sersync
echo "rsyncpass" > /usr/local/sersync/pass
chmod 600 /usr/local/sersync/pass
grep sersync /etc/profile || echo "PATH=$PATH:/usr/local/sersync/">>/etc/profile
}
install_rsync
install_inotify
install_sersync
#!/bin/bash
# --------------------------------------------------
#Author: 晴天
#Email: admin@attacker.club
#website: http://attacker.club
# --------------------------------------------------
yum install rsync -y
cat > /etc/rsyncd.conf<<EOF
#Rsync server
uid = root
gid = root
use chroot = no
# 安全相关
max connections = 2000
# 并发连接数
timeout = 600
# 超时时间(秒)
pid file =/var/run/rsyncd.pid
# 指定rsync的pid目录
lock file =/var/run/rsync.lock
# 指定rsync的锁文件【重要】
log file = /var/log/rsyncd.log
# 指定rsync的日志目录
ignore errors
read only = false
list = false
# limit access to private LANs
hosts allow = 10.0.0.0/8 172.16.0.0/16 192.168.0.0/16
hosts deny=*
# hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file =/etc/rsync.password
#################################################
# 模块
# [bind]
# comment = dns config
# path = /var/named/app
[nginx]
comment = web config
path = /usr/local/nginx/conf/vhosts
EOF
## 权限
echo "rsync_backup:rsyncpass">/etc/rsync.password
chmod 600 /etc/rsync.password
## 开机启动
#pkill rsync && /bin/rsync --daemon
grep rsync /etc/rc.local|| echo '/usr/bin/rsync --daemon' >> /etc/rc.local
systemctl restart rsyncd
systemctl enable rsyncd
<localpath watch="/usr/local/nginx/conf/vhosts">
<remote ip="172.16.1.11" name="nginx"/>
</localpath>
/usr/local/sersync/check_sersync.sh
sersync="/usr/local/sersync/sersync2"
nginx="/usr/local/sersync/nginx.xml"
status=$(ps aux |grep 'sersync2'|grep -v 'grep'|wc -l)
if [ $status -eq 0 ];then
$sersync -d -r -o $nginx &
else
exit 0;
fi
EOF
# 脚本监控
crontab -l
*/5 * * * * sh /usr/local/sersync/check_sersync.sh