一台机器上同一个应用部署多个实例,怎么弄?
要保证不同的实例互不干扰,日志文件分别保存在各自不同的目录下
代码是同一个分支,web工程的web.xml文件部分如下:
<context-param>
<param-name>systemConfigLocation</param-name>
<param-value>classpath:config-wcs.properties</param-value>
</context-param>
<context-param>
<param-name>systemConfigLocationOverride</param-name>
<param-value>file:${user.home}/config/wcs-release.properties</param-value>
</context-param>
上面的wcs-release.properties就是配置文件
也就是说,同一份代码,部署多个实例,例如部署4个实例,我就可以在配置目录中创建4个配置文件
例如:wcs-release.properties, wcs2-release.properties,wcs3-release.properties,wcs4-release.properties
所以,在发布脚本中,我就可以根据传入的参数用sed命令修改为期望的配置文件
例如:
输入wcs2, 就将web.xml文件中的wcs-properties文件替换为wcs2-properties
输入wcs3, 就将web.xml文件中的wcs-properties文件替换为wcs3-properties
就可以实现,同一份代码,同一个脚本,在同一台机器,部署多个实例,就可以够级一个小的集群。
附上我修改后的部署脚本:
#!/bin/sh
DIR="/home/www/work/taofen8_3.0"
BRANCH="trunk"
APP="www"
TOMCAT="tomcat6"
STATIC="no"
read -p "Please input the app name [invite,wcs,wcs2,wcm,wcm2]" APP
if [ -z $APP ]; then
APP="invite"
fi
if [ $APP = "download" ]; then
cd $DIR/statics/d
svn up
cd /home/www/
else
TOMCAT="tomcat_$APP"
read -p "Please input the branch [trunk is default]:" BRANCH
if [ -z $BRANCH ]; then
BRANCH="trunk"
fi
read -p "Only build static file? [yes|no] [no is default]" STATIC
if [ -z $STATIC ]; then
STATIC="no"
fi
if [ $STATIC = "yes" ]; then
cd $DIR/statics/$APP
svn up
cd /home/www/
else
DIR="$DIR/tf8-$APP/$BRANCH"
echo "DIR is now $DIR, and APPLIATION is $APP"
cd $DIR
svn up
### replace web.xml propertiex file
xml=$DIR"/src/main/webapp/WEB-INF/web.xml"
prop=$APP"-release.properties<\/param-value>"
echo "replace $xml $prop"
sed -i "s/config\/\(.*\)/config\/$prop/g" $xml
### replace number
war=`echo $APP | sed -r 's/(.*)([0-9])/\1/'`
sudo mvn clean package -Dmaven.test.skip=true replacer:replace
cd /home/www/
sudo service $TOMCAT stop
BakName=$APP$(date +"%Y%m%d%H%M")
mv /home/www/deploy/$APP /home/www/deploy/rollback/$BakName
rm -rf /home/www/deploy/$APP
cp -r $DIR/target/$war /home/www/deploy/$APP
sudo service $TOMCAT restart
fi
fi
exit 0