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

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

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

1、下载安装Jdk17

下载安装

bash 复制代码
# 更新您的系统,不一定需要
# 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安装

bash 复制代码
[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

配置使用的仓库

bash 复制代码
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

bash 复制代码
yum install fontconfig
yum install jenkins

启动Jenkins服务

bash 复制代码
# 启动Jenkins服务
sudo systemctl enable jenkins
sudo systemctl start jenkins
# 查看启动状态
sudo systemctl status jenkins

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

bash 复制代码
cat /var/lib/jenkins/secrets/initialAdminPassword

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

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

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

bash 复制代码
sudo systemctl stop firewalld

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

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

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

bash 复制代码
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,可以配置默认端口等参数

bash 复制代码
# 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="

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

bash 复制代码
# 生效配置
sudo systemctl daemon-reload
# 重启服务
sudo systemctl restart jenkins
相关推荐
。puppy20 分钟前
HCIP--3实验- 链路聚合,VLAN间通讯,Super VLAN,MSTP,VRRPip配置,OSPF(静态路由,环回,缺省,空接口),NAT
运维·服务器
颇有几分姿色29 分钟前
深入理解 Linux 内存管理:free 命令详解
linux·运维·服务器
光芒再现dev1 小时前
已解决,部署GPTSoVITS报错‘AsyncRequest‘ object has no attribute ‘_json_response_data‘
运维·python·gpt·语言模型·自然语言处理
AndyFrank1 小时前
mac crontab 不能使用问题简记
linux·运维·macos
成都古河云2 小时前
智慧场馆:安全、节能与智能化管理的未来
大数据·运维·人工智能·安全·智慧城市
算法与编程之美2 小时前
文件的写入与读取
linux·运维·服务器
Amelio_Ming2 小时前
Permissions 0755 for ‘/etc/ssh/ssh_host_rsa_key‘ are too open.问题解决
linux·运维·ssh
心灵彼岸-诗和远方2 小时前
Devops业务价值流:软件研发最佳实践
运维·产品经理·devops
JuiceFS3 小时前
好未来:多云环境下基于 JuiceFS 建设低运维模型仓库
运维·云原生
Ven%3 小时前
centos查看硬盘资源使用情况命令大全
linux·运维·centos