本例介绍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. c99的新功能

    在ANSI的标准确立后,C语言的规范在一段时间内没有大的变动,然而C++在自己的标准化创建过程中继续发展壮大.<标准修正案一>在1994年为C语言创建了一个新标准,但是只修正了一些C89标 ...

  2. C++编程习惯

    1.初始化列表,尽量使用. 2.函数是否加const,只用而不改变就推荐加上const.如自定义的get某个属性的函数. 3.函数参数尽量用引用传递,返回值也优先考虑引用类型(引用必须保证在使用前,本 ...

  3. 最新新浪长连接转为短连接的API与请求示例

    新浪短网址api是新浪官方对外公开的长链接转为短链接的API,可以将冗长的链接地址缩短生成 t.cn/xxx 格式的短链接. API有两种格式 http://lnurl.cn/sina/short-a ...

  4. GreenPlum 常用命令

    gpstate 命令 参数 作用 gpstate -b => 显示简要状态 gpstate -c => 显示主镜像映射 gpstart -d => 指定数据目录(默认值:$MASTE ...

  5. IntelliJ IDEA 2017 Dubbo Elastic-job Redis Zookeeper RabbitMQ FastDFS MyCat 简介以及部分实现(三)

    前言    首先需要说明一下,与前两章的安装篇不太一样,这篇主要扫清一下这些插件/框架 等都是干什么用的,大多数都会用于服务端或监测工具或其他,作为新手建立一个大概的思想更好的了解自己的项目.废话不多 ...

  6. Halting Problem

    Halting Problem: 传送门:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4049 总结一个小规律:题目中给的 ...

  7. HTTP请求响应的过程

    1. TCP/IP协议分层结构 应用层(含括了OSI七层中的上三层,分别为应用层,表示层, 会话层):DNS,  URI,  HTML,  HTTP,  TLS/SSL,  SMTP,   POP,  ...

  8. 【caffe Blob】caffe中与Blob相关的代码注释、使用举例

    首先,Blob使用的小例子(通过运行结果即可知道相关功能): #include <vector> #include <caffe/blob.hpp> #include < ...

  9. crontab 定时访问指定url,定时脚本

    一.contab格式说明 二.定时访问url: 1.连接远程主机,连接成功后,输入命令  crontab -e : 2.参照VI编辑器.按字母 i 进入编辑模式,输入需要执行的脚本:(在这里之前要检查 ...

  10. java 静态数组 和非静态数组的区别

    区别:1,数组创建时间不同,静态的是一定义出来就创建了,动态的则是定义时不创建,使用时才创建,一定意义上节省了内存空间.2,使用场景不同,一开始就知道数组长度的使用静态初始化,反之,动态初始化. 静态 ...