Jenkins的安裝、部署、啓動(完整教程)

測試環境

  • Linux系統 Centos 7

安裝步驟:

一、安裝jdk

我安裝的是jdk8,此處就很少說了,本身百度哈,很簡單java

二、安裝jenkins

首先依次執行以下三個命令: 2.一、導入鏡像:python

[root@centos7 ~]# sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
--2019-12-24 17:59:44--  https://pkg.jenkins.io/redhat-stable/jenkins.repo
Resolving pkg.jenkins.io (pkg.jenkins.io)... 52.202.51.185
Connecting to pkg.jenkins.io (pkg.jenkins.io)|52.202.51.185|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 85
Saving to: ‘/etc/yum.repos.d/jenkins.repo’

100%[=====================================================================================================================================================>] 85          --.-K/s   in 0s      

2019-12-24 18:00:47 (17.4 MB/s) - ‘/etc/yum.repos.d/jenkins.repo’ saved [85/85]

2.二、導入公鑰git

[root@centos7 ~]# sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key

2.三、安裝jenkins:github

[root@centos7 ~]# yum install jenkins
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package jenkins.noarch 0:2.204.1-1.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================================================================
 Package                                      Arch                                        Version                                           Repository                                    Size
===============================================================================================================================================================================================
Installing:
 jenkins                                      noarch                                      2.204.1-1.1                                       jenkins                                       60 M

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

Total download size: 60 M
Installed size: 61 M
Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
jenkins-2.204.1-1.1.noarch.rpm FAILED                                          
http://pkg.jenkins.io/redhat-stable/jenkins-2.204.1-1.1.noarch.rpm: [Errno 12] Timeout on http://pkg.jenkins.io/redhat-stable/jenkins-2.204.1-1.1.noarch.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
Trying other mirror.
jenkins-2.204.1-1.1.noarch.rpm FAILED                                          
http://pkg.jenkins.io/redhat-stable/jenkins-2.204.1-1.1.noarch.rpm: [Errno 12] Timeout on http://pkg.jenkins.io/redhat-stable/jenkins-2.204.1-1.1.noarch.rpm: (28, 'Connection timed out after 30001 milliseconds')
Trying other mirror.
jenkins-2.204.1-1.1.noarch.rpm                                                                                                                                          |  60 MB  00:04:26     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
** Found 1 pre-existing rpmdb problem(s), 'yum check' output follows:
authconfig-6.2.8-30.el7.x86_64 has missing requires of newt-python
  Installing : jenkins-2.204.1-1.1.noarch                                                                                                                                                  1/1 
  Verifying  : jenkins-2.204.1-1.1.noarch                                                                                                                                                  1/1 

Installed:
  jenkins.noarch 0:2.204.1-1.1                                                                                                                                                                 

Complete!

2.四、修改配置文件docker

[root@centos7 ~]# vi /etc/sysconfig/jenkins

修改這部分:json

## Default:     8080
## ServiceRestart: jenkins
#
# Port Jenkins is listening on.
# Set to -1 to disable
#
JENKINS_PORT="8091"

## Type:        string
## Default:     ""
## ServiceRestart: jenkins

2.五、啓動jenkinscentos

[root@centos7 ~]# systemctl  start  jenkins
Job for jenkins.service failed because the control process exited with error code. See "systemctl status jenkins.service" and "journalctl -xe" for details.

2.六、查看jenkins的啓動狀態瀏覽器

