【Jenkins】Centos环境安装Jenkins(通过rpm安装)

2023-12-13 19:47:52

在Centos操作系统中通过rpm安装Jenkins

参考官网 https://www.jenkins.io/doc/book/installing/linux/#red-hat-centos

1、下载安装Jdk17

下载安装

# 更新您的系统,不一定需要
# sudo yum -y update
# 安装将用于下载 Java 17 二进制文件的 wget 命令行工具。
sudo yum -y install wget vim
# 下载 Java 17 二进制文件
wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.rpm
# 在 CentOS 7/RHEL 7 上安装 Java 17
sudo yum -y install ./jdk-17_linux-x64_bin.rpm

验证Java安装

[root@localhost ~]# java -version
java version "17.0.9" 2023-10-17 LTS
Java(TM) SE Runtime Environment (build 17.0.9+11-LTS-201)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.9+11-LTS-201, mixed mode, sharing)
[root@localhost ~]# 

2、下载安装Jenkins

配置使用的仓库

sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
# 升级系统,不一定需要
sudo yum upgrade

安装jenkins

yum install fontconfig
yum install jenkins

启动Jenkins服务

# 启动Jenkins服务
sudo systemctl enable jenkins
sudo systemctl start jenkins
# 查看启动状态
sudo systemctl status jenkins

首次启动时,会自动创一个管理员账号,通过如下指令查看管理员密码

cat /var/lib/jenkins/secrets/initialAdminPassword

3、防火墙停用或端口开放

Jenkins启动默认端口8080,可以通过如下指令临时关闭防火墙。

但是,重启系统后防火墙将会重新启动。

sudo systemctl stop firewalld

可以禁用防火墙服务永久停用

# 停止防火墙服务
sudo systemctl stop firewalld
# 禁用防火墙服务
sudo systemctl disable firewalld
# 检查防火墙状态
sudo systemctl status firewalld

也可以通过如下操作,开放端口

YOURPORT=8080
PERM="--permanent"
SERV="$PERM --service=jenkins"

firewall-cmd $PERM --new-service=jenkins
firewall-cmd $SERV --set-short="Jenkins ports"
firewall-cmd $SERV --set-description="Jenkins port exceptions"
firewall-cmd $SERV --add-port=$YOURPORT/tcp
firewall-cmd $PERM --add-service=jenkins
firewall-cmd --zone=public --add-service=http --permanent
firewall-cmd --reload

4、打开Jenkins,初始化配置

1)浏览器打开http://localhost:8080输入上面的管理员密码/var/lib/jenkins/secrets/initialAdminPassword
在这里插入图片描述

2)点击安装推荐的插件,安装插件需要几分钟时间,稍等一会儿!

在这里插入图片描述

3)这可以创建一个管理账户,也可以点击“使用admin账户继续”,那么admin的密码就是上面自动生成的管理员密码,可以自行修改!

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

至此,配置完成,可以创建任务了!

5、端口及其他参数配置

打开文件/usr/lib/systemd/system/jenkins.service,可以配置默认端口等参数

# Directory where Jenkins stores its configuration and workspaces
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=%L/jenkins/jenkins.log"

# The Java home directory. When left empty, JENKINS_JAVA_CMD and PATH are consulted.
#Environment="JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64"

# The Java executable. When left empty, JAVA_HOME and PATH are consulted.
#Environment="JENKINS_JAVA_CMD=/etc/alternatives/java"

# 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="

# 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="

修改后通过以下命令让配置生效

# 生效配置
sudo systemctl daemon-reload
# 重启服务
sudo systemctl restart jenkins

文章来源:https://blog.csdn.net/wlddhj/article/details/134955629
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。