修改代碼,打包,上傳,重啓... 大把的時間花費在這些重複無味的工做上。筆者與當前主流的價值觀保持一致:咱們應該把時間花費在更有意義的事情上。咱們能夠嘗試藉助一些工具,讓這些重複機械的工做交給計算機去完成,這也是咱們作軟件開發的核心思想借用 Jenkins 持續集成重複工做是一個很不錯的選擇。--引用 html
jenkins部署java
chy01 -192.168.212.11 jenkins的服務端 chy02-192.168.212.12 私有倉庫的機器linux
[root@chy01 tmp]# cd sample/ [root@chy01 sample]# ls 1.txt discz.html sample [root@chy01 sample]# wget https://codeload.github.com/94fzb/zrlog/zip/master --2017-11-24 05:05:34-- https://codeload.github.com/94fzb/zrlog/zip/master Resolving codeload.github.com (codeload.github.com)... 192.30.255.120, 192.30.255.121 Connecting to codeload.github.com (codeload.github.com)|192.30.255.120|:443... connected. HTTP request sent, awaiting response... 200 OK Length: unspecified [application/zip] Saving to: ‘master’ [ <=> ] 1,900,233 901KB/s in 2.1s
2017-11-24 05:05:37 (901 KB/s) - ‘master’ saved [1900233]git
//下載zrlog的源碼包
[root@chy01 sample]# unzip master 須要解壓
[root@chy01 sample]# mv zrlog-master/* .
[root@chy01 sample]# git add --all
[root@chy01 sample]# git commit -m "add zrlog"
[root@chy01 sample]# git push
Counting objects: 446, done.
Compressing objects: 100% (417/417), done.
Writing objects: 100% (445/445), 3.39 MiB | 6.19 MiB/s, done.
Total 445 (delta 50), reused 0 (delta 0)
To git@192.168.212.12:/data/gitroot/sample.git
d22de14..03a39b2 master -> mastergithub
如上的準備工做已完成如今正式構建倉庫 在另一臺機器上(客戶端)安裝jdk + tomcat,其中jdk能夠爲openjdk,版本1.8 (在192.168.212.10安裝jdk+tomcat)
[root@chy tomcat]# yum install -y java-1.8.0-openjdk
//安裝jdk
[root@chy tomcat]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.23/bin/apache-tomcat-8.5.23.tar.gz 下載二進制包
[root@chy src]# tar zxvf apache-tomcat-8.5.23.tar.gz
apache-tomcat-8.5.23/conf/
[root@chy src]# mv apache-tomcat-8.5.23 /usr/local/tomcat
[root@chy tomcat]# vim /usr/local/tomcat/conf/tomcat-users.xml //配置管理入口,必定要配置。
//增長以下內容定義的是jenkins的用戶與密碼:
<role rolename="chy1"/>
<role rolename="chy1-gui"/>
<role rolename="chy1-script"/>
<role rolename="manager"/>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/><user name="chy1" password="chy123456789" roles="chy1,manager,chy1-gui,chy1-script,manager-gui,manager-script,manager-jmx,manager-status" />
如上須要放在倒數第二行。
[root@chy tomcat]# /usr/local/tomcat/bin/startup.sh //啓動
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@chy tomcat]# /usr/local/tomcat/bin/shutdown.sh //以後須要重啓,先shutdown
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
[root@chy tomcat]# /usr/local/tomcat/bin/startup.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.web
下面咱們就須要去訪問並進行下一步配置:
以下出現了403問題
解決方案: apache
[root@chy tomcat]# vim /usr/local/tomcat/webapps/manager/META-INF/context.xml <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|192.168.212.*"/> //這裏要增長下ip的網段,支持正則匹配由於這裏只容許了本地並無容許其它的ip地址,其中咱們的jenkins也要訪問tomcat的因此這裏就正則匹配所有就能夠了。
再次重啓 Tomcat 服務!bootstrap
當咱們再次刷新進入,就會看到以下界面:
這個就是咱們將來須要讓Jenkins 經過這個接口來更新咱們開發好的war包!接下來安裝war包vim
[root@chy01 local]# wget http://mirrors.hust.edu.cn/apache/maven/maven-3/3.5.2/binaries/apache-maven-3.5.2-bin.tar.gz [root@chy01 local]# tar zxvf apache-maven-3.5.2-bin.tar.gz [root@chy01 local]# ls apache-maven-3.5.2 bin boot conf lib LICENSE NOTICE README.txt [root@chy01 local]# /usr/local/apache-maven-3.5.2/bin/mvn --version Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T15:58:13+08:00) Maven home: /usr/local/apache-maven-3.5.2 Java version: 1.8.0_151, vendor: Oracle Corporation Java home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64/jre Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "3.10.0-514.el7.x86_64", arch: "amd64", family: "unix"
安裝好maven,接下來配置jenkinstomcat
2下拉到Maven,Maven安裝,Name(自定義,如maven3.5.2),MAVEN_HOME填 「/usr/local/apache-maven-3.5.2」
左下角「save」 至此,咱們的基礎搭建就搞定了!