本例介绍jenkins已war包运行及开机启动配置

  环境:Linux环境(CentOS 7.4)

以war包运行

  1、下载jenkins.war包

  2、启动war包( 默认端口:8080,默认JENKINS_HOME目录:~/.jenkins )

    前台启动命令:java -jar jenkins.war

    后台启动命令:nohup java -jar jenkins.war &

  3、使用浏览器打开地址:http://ip:8080,即可访问到jenkins

    关闭jenkins,页面访问地址:http://ip:8080/exit

    重启jenkins,页面访问地址:http://ip:8080/restart

  4、其他安装参考【Linux】Jenkins安装(一)

  5、修改JENKINS_HOME目录启动,需要新建一个脚本jenkins.sh,然后运行脚本 

 #!/bin/bash
# 导入JENKINS_HOME环境变量
export JENKINS_HOME=/data/soft/jenkins cd $JENKINS_HOME # 启动Jenkins
nohup java -jar jenkins.war --ajp13Port=- --httpPort= >/dev/null >& &

  6、构建shell,demo如下:

 #!/bin/bash
# 编译+部署zeus站点 # 保持Jenkins启动的Service(tomcat) 不被杀死
export BUILD_ID=dontKillMe # 需要配置如下参数
# 项目路径,在Execute Shell中国配置项目路径, pwd 就可以获得项目路径
# export PROJ_PATH=这个jenkins任务在部署机器上的路径
export PROJ_PATH=`pwd` # 输入你在环境上tomcat的全路径
# export TOMCAT_APP_PATH=tomcat在部署机器上的路径
export TOMCAT_APP_PATH=/data/soft/apache-tomcat- ### base 函数
killTomcat()
{
pid=`ps -ef | grep tomcat- | grep -v grep | awk '{print $2}'`
echo "Tomcat Id is : $pid"
if [ ! -n "$pid" ];
then
echo "No Tomcat Pid alive"
else
echo "Tomcat Pid alive"
fi
} cd $PROJ_PATH/god-site
pwd mvn clean package # 停tomcat
killTomcat # 删除原有工程
rm -rf $TOMCAT_APP_PATH/webapps/zeus.war # 复制新的工程
cp $PROJ_PATH/god-site/god-web/god-web-zeus/target/zeus.war $TOMCAT_APP_PATH/webapps/ # 启动Tomcat
cd $TOMCAT_APP_PATH
sh bin/startup.sh

  补充:

  使用java -jar 命令的时候可以加入启动参数,启动命令格式:java -jar jenkins.war [--option=value] [--option=value],

  到达一些配置效果,例如:

    修改jenkins端口启动命令:java -jar jenkins.war --httpPort=18080

  其他启动参数查看命令:java -jar jenkins.war --help

 [root@H__D jenkins]# java -jar jenkins.war --help
