自动化同步文档



一、本地同步准备

172.18.1.247同步到172.18.1.249

1、双击互信

注意不要破坏自动构建平台172.18.1.247的环境,只需要在172.18.1.247上复制key到其他节点即可。

# ssh-copy-id root@172.18.1.249

输入密码即可

2、在172.18.1.249上创建同步模块

安装rsync

# yum –y install rsync

# vim /etc/rsyncd.conf

uid     = root
gid     = root
use chroot     = yes
max connections = 30
pid file=/var/run/rsyncd.pid
log file=/var/log/rsyncd.log
list = no
[ www.epay.com ] #要同步到模块
uid=root       #授权的用户
gid=root       #授权用户所在地组
path           = /data/app/www.epay.com  #模块对应的目录
hosts allow    = 172.18.1.0/24  #允许同步到主机ip范围
read only      = no   #是否只读


同步本地目录,让172.18.1.249主机可以同步文件

# chkconfig rsync on

# service xinetd start   //xinetd 服务是跟各种小文件传送相关的服务,所以必须启动

# rsync –daemon –config=/etc/rsyncd.conf

创建同步模块对应的目录

# mkdir /data/app/www.epay.com

# chown –R tomcat.tomcat /data/app/www.epay.com

好了,本地做完了,做172.18.1.247自动构建平台上的配置



二、自动构建平台脚本配置

1、创建脚本目录

# cd /data/jenkins/scripts/

# mkidr epay.3194

# cd epay.3194/

# vim epay_3194.sh  #自动构建脚本


