1. 安裝 Java。目前一般jdk要求11以上,否則會報錯
2. 手動添加 Jenkins 倉庫
先創建一個專門的Jenkins文件夾:mkdir jenkins
然后? 執行?
sudo curl -fsSL https://pkg.jenkins.io/redhat/jenkins.io.key -o /etc/pki/rpm-gpg/jenkins.io.key
然后,更新你的倉庫配置文件。編輯或創建 /etc/yum.repos.d/jenkins.repo
文件,內容如下:
[Jenkins]
name=Jenkins
baseurl=https://pkg.jenkins.io/redhat/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/jenkins.io.key
enabled=1
3. 清理 YUM 緩存并安裝
sudo yum clean all
sudo yum makecache
再嘗試安裝Jenkins
sudo yum install jenkins
啟動 Jenkins 服務
sudo systemctl start jenkins
sudo systemctl enable jenkins
4. 檢查 Jenkins 狀態
sudo systemctl status jenkins
可能遇到的一些問題
1.例如會報以下錯誤:
Jul 14 14:24:53 iZ7xv7q3yjgje58dc089w0Z systemd[1]: start request repeated too quickly for jenkins.service
Jul 14 14:24:53 iZ7xv7q3yjgje58dc089w0Z systemd[1]: Failed to start Jenkins Continuous Integration Server.
Jul 14 14:24:53 iZ7xv7q3yjgje58dc089w0Z systemd[1]: Unit jenkins.service entered failed state.
Jul 14 14:24:53 iZ7xv7q3yjgje58dc089w0Z systemd[1]: jenkins.service failed.
Jul 14 14:24:59 iZ7xv7q3yjgje58dc089w0Z systemd[1]: [/usr/lib/systemd/system/jenkins.service:16] Unknown lvalue 'StartLimitBurst' in section 'Unit'
Jul 14 14:24:59 iZ7xv7q3yjgje58dc089w0Z systemd[1]: [/usr/lib/systemd/system/jenkins.service:17] Unknown lvalue 'StartLimitIntervalSec' in section 'Unit'
找到并編輯 /usr/lib/systemd/system/jenkins.service
文件,找到以下對應的兩行配置
StartLimitBurst=5
StartLimitIntervalSec=0
刪除或者注釋掉
2.? 錯誤2? jdk版本不對應
Jul 14 17:43:15 iZ7xv7q3yjgje58dc089w0Z systemd[1]: Starting Jenkins Continuous Integration Server...
Jul 14 17:43:16 iZ7xv7q3yjgje58dc089w0Z jenkins[1147]: Error: A JNI error has occurred, please check your installation and try again
Jul 14 17:43:16 iZ7xv7q3yjgje58dc089w0Z jenkins[1147]: Exception in thread "main" java.lang.UnsupportedClassVersionError: executable/Main has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
Jul 14 17:43:16 iZ7xv7q3yjgje58dc089w0Z jenkins[1147]: at java.lang.ClassLoader.defineClass1(Native Method)
排除Jenkins問題常用命令
journalctl -u jenkins.service -n 100 --no-pager?
journalctl
:是用于查看系統日志的工具,特別是與systemd
相關的日志。它能幫助你查看服務的日志、錯誤信息以及其他系統事件。-u jenkins.service
:表示你要查看的是與jenkins.service
相關的日志。這里的-u
是unit
的縮寫,jenkins.service
是 Jenkins 服務的名字。-n 100
:表示顯示最后的 100 行日志。如果你想查看更多或更少的日志,可以調整這個數字。--no-pager
:表示日志輸出時不使用分頁工具(如less
)。通常,journalctl
會分頁輸出日志,但加上--no-pager
之后,它會一次性輸出所有日志,而不會等待用戶輸入以查看更多內容。