【Linux】Jenkins以war包運行及開機啓動配置(四)

  本例介紹jenkins已war包運行及開機啓動配置html

  環境:Linux環境(CentOS 7.4)java

以war包運行

  一、下載jenkins.war包web

  二、啓動war包( 默認端口:8080,默認JENKINS_HOME目錄:~/.jenkins )shell

    前臺啓動命令:java -jar jenkins.war
apache

    後臺啓動命令:nohup java -jar jenkins.war &vim

  三、使用瀏覽器打開地址:http://ip:8080,便可訪問到jenkinswindows

    關閉jenkins,頁面訪問地址:http://ip:8080/exit瀏覽器

    重啓jenkins,頁面訪問地址:http://ip:8080/restarttomcat

  四、其餘安裝參考【Linux】Jenkins安裝(一)bash

  五、修改JENKINS_HOME目錄啓動,須要新建一個腳本jenkins.sh,而後運行腳本 

1 #!/bin/bash
2 # 導入JENKINS_HOME環境變量
3 export JENKINS_HOME=/data/soft/jenkins
4 
5 cd $JENKINS_HOME
6 
7 # 啓動Jenkins
8 nohup java -jar jenkins.war  --ajp13Port=-1 --httpPort=18080 >/dev/null 2>&1 &

  六、構建shell,demo以下:

 1 #!/bin/bash
 2 # 編譯+部署zeus站點
 3 
 4 # 保持Jenkins啓動的Service(tomcat) 不被殺死
 5 export BUILD_ID=dontKillMe
 6 
 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-site
31 pwd
32 
33 mvn clean package
34 
35 # 停tomcat
36 killTomcat
37 
38 # 刪除原有工程
39 rm -rf $TOMCAT_APP_PATH/webapps/zeus.war
40 
41 # 複製新的工程
42 cp $PROJ_PATH/god-site/god-web/god-web-zeus/target/zeus.war $TOMCAT_APP_PATH/webapps/
43 
44 # 啓動Tomcat
45 cd $TOMCAT_APP_PATH
46 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 --help
 2 Running from: /data/soft/jenkins/jenkins.war
 3 webroot: $user.home/.jenkins
 4 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}/war
 9    --pluginroot             = folder where the plugin archives are expanded into. Default is ${JENKINS_HOME}/plugins
10                               (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 folder
12    --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 52 and above)
15    --javaHome               = Override the JAVA_HOME variable
16    --toolsJar               = The location of tools.jar. Default is JAVA_HOME/lib/tools.jar
17    --config                 = load configuration properties from here. Default is ./winstone.properties
18    --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 ./lib
20 
21    --extraLibFolder         = folder for additional jar files to add to Jetty classloader
22 
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 interfaces
29    --httpKeepAliveTimeout   = how long idle HTTP keep-alive connections are kept around (in ms; default 5000)?
30    --httpsPort              = set the https listening port. -1 to disable, Default is disabled
31    --httpsListenAddress     = set the https listening address. Default is all interfaces
32    --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.ks
34    --httpsKeyStorePassword  = the password for the SSL KeyStore file. Default is null
35    --httpsKeyManagerType    = the SSL KeyManagerFactory type (eg SunX509, IbmX509). Default is SunX509
36    --httpsPrivateKey        = this switch with --httpsCertificate can be used to run HTTPS with OpenSSL secret key
37      / --httpsCertificate     file and the corresponding certificate file
38    --http2Port              = set the http2 listening port. -1 to disable, Default is disabled
39    --http2ListenAddress     = set the http2 listening address. Default is all interfaces
40    --excludeCipherSuites    = set the ciphers to exclude (comma separated, use blank quote " " to exclude none) (default is
41                            // 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 cipher 
46                            // suites that may be accidentally included via include patterns. 
47                            // The default enabled cipher list in Java will not include these 
48                            // (but they are available in the supported list). 
49                            "^SSL_.*$", 
50                            "^.*_NULL_.*$", 
51                            "^.*_anon_.*$" 
52    --controlPort            = set the shutdown/control port. -1 to disable, Default disabled
53 
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 60 minutes
56    --sessionEviction        = set the session eviction timeout for idle sessions in seconds. Default value is 180. -1 never evict, 0 evict on exit
57    --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 in a form submission to protect
60                               against hash DoS attack (oCERT #2011-003). Default is 10000.
61    --useJmx                 = Enable Jetty Jmx
62    --qtpMaxThreadsCount     = max threads number when using Jetty Queued Thread Pool
63    --jettyAcceptorsCount    = Jetty Acceptors number
64    --jettySelectorsCount    = Jetty Selectors number
65    --usage / --help         = show this message
66  Security options:
67    --realmClassName               = Set the realm class to use for user authentication. Defaults to ArgumentsRealm class
68 
69    --argumentsRealm.passwd.<user> = Password for user <user>. Only valid for the ArgumentsRealm realm class
70    --argumentsRealm.roles.<user>  = Roles for user <user> (comma separated). Only valid for the ArgumentsRealm realm class
71 
72    --fileRealm.configFile         = File containing users/passwds/roles. Only valid for the FileRealm realm class
73 
74  Access logging:
75    --accessLoggerClassName        = Set the access logger class to use for user authentication. Defaults to disabled
76    --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)

 開機啓動配置

  參考:【Linux】開機自動啓動腳本

  一、編寫啓動腳本jenkins

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

 1 #!/bin/bash 
 2 
 3 # 導入環境變量 
 4 export JENKINS_HOME=/data/soft/jenkins 
 5 export JAVA_HOME=/data/soft/jdk1.8.0_181
 6 
 7 cd $JENKINS_HOME 
 8 
 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 

  二、給jenkins.sh文件受權

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

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

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

  四、重啓計算機

    命令:reboot

 Jenkins經常使用功能

  一、備份、遷移、恢復jenkins

  首先找到JENKINS_HOME,由於Jenkins的全部的數據都是以文件的形式存放在JENKINS_HOME目錄中。無論是遷移仍是備份,只須要操做JENKINS_HOME就好了。

  遷移:建議將JENKINS_HOME打包後在拷貝,windows能夠用zip,rar等,Linux有zip,tar等,而後將打包的文件解壓到新的JENKINS_HOME目錄就好了。

  備份:若是是臨時備份,整個壓縮文件就好了。

  恢復:恢復的時候須要先中止jenkins。

  二、升級Jenkins

  Jenkins的開發迭代很是快,每週發佈一個開發版本,長期支持版每半年更新一次(ps:大版本更新)。如此頻繁的更新,怎麼升級呢?

  war:下載新版的war文件,替換舊版本war文件。重啓便可。

  二進制:卸載舊版本,安裝新版本便可。

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

相關文章
相關標籤/搜索