#!/bin/bash
eval  `dirname$0`/env.sh
item="epay.3194"
TESTSERVER=172.18.1.249
WORKSPACE="/data/jenkins/jobs/epay的日志上传/workspace"
Test=0
#创建中间站,作为导出svn版本包的中转站,导出并解压程序包
function init(){
       cd$WORKSPACE
       mkdir -p/dev/shm/$item
       rm -rf/dev/shm/$item/*
       TargetPack=`ls-t |grep -P "zip$|war$"|head -n 1`
       cp -r$WORKSPACE/$TargetPack /dev/shm/$item/
       cd/dev/shm/$item
       unzip$TargetPack >/dev/null 2>&1
       rm -f$TargetPack 2>/dev/null
}
#function modify_system_propety(){
#     local flag
#     flag="$1"
#     system_file="/dev/shm/$item/WEB-INF/classes/plantform/system.properties"
#     fromdos$system_file
#     [ -f$system_file ] && cp/data/jenkins/scripts/epay.3194/conf/system.properties $system_file
#
#}
#
#修改日志文件
function modify_log4j(){
       logfile="/dev/shm/$item/WEB-INF/classes/log4j.properties"
       fromdos$logfile
       modifycommand="
s@log4j.appender.file.File=.*@log4j.appender.file.File=/data/soft/tomcat_3194/logs/catalina.out@g"
        [ -f$logfile ] && sed -i "$modifycommand" $logfile
}
#修改数据库连接
function modify_dbconfig() {
        localflag
       flag="$1"
        if ["x$flag" == "xtest" ]
        then
               /bin/cp /data/jenkins/scripts/epay.3194/conf/test/*  /dev/shm/$item/WEB-INF/classes/
        elif ["x$flag" == "xproduct" ]
        then
                /bin/cp/data/jenkins/scripts/epay.3194/conf/product/* /dev/shm/$item/WEB-INF/classes/
        fi
}
#同步到测试服务器和共享存储
function depoly()
{
       local flag
       flag="$1"
#同步到测试服务器
       if ["x$flag" == "xtest" ]
       then
           domain=`echo "$TESTDOMAIN"|cut-d: -f1`
           cd /dev/shm/$item && rsync -lrRptW--delete --contimeout=3 --exclude-from=/etc/list . $TESTSERVER::$domain
            ssh$TESTSERVER "chown -R tomcat.tomcat /data/app/www.epay.com_3194 &&/etc/init.d/tomcat_3194 restart"
#     port=`echo"$APPDIR"|grep -o -P "\.\d+$"|sed "s/\.//g"`
#同步到共享存储
       elif ["x$flag" == "xproduct" ]
       then
           ssh 172.18.3.24 "[ ! -d/mnt/share/deploy/dist/store/www.epay.com.3194 ] && mkdir -p  /mnt/share/deploy/dist/store/www.epay.com.3194"
           cd /dev/shm/$item && rsync -lrRptW--delete --exclude-from=/etc/list .172.18.3.24:/mnt/share/deploy/dist/store/www.epay.com.3194
       fi
}
init
#modify_system_propety
modify_log4j
#Test=0
echo $TESTSERVER
modify_dbconfig test
depoly test
####同步到共享存储
echo
modify_dbconfig product
depoly product

# vim env.sh   #环境脚本,用来在自动构建平台上发邮件之用

#!/bin/bash
echo TESTDOMAIN="www.epay.com:3194"
echo TESTSERVER="172.18.1.249"
echo APPDIR="/data/app/www.epay.com.3194"
echo APPLOG="/data/soft/tomcat_3194/logs"
info="/tmp/svninfo"
/usr/bin/svn log --username superadmin --password'jgxt!%-a.1315'svn://172.18.1.111/CPU/BLD/Server/EPAYLOG/EPAY_LOG_V0.003_20131125 |awk'{RS="--";}{if(NR==2){ print $0}}' > /tmp/svninfo
changetime=`grep '|' $info |awk -F'|' '{print $3}'`
author=`grep '|' $info |awk -F'|' '{print $2}'`
message=`grep -v '|' $info|grep -P -i"v\d\.\d+_?(\d*)"|xargs|sed 's/ //g'`
messageall=`grep -v '|' $info`
echo SVN_COMMIT_MSG="$message"
echo SVN_COMMIT_MSG_ALL="$messageall"
echo SVN_CHANGE_TIME="$changetime"
echo  SVN_COMMIT_AUTHOR="$author"

可以创建一个配置文件的目录,存放其他需要修改的文件

# mkdir conf

# cd conf

# mkdir test  创建测试环境需要的目录

# mkdir product 创建生产环境需要的目录

# cd conf/test

# vim db.properties

#cmp
cmp.db.url=jdbc:postgresql://172.18.1.241:1921/cmp
cmp.db.user=cmp
cmp.db.pwd=aa(*&&^&a25pxpdf(*&e
#base
base.db.url=jdbc:postgresql://172.18.1.241:1921/base
base.db.user=base
base.db.pwd=b(*&a12s)((*idf(*&e
#channel
channel.db.url=jdbc:postgresql://172.18.1.242:1921/channel
channel.db.user=channel
channel.db.pwd=C30_fadfe_Fef3eDW389


# cd conf/product

# vim db.properties

#cmp
cmp.db.url=jdbc:postgresql://172.18.1.241:1921/cmp
cmp.db.user=cmp
cmp.db.pwd=aa(*&&^&a25pxpdf(*&e
#base
base.db.url=jdbc:postgresql://172.18.1.241:1921/base
base.db.user=base
base.db.pwd=b(*&a12s)((*idf(*&e
#channel
channel.db.url=jdbc:postgresql://172.18.1.242:1921/channel
channel.db.user=channel
channel.db.pwd=C30_fadfe_Fef3eDW389



这些做完了之后,就去自动构建平台的web界面配置,构建吧。

http://115.238.91.226:60004/redmine/projects/ywxm/wiki/H2_%E6%9E%84%E5%BB%BA%E5%B9%B3%E5%8F%B0jenkins


自动构建平台点击构建完成后,可以在测试环境监测tomcat启动的过程

1,进入到tomcat的日志目录中

# cd /data/soft/tomcat_3194/logs

# service tomcat_3194 restart && tail -f catalina.out



可能会有以下报错

常见报错:exception

java.io.FileNotFoundException: /overseas_memcached.log (Permission denied)

修改启动脚本,将tomcat的启动用户修改成root,不要用tomcat用户启动

export TOMCAT_USER=root



java.net.UnknownHostException: playapp: playapp: Name or service not known

这个是主机名称错误,编辑hosts文件,给主机加个别名

#vim /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 playapp


解决后重新启动就不会出错了.