Running from: /data/soft/jenkins/jenkins.war
webroot: $user.home/.jenkins
Jenkins Automation Server Engine 2.184
Usage: java -jar jenkins.war [--option=value] [--option=value] Options:
--webroot = folder where the WAR file is expanded into. Default is ${JENKINS_HOME}/war
--pluginroot = folder where the plugin archives are expanded into. Default is ${JENKINS_HOME}/plugins
(NOTE: this option does not change the directory where the plugin archives are stored)
--extractedFilesFolder = folder where extracted files are to be located. Default is the temp folder
--daemon = fork into background and run as daemon (Unix only)
--logfile = redirect log messages to this file
--enable-future-java = allows running with new Java versions which are not fully supported (class version and above)
--javaHome = Override the JAVA_HOME variable
--toolsJar = The location of tools.jar. Default is JAVA_HOME/lib/tools.jar
--config = load configuration properties from here. Default is ./winstone.properties
--prefix = add this prefix to all URLs (eg http://localhost:8080/prefix/resource). Default is none
--commonLibFolder = folder for additional jar files. Default is ./lib --extraLibFolder = folder for additional jar files to add to Jetty classloader --logThrowingLineNo = show the line no that logged the message (slow). Default is false
--logThrowingThread = show the thread that logged the message. Default is false
--debug = set the level of debug msgs (-). Default is (INFO level) --httpPort = set the http listening port. - to disable, Default is
--httpListenAddress = set the http listening address. Default is all interfaces
--httpKeepAliveTimeout = how long idle HTTP keep-alive connections are kept around (in ms; default )?
--httpsPort = set the https listening port. - to disable, Default is disabled
--httpsListenAddress = set the https listening address. Default is all interfaces
--httpsKeepAliveTimeout = how long idle HTTPS keep-alive connections are kept around (in ms; default )?
--httpsKeyStore = the location of the SSL KeyStore file. Default is ./winstone.ks
--httpsKeyStorePassword = the password for the SSL KeyStore file. Default is null
--httpsKeyManagerType = the SSL KeyManagerFactory type (eg SunX509, IbmX509). Default is SunX509
--httpsPrivateKey = this switch with --httpsCertificate can be used to run HTTPS with OpenSSL secret key
/ --httpsCertificate file and the corresponding certificate file
--http2Port = set the http2 listening port. - to disable, Default is disabled
--http2ListenAddress = set the http2 listening address. Default is all interfaces
--excludeCipherSuites = set the ciphers to exclude (comma separated, use blank quote " " to exclude none) (default is
// Exclude weak / insecure ciphers
"^.*_(MD5|SHA|SHA1)$",
// Exclude ciphers that don't support forward secrecy
"^TLS_RSA_.*$",
// The following exclusions are present to cleanup known bad cipher
// suites that may be accidentally included via include patterns.
// The default enabled cipher list in Java will not include these
// (but they are available in the supported list).
"^SSL_.*$",
"^.*_NULL_.*$",
"^.*_anon_.*$"
--controlPort = set the shutdown/control port. - to disable, Default disabled --useJasper = enable jasper JSP handling (true/false). Default is false
--sessionTimeout = set the http session timeout value in minutes. Default to what webapp specifies, and then to minutes
--sessionEviction = set the session eviction timeout for idle sessions in seconds. Default value is . - never evict, evict on exit
--mimeTypes=ARG = define additional MIME type mappings. ARG would be EXT=MIMETYPE:EXT=MIMETYPE:...
(e.g., xls=application/vnd.ms-excel:wmf=application/x-msmetafile)
--maxParamCount=N = set the max number of parameters allowed in a form submission to protect
against hash DoS attack (oCERT #-). Default is .
--useJmx = Enable Jetty Jmx
--qtpMaxThreadsCount = max threads number when using Jetty Queued Thread Pool
--jettyAcceptorsCount = Jetty Acceptors number
--jettySelectorsCount = Jetty Selectors number
--usage / --help = show this message
Security options:
--realmClassName = Set the realm class to use for user authentication. Defaults to ArgumentsRealm class --argumentsRealm.passwd.<user> = Password for user <user>. Only valid for the ArgumentsRealm realm class
--argumentsRealm.roles.<user> = Roles for user <user> (comma separated). Only valid for the ArgumentsRealm realm class --fileRealm.configFile = File containing users/passwds/roles. Only valid for the FileRealm realm class Access logging:
--accessLoggerClassName = Set the access logger class to use for user authentication. Defaults to disabled
--simpleAccessLogger.format = The log format to use. Supports combined/common/resin/custom (SimpleAccessLogger only)
--simpleAccessLogger.file = The location pattern for the log file(SimpleAccessLogger only)

开机启动配置

  参考:【Linux】开机自动启动脚本

  1、编写启动脚本jenkins

    命令:vim /data/soft/jenkins/jenkins.sh

 #!/bin/bash 

 # 导入环境变量
export JENKINS_HOME=/data/soft/jenkins
export JAVA_HOME=/data/soft/jdk1..0_181 cd $JENKINS_HOME pid=`ps -ef | grep jenkins.war | grep -v 'grep'| awk '{print $2}'`
if [ "$1" = "start" ];then
if [ -n "$pid" ];then
echo 'jenkins is running...'
else
### java启动服务 配置java安装根路径,和启动war包存的根路径
nohup $JAVA_HOME/bin/java -Xms128m -Xmx256m -jar $JENKINS_HOME/jenkins.war --ajp13Port=- --httpPort= >/dev/null >& &
fi
elif [ "$1" = "stop" ];then
exec ps -ef | grep jenkins | grep -v grep | awk '{print $2}'| xargs kill -
echo 'jenkins is stop...'
else
echo "Please input like this:"./jenkins.sh start" or "./jenkins stop""
fi

  2、给jenkins.sh文件授权

    命令:chmod +x /data/soft/jenkins/jenkins.sh

  3、在/etc/rc.d/rc.local文件底部,添加内容:

 # jenkins
/data/soft/jenkins/jenkins.sh start

  4、重启计算机

    命令:reboot

Jenkins常用功能

  1、备份、迁移、恢复jenkins

  首先找到JENKINS_HOME,因为Jenkins的所有的数据都是以文件的形式存放在JENKINS_HOME目录中。不管是迁移还是备份,只需要操作JENKINS_HOME就行了。

  迁移:建议将JENKINS_HOME打包后在拷贝,windows可以用zip,rar等,Linux有zip,tar等,然后将打包的文件解压到新的JENKINS_HOME目录就行了。

  备份:如果是临时备份,整个压缩文件就行了。

  恢复:恢复的时候需要先停止jenkins。

  2、升级Jenkins

  Jenkins的开发迭代非常快,每周发布一个开发版本,长期支持版每半年更新一次(ps:大版本更新)。如此频繁的更新,怎么升级呢?

  war:下载新版的war文件,替换旧版本war文件。重启即可。

  二进制:卸载旧版本,安装新版本即可。

  Jenkins程序下载地址:http://mirrors.jenkins-ci.org/

 

  

    

【Linux】Jenkins以war包运行及开机启动配置(四)的更多相关文章

  1. Linux tomcat部署War包,Linux在Tomcat部署JavaWeb项目,Linux部署War包

    Linux tomcat部署War包,Linux在Tomcat部署JavaWeb项目,Linux部署War包 >>>>>>>>>>>& ...

  2. jenkins部署war包到远程服务器的tomcat

    一.目的 jenkins上将war包,部署到远程服务器的tomcat上. 这边tomcat在windows 主机A上,版本apache-tomcat-8.5.23. jenkins在主机B上,cent ...

  3. jenkins相关war包下载

    1.jenkins的war包下载地址 地址:http://mirrors.jenkins-ci.org/,打开链接后,表格有war列,Releases行是短期更新包.LTS是长期更新包.一般选择Rel ...

  4. CentOS下nginx+php的配置及nginx开机启动配置

    关闭防火墙 (不然外链接是访问不了 apache) service iptables stop 关闭安全系统 SELinux( 不然报403 访问页面错误 ) 1.Nginx安装主要在于配置文件的修改 ...

  5. spring boot生成的war包运行时出现java.lang.NullPointerException: null

    最近写了一个数据库同步的程序,见之前的博客,没有用到spring框架来集成,用的时纯Java代码.然后,项目经理要我把程序合到spring boot框架中,因为涉及到多数据源,时间又比较紧,同意我直接 ...

  6. gitlab+jenkins+tomcat war包部署(此文有新版本)

    对本文进行格式整理,url: https://www.cnblogs.com/huandada/p/9969234.html 整个项目的框架为: 1.gitlab的安装(Centos7) 新建/etc ...

  7. Jenkins的war包安装

    安装Jenkins首先要安装jdk,在官网下载jdk安装并配置环境变量 1.Jenkins下载地址,下载war包 https://www.jenkins.io/download/ 2.打开命令行窗口, ...

  8. 【Tomcat部署】Linux环境部署war包到tomcat

    以turbine为例. 一.部署 1.下载或者生成war包(从maven上下载war包,并改名字为turbine.war) 2.将turbine.war拷贝到$TOMCAT_HOME/webapps中 ...

  9. springboot项目作为war包运行

    一.首先是pom文件中设置打成war包 < packaging>war< /packaging> 二.然后是修改依赖: <dependency> <group ...

随机推荐

  1. 51Nod 最大公约数之和V1,V2,V3;最小公倍数之和V1,V2,V3

    1040 最大公约数之和 给出一个n,求1-n这n个数,同n的最大公约数的和.比如:n = 6 1,2,3,4,5,6 同6的最大公约数分别为1,2,3,2,1,6,加在一起 = 15 输入 1个数N ...

  2. 错误信息: The server cannot or will not process the request due to something that is perceived to be a client error

    错误原因:在提交的表单中有 date 类型的数据,也就是不能传输日期类型的数据. 嗯!我知道,去吧!

  3. Djiango权限组件

    一. login中注册 权限url def login(request): if request.method == "POST": username = request.POST ...

  4. js获取当前时间往后加6天

    获取当前时间往后加6天,并绑定星期几(星期几是最笨的的方法,一个一个判读),后期在优化 <!DOCTYPE html> <html lang="en"> & ...

  5. pycharm注册使用

    先在PyCharm官网下载安装包 链接:https://www.jetbrains.com/pycharm/download/#section=linux 选择平台为Linux,可以看到当前版本为20 ...

  6. YAML_03 用playbook安装Apache,修改端口,配置ServerName,修改主页,设置开机自启

    ansible]# vim http.yml --- - hosts: cache   remote_user: root   tasks:     - name: install one speci ...

  7. 布鲁克斯法则 (Brooks's Law)

    软件开发后期,添加人力只会使项目开发得更慢. 这个定律表明,在许多情况下,试图通过增加人力来加速延期项目的交付,将会使项目交付得更晚.布鲁克斯也明白,这是一种过度简化.但一般的推理是,新资源的增加时间 ...

  8. test命令用法。功能:检查文件和比较值

    test命令用法.功能:检查文件和比较值 1)判断表达式 if test  (表达式为真) if test !表达式为假 test 表达式1 –a 表达式2                  两个表达 ...

  9. javascript练习题

    function Vertex(city, x) { this.name = city; this.num = x; } var node0 = new Vertex("邯郸", ...

  10. lixuxmint系统定制与配置(2)-输入法

    小书匠Linux RIME的官网在这里 1.安装 刚开始是使用ibus-rime,后来使用过程感觉不舒服,就换回fcitx-rime.使用以下命令安装fcitx-rime sudo apt insta ...