Centos7安装最新版Jenkins安装启动失败解决方案

首先,Jenkins官方提示后期最新版不在支持Centos7,所以建议还是用Ubuntu系统好点。

我这里是2023年12月安装的jenkins-2.426.2-1.1.noarch.rpm,不建议用docker安装,不然得去容器里面安装Git、JDK、NodeJS、Maven等,或者挂载进去,感觉搞不太懂。

安装与卸载:

1、安装与卸载
安装:rpm -ivh jenkins-2.426.2-1.1.noarch.rpm
卸载:rpm -e --nodeps jenkins-2.426.2-1.1.noarch

如果不知道安装的是什么版本,可以rpm -qa | grep jenkins查询

2、在启动前,旧版本的Jenkins配置文件是在/etc/sysconfig/jenkins,但是新版本的配置文件是/usr/lib/systemd/system/jenkins.service这个文件,文件描述让用户使用systemctl edit jenkins来修改,我并没有这么做,感觉麻烦,直接改的,修改后的全部文件在下面

#
# This file is managed by systemd(1). Do NOT edit this file manually!
# To override these settings, run:
#
#     systemctl edit jenkins
#
# For more information about drop-in files, see:
#
#     https://www.freedesktop.org/software/systemd/man/systemd.unit.html
#

[Unit]
Description=Jenkins Continuous Integration Server
Requires=network.target
After=network.target

[Service]
Type=notify
NotifyAccess=main
ExecStart=/usr/bin/jenkins
Restart=on-failure
SuccessExitStatus=143

# Configures the time to wait for start-up. If Jenkins does not signal start-up
# completion within the configured time, the service will be considered failed
# and will be shut down again. Takes a unit-less value in seconds, or a time span
# value such as "5min 20s". Pass "infinity" to disable the timeout logic.
#TimeoutStartSec=90

# Unix account that runs the Jenkins daemon
# Be careful when you change this, as you need to update the permissions of
# $JENKINS_HOME, $JENKINS_LOG, and (if you have already run Jenkins)
# $JENKINS_WEBROOT.
User=root # 修改
Group=root # 修改

# Directory where Jenkins stores its configuration and workspaces

# 这里需要在shell用root用户修改一下JENKINS_HOME的目录所有者,chown -R root:root /var/lib/jenkins/
# 建议修改插件地址为清华源,不然下载插件很慢甚至失败,vi /var/lib/jenkins/hudson.model.UpdateCenter.xml
# https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json
Environment="JENKINS_HOME=/var/lib/jenkins"
WorkingDirectory=/var/lib/jenkins



# Location of the Jenkins WAR
#Environment="JENKINS_WAR=/usr/share/java/jenkins.war"

# Location of the exploded WAR
Environment="JENKINS_WEBROOT=%C/jenkins/war"

# Location of the Jenkins log. By default, systemd-journald(8) is used.
Environment="JENKINS_LOG=/var/log/jenkins/jenkins.log"  # 修改,自己的手动去创建jenkins目录,否则启动报错

# The Java home directory. When left empty, JENKINS_JAVA_CMD and PATH are consulted.
Environment="JAVA_HOME=/usr/local/jdk17"  # 修改,Jenkins提示用最新的JDK,实际上JDK11也可以,服务器上可以不用配置JDK,因为我打包用的是JDK8,只需要指定一下路径即可

# The Java executable. When left empty, JAVA_HOME and PATH are consulted.
Environment="JENKINS_JAVA_CMD=/usr/local/jdk17/bin/java"  # 这里需要根据上面配置的JDK来指定java可执行程序的位置,一般就在JDK目录的bin下面

# Arguments for the Jenkins JVM
Environment="JAVA_OPTS=-Djava.awt.headless=true"

# IP address to listen on for HTTP requests.
# The default is to listen on all interfaces (0.0.0.0).
#Environment="JENKINS_LISTEN_ADDRESS="

# Port to listen on for HTTP requests. Set to -1 to disable.
# To be able to listen on privileged ports (port numbers less than 1024),
# add the CAP_NET_BIND_SERVICE capability to the AmbientCapabilities
# directive below.
Environment="JENKINS_PORT=8080"

# IP address to listen on for HTTPS requests. Default is disabled.
#Environment="JENKINS_HTTPS_LISTEN_ADDRESS="

# Port to listen on for HTTPS requests. Default is disabled.
# To be able to listen on privileged ports (port numbers less than 1024),
# add the CAP_NET_BIND_SERVICE capability to the AmbientCapabilities
# directive below.
#Environment="JENKINS_HTTPS_PORT=443"

# Path to the keystore in JKS format (as created by the JDK's keytool).
# Default is disabled.
#Environment="JENKINS_HTTPS_KEYSTORE=/path/to/keystore.jks"

# Password to access the keystore defined in JENKINS_HTTPS_KEYSTORE.
# Default is disabled.
#Environment="JENKINS_HTTPS_KEYSTORE_PASSWORD=s3cR3tPa55w0rD"

# IP address to listen on for HTTP2 requests. Default is disabled.
#Environment="JENKINS_HTTP2_LISTEN_ADDRESS="

# HTTP2 port to listen on. Default is disabled.
# To be able to listen on privileged ports (port numbers less than 1024),
# add the CAP_NET_BIND_SERVICE capability to the AmbientCapabilities
# directive below.
#Environment="JENKINS_HTTP2_PORT="

