部署在tomcat下面的jenkins啟動了多個實例,界面訪問報錯
最近因為機房停電,機器上面的所有服務有出現重啟,包括jenkins服務。jenkins在重啟之後出現了不能訪問,界面報錯信息:
報錯說啟動了多個實例,點擊下面的“Ignore this problem and keep using Jenkins anyway”按鈕,可以恢復到原來正常的界面,但是這個報錯,不久又會出現。
原因分析
因為jenkins是放在tomcat下面的,查看tomcat進程,發現確實只有一個,端口也沒有什麽異常:
[root@master-2 bin]# ps -ef|grep tomcat root 21780 1 43 15:15 pts/2 00:00:12 /usr/local/jdk/bin/java -Djava.util.logging.config.file=/usr/local/apache-tomcat-8.0.48/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dignore.endorsed.dirs= -classpath /usr/local/apache-tomcat-8.0.48/bin/bootstrap.jar:/usr/local/apache-tomcat-8.0.48/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/apache-tomcat-8.0.48 -Dcatalina.home=/usr/local/apache-tomcat-8.0.48 -Djava.io.tmpdir=/usr/local/apache-tomcat-8.0.48/temp org.apache.catalina.startup.Bootstrap start root 12245 7771 0 15:16 pts/2 00:00:00 grep --color=auto tomcat [root@master-2 bin]# [root@master-2 bin]# [root@master-2 bin]# [root@master-2 bin]# [root@master-2 bin]# netstat -tlunp|grep 28080 tcp 0 0 0.0.0.0:23000 0.0.0.0:* LISTEN 28080/fdfs_storaged tcp6 6 0 :::28080 :::* LISTEN 12168/java [root@master-2 bin]#
根據https://stackoverflow.com/questions/44378841/jenkins-detecting-more-than-one-instance的提示:
? Check if another java process is running which runs jenkins e.g. in unix using top
? If you‘re using tomcat, search for a second instance of tomcat having the jenkins.war exploded somewhere
? Could be helpful to just have one version of java installed
查看jenkins,懷疑可能是哪裏啟動了多個jenkins進程,發現有兩個一模一樣的jenkins進程,只是進程號不一樣:
[root@master-2 home]# ps -ef|grep jenkins samba 10835 10820 0 May18 ? 00:00:05 /bin/tini -- /usr/local/bin/jenkins.sh samba 10854 10835 0 May18 ? 00:03:53 java -Duser.home=/var/jenkins_home -jar /usr/share/jenkins/jenkins.war root 30593 21780 0 10:34 pts/2 00:00:00 sh -c { while [ -d ‘/root/.jenkins/workspace/locman@tmp/durable-9c600ea7‘ -a \! -f ‘/root/.jenkins/workspins-result.txt‘ ]; do touch ‘/root/.jenkins/workspace/locman@tmp/durable-9c600ea7/jenkins-log.txt‘; sleep 3; done } & jsc=durable-95de6aeeb4c40d371cff43dc ‘/root/.jenkins/workspace/locman@tmp/durable-9c600ea7/script.sh‘ > ‘/root/.jenkins/workspace/locman@tmp/durable-9c600ea7/jenkins-log.txt‘ 2>&1; echo $?tmp/durable-9c600ea7/jenkins-result.txt‘; wait #這個進程後面的21780看,應該是之前tomcat正常啟動的進程 *root 30596 30593 0 10:34 pts/2 00:00:00 sh -c { while [ -d ‘/root/.jenkins/workspace/locman@tmp/durable-9c600ea7‘ -a \! -f ‘/root/.jenkins/workspins-result.txt‘ ]; do touch ‘/root/.jenkins/workspace/locman@tmp/durable-9c600ea7/jenkins-log.txt‘; sleep 3; done } & jsc=durable-95de6aeeb4c40d371cff43dc ‘/root/.jenkins/workspace/locman@tmp/durable-9c600ea7/script.sh‘ > ‘/root/.jenkins/workspace/locman@tmp/durable-9c600ea7/jenkins-log.txt‘ 2>&1; echo $?tmp/durable-9c600ea7/jenkins-result.txt‘; wait #這個進程有點異常 root 30597 30593 0 10:34 pts/2 00:00:00 /bin/sh -xe /root/.jenkins/workspace/locman@tmp/durable-9c600ea7/script.sh root 30600 30597 44 10:34 pts/2 00:00:13 /usr/local/jdk/bin/java -classpath /var/jenkins_home/apache-maven-3.5.2/boot/plexus-classworlds-2.5.2.jare/apache-maven-3.5.2/bin/m2.conf -Dmaven.home=/var/jenkins_home/apache-maven-3.5.2 -Dlibrary.jansi.path=/var/jenkins_home/apache-maven-3.5.2/lib/jansi-natory=/home/.jenkins/workspace/locman/locman-service-controller org.codehaus.plexus.classworlds.launcher.Launcher package -DskipTests root 30702 30600 0 10:35 pts/2 00:00:00 /bin/sh -c cd /home/.jenkins/workspace/locman/locman-service-controller && /usr/local/jdk/jre/../bin/java.javac.JavacCompiler8324825440823874050arguments root 31210 7771 0 10:35 pts/2 00:00:00 grep --color=auto jenkins [root@master-2 home]#
原因說明:
因為jenkins是放在tomcat下面的,將jenkins.war解壓到了/usr/local/apache-tomcat-8.0.48/webapps/ROOT目錄下面,但是還放了一個jenkins.war在webapps下面忘記刪掉。因此在啟動tomcat的時候,就一起啟動了webapps下面的jenkins.war和ROOT目錄下面的jenkins包內容。所以就啟動了兩個jenkins實例。
jenkins.war放在webapps目錄下面和解壓到ROOT目錄下面的區別:
ROOT目錄下面默認是tomcat的管理程序,但是如果你把自己的jenkins發布到root下面的話,你可以不通過項目名直接訪問你的項目,直接使用通過http://localhost:8080直接訪問你的項目(下圖端口號用的28080):
如果放在webapps下面,訪問的時候,就需要通過項目名稱來訪問http://localhost:8080/jenkins/(下圖端口號用的28080):
解決方法:
殺掉所有的jenkins和tomcat進程,然後將webapps下面的jenkins.war改個名字或者刪掉,再重啟tomcat
[root@master-2 webapps]# mv jenkins.war jenkins.war.bak
[root@master-2 bin]#
[root@master-2 bin]# ./startup.sh
[root@master-2 webapps]# ps -ef|grep jenkins
root 3611 7771 0 10:54 pts/2 00:00:00 grep --color=auto jenkins
samba 10835 10820 0 May18 ? 00:00:05 /bin/tini -- /usr/local/bin/jenkins.sh
samba 10854 10835 0 May18 ? 00:03:54 java -Duser.home=/var/jenkins_home -jar /usr/share/jenkins/jenkins.war
[root@master-2 webapps]# ps -ef|grep tomcat
root 1238 1 19 10:41 pts/2 00:02:33 /usr/local/jdk/bin/java -Djava.util.logging.config.file=/usr/local/apache-tomcat-8.0.48/conf/logging.proprg.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dignore.endorsed.dicat-8.0.48/bin/bootstrap.jar:/usr/local/apache-tomcat-8.0.48/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/apache-tomcat-8.0.48 -Dcatalina.home=/usr/locpdir=/usr/local/apache-tomcat-8.0.48/temp org.apache.catalina.startup.Bootstrap start
root 3632 7771 0 10:54 pts/2 00:00:00 grep --color=auto tomcat
然後暫時沒有出現這個錯誤了。
備註:webapps下面的jenkins.war一直都存在,在異常停電重啟之前,沒有發現報這個錯。目前暫時還沒出現上面的報錯了,問題是否解決還需後續繼續觀察
部署在tomcat下面的jenkins啟動了多個實例,界面訪問報錯