打赏 Fork me on GitHub

[原]Jenkins(十五)---jenkins插件之deploy

/**

* lihaibo

* 文章内容都是根据自己工作情况实践得出。

*如有错误,请指正

* 版权声明:本博客欢迎转发,但请保留原作者信息!

http://www.cnblogs.com/horizonli/p/5407551.html

*/

一、deploy插件

在jenkins中发布application到远端有很多方法,除了publish over ssh外还有个插件deploy.hpi也可以实现。

 

   插件下载地址:

链接: http://pan.baidu.com/s/1pLotSmR 密码: jzud   
插件安装方法: 点击:Jenkins(三)---Jenkins初始配置和插件配置
或手动转到 http://www.cnblogs.com/horizonli/p/5331970.html

二、配置 启用插件前需要对远程端的容器进行环境初始化(这里以tomcat为例)

 1.tomcat能正常启动

 2.tomcat能在web界面使用用户登录到app  manager

  1)配置增加tomcat用户:

   

  2)添加用户和角色

  

 3)登录tomcat manager

 

登录后如果能看到下面的界面表示配置正确

三、使用deploy插件发布war包到远程容器(这里以tomcat为例)

在系统设置中配置maven/jdk/git  可以参考:Jenkins(三)---Jenkins初始配置和插件配置 (除去七 SSH这一节 )

启动插件

  

打开之后填写

这里单独说下war包的路径和界面:

在后台看是这样的:

从前台看这样的:

界面地址:

这个地址就是用设置的用户和密码登录后的界面地址如下图:

四、利用deploy插件发布application到远程主机

   1.首先确保远程主机上的tomcat能正常启动并能使用用户登录到application管理界面

   2.再进行构建操作

   3.如下图所示构建成功

INFO] Building war: /opt/jenkins_tomcat6/jobs/quick4j_demo/workspace/target/quick4j.war

[INFO] WEB-INF/web.xml already added, skipping

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.782 s
[INFO] Finished at: 2016-04-19T14:06:53+08:00
[INFO] Final Memory: 27M/438M
[INFO] ------------------------------------------------------------------------
[JENKINS] Archiving /opt/jenkins_tomcat6/jobs/quick4j_demo/workspace/pom.xml to com.eliteams/quick4j/1.0.0/quick4j-1.0.0.pom
[JENKINS] Archiving /opt/jenkins_tomcat6/jobs/quick4j_demo/workspace/target/quick4j.war to com.eliteams/quick4j/1.0.0/quick4j-1.0.0.war
channel stopped
Deploying /opt/jenkins_tomcat6/jobs/quick4j_demo/workspace/target/quick4j.war to container Tomcat 6.x Remote
  [/opt/jenkins_tomcat6/jobs/quick4j_demo/workspace/target/quick4j.war] is not deployed. Doing a fresh deployment.
  Deploying [/opt/jenkins_tomcat6/jobs/quick4j_demo/workspace/target/quick4j.war]

Finished: SUCCESS

   4.测试是否发布成功

    4.1检查tomcat manager页面

    

   4.2web界面查看

 

====================================================================================

遇到的问题总结:

    问题一:部署app的时候,tomcat出现“403/401 for URL: http://172.16.18.192:8090/manager/text/list” 和The username you provided is not allowed to use the text-based Tomcat Manager (error 403)

    问题点: tomcat用户配置文件

    解决方案:检查用户名和密码是否正确  是否添加了用户角色和权限.

    问题二(最常见):部署完app后会出现内存溢出"java.lang.OutOfMemoryError: PermGen space"

    问题点:tomcat的虚拟机内存不足,需要设置更大的内存

    解决方案:1.找到tomcat路径,用编辑器打开catalina.sh,在“echo "Using CATALINA_BASE:    $CATALINA_BASE"”上面加入以下行:

            JAVA_OPTS="-server -XX:PermSize=64M -XX:MaxPermSize=128m

                 2.用脚本重启tomcat服务器,再部署。

                 重启tomcat示例脚本:

              

#!/bin/bash
#Time
log_time=`date +[%Y-%m-%d]%H:%M:%S`

###manual_properties###
tomcat_basehome=/opt/tomcat6/apache-tomcat-6.0.45
tomcat_port=9090
shell_environment=/bin/bash
war_Dir=/opt/jenkins
war_Name=quick4j.war
###manual_properties###



