【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
相关推荐
传而习乎11 分钟前
Linux:CentOS 7 解压 7zip 压缩的文件
linux·运维·centos
soulteary13 分钟前
突破内存限制:Mac Mini M2 服务器化实践指南
运维·服务器·redis·macos·arm·pika
运维&陈同学2 小时前
【zookeeper01】消息队列与微服务之zookeeper工作原理
运维·分布式·微服务·zookeeper·云原生·架构·消息队列
是阿建吖!2 小时前
【Linux】进程状态
linux·运维
明明跟你说过2 小时前
Linux中的【tcpdump】:深入介绍与实战使用
linux·运维·测试工具·tcpdump
Mr_Xuhhh3 小时前
重生之我在学环境变量
linux·运维·服务器·前端·chrome·算法
朝九晚五ฺ11 小时前
【Linux探索学习】第十四弹——进程优先级:深入理解操作系统中的进程优先级
linux·运维·学习
Kkooe12 小时前
GitLab|数据迁移
运维·服务器·git
久醉不在酒12 小时前
MySQL数据库运维及集群搭建
运维·数据库·mysql
谭震鸿13 小时前
Zookeeper集群搭建Centos环境下
分布式·zookeeper·centos