java命令运行war包 端口_【Linux】Jenkins以war包运行及开机启动配置(四)

本例介绍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

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

1 #!/bin/bash2 # 导入JENKINS_HOME环境变量3 export JENKINS_HOME=/data/soft/jenkins4

5 cd $JENKINS_HOME6

7 # 启动Jenkins8 nohup java -jar jenkins.war --ajp13Port=-1 --httpPort=18080 >/dev/null 2>&1 &

6、构建shell,demo如下:

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

1 #!/bin/bash2 # 编译+部署zeus站点3

4 # 保持Jenkins启动的Service(tomcat) 不被杀死5 export BUILD_ID=dontKillMe6

7 # 需要配置如下参数8 # 项目路径,在Execute Shell中国配置项目路径, pwd就可以获得项目路径9 # export PROJ_PATH=这个jenkins任务在部署机器上的路径10 export PROJ_PATH=`pwd`11

12 # 输入你在环境上tomcat的全路径13 # export TOMCAT_APP_PATH=tomcat在部署机器上的路径14 export TOMCAT_APP_PATH=/data/soft/apache-tomcat-8080

15

16

17 ### base 函数18 killTomcat()19 {20 pid=`ps -ef | grep tomcat-8080 | grep -v grep | awk '{print $2}'`21 echo "Tomcat Id is : $pid"

22 if [ ! -n "$pid"];23 then

24 echo "No Tomcat Pid alive"

25 else

26 echo "Tomcat Pid alive"

27 fi

28 }29

30 cd $PROJ_PATH/god-site31 pwd

32

33 mvn clean package34

35 # 停tomcat36 killTomcat37

38 # 删除原有工程39 rm -rf $TOMCAT_APP_PATH/webapps/zeus.war40

41 # 复制新的工程42 cp $PROJ_PATH/god-site/god-web/god-web-zeus/target/zeus.war $TOMCAT_APP_PATH/webapps/

43

44 # 启动Tomcat45 cd $TOMCAT_APP_PATH46 sh bin/startup.sh

View Code

补充:

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

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

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

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

1 [root@H__D jenkins]# java -jar jenkins.war --help2 Running from: /data/soft/jenkins/jenkins.war3 webroot: $user.home/.jenkins4 Jenkins Automation Server Engine 2.184

5 Usage: java -jar jenkins.war [--option=value] [--option=value]6

7 Options:8 --webroot = folder where the WAR file is expanded into. Default is ${JENKINS_HOME}/war9 --pluginroot = folder where the plugin archives are expanded into. Default is ${JENKINS_HOME}/plugins10 (NOTE: this option does not change the directory where the plugin archives are stored)11 --extractedFilesFolder =folder where extracted files are to be located. Default is the temp folder12 --daemon =fork into background and run as daemon (Unix only)13 --logfile = redirect log messages to this file

