CenterOS7.9 安装Jenkins

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
4.1 获取jenkins安装源文件

[root@bogon ~]#  sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat/jenkins.repo --no-check-certificate
-bash: wget: 未找到命令
[root@bogon ~]# yum -y install wget #wget 没找到的话需要安装一下
[root@bogon ~]#  sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat/jenkins.repo --no-check-certificate

4.2 导入公钥

 sudo rpm --import https://pkg.jenkins.io/redhat/jenkins.io.key

4.3 安装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.
7. 访问ip+端口号(jenkins的默认端口号是8080,可以在配置文件中修改端口)看下Dashboard,404了,需要设置对应端口的防火墙规则

[root@bogon ~]# firewall-cmd --zone=public --add-port=8080/tcp --permanent
success
[root@bogon ~]# systemctl restart firewalld.service #重启防火墙服务
[root@bogon ~]#

8.再次访问dashboard,按照提示获取管理员密码

[root@bogon secrets]# cd /var/lib/jenkins/secrets
[root@bogon secrets]# ls
initialAdminPassword  jenkins.model.Jenkins.crumbSalt  master.key
[root@bogon secrets]# vi initialAdminPassword

[1]+  已停止               vi initialAdminPassword
[root@bogon secrets]#

9.安装推荐插件

10. 可以使用了~

11.别忘了设置服务开机启动

systemctl enable  jenkins

posted @ 2022-07-21 12:06  天气说变冷就变冷  阅读(4625)  评论(0编辑  收藏  举报