【一步到位】Jenkins的安装、部署、启动(完整教程)

一、测试环境

  • Linux系统 Centos 7

二、安装步骤:

1、安装jdk

我安装的是jdk8,此处就不多说了,自己百度哈,很简单

2、安装jenkins

首先依次执行如下三个命令:
2.1、导入镜像:

 
  1. [root@centos7 ~]# sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo

  2. --2019-12-24 17:59:44-- https://pkg.jenkins.io/redhat-stable/jenkins.repo

  3. Resolving pkg.jenkins.io (pkg.jenkins.io)... 52.202.51.185

  4. Connecting to pkg.jenkins.io (pkg.jenkins.io)|52.202.51.185|:443... connected.

  5. HTTP request sent, awaiting response... 200 OK

  6. Length: 85

  7. Saving to: ‘/etc/yum.repos.d/jenkins.repo’

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

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

2.2、导入公钥

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

2.3、安装jenkins:

 
  1. [root@centos7 ~]# yum install jenkins

  2. Loaded plugins: fastestmirror

  3. Loading mirror speeds from cached hostfile

  4. Resolving Dependencies

  5. --> Running transaction check

  6. ---> Package jenkins.noarch 0:2.204.1-1.1 will be installed

  7. --> Finished Dependency Resolution

  8. Dependencies Resolved

  9. ===============================================================================================================================================================================================

  10. Package Arch Version Repository Size

  11. ===============================================================================================================================================================================================

  12. Installing:

  13. jenkins noarch 2.204.1-1.1 jenkins 60 M

  14. Transaction Summary

  15. ===============================================================================================================================================================================================

  16. Install 1 Package

  17. Total download size: 60 M

  18. Installed size: 61 M

  19. Is this ok [y/d/N]: y

  20. Downloading packages:

  21. Delta RPMs disabled because /usr/bin/applydeltarpm not installed.

  22. jenkins-2.204.1-1.1.noarch.rpm FAILED

  23. 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')

  24. Trying other mirror.

  25. jenkins-2.204.1-1.1.noarch.rpm FAILED

  26. 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')

  27. Trying other mirror.

  28. jenkins-2.204.1-1.1.noarch.rpm | 60 MB 00:04:26

  29. Running transaction check

  30. Running transaction test

  31. Transaction test succeeded

  32. Running transaction

  33. Warning: RPMDB altered outside of yum.

  34. ** Found 1 pre-existing rpmdb problem(s), 'yum check' output follows:

  35. authconfig-6.2.8-30.el7.x86_64 has missing requires of newt-python

  36. Installing : jenkins-2.204.1-1.1.noarch 1/1

  37. Verifying : jenkins-2.204.1-1.1.noarch 1/1

  38. Installed:

  39. jenkins.noarch 0:2.204.1-1.1

  40. Complete!

2.4、修改配置文件

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

修改这部分:

 
  1. ## Default: 8080

  2. ## ServiceRestart: jenkins

  3. #

  4. # Port Jenkins is listening on.

  5. # Set to -1 to disable

  6. #

  7. JENKINS_PORT="8091"

  8. ## Type: string

  9. ## Default: ""

  10. ## ServiceRestart: jenkins

2.5、启动jenkins

 
  1. [root@centos7 ~]# systemctl start jenkins

  2. Job for jenkins.service failed because the control process exited with error code. See "systemctl status jenkins.service" and "journalctl -xe" for details.

2.6、查看jenkins的启动状态

 
  1. [root@centos7 ~]# systemctl status jenkins

  2. ● jenkins.service - LSB: Jenkins Automation Server

  3. Loaded: loaded (/etc/rc.d/init.d/jenkins; bad; vendor preset: disabled)

  4. Active: failed (Result: exit-code) since Tue 2019-12-24 18:12:05 CST; 11s ago

  5. Docs: man:systemd-sysv-generator(8)

  6. Process: 23175 ExecStart=/etc/rc.d/init.d/jenkins start (code=exited, status=1/FAILURE)

  7. Dec 24 18:12:05 centos7 systemd[1]: Starting LSB: Jenkins Automation Server...

  8. Dec 24 18:12:05 centos7 runuser[23180]: pam_unix(runuser:session): session opened for user jenkins by (uid=0)

  9. Dec 24 18:12:05 centos7 jenkins[23175]: Starting Jenkins bash: /usr/bin/java: Is a directory

  10. Dec 24 18:12:05 centos7 systemd[1]: jenkins.service: control process exited, code=exited status=1

  11. Dec 24 18:12:05 centos7 jenkins[23175]: [FAILED]

  12. Dec 24 18:12:05 centos7 systemd[1]: Failed to start LSB: Jenkins Automation Server.

  13. Dec 24 18:12:05 centos7 systemd[1]: Unit jenkins.service entered failed state.

  14. Dec 24 18:12:05 centos7 systemd[1]: jenkins.service failed.

