1.從官網下載最新版本的tomcat
下載地址:https://tomcat.apache.org/
2.Jenkins 官方網站下載最新版本war包
Jenkins官網地址:http://jenkins-ci.org/
3.安裝Jenkins
步驟一、將jenkins的war包拷貝到 $TOMCAT_HOME/webapps 下(不用解壓),刪除 webapps 下其他目錄
步驟二、建立存放jenkins資料的目錄,並新增環境變數,命令如下:
mkdir /jenkins vi /etc/profile 新增 export JENKINS_HOME=/jenkins
步驟三、寫啟動jenkins服務指令碼,命令如下:
vi /etc/init.d/jenkins
新增如下內容,如果你希望用指定使用者啟動,請修改 JENKINS_USER=root 的值,但要記得更改 /jenkins 以及Tomcat 目錄的訪問許可權。另外其他環境變數例如 JAVA_HOME 和 TOMCAT_HOME 要根據你實際JDK和Tomcat的安裝目錄修改。
#!/bin/sh # # Startup script for the Jenkins Continuous Integration server # (via Jakarta Tomcat Java Servlets and JSP server) # # chkconfig: - 85 15 # description: Jakarta Tomcat Java Servlets and JSP server # processname: tomcat # pidfile: /var/run/tomcat.pid # Set Tomcat environment. JENKINS_USER=root LOCKFILE=/var/lock/jenkins export PATH=/usr/local/bin:$PATH export HOME=/jenkins export JAVA_HOME=/opt/jdk1.8.0_161 export JENKINS_BASEDIR=/jenkins export TOMCAT_HOME=/opt/apache-tomcat-9.0.8 export CATALINA_PID=$JENKINS_BASEDIR/jenkins-tomcat.pid export CATALINA_OPTS="-DJENKINS_HOME=$JENKINS_BASEDIR/jenkins-home -Xmx512m -Djava.awt.headless=true" [ -f $TOMCAT_HOME/bin/catalina.sh ] || exit 0 export PATH=$PATH:/usr/bin:/usr/local/bin # See how we were called. case "$1" in start) # Start daemon. echo -n "Starting Tomcat: " su -p -s /bin/sh $JENKINS_USER -c "$TOMCAT_HOME/bin/catalina.sh start" RETVAL=$? echo [ $RETVAL = 0 ] && touch $LOCKFILE ;; stop) # Stop daemons. echo -n "Shutting down Tomcat: " su -p -s /bin/sh $JENKINS_USER -c "$TOMCAT_HOME/bin/catalina.sh stop" RETVAL=$? echo [ $RETVAL = 0 ] && rm -f $LOCKFILE ;; restart) $0 stop $0 start ;; condrestart) [ -e $LOCKFILE ] && $0 restart ;; status) status tomcat ;; *) echo "Usage: $0 {start|stop|restart|status}" exit 1 esac exit 0
步驟四、賦予啟動指令碼可執行許可權,並設定開機啟動,命令如下:
chmod a+x /etc/init.d/jenkins chkconfig jenkins on service jenkins start
步驟五、http://192.168.1.171:8080/jenkins/ 可以看到 Jenkins 已經啟動了
佈置 Nginx 做一下反向代理
步驟一、下載並安裝nginx
步驟二、編輯nginx啟動檔案,命令如下:
vi /etc/nginx/nginx.conf
修改成如下內容
user root; worker_processes auto; error_log /var/log/nginx/error.log error; events { worker_connections 10240; } http{ server { listen 80; server_name ci.abc.com; client_max_body_size 60M; client_body_buffer_size 512k; location / { proxy_pass http://localhost:8080; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } }
啟動nginx service nginx start
步驟三、修改本機hosts檔案(C:WindowsSystem32driversetchosts)
192.168.1.171 ci.abc.com
步驟四、訪問
這次我們在瀏覽器裡輸入 http://ci.abc.com/jenkins 可以看到頁面了!