【CentOS7】安裝、配置 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!
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章