出现这种情况的解决办法是:

修改 jenkins 的配置文件中使用的 jdk 路径

 
  1. [root@centos7 ~]# echo $JAVA_HOME

  2. /usr/java/jdk1.8.0_191

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

注意:这里echo $JAVA_HOME 出来的路径,后面一定跟启动路径(/bin/java)

2.7、重启并查看 jenkins 状态

 
  1. systemctl daemon-reload

  2. systemctl restart jenkins

我的 jenkins 启动后是这样子的:

 
  1. [root@centos7 docker]# systemctl daemon-reload

  2. [root@centos7 docker]# systemctl restart jenkins

  3. [root@centos7 docker]# systemctl status jenkins

  4. ● jenkins.service - LSB: Jenkins Automation Server

  5. Loaded: loaded (/etc/rc.d/init.d/jenkins; bad; vendor preset: disabled)

  6. Active: active (running) since Tue 2019-12-24 18:16:08 CST; 12s ago

  7. Docs: man:systemd-sysv-generator(8)

  8. Process: 23787 ExecStart=/etc/rc.d/init.d/jenkins start (code=exited, status=0/SUCCESS)

  9. CGroup: /system.slice/jenkins.service

  10. └─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...

  11. Dec 24 18:16:02 centos7 systemd[1]: Starting LSB: Jenkins Automation Server...

  12. Dec 24 18:16:02 centos7 runuser[23792]: pam_unix(runuser:session): session opened for user jenkins by (uid=0)

  13. Dec 24 18:16:08 centos7 runuser[23792]: pam_unix(runuser:session): session closed for user jenkins

  14. Dec 24 18:16:08 centos7 systemd[1]: Started LSB: Jenkins Automation Server.

  15. Dec 24 18:16:08 centos7 jenkins[23787]: Starting Jenkins [ OK ]

  16. [root@centos7 ~]# lsof -i:8091

  17. COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

  18. java 23832 jenkins 160u IPv4 11605726 0t0 TCP *:jamlink (LISTEN)

好了,此时已经表示 Jenkins 顺利安装并启动成功了!
 

2.8、访问浏览器: 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 改成如下三个地址之一均可:

 
  1. # 修改更新地址(到其中一种即可):

  2. http://mirror.xmission.com/jenkins/updates/update-center.json

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

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

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

然后重启并查看 jenkins 状态:

 
  1. [root@centos7 ~]# vi hudson.model.UpdateCenter.xml

  2. [root@centos7 ~]# systemctl daemon-reload

  3. [root@centos7 ~]# systemctl restart jenkins

  4. [root@centos7 ~]# systemctl status jenkins

查看密码:

cat /var/lib/jenkins/secrets/initialAdminPassword

然后直接选推荐安装的插件,或者直接下一步就完事儿了!
 

2.9、设置jenkin语言为中文

需要的话,还可以设置语言为中文

三、卸载

 
  1. [root@centos7 ~]# rpm -e jenkins

  2. warning: /etc/sysconfig/jenkins saved as /etc/sysconfig/jenkins.rpmsave

  3. warning: /etc/init.d/jenkins saved as /etc/init.d/jenkins.rpmsave

  4. [root@centos7 ~]# systemctl stop jenkins

  5. Failed to stop jenkins.service: Access denied

  6. See system logs and 'systemctl status jenkins.service' for details.

  7. Failed to get load state of jenkins.service: Access denied

  8. [root@centos7 ~]# rpm -ql jenkins

  9. package jenkins is not installed

  10. [root@centos7 ~]# find / -iname jenkins | xargs -n 1000 rm -rf

  11. [root@centos7 ~]#

 

 最后: 下方这份完整的软件测试视频教程已经整理上传完成,需要的朋友们可以自行领取【保证100%免费】

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值