14 --enable-future-java = allows running with new Java versions which are not fully supported (class version 52and above)15 --javaHome =Override the JAVA_HOME variable16 --toolsJar = The location of tools.jar. Default is JAVA_HOME/lib/tools.jar17 --config = load configuration properties from here. Default is ./winstone.properties18 --prefix = add this prefix to all URLs (eg http://localhost:8080/prefix/resource). Default is none

19 --commonLibFolder = folder for additional jar files. Default is ./lib20

21 --extraLibFolder = folder foradditional jar files to add to Jetty classloader22

23 --logThrowingLineNo = show the line no that logged the message (slow). Default is false

24 --logThrowingThread = show the thread that logged the message. Default is false

25 --debug = set the level of debug msgs (1-9). Default is 5(INFO level)26

27 --httpPort = set the http listening port. -1 to disable, Default is 8080

28 --httpListenAddress =set the http listening address. Default is all interfaces29 --httpKeepAliveTimeout = how long idle HTTP keep-alive connections are kept around (in ms; default 5000)?

30 --httpsPort = set the https listening port. -1to disable, Default is disabled31 --httpsListenAddress =set the https listening address. Default is all interfaces32 --httpsKeepAliveTimeout = how long idle HTTPS keep-alive connections are kept around (in ms; default 5000)?

33 --httpsKeyStore = the location of the SSL KeyStore file. Default is ./winstone.ks34 --httpsKeyStorePassword = the password for the SSL KeyStore file. Default is null

35 --httpsKeyManagerType =the SSL KeyManagerFactory type (eg SunX509, IbmX509). Default is SunX50936 --httpsPrivateKey = this switch with --httpsCertificate can be used to run HTTPS with OpenSSL secret key37 / --httpsCertificate file and the corresponding certificate file

38 --http2Port = set the http2 listening port. -1to disable, Default is disabled39 --http2ListenAddress =set the http2 listening address. Default is all interfaces40 --excludeCipherSuites = set the ciphers to exclude (comma separated, use blank quote " "to exclude none) (default is41 //Exclude weak / insecure ciphers

42 "^.*_(MD5|SHA|SHA1)$",43 //Exclude ciphers that don't support forward secrecy

44 "^TLS_RSA_.*$",45 //The following exclusions are present to cleanup known bad cipher46 //suites that may be accidentally included via include patterns.47 //The default enabled cipher list in Java will not include these48 //(but they are available in the supported list).

49 "^SSL_.*$",50 "^.*_NULL_.*$",51 "^.*_anon_.*$"

52 --controlPort = set the shutdown/control port. -1to disable, Default disabled53

54 --useJasper = enable jasper JSP handling (true/false). Default is false

55 --sessionTimeout = set the http session timeout value in minutes. Default to what webapp specifies, and then to 60minutes56 --sessionEviction = set the session eviction timeout for idle sessions in seconds. Default value is 180. -1 never evict, 0evict on exit57 --mimeTypes=ARG = define additional MIME type mappings. ARG would be EXT=MIMETYPE:EXT=MIMETYPE:...58 (e.g., xls=application/vnd.ms-excel:wmf=application/x-msmetafile)59 --maxParamCount=N = set the max number of parameters allowed ina form submission to protect60 against hash DoS attack (oCERT #2011-003). Default is 10000.61 --useJmx =Enable Jetty Jmx62 --qtpMaxThreadsCount =max threads number when using Jetty Queued Thread Pool63 --jettyAcceptorsCount =Jetty Acceptors number64 --jettySelectorsCount =Jetty Selectors number65 --usage / --help =show this message66 Security options:67 --realmClassName = Set the realm class to use foruser authentication. Defaults to ArgumentsRealm class68

69 --argumentsRealm.passwd. = Password for user . Only valid forthe ArgumentsRealm realm class70 --argumentsRealm.roles. = Roles for user (comma separated). Only valid forthe ArgumentsRealm realm class71

72 --fileRealm.configFile = File containing users/passwds/roles. Only valid forthe FileRealm realm class73

74 Access logging:75 --accessLoggerClassName = Set the access logger class to use foruser authentication. Defaults to disabled76 --simpleAccessLogger.format = The log format to use. Supports combined/common/resin/custom (SimpleAccessLogger only)77 --simpleAccessLogger.file = The location pattern for the log file(SimpleAccessLogger only)

开机启动配置

1、编写启动脚本jenkins

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

1 #!/bin/bash2

3 # 导入环境变量4 export JENKINS_HOME=/data/soft/jenkins5 export JAVA_HOME=/data/soft/jdk1.8.0_1816

7 cd $JENKINS_HOME8

9 pid=`ps -ef | grep jenkins.war | grep -v 'grep'| awk '{print $2}'`10 if [ "$1" = "start" ];then

11 if [ -n "$pid" ];then

12 echo 'jenkins is running...'

13 else

14 ### java启动服务 配置java安装根路径,和启动war包存的根路径15 nohup $JAVA_HOME/bin/java -Xms128m -Xmx256m -jar $JENKINS_HOME/jenkins.war --ajp13Port=-1 --httpPort=18080 >/dev/null 2>&1 &

16 fi

17 elif [ "$1" = "stop" ];then

18 exec ps -ef | grep jenkins | grep -v grep | awk '{print $2}'| xargs kill -9

19 echo 'jenkins is stop...'

20 else

21 echo "Please input like this:"./jenkins.sh start"or"./jenkins stop""

22 fi

2、给jenkins.sh文件授权

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

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

1 # jenkins2 /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/

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值