#update server environment
echo "**********************************  ${log_time} *************************************"
echo "updating server  environment start"
export JAVA_HOME=/app/java/jdk1.8.0_11
export JRE_HOME=/app/java/jdk1.8.0_11/jre
export PATH=$JAVA_HOME/bin:$PATH 
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar/
export CATALINA_2_HOME=/opt/tomcat6/apache-tomcat-6.0.45
export CATALINA_2_BASE=/opt/tomcat6/apache-tomcat-6.0.45
export TOMCAT_2_HOME=/opt/tomcat6/apache-tomcat-6.0.45
sleep 3
echo "updating server  environment  end"

#build check funcation
echo "check tomcat status..."
check_tomcat_status(){
      netstat -ant|grep ${tomcat_port}
      t=$?
       if [ $t -eq 0 ]; then
           echo "tomcat is running....port is ${tomcat_port}"
           echo "shutdown tomcat....."
           echo ">>>>>>>shutdown tomcat begin<<<<<<<<"
            ${shell_environment} ${tomcat_basehome}/bin/shutdown.sh
           echo ">>>>>>>shutdown tomcat end <<<<<<<<"
           sleep 5
       elif [ $t -ne 0 ];then 
             echo "tomcat is poweroff"
              ${shell_environment} ${tomcat_basehome}/bin/shutdown.sh
             sleep 5
       fi
} 

#check tomcat status invoke function
check_tomcat_status


#transfer  application package
deploy_Loaction=${tomcat_basehome}/webapps/
war_Dir_Data=`ls ${war_Dir}`
echo "start  transfer  war package to tomcat webapps ......."

if [ -z $war_Dir ];then
     echo "Folder ${war_Dir} is empty.please check war package in this folder!"
     exit 1 
else
     echo "Find ${war_Dir} exist war package ${war_Name}"
    # echo "deleteing old  package ${war_Name} in ${war_Dir}"
    # rm ${war_Dir}/${war_Name}
     echo "deleteing old  package ${war_Name} in ${deploy_Loaction}" 
     rm ${deploy_Loaction}${war_Name}
     echo "start  transfer ${war_Name} to ${deploy_Loaction}"
     cp ${war_Dir}/${war_Name}  ${deploy_Loaction}
     sleep 3 
fi
#reboot tomcat 
echo " >>>>>>>  rebooting  tomcat begin <<<<<<<<"
${shell_environment} ${tomcat_basehome}/bin/startup.sh
echo " >>>>>>>  rebooting  tomcat end <<<<<<<<"
echo "the log you can read in canalina.out"
echo "************************ deploy war package into container Successlly  **********************************"

    问题三:遇到“Connection refused”的异常

    问题点:tomcat

    解决方案:请检查远程机的容器是否启动、端口是否设置正常,不同的容器配置方式不一样,请参考相应容器的配置文档

    问题四:遇到“Deployed application at context path /xxx but context failed to start”

    问题点:tomcat

    解决方案:到远程机的WEB容器下查看日志

 

问题总结部分参考:http://blog.csdn.net/houyefeng/article/details/50996198

   

  

 --------------------目录电梯---------------------

[原]Jenkins(一)---我理解的jenkins是这样的

[原]Jenkins(二)---jenkins之Git+maven+jdk+tomcat

[原]Jenkins(三)---Jenkins初始配置和插件配置

[原]Jenkins(四)---Jenkins添加密钥对

[原]jenkins(五)---jenkins添加项目

[原]jenkins(六)---jenkins远程部署脚本

[原]Jenkins(七)---jenkins项目编译测试发布由maven构建的web项目

[原]Jenkins(八)---jenkins构建项目报错时发送错误报告邮件

[原]Jenkins(九)---jenkins分别发布多个项目到多个远程主机

[原]Jenkins(十)---jenkins注册管理员admin并赋所有权限给admin

[原]Jenkins(十一)---jenkins使用管理员admin创建用户和分配权限

[原]Jenkins(十二)---jenkins管理员用户无法登陆解决办法Access Denied

[原]Jenkins(十三)---jenkins用户权限管理

[原]Jenkins(十四)---jenkins示例:admin管理所有项目,新建用户只能看部分项目

[原]Jenkins(十五)---jenkins插件之deploy 

   
    

  

posted @ 2016-04-19 14:29  my_cool2007  阅读(3589)  评论(2编辑  收藏