centos安装的是java8根据jenkins的提示,所以选择2.164


You will need to explicitly install a Java runtime environment, because Oracle's Java RPMs are incorrect and fail to register as providing a java dependency. Thus, adding an explicit dependency requirement on Java would force installation of the OpenJDK JVM.

  • 2.164 (2019-02) and newer: Java 8 or Java 11
  • 2.54 (2017-04) and newer: Java 8
  • 1.612 (2015-05) and newer: Java 7

本文采用rpm形式安装,下载网址

https://archives.jenkins-ci.org/redhat-stable/

rpm安装:

rpm -ivh jenkins-2.164.1-1.1.noarch.rpm

配置jenkis的端口:

vim /etc/sysconfig/jenkins

找到修改端口号:

JENKINS\_PORT="8080" 修改此端口号

新版Jenkins配置文件需要在启动service里面更改

vim /usr/lib/systemd/system/jenkins.service

编辑更改这一行

Environment="JENKINS_PORT=7998”

启动jenkins

service jenkins start
service jenkins stop
service jenkins restart

启动失败日志:

[root@iZuefw6wnv6uycZ ~]# systemctl status jenkins.service
● jenkins.service - LSB: Jenkins Automation Server
   Loaded: loaded (/etc/rc.d/init.d/jenkins; bad; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2024-12-10 13:35:05 CST; 12s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 15057 ExecStart=/etc/rc.d/init.d/jenkins start (code=exited, status=1/FAILURE)

Dec 10 13:35:05 iZuefw6wnv6uycZ systemd[1]: Starting LSB: Jenkins Automation Server...
Dec 10 13:35:05 iZuefw6wnv6uycZ runuser[15062]: pam_unix(runuser:session): session opened for user jenkins by (uid=0)
Dec 10 13:35:05 iZuefw6wnv6uycZ jenkins[15057]: Starting Jenkins bash: /usr/bin/java: No such file or directory
Dec 10 13:35:05 iZuefw6wnv6uycZ runuser[15062]: pam_unix(runuser:session): session closed for user jenkins
Dec 10 13:35:05 iZuefw6wnv6uycZ jenkins[15057]: [FAILED]
Dec 10 13:35:05 iZuefw6wnv6uycZ systemd[1]: jenkins.service: control process exited, code=exited status=1
Dec 10 13:35:05 iZuefw6wnv6uycZ systemd[1]: Failed to start LSB: Jenkins Automation Server.
Dec 10 13:35:05 iZuefw6wnv6uycZ systemd[1]: Unit jenkins.service entered failed state.
Dec 10 13:35:05 iZuefw6wnv6uycZ systemd[1]: jenkins.service failed.

可以查看到这里面Starting Jenkins bash: /usr/bin/java: No such file or directory 表示在/usr/bin/java 找到不到java环境,但我是配置了的。所以这里需要配置到对应路径的软连接

ln -s /home/env/java/jdk1.8.0_431/bin/java /usr/bin/java

再次启动则启动成功

[root@iZuefw6wnv6uycZ ~]# service jenkins start
Starting jenkins (via systemctl):                          [  OK  ]
[root@iZuefw6wnv6uycZ ~]# systemctl status jenkins.service
● jenkins.service - LSB: Jenkins Automation Server
   Loaded: loaded (/etc/rc.d/init.d/jenkins; bad; vendor preset: disabled)
   Active: active (running) since Tue 2024-12-10 13:39:59 CST; 6s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 15095 ExecStart=/etc/rc.d/init.d/jenkins start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/jenkins.service
           └─15114 /usr/bin/java -Dcom.sun.akuma.Daemon=daemonized -Djava.awt.headless=true -DJENKINS_HOME=/var/lib/jenkins -jar /usr/lib/jenkins/jenkins....

Dec 10 13:39:58 iZuefw6wnv6uycZ systemd[1]: Starting LSB: Jenkins Automation Server...
Dec 10 13:39:58 iZuefw6wnv6uycZ runuser[15100]: pam_unix(runuser:session): session opened for user jenkins by (uid=0)
Dec 10 13:39:59 iZuefw6wnv6uycZ runuser[15100]: pam_unix(runuser:session): session closed for user jenkins
Dec 10 13:39:59 iZuefw6wnv6uycZ systemd[1]: Started LSB: Jenkins Automation Server.
Dec 10 13:39:59 iZuefw6wnv6uycZ jenkins[15095]: Starting Jenkins [  OK  ]

打开jenkins

在浏览器中访问ip:端口 , 首次进入会要求输入初始密码,

初始密码在:/var/lib/jenkins/secrets/initialAdminPassword

查看密码:

[root@iZuefw6wnv6uycZ ~]# cat /var/lib/jenkins/secrets/initialAdminPassword
e912eae446234c02bdc5a8aea1de6b04

接下来选择“Install suggested plugins”安装默认的插件,Jenkins就下载相关的插件进行安装,有时候因为访问外网原因,可以选择手动安装,进入界面自己选择安装。

然后在世配置管理员命令和密码即可

最后修改:2024 年 12 月 27 日
如果觉得我的文章对你有用,请随意赞赏