[root@centos7 ~]# systemctl status  jenkins
● jenkins.service - LSB: Jenkins Automation Server
   Loaded: loaded (/etc/rc.d/init.d/jenkins; bad; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2019-12-24 18:12:05 CST; 11s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 23175 ExecStart=/etc/rc.d/init.d/jenkins start (code=exited, status=1/FAILURE)

Dec 24 18:12:05 centos7  systemd[1]: Starting LSB: Jenkins Automation Server...
Dec 24 18:12:05 centos7 runuser[23180]: pam_unix(runuser:session): session opened for user jenkins by (uid=0)
Dec 24 18:12:05 centos7 jenkins[23175]: Starting Jenkins bash: /usr/bin/java: Is a directory
Dec 24 18:12:05 centos7  systemd[1]: jenkins.service: control process exited, code=exited status=1
Dec 24 18:12:05 centos7 jenkins[23175]: [FAILED]
Dec 24 18:12:05 centos7 systemd[1]: Failed to start LSB: Jenkins Automation Server.
Dec 24 18:12:05 centos7  systemd[1]: Unit jenkins.service entered failed state.
Dec 24 18:12:05 centos7 systemd[1]: jenkins.service failed.

出現這種狀況的解決辦法是:<br> 修改 jenkins 的配置文件中使用的 jdk 路徑bash

[root@centos7 ~]#  echo $JAVA_HOME
/usr/java/jdk1.8.0_191

[root@centos7 ~]# vi /etc/init.d/jenkins

注意:這裏echo $JAVA_HOME 出來的路徑,後面必定跟啓動路徑(/bin/java)session

2.七、重啓並查看 jenkins 狀態

systemctl daemon-reload

systemctl restart jenkins

個人 jenkins 啓動後是這樣子的:

[root@centos7 docker]# systemctl daemon-reload
[root@centos7 docker]# systemctl restart jenkins 
[root@centos7 docker]# systemctl status jenkins
● jenkins.service - LSB: Jenkins Automation Server
   Loaded: loaded (/etc/rc.d/init.d/jenkins; bad; vendor preset: disabled)
   Active: active (running) since Tue 2019-12-24 18:16:08 CST; 12s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 23787 ExecStart=/etc/rc.d/init.d/jenkins start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/jenkins.service
           └─23832 /software/jdk1.8.0_191/bin/java -Dcom.sun.akuma.Daemon=daemonized -Djava.awt.headless=true -DJENKINS_HOME=/var/lib/jenkins -jar /usr/lib/jenkins/jenkins.war --logfile=/v...

Dec 24 18:16:02 centos7 systemd[1]: Starting LSB: Jenkins Automation Server...
Dec 24 18:16:02 centos7 runuser[23792]: pam_unix(runuser:session): session opened for user jenkins by (uid=0)
Dec 24 18:16:08 centos7 runuser[23792]: pam_unix(runuser:session): session closed for user jenkins
Dec 24 18:16:08 centos7 systemd[1]: Started LSB: Jenkins Automation Server.
Dec 24 18:16:08 centos7 jenkins[23787]: Starting Jenkins [  OK  ]
[root@centos7 ~]# lsof -i:8091
COMMAND   PID    USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
java    23832 jenkins  160u  IPv4 11605726      0t0  TCP *:jamlink (LISTEN)

好了,此時已經表示 Jenkins 順利安裝並啓動成功了!<br><br>

2.八、訪問瀏覽器: http://localhost:8091/ 出現以下提示:

Please wait while Jenkins is getting ready to work...

解決辦法: 進入jenkins的工做目錄(/var/lib/jenkins/),打開 hudson.model.UpdateCenter.xml
http://updates.jenkins-ci.org/update-center.json 改爲以下三個地址之一都可:

# 修改更新地址(到其中一種便可):
http://mirror.xmission.com/jenkins/updates/update-center.json

http://updates.jenkins.io/update-center.json

https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json

http://mirror.esuni.jp/jenkins/updates/update-center.json

而後重啓並查看 jenkins 狀態:

[root@centos7 ~]# vi hudson.model.UpdateCenter.xml 
[root@centos7 ~]# systemctl daemon-reload
[root@centos7 ~]# systemctl restart jenkins 
[root@centos7 ~]# systemctl status jenkins

查看密碼:

cat /var/lib/jenkins/secrets/initialAdminPassword

而後直接選推薦安裝的插件,或者直接下一步就完事兒了!<br><br>

2.九、設置jenkin語言爲中文<br> 須要的話,還能夠設置語言爲中文

卸載

[root@centos7 ~]# rpm -e jenkins
warning: /etc/sysconfig/jenkins saved as /etc/sysconfig/jenkins.rpmsave
warning: /etc/init.d/jenkins saved as /etc/init.d/jenkins.rpmsave
[root@centos7 ~]# systemctl stop jenkins
Failed to stop jenkins.service: Access denied
See system logs and 'systemctl status jenkins.service' for details.
Failed to get load state of jenkins.service: Access denied
[root@centos7 ~]# rpm -ql jenkins
package jenkins is not installed
[root@centos7 ~]# find / -iname jenkins | xargs -n 1000 rm -rf
[root@centos7 ~]#
相關文章
相關標籤/搜索