first commit
This commit is contained in:
commit
ba848e218d
1001 changed files with 152333 additions and 0 deletions
60
shell/rsync同步/rsync_client.sh.md
Normal file
60
shell/rsync同步/rsync_client.sh.md
Normal file
|
@ -0,0 +1,60 @@
|
|||
```
|
||||
#!/bin/bash
|
||||
|
||||
##Edit by wangsuipeng
|
||||
##Date 2016/10/20
|
||||
|
||||
## Rsync 客户端脚本
|
||||
## 脚本说明:
|
||||
##
|
||||
## 操作说明:执行过本脚本以后,需要添加到定时任务中
|
||||
## 并删除定时任务中的其他应用同步命令,即
|
||||
## 带有/opt/appl/assist/rsync/的脚本,为
|
||||
## 安全起见,请确认是否是应用同步脚本
|
||||
|
||||
|
||||
##项目名
|
||||
read -p "The Project name:[Not username]" PRO_NAME
|
||||
|
||||
##服务端IP
|
||||
read -p "The Server IP:" PRO_HOST_IP
|
||||
|
||||
##脚本存放位置
|
||||
DIRPATH=/usr/local/rsync
|
||||
|
||||
##密码文件
|
||||
PASS_CFG=$DIRPATH/rsyncd.pass
|
||||
|
||||
##脚本文件
|
||||
SCRIPT=$DIRPATH/rsync_${PRO_HOST_IP}-${PRO_NAME}.sh
|
||||
|
||||
EXCLUDE_CONF()
|
||||
{
|
||||
cat > /usr/local/rsync/exclude << EOF
|
||||
log/*
|
||||
logs/*
|
||||
temp/*
|
||||
backup/*
|
||||
deployment/*
|
||||
*.tar.gz
|
||||
*.tgz
|
||||
*.log
|
||||
*.out
|
||||
EOF
|
||||
}
|
||||
|
||||
if [ -d $DIRPATH ]
|
||||
then
|
||||
if [ -f $DIRPATH/rsyncd.pwd ]
|
||||
then
|
||||
cd $DIRPATH && tar zcvf bak.`date +%d%H%M`.tar.gz --exclude *.tar.gz * --remove-files >/dev/null 2>&1
|
||||
fi
|
||||
else
|
||||
mkdir -p $DIRPATH
|
||||
fi
|
||||
|
||||
EXCLUDE_CONF
|
||||
echo "/usr/bin/rsync -arP --delete --exclude-from=/usr/local/rsync/exclude --password-file=$PASS_CFG rsync@$PRO_HOST_IP::${PRO_NAME}2016 /opt/appl/$PRO_NAME/" > $SCRIPT
|
||||
chmod +x $SCRIPT
|
||||
echo "123456" > $PASS_CFG
|
||||
```
|
68
shell/rsync同步/rsync_client_dr.sh.md
Normal file
68
shell/rsync同步/rsync_client_dr.sh.md
Normal file
|
@ -0,0 +1,68 @@
|
|||
```
|
||||
#!/bin/bash
|
||||
|
||||
##Edit by wangsuipeng
|
||||
##Date 2016/10/25
|
||||
|
||||
## Rsync 客户端脚本-用于灾备环境搭建
|
||||
##
|
||||
## 脚本说明:
|
||||
##
|
||||
## 操作说明:执行过本脚本以后,需要添加到定时任务中
|
||||
## 并删除定时任务中的其他应用同步命令,即
|
||||
## 带有/opt/appl/assist/rsync/的脚本,为
|
||||
## 安全起见,请确认是否是应用同步脚本
|
||||
|
||||
|
||||
##项目名
|
||||
read -p "The Project name[Not username]:" PRO_NAME
|
||||
|
||||
##服务端IP
|
||||
read -p "The Server IP:" PRO_HOST_IP
|
||||
|
||||
##容器
|
||||
read -p "The Software[jboss/tomcat]:" SOFT
|
||||
|
||||
yum -y install rsync xinetd > /dev/null 2>&1
|
||||
##脚本存放位置
|
||||
DIRPATH=/usr/local/rsync
|
||||
|
||||
##密码文件
|
||||
PASS_CFG=$DIRPATH/rsyncd.pass
|
||||
|
||||
##脚本文件
|
||||
SCRIPT=$DIRPATH/rsync_${PRO_HOST_IP}-${PRO_NAME}.sh
|
||||
|
||||
EXCLUDE_CONF()
|
||||
{
|
||||
cat > /usr/local/rsync/exclude << EOF
|
||||
log/*
|
||||
logs/*
|
||||
temp/*
|
||||
backup/*
|
||||
deployment/*
|
||||
*.tar.gz
|
||||
*.tgz
|
||||
*.log
|
||||
*.out
|
||||
jdk*
|
||||
work/*
|
||||
EOF
|
||||
}
|
||||
|
||||
if [ -d $DIRPATH ]
|
||||
then
|
||||
if [ -f $DIRPATH/rsyncd.pwd ]
|
||||
then
|
||||
cd $DIRPATH && tar zcvf bak.`date +%d%H%M`.tar.gz --exclude *.tar.gz * --remove-files >/dev/null 2>&1
|
||||
fi
|
||||
else
|
||||
mkdir -p $DIRPATH
|
||||
fi
|
||||
|
||||
EXCLUDE_CONF
|
||||
echo "#!/bin/bash" > $SCRIPT
|
||||
echo "/usr/bin/rsync -arP --delete --bwlimit=200 --exclude-from=/usr/local/rsync/exclude --password-file=$PASS_CFG rsync@$PRO_HOST_IP::${PRO_NAME}19 /opt/appl/$PRO_NAME/$SOFT" >> $SCRIPT
|
||||
chmod +x $SCRIPT
|
||||
echo "123456" > $PASS_CFG
|
||||
```
|
103
shell/rsync同步/rsync_server.sh.md
Normal file
103
shell/rsync同步/rsync_server.sh.md
Normal file
|
@ -0,0 +1,103 @@
|
|||
```
|
||||
#!/bin/bash
|
||||
|
||||
##Edit by wangsuipeng
|
||||
##Date 2016/10/20
|
||||
|
||||
## Rsync 服务器端脚本
|
||||
## 脚本说明:如果系统中已存在rsyncd.conf文件,在该文件后面追加配置项,
|
||||
## 如果不存在,则新建该文件,并添加配置项
|
||||
## 操作说明:执行过本脚本以后,需要做客户端配置
|
||||
|
||||
##项目名
|
||||
read -p "The Project name:[Not username]" PRO_NAME
|
||||
|
||||
##客户端IP
|
||||
read -p "The Client IP:" PRO_BACK_IP
|
||||
|
||||
##项目存放位置(类似/opt/appl/project)
|
||||
read -p "The Project path:[/opt/appl/project]" 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}2016]
|
||||
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}2016]
|
||||
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
|
||||
fi
|
||||
|
||||
service xinetd restart
|
||||
|
||||
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
|
||||
```
|
103
shell/rsync同步/rsync_server_dr.sh.md
Normal file
103
shell/rsync同步/rsync_server_dr.sh.md
Normal file
|
@ -0,0 +1,103 @@
|
|||
```
|
||||
#!/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
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue