103 lines
No EOL
1.9 KiB
Markdown
103 lines
No EOL
1.9 KiB
Markdown
```
|
||
#!/bin/bash
|
||
|
||
##Edit by wangsuipeng
|
||
##Date 2016/10/25
|
||
|
||
## Rsync 服务器端脚本-用于灾备环境搭建
|
||
##
|
||
## 脚本说明:如果系统中已存在rsyncd.conf文件,在该文件后面追加配置项,
|
||
## 如果不存在,则新建该文件,并添加配置项
|
||
## 操作说明:执行过本脚本以后,需要做客户端配置
|
||
|
||
##项目名
|
||
read -p "The Project name[Not username]:" PRO_NAME
|
||
|
||
##灾备IP
|
||
read -p "The DR IP:" PRO_BACK_IP
|
||
|
||
##项目存放位置(类似/opt/appl/project/[tomcat/jboss])
|
||
read -p "The Project path[/opt/appl/project/[tomcat/jboss]]:" PRO_PATH
|
||
|
||
##项目用户UID
|
||
PRO_UID=`stat -c %u $PRO_PATH`
|
||
|
||
##配置文件
|
||
RSYNC_CFG=/etc/rsyncd.conf
|
||
|
||
##密码文件
|
||
PASS_CFG=/etc/rsyncd.pass
|
||
|
||
yum -y install rsync xinetd > /dev/null 2>&1
|
||
|
||
##存在rsyncd.conf文件
|
||
EXCFG()
|
||
{
|
||
cat >> $RSYNC_CFG <<EOF
|
||
[${PRO_NAME}19]
|
||
path = $PRO_PATH
|
||
uid = $PRO_UID
|
||
gid = 1500
|
||
read only = yes
|
||
list = yes
|
||
allows host = $PRO_BACK_IP
|
||
secrets file = /etc/rsyncd.pass
|
||
EOF
|
||
}
|
||
|
||
|
||
##不存在rsyncd.conf文件
|
||
NOCFG()
|
||
{
|
||
cat > $RSYNC_CFG <<EOF
|
||
uid = root
|
||
gid = root
|
||
use chroot = no
|
||
max connections = 100
|
||
timout = 600
|
||
pid file = /var/run/rsyncd.pid
|
||
lock file =/var/run/rsyncd.lock
|
||
log file = /var/log/rsyncd.log
|
||
|
||
[${PRO_NAME}19]
|
||
path = $PRO_PATH
|
||
uid = $PRO_UID
|
||
gid = 1500
|
||
read only = yes
|
||
list = yes
|
||
allows host = $PRO_BACK_IP
|
||
secrets file = /etc/rsyncd.pass
|
||
EOF
|
||
}
|
||
|
||
if [ -f $RSYNC_CFG ]
|
||
then
|
||
EXCFG
|
||
else
|
||
NOCFG
|
||
fi
|
||
|
||
echo "rsync:123456" > $PASS_CFG
|
||
|
||
if grep -q "rsync:$PRO_BACK_IP:allow" /etc/hosts.allow
|
||
then
|
||
# exit 0 ---直接退出脚本
|
||
echo
|
||
else
|
||
echo "rsync:$PRO_BACK_IP:allow" >> /etc/hosts.allow
|
||
fi
|
||
|
||
if grep -q "\byes\b" /etc/xinetd.d/rsync
|
||
then
|
||
sed -i 's/yes/no/g' /etc/xinetd.d/rsync
|
||
/etc/init.d/xinetd restart
|
||
fi
|
||
|
||
if grep -q "\b873\b" /etc/sysconfig/iptables
|
||
then
|
||
# exit 0 ---直接退出脚本
|
||
echo
|
||
else
|
||
iptables -I INPUT 1 -p tcp -m state --state NEW -m tcp --dport 873 -j ACCEPT && service iptables save && service iptables restart
|
||
fi
|
||
``` |