编程语言
首页 > 编程语言> > Jenkins升级java版本

Jenkins升级java版本

作者:互联网

1.安装JDK11

yum install java-11-openjdk* -y

2.查看当前使用的java版本 可以看到以下信息则可以继续安装jenkins

[root@bogon ~]# java -version
openjdk version "11.0.15" 2022-04-19 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.15+9-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.15+9-LTS, mixed mode, sharing)

3.如果以前已经安装过其它版本的java 运行时环境,则需要切换使用jdk11,使用 alternatives --config java 切换java版本,切换版本后验证下是否切换成功

[root@bogon ~]# java -version
openjdk version "1.8.0_332"
OpenJDK Runtime Environment (build 1.8.0_332-b09)
OpenJDK 64-Bit Server VM (build 25.332-b09, mixed mode)
[root@bogon ~]# alternatives --config java
 
共有 2 个提供“java”的程序。
 
  选项    命令
-----------------------------------------------
   1           java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.15.0.9-2.el7_9.x86_64/bin/java)
*+ 2           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-1.el7_9.x86_64/jre/bin/java)
 
按 Enter 保留当前选项[+],或者键入选项编号:1
[root@bogon ~]# java -version
openjdk version "11.0.15" 2022-04-19 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.15+9-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.15+9-LTS, mixed mode, sharing)

4.java版本切换为jdk11后,安装jenkins

yum install jenkins -y

5.尝试启动jenkins

systemctl start jenkins

6.无报错的话可以查看下jenkins的状态,看下是否运行成功了

[root@bogon ~]# systemctl status jenkins
● jenkins.service - Jenkins Continuous Integration Server
   Loaded: loaded (/usr/lib/systemd/system/jenkins.service; disabled; vendor preset: disabled)
   Active: active (running) since 四 2022-07-21 11:11:11 CST; 1min 26s ago
 Main PID: 1744 (java)
   CGroup: /system.slice/jenkins.service
           └─1744 /usr/bin/java -Djava.awt.headless=true -jar /usr/share/java/jenkins.war --webroot=%C/jenkins/war --httpPort=8080
如果有报错的话,需要使用 journalctl -xe 命令看下日志信息,这里演示下如果使用的jdk1.8而非jdk11的情况, jenkins-2.360-1.1 版本需要使用jdk11里的运行时环境

alternatives --config java
 
共有 2 个提供“java”的程序。
 
  选项    命令
-----------------------------------------------
 + 1           java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.15.0.9-2.el7_9.x86_64/bin/java)
*  2           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-1.el7_9.x86_64/jre/bin/java)
 
按 Enter 保留当前选项[+],或者键入选项编号:2
[root@bogon secrets]# systemctl start  jenkins
Job for jenkins.service failed. See "systemctl status jenkins.service" and "journalctl -xe" for details.
[root@bogon secrets]# journalctl -xe
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit jenkins.service has failed.
--
-- The result is failed.
bogon systemd[1]: Unit jenkins.service entered failed state.
bogon systemd[1]: jenkins.service failed.
bogon systemd[1]: jenkins.service holdoff time over, scheduling restart.
bogon systemd[1]: Stopped Jenkins Continuous Integration Server.
-- Subject: Unit jenkins.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit jenkins.service has finished shutting down.
bogon systemd[1]: Starting Jenkins Continuous Integration Server...
-- Subject: Unit jenkins.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit jenkins.service has begun starting up.
....
bogon jenkins[2448]: Jenkins requires Java versions [17, 11] but you are running with Java 1.8 from /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-1.el7_9.x86_64/jre
...
-- Subject: Unit jenkins.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit jenkins.service has failed.
--
-- The result is failed.

其中 Jenkins requires Java versions [17, 11] but you are running with Java 1.8 from /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-1.el7_9.x86_64/jre 的意思就是 jre的版本太低,需要使用jdk11的jre.

标签:java,service,--,openjdk,1.8,版本,jenkins,Jenkins
来源: https://www.cnblogs.com/HappyTeemo/p/16607445.html