2021年7月20日 星期二

[研究]Jenkins 2.289.2-1.1 stable 安裝(CentOS 8.4 x64)

[研究]Jenkins 2.289.2-1.1 stable 安裝(CentOS 8.4 x64)

2021-07-20

Jenkins CI是領先的開源持續集成服務器。內建 Java,提供了上千個插件,支持構建和測試幾乎任何項目。


Jenkins是由Java撰寫的 OpenSource 開源持續整合工具,可以幫助使用者達成專案建置、測試及部署等階段自動化的目標,實現測試自動化及持續整合的工具。

官方網站
https://jenkins-ci.org/

安裝教學 (第一個是 stable 版的,GPG Key的網址不同;第二三個是相同)

https://pkg.jenkins.io/redhat-stable/
https://pkg.jenkins.io/redhat/
http://pkg.jenkins-ci.org/redhat/
https://www.jenkins.io/doc/book/installing/linux/#red-hat-centos


Jenkins 2.289.2-1.1 stable 安裝 (Long Term Support release, LTSR)

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.key


Jenkins 2.302-1.1 Weekky 安裝 (Weekly release)

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

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


共通步驟

# 安裝 JDK ( Jenkins 安裝很慢,建議和 JDK 分開安裝,避免失敗時候連 JDK 都要清除重新安裝) ( Jenkins 2.164 (2019-02) 或更新版本需要  Java 8 or Java 11 )

sudo dnf -y install  java-11

# 安裝 ( 可能非常慢,或高速傳一下就變很慢,甚至 time out 安裝失敗,可能要多安裝幾次才會成功;建議下載 rpm 安裝)

sudo yum -y install jenkins  

#或

sudo wget https://ftp.osuosl.org/pub/jenkins/redhat-stable/jenkins-2.289.2-1.1.noarch.rpm  

sudo  rpm -Uvh jenkins-2.289.2-1.1.noarch.rpm

# 可自動啟動

sudo systemctl daemon-reload

# 啟動

sudo systemctl start jenkins

# 設定開機時後自動啟動

sudo systemctl enable jenkins

# 檢查狀態 (按 Q 結束)

#sudo systemctl status jenkins

#若需要變更 port (變更後需要 sudo systemctl restart jenkins 重新啟動才生效)

# sudo  vi /usr/lib/firewalld/services/jenkins.xml  
# sudo systemctl restart jenkins

# 啟動 Web介面

firefox  http://localhost:8080/  &


(下圖) sudo  cat  /var/lib/jenkins/secrets/initialAdminPassword

取得密碼,貼入上圖中,按下 Continue 按鈕


(下圖) 插件 (plugins) 安裝很慢,預設是 Install suggested plugins,若想快速安裝完或選自己像要的,可選右邊 Select plugins to install
(下圖) 若想安裝 git 相關 plugins,可輸入 git 找


(下圖) 想看有無 OWASP Dependency Track plugins,似乎沒有

(下圖) 省時,先不安裝 plugins,可選上方 None,按右下角 Install 按鈕


(下圖) 若有勾選,會安裝,插件 Plugin 安裝中,可能會因為某些網站下載太慢,導致安裝失敗,或許 Retry 可以安裝成功。

(下圖) 上圖 2.289.2 Stable 版,下圖 2.302 Weekly 版,建議插件一樣

(下圖)若部分 plugins 安裝失敗,可按下 Retry 按鈕,或按 Continue 先略過不理會。

(下圖) 




(下圖) 變更密碼

(下圖) 

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

執行 sudo yum -y install jenkins  失敗時的清除

一般都是 jenkins-2.289.2-1.1.noarch.rpm 下載很慢甚至 Time Out 而失敗中斷,此時若清除,指令一定要加上 sudo,否則會執行成功,但 0 個移除。


[MIRROR] jenkins-2.289.2-1.1.noarch.rpm: Curl error (28): Timeout was reached for https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat-stable/jenkins-2.289.2-1.1.noarch.rpm [Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds]
[MIRROR] jenkins-2.289.2-1.1.noarch.rpm: Curl error (28): Timeout was reached for https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat-stable/jenkins-2.289.2-1.1.noarch.rpm [Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds]
[MIRROR] jenkins-2.289.2-1.1.noarch.rpm: Curl error (28): Timeout was reached for https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat-stable/jenkins-2.289.2-1.1.noarch.rpm [Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds]
[MIRROR] jenkins-2.289.2-1.1.noarch.rpm: Curl error (18): Transferred a partial file for https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat-stable/jenkins-2.289.2-1.1.noarch.rpm [transfer closed with 39218952 bytes remaining to read]
[FAILED] jenkins-2.289.2-1.1.noarch.rpm: No more mirrors to try - All mirrors were already tried without success

The downloaded packages were saved in cache until the next successful transaction.
You can remove cached packages by executing 'yum clean packages'.
Error: Error downloading packages:
  Cannot download jenkins-2.289.2-1.1.noarch.rpm: All mirrors were tried

