【CentOS-7】安装、配置 Jenkins

【CentOS7】小白安装、配置 Jenkins


官网

https://jenkins.io/zh/

# 文档

https://jenkins.io/zh/doc/

Jenkins 用户手册 

欢迎浏览 Jenkins 用户手册,这个手册主要介绍如何使用 Jenkins 现有的功能和插件特性。

如果想通过开发插件来扩展 Jenkins 的能力,请参考扩展 Jenkins (开发者手册)。

Jenkins 是什么?

Jenkins是一款开源 CI&CD 软件,用于自动化各种任务,包括构建、测试和部署软件。

CI(Continuous integration,中文意思是持续集成)是一种软件开发时间。
持续集成强调开发人员提交了新代码之后,立刻进行构建、(单元)测试。根据测试结果,我们可以确定新代码和原有代码能否正确地集成在一起。借用网络图片对CI加以理解。

#

CD(Continuous Delivery, 中文意思持续交付)是在持续集成的基础上,将集成后的代码部署到更贴近真实运行环境(类生产环境)中。
比如,我们完成单元测试后,可以把代码部署到连接数据库的 Staging 环境中更多的测试。如果代码没有问题,可以继续手动部署到生产环境。

Jenkins 支持各种运行方式,可通过系统包、Docker 或者通过一个独立的 Java 程序。

关于此文档

此文档由流水线入门指南开始,通过让用户熟悉 Jenkins 主要功能的流水线来了解 Jenkins。

除此之外,教程主要向读者介绍如何通过流水线和 Blue Ocean 来编排自动化构建过程。

如果读者是一个 Jenkins 初学者,那么入门指南将是一个比较不错的开始,如果想要更多更详细的内容,请查看用户手册

文档范围

Jenkins 是一个扩展性非常强的软件,其功能主要通过插件来扩展。

在 Jenkins 里面有非常多的插件,不过此文档的入门指南教程用户手册都是基于 Jenkins 安装 和 Blue Ocean 插件安装,以及建议安装的插件,安装后向导等安装的插件。


【安装】

# java 环境

yum install java -y

# git 环境

yum install git -y
### 方法一:安装 rpm 源

wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo

rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key

# 安装

yum install jenkins -y


### 方法二:

wget https://mirror.tuna.tsinghua.edu.cn/jenkins/redhat/jenkins-2.228-1.1.noarch.rpm

rpm -ivh jenkins-2.228-1.1.noarch.rpm

【配置】

vim /etc/sysconfig/jenkins

###

# 默认监听端口
JENKINS_PORT="8080"
## Path:        Development/Jenkins
## Description: Jenkins Automation Server
## Type:        string
## Default:     "/var/lib/jenkins"
## ServiceRestart: jenkins
#
# Directory where Jenkins store its configuration and working
# files (checkouts, build reports, artifacts, ...).
#
JENKINS_HOME="/var/lib/jenkins"

## Type:        string
## Default:     ""
## ServiceRestart: jenkins
#
# Java executable to run Jenkins
# When left empty, we'll try to find the suitable Java.
#
JENKINS_JAVA_CMD=""

## Type:        string
## Default:     "jenkins"
## ServiceRestart: jenkins
#
# Unix user account that runs the Jenkins daemon
# Be careful when you change this, as you need to update
# permissions of $JENKINS_HOME and /var/log/jenkins.
#
JENKINS_USER="jenkins"

## Type:        string
## Default: "false"
## ServiceRestart: jenkins
#
# Whether to skip potentially long-running chown at the
# $JENKINS_HOME location. Do not enable this, "true", unless
# you know what you're doing. See JENKINS-23273.
#
#JENKINS_INSTALL_SKIP_CHOWN="false"

## Type: string
## Default:     "-Djava.awt.headless=true"
## ServiceRestart: jenkins
#
# Options to pass to java when running Jenkins.
#
JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true"

## Type:        integer(0:65535)
## Default:     8080
## ServiceRestart: jenkins
#
# Port Jenkins is listening on.
# Set to -1 to disable
#
JENKINS_PORT="8080"

## Type:        string
## Default:     ""
## ServiceRestart: jenkins
#
# IP address Jenkins listens on for HTTP requests.
# Default is all interfaces (0.0.0.0).
#
JENKINS_LISTEN_ADDRESS=""

## Type:        integer(0:65535)
## Default:     ""
## ServiceRestart: jenkins
#
# HTTPS port Jenkins is listening on.
# Default is disabled.
#
JENKINS_HTTPS_PORT=""

## Type:        string
## Default:     ""
## ServiceRestart: jenkins
#
# Path to the keystore in JKS format (as created by the JDK 'keytool').
# Default is disabled.
#
JENKINS_HTTPS_KEYSTORE=""

## Type:        string
## Default:     ""
## ServiceRestart: jenkins
#
# Password to access the keystore defined in JENKINS_HTTPS_KEYSTORE.
# Default is disabled.
#
JENKINS_HTTPS_KEYSTORE_PASSWORD=""

## Type:        string
## Default:     ""
## ServiceRestart: jenkins
#
# IP address Jenkins listens on for HTTPS requests.
# Default is disabled.
#
JENKINS_HTTPS_LISTEN_ADDRESS=""