# Controls which capabilities to include in the ambient capability set for the
# executed process. Takes a whitespace-separated list of capability names, e.g.
# CAP_SYS_ADMIN, CAP_DAC_OVERRIDE, CAP_SYS_PTRACE. Ambient capability sets are
# useful if you want to execute a process as a non-privileged user but still
# want to give it some capabilities. For example, add the CAP_NET_BIND_SERVICE
# capability to be able to listen on privileged ports (port numbers less than
# 1024).
#AmbientCapabilities=CAP_NET_BIND_SERVICE

# Debug level for logs. The higher the value, the more verbose. 5 is INFO.
#Environment="JENKINS_DEBUG_LEVEL=5"

# Set to true to enable logging to /var/log/jenkins/access_log.
#Environment="JENKINS_ENABLE_ACCESS_LOG=false"

# Servlet context (important if you want to use reverse proxying)
#Environment="JENKINS_PREFIX=/jenkins"

# Arbitrary additional arguments to pass to Jenkins.
# Full option list: java -jar jenkins.war --help
#Environment="JENKINS_OPTS="

# Maximum core file size. If unset, the value from the OS is inherited.
#LimitCORE=infinity

# Maximum file size. If unset, the value from the OS is inherited.
#LimitFSIZE=infinity

# File descriptor limit. If unset, the value from the OS is inherited.
#LimitNOFILE=8192

# Maximum number of processes. If unset, the value from the OS is inherited.
#LimitNPROC=32768

# Set the umask to control the permission bits of files that Jenkins creates.
#
# 0027 makes files read-only for group and inaccessible for others, which some
# security sensitive users might consider beneficial, especially if Jenkins
# is running on a server that is used for multiple purposes. Beware that 0027
# permissions would interfere with sudo scripts that run on the controller
# (see JENKINS-25065).
#
# Note also that the particularly sensitive parts of $JENKINS_HOME (such as
# credentials) are always written without 'other' access. So the umask values
# only affect job configuration, build records, etc.
#
# If unset, the value from the OS is inherited, which is normally 0022.
# The default umask comes from pam_umask(8) and /etc/login.defs.
#UMask=0022

[Install]
WantedBy=multi-user.target

3、建议不要直接复制粘贴我这个文件内容,自己动手去修改安装的时候自动生成的,避免版本不一致内容有变化

4、修改完成后执行systemctl daemon-reload重新加载配置文件,systemctl enable jenkins.service --now,设置Jenkins开机启动,--now表示马上启动

至于怎么安装插件、配置流水线,自行百度啦

  • 13
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1. 安装JDK CentOS 7 默认的 JDK 版本是 1.8,如果需要安装其他版本的 JDK,可以执行以下命令: a. 首先,下载对应版本的 JDK,这里下载的是 JDK 11: wget https://download.java.net/java/GA/jdk11/13/GPL/openjdk-11.0.1_linux-x64_bin.tar.gz b. 解压文件: tar -zxvf openjdk-11.0.1_linux-x64_bin.tar.gz c. 将解压后的文件夹移动到 /usr/local 目录下: sudo mv jdk-11.0.1 /usr/local/ d. 配置环境变量: sudo vim /etc/profile 在文件末尾添加以下内容: export JAVA_HOME=/usr/local/jdk-11.0.1 export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export PATH=$PATH:$JAVA_HOME/bin e. 使环境变量生效: source /etc/profile 2. 安装Jenkins a. 导入 Jenkins 的 GPG 密钥: sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key b. 创建 Jenkins 的 Yum 源: sudo vim /etc/yum.repos.d/jenkins.repo 添加以下内容: [jenkins] name=Jenkins stable baseurl=https://pkg.jenkins.io/redhat-stable gpgcheck=1 c. 安装 Jenkins: sudo yum install jenkins d. 启动 Jenkins: sudo systemctl start jenkins e. 开启 Jenkins 的自动启动: sudo systemctl enable jenkins f. 查看 Jenkins 的状态: sudo systemctl status jenkins 如果成功安装,会显示 active (running)。 g. 配置 Jenkins: 在浏览器中输入服务器的 IP 地址或域名,加上端口号 8080,如:http://192.168.1.100:8080/,打开 Jenkins 的 Web 界面。根据界面提示,输入初始密码,然后按照提示完成 Jenkins 的配置。 3. 配置 Jenkins 的 JDK 环境 a. 在 Jenkins 的 Web 界面中,点击 Manage Jenkins -> Global Tool Configuration。 b. 在 JDK 部分,点击 JDK installations...,然后点击 Add JDK。 c. 输入 JDK 的名称,然后选择 JDK 的安装路径,这里选择之前安装的 JDK 11 的路径:/usr/local/jdk-11.0.1。 d. 点击保存,完成 JDK 的配置。 4. 配置 Jenkins 的 Maven 环境 a. 在 Jenkins 的 Web 界面中,点击 Manage Jenkins -> Global Tool Configuration。 b. 在 Maven 部分,点击 Maven installations...,然后点击 Add Maven。 c. 输入 Maven 的名称,然后选择 Maven 的安装路径,这里选择 /usr/local/apache-maven-3.6.3。 d. 点击保存,完成 Maven 的配置。 至此,CentOS 7 上的 JDK 环境和最新版本的 Jenkins 都已经安装好了,可以在 Jenkins 上进行持续集成和持续部署了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值