[john@localhost ~]$ yum -y clean packages
0 files removed

[john@localhost ~]$ sudo yum -y clean packages
[sudo] password for john: 
8 files removed
[john@localhost ~]$ 

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

手動安裝Jenkins

因為安裝時候發現Jenkins沒有其他相依套件,可以考慮下載 rpm 檔案直接安裝


[john@localhost ~]$ sudo yum -y install jenkins 
Last metadata expiration check: 0:07:16 ago on Tue 20 Jul 2021 04:21:18 AM EDT.
Dependencies resolved.
================================================================================
 Package          Architecture    Version                Repository        Size
================================================================================
Installing:
 jenkins          noarch          2.289.2-1.1            jenkins           71 M

Transaction Summary
================================================================================
Install  1 Package

Total download size: 71 M
Installed size: 71 M
Downloading Packages:
[MIRROR] jenkins-2.289.2-1.1.noarch.rpm: Curl error (28): Timeout was reached for https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat-stable/jenkins-2.289.2-1.1.noarch.rpm [Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds]
[MIRROR] jenkins-2.289.2-1.1.noarch.rpm: Curl error (28): Timeout was reached for https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat-stable/jenkins-2.289.2-1.1.noarch.rpm [Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds]
[MIRROR] jenkins-2.289.2-1.1.noarch.rpm: Curl error (28): Timeout was reached for https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat-stable/jenkins-2.289.2-1.1.noarch.rpm [Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds]
[MIRROR] jenkins-2.289.2-1.1.noarch.rpm: Curl error (18): Transferred a partial file for https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat-stable/jenkins-2.289.2-1.1.noarch.rpm [transfer closed with 39218952 bytes remaining to read]
[FAILED] jenkins-2.289.2-1.1.noarch.rpm: No more mirrors to try - All mirrors were already tried without success

The downloaded packages were saved in cache until the next successful transaction.
You can remove cached packages by executing 'yum clean packages'.
Error: Error downloading packages:
  Cannot download jenkins-2.289.2-1.1.noarch.rpm: All mirrors were tried

[john@localhost ~]$

Google 查哪有 "jenkins-2.289.2-1.1.noarch.rpm"

https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat-stable/

https://mirrors.huaweicloud.com/jenkins/redhat-stable/

https://ftp.osuosl.org/pub/jenkins/redhat-stable/

選個快的下載,用 rpm 進行安裝


[john@localhost ~]$ sudo wget https://ftp.osuosl.org/pub/jenkins/redhat-stable/jenkins-2.289.2-1.1.noarch.rpm  

[john@localhost ~]$ rpm -Uvh jenkins-2.289.2-1.1.noarch.rpm
error: can't create transaction lock on /var/lib/rpm/.rpm.lock (Permission denied)

[john@localhost ~]$ sudo  rm  -fr  /var/lib/rpm/.rpm.lock

[john@localhost ~]$ rpm -Uvh jenkins-2.289.2-1.1.noarch.rpm
error: can't create transaction lock on /var/lib/rpm/.rpm.lock (No such file or directory)

[john@localhost dnf]$ sudo rpm -Uvh jenkins-2.289.2-1.1.noarch.rpm
[sudo] password for john: 
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:jenkins-2.289.2-1.1              ################################# [100%]

[john@localhost ~]$ 


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

變更 port

如果要變更 port,修改 jenkins.xml 中內容。


[john@localhost default]$ sudo find / -name jenkins.xml -print
find: ‘/proc/1274/task/1274/net’: Invalid argument
find: ‘/proc/1274/net’: Invalid argument
find: ‘/run/user/1000/gvfs’: Permission denied
/usr/lib/firewalld/services/jenkins.xml

[john@localhost default]$ sudo vi /usr/lib/firewalld/services/jenkins.xml  

內容


<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>jenkins</short>
  <description>Jenkins is an open source automation server written in Java.</description>
  <port protocol="tcp" port="8080"/>
</service>

就算執行 sudo  systemctl  restart  jenkins 或 reboot,依然使用 port 8080,以上修改實測無效。   

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

修改 port 

找一下相關檔案


[john@localhost ~]$ sudo find / -name jenkins -print  
find: ‘/run/user/1000/gvfs’: Permission denied
/run/lock/subsys/jenkins
/etc/logrotate.d/jenkins
/etc/sysconfig/jenkins
/etc/rc.d/init.d/jenkins
/var/lib/jenkins
/var/log/jenkins
/var/cache/jenkins
/usr/lib/jenkins

[john@localhost ~]$ sudo vi /etc/sysconfig/jenkins

找到


JENKINS_PORT="8080"   

改成


JENKINS_PORT="8082"   

存檔,執行 sudo systemctl restart jenkins 重新啟動 Jenkins,讓設定生效。


[john@localhost ~]$ sudo systemctl restart jenkins  
[john@localhost ~]$

實際測試,有效。

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

xxx

xxx

xxx

(完)


沒有留言:

張貼留言