(1)安裝JDK 官網下載jdk:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 下載jdk8,放到/usr/local/src/目錄下 [root@linux-node3 ~]# tar -zxvf jdk-8u151-linux-x64.tar.gz [root@linux-node3 ~]# mv jdk1.8.0_151 /usr/local/jdk1.8 [root@linux-node3 ~]# vim /etc/profile 增長以下內容: JAVA_HOME=/usr/local/jdk1.8/ JAVA_BIN=/usr/local/jdk1.8/bin JRE_HOME=/usr/local/jdk1.8/jre PATH=$PATH:/usr/local/jdk1.8/bin:/usr/local/jdk1.8/jre/bin CLASSPATH=/usr/local/jdk1.8/jre/lib:/usr/local/jdk1.8/lib:/usr/local/jdk1.8/jre/lib/charsets.jar [root@linux-node3 ~]# source /etc/profile [root@linux-node3 ~]# java -version java version "1.8.0_151" Java(TM) SE Runtime Environment (build 1.8.0_151-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode) (2)安裝tomcat [root@linux-node3 ~]# wget http://apache.fayea.com/tomcat/tomcat-8/v8.5.20/bin/apache-tomcat-8.5.20.tar.gz [root@linux-node3 ~]# tar -zxvf apache-tomcat-8.5.24.tar.gz [root@linux-node3 ~]# mv apache-tomcat-8.5.24 /usr/local/tomcat [root@linux-node3 ~]# /usr/local/tomcat/bin/startup.sh [root@linux-node3 ~]# netstat -tulnp |grep 8080 tcp6 0 0 :::8080 :::* LISTEN 3765/java 提示:三個端口8080爲提供web服務的端口,8005爲管理端口,8009端口爲第三方服務調用的端口,好比httpd和Tomcat結合時會用到 (3)配置tomcat [root@linux-node3 ~]# vim /usr/local/tomcat/conf/tomcat-users.xml <tomcat-users> <role rolename="admin"/> <role rolename="admin-gui"/> <role rolename="admin-script"/> <role rolename="manager"/> <role rolename="manager-gui"/> <role rolename="manager-script"/> <role rolename="manager-jmx"/> <role rolename="manager-status"/> <user name="admin" password="admin123456" roles="admin,manager,admin-gui,admin-script,manager-gui,manager-script,manager-jmx,manager-status" /> </tomcat-users> [root@linux-node3 ~]# /usr/local/tomcat/bin/shutdown.sh [root@linux-node3 ~]# /usr/local/tomcat/bin/startup.sh 在訪問tomcat時,點擊"manager webapp"會跳出一個驗證彈框,輸入用戶名密碼
會跳轉到如下界面,說明用戶名密碼無誤,如圖:html
(1)下載zrlog的代碼 [root@linux-node2 home]# wget https://codeload.github.com/94fzb/zrlog/zip/master --2017-12-25 11:02:45-- https://codeload.github.com/94fzb/zrlog/zip/master Resolving codeload.github.com (codeload.github.com)... 192.30.255.121, 192.30.255.120 Connecting to codeload.github.com (codeload.github.com)|192.30.255.121|:443... connected. HTTP request sent, awaiting response... 200 OK Length: unspecified [application/zip] Saving to: ‘master’ [ <=> ] 1,669,502 199KB/s in 8.6s 2017-12-25 11:02:56 (189 KB/s) - ‘master’ saved [1669502] [root@linux-node2 home]# du -sh 1.7M. [root@linux-node2 home]# du -sh master 1.6Mmaster (2)解壓 [root@linux-node2 home]# yum install -y unzip [root@linux-node2 home]# unzip master (3)初始化倉庫,並將zrlog的代碼push到gitlab [root@linux-node2 home]# mkdir Java [root@linux-node2 Java]# mv zrlog-master/* Java/ [root@linux-node2 Java]# git remote add orgin git@192.168.56.11:java/zrlog.git [root@linux-node2 Java]# git add . [root@linux-node2 Java]# git commit -m "add origin" # On branch master nothing to commit, working directory clean [root@linux-node2 Java]# ll total 48 drwxr-xr-x 2 root root 55 Dec 25 17:45 bin -rw-r--r-- 1 root root 6114 Dec 25 17:45 CHANGELOG.md drwxr-xr-x 2 root root 42 Dec 25 17:45 doc -rw-r--r-- 1 root root 11358 Dec 25 17:45 LICENSE -rwxr-xr-x 1 root root 6468 Dec 25 17:45 mvnw -rw-r--r-- 1 root root 4994 Dec 25 17:45 mvnw.cmd -rw-r--r-- 1 root root 7664 Dec 25 17:45 pom.xml -rw-r--r-- 1 root root 3574 Dec 25 17:45 README.md drwxr-xr-x 4 root root 28 Dec 25 17:45 src [root@linux-node2 Java]# git push origin master Counting objects: 457, done. Compressing objects: 100% (426/426), done. Writing objects: 100% (457/457), 2.98 MiB | 1.72 MiB/s, done. Total 457 (delta 51), reused 0 (delta 0) remote: Resolving deltas: 100% (51/51), done. To git@192.168.56.11:java/zrlog.git * [new branch] master -> master
(1)新建項目java
登陸jenkins,點擊「新建」,任務名稱自定義(zr_blog)node
選擇「構建一個maven項目」linux
點擊「肯定」git
(2)配置項目github
源碼管理web
選擇 「git」, Repository URL填寫你的git地址,並配置對應的key,你們最好事前先在jenkins這臺機器上可以直接遠程git操做私有倉庫apache
構建觸發器、構建環境、Pre Steps保持默認vim
Build瀏覽器
「Root POM」爲pom.xml, Goals and options 填寫 clean install -D maven.test.skip=true
Post Steps、構建設置保持默認
構建後操做
點擊「增長構建後操做步驟」選擇「Deploy war/ear to a container」,「WAR/EAR files」填寫「**/*.war」,Contex path留空,Containers選擇Tomcat 8.x,Tomcat URL填寫要把war包發佈到的那臺機器的url,如http://192.168.56.13:8080
Credentials這裏須要點擊右側的Add,添加用戶名和密碼
點擊"當即構建"查看控制檯信息,如圖:
(3)查看發佈結果
查看linux-node3的webapps目錄,會有相對應的war包,並已經進行解壓,使用瀏覽器訪問
[root@linux-node3 ~]# ll /usr/local/tomcat/webapps/ total 7160 drwxr-x--- 14 root root 4096 Dec 25 03:08 docs drwxr-x--- 6 root root 4096 Dec 25 03:08 examples drwxr-x--- 5 root root 4096 Dec 25 03:08 host-manager drwxr-x--- 6 root root 4096 Dec 25 04:05 manager drwxr-x--- 3 root root 4096 Dec 25 03:08 ROOT drwxr-x--- 9 root root 4096 Dec 25 04:04 zrlog-1.8.0 -rw-r----- 1 root root 7306944 Dec 25 04:04 zrlog-1.8.0.war