## Type:        integer(0:65535)
## Default:     ""
## ServiceRestart: jenkins
#
# HTTP2 port Jenkins is listening on.
# Default is disabled.
#
# Notice: HTTP2 support may require additional configuration, see Winstone
# documentation for more information.
#
JENKINS_HTTP2_PORT=""

## Type:        string
## Default:     ""
## ServiceRestart: jenkins
#
# IP address Jenkins listens on for HTTP2 requests.
# Default is disabled.
#
# Notice: HTTP2 support may require additional configuration, see Winstone
# documentation for more information.
#
JENKINS_HTTP2_LISTEN_ADDRESS=""

## Type:        integer(1:9)
## Default:     5
## ServiceRestart: jenkins
#
# Debug level for logs -- the higher the value, the more verbose.
# 5 is INFO.
#
JENKINS_DEBUG_LEVEL="5"

## Type:        yesno
## Default:     no
## ServiceRestart: jenkins
#
# Whether to enable access logging or not.
#
JENKINS_ENABLE_ACCESS_LOG="no"

## Type:        integer
## Default:     100
## ServiceRestart: jenkins
#
# Maximum number of HTTP worker threads.
#
JENKINS_HANDLER_MAX="100"

## Type:        integer
## Default:     20
## ServiceRestart: jenkins
#
# Maximum number of idle HTTP worker threads.
#
JENKINS_HANDLER_IDLE="20"

## Type:        string
## Default:     ""
## ServiceRestart: jenkins
#
# Folder for additional jar files to add to the Jetty class loader.
# See Winstone documentation for more information.
# Default is disabled.
#
JENKINS_EXTRA_LIB_FOLDER=""

## Type:        string
## Default:     ""
## ServiceRestart: jenkins
#
# Pass arbitrary arguments to Jenkins.
# Full option list: java -jar jenkins.war --help
#
JENKINS_ARGS=""

【启动】

# 启动服务

systemctl start jenkins

# 查看端口

ps -ef | grep jenkins

【防火墙】

# 查看防火墙【服务】状态
systemctl status firewalld
 
# 查看防火墙【运行】状态
firewall-cmd --state
 
# 开启
service firewalld start
 
# 重启
service firewalld restart
 
# 关闭
service firewalld stop
 
# 查询端口是否开放
firewall-cmd --query-port=8080/tcp
 
# 开放80端口
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=8080-8085/tcp
 
# 移除端口
firewall-cmd --permanent --remove-port=8080/tcp
 
# 查看防火墙的开放的端口
firewall-cmd --permanent --list-ports
 
# 重启防火墙(修改配置后要重启防火墙)
firewall-cmd --reload

安装后设置向导

下载安装并运行 Jenkins 后,即将开始进入安装向导。

此安装向导会引导您完成几个快速“一次性”步骤来解锁 Jenkins, 使用插件对其进行自定义,并创建第一个可以继续访问 Jenkins 的管理员用户。

浏览到 http://localhost:8080(或安装时为 Jenkins 配置的任何端口),并等待 解锁 Jenkins 页面出现。 

从 Jenkins 控制台日志输出中,复制自动生成的字母数字密码(在两组星号之间)。

# 查看 jenkins 日志

vim /var/log/jenkins/jenkins.log


# 找到以下内容


*************************************************************
*************************************************************
*************************************************************

Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:

2da96ea3119840c58013d7fba19e1b86

This may also be found at: /var/lib/jenkins/secrets/initialAdminPassword

*************************************************************
*************************************************************
*************************************************************

在 解锁 Jenkins 页面上,将此 密码 粘贴到管理员密码字段中,然后单击 继续 。

Notes:

  • 如果您以分离模式在 Docker 中运行 Jenkins,则可以从 Docker 日志(above) 访问 Jenkins 控制台日志。

  • Jenkins控制台日志显示可以获取密码的位置(在Jenkins主目录中)。 必须在新Jenkins安装中的安装向导中输入此密码才能访问Jenkins的主UI。 如果您在设置向导中跳过了后续的用户创建步骤, 则此密码还可用作默认admininstrator帐户的密码(使用用户名“admin”)

创建第一个管理员用户

最后,在 customizing Jenkins with plugins 之后,Jenkins 要求您创建第一个管理员用户。 . 出现“ 创建第一个管理员用户 ”页面时, 请在各个字段中指定管理员用户的详细信息,然后单击 保存完成 。 . 当 Jenkins 准备好了 出现时,单击 开始使用 Jenkins

Notes: 

  • 这个页面可能显示 Jenkins 几乎准备好了! 
  • 相反,如果是这样,请单击 重启 。
  • 如果该页面在一分钟后不会自动刷新,请使用 Web 浏览器手动刷新页面。如果需要,请使用您刚刚创建的用户的凭据登录到 Jenkins,并准备好开始使用 Jenkins!
发布了35 篇原创文章 · 获赞 4 · 访问量 5420

猜你喜欢

转载自blog.csdn.net/qu6zhi/article/details/105179181
今日推荐