Linux 中的 Jenkins 安装Linux 中的 Jenkins 安装Linux 中的 Jenkins 安装Linux 中的 Jenkins 安装
  • 业务
  • 目标
  • 支持
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容

Linux 中的 Jenkins 安装

发表 admin at 2025年2月28日
类别
  • 未分类
标签

詹金斯

Jenkins 是一个独立的基于 Java 的程序,可以开箱即用,包含适用于 Windows、Mac OS X 和其他类 Unix 操作系统的软件包。在与 Oracle 发生争议后,该项目被从 Hudson 分叉出来。在 servlet 容器(Tomcat、Glass Fish)中运行。受 400 多个插件支持。在这篇文章中我们将了解如何安装 Jenkins。

Jenkins 需要 Java 才能运行,在安装 Jenkins 之前,请确保系统上安装了 Java。使用以下命令检查已安装的 Java 版本。

[root@localhost ~]# java -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
[root@localhost ~]#

如果您的机器中没有找到java,请使用以下方法安装它。

[root@localhost ~]# cd /opt/
[root@localhost opt]#wget --no-cookies --no-check-certificate --header "Cookie: 
gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie"
 "http://download.oracle.com/otn-pub/java/jdk/8u91-b14/jdk-8u91-linux-x64.tar.gz "
[root@localhost opt]#tar xzf jdk-8u91-linux-x64.tar.gz
[root@localhost opt]# cd jdk1.8.0_91/
[root@localhost jdk1.8.0_91]# alternatives --install /usr/bin/java java
                               /opt/jdk1.8.0_91/bin/java 2
[root@localhost jdk1.8.0_91]# alternatives --config java

There are 4 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
   1      /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.101-2.6.6.1.el7_2.x86_64/jre/bin/java
*  2      /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.91-0.b14.el7_2.x86_64/jre/bin/java
 + 3      /opt/jdk1.7.0_79/bin/java
   4      /opt/jdk1.8.0_91/bin/java

Enter to keep the current selection[+], or type selection number: 4
[root@localhost jdk1.8.0_91]#java --version
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

默认 CentOS 版本的 Java 与 Jenkins 不兼容。 Jenkins 通常与 Sun 的 Java 实现配合使用效果最佳,但由于许可原因,该 Java 版本并未包含在 CentOS 中。所以从官方网站安装最新版本的java。成功安装java之后安装Jenkins包

詹金斯的安装

为了安装 Jenkins,我们必须使用以下命令将 Jenkins 存储库添加到 yum 存储库。

[root@localhost ~]# wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org
/redhat/jenkins.repo
--2016-06-03 01:06:58--  http://pkg.jenkins-ci.org/redhat/jenkins.repo
Resolving pkg.jenkins-ci.org (pkg.jenkins-ci.org)... 52.202.51.185
Connecting to pkg.jenkins-ci.org (pkg.jenkins-ci.org)|52.202.51.185|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 75
Saving to: ‘/etc/yum.repos.d/jenkins.repo’

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

2016-06-03 01:07:00 (5.42 MB/s) - ‘/etc/yum.repos.d/jenkins.repo’ saved [75/75]

[root@localhost ~]# rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key
[root@localhost ~]# yum install jenkins
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * atomic: www4.atomicorp.com
 * base: centos.excellmedia.net
 * epel: mirror.wanxp.id
 * extras: centos.excellmedia.net
 * nux-dextop: li.nux.ro
 * updates: centos.excellmedia.net
Resolving Dependencies
--> Running transaction check
---> Package jenkins.noarch 0:2.7-1.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=========================================================================
 Package          Arch            Version            Repository        Size
=========================================================================
Installing:
 jenkins          noarch          2.7-1.1            jenkins           65 M

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

Total download size: 65 M
Installed size: 66 M
Is this ok [y/d/N]: y
Downloading packages:
No Presto metadata available for jenkins
jenkins-2.7-1.1.noarch.rpm                             |  65 MB   02:23
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : jenkins-2.7-1.1.noarch                                   1/1
  Verifying  : jenkins-2.7-1.1.noarch                                   1/1

Installed:
  jenkins.noarch 0:2.7-1.1

Complete!
[root@localhost ~]#

Jenkins 安装完成后,停止防火墙或按以下方式在防火墙中添加 Jenkins 端口。

[root@localhost ~]# firewall-cmd --zone=public --add-port=8080/tcp --permanent
success
[root@localhost ~]# firewall-cmd --zone=public --add-service=http --permanent
success
[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]# firewall-cmd --list-all
public (default, active)
  interfaces: enp2s0
  sources:
  services: dhcpv6-client http ssh
  ports: 8080/tcp
  masquerade: no
  forward-ports:
  icmp-blocks:
  rich rules:
[root@localhost ~]#

现在我们可以使用systemctl启动Jensis服务,如下所示


[root@localhost ~]# systemctl start jenkins
[root@localhost ~]# systemctl status jenkins
● jenkins.service - LSB: Jenkins Continuous Integration Server
   Loaded: loaded (/etc/rc.d/init.d/jenkins)
   Active: active (running) since Fri 2016-06-03 01:27:17 EDT; 9s ago
     Docs: man:systemd-sysv-generator(8)
  Process:6488 ExecStart=/etc/rc.d/init.d/jenkins start(code=exited,status=0/SUCCESS)
   CGroup: /system.slice/jenkins.service
           └─6503 /etc/alternatives/java -Dcom.sun.akuma.Daemon=daemonize...

Jun 03 01:27:12 localhost.localdomain systemd[1]: Starting LSB: Jenkins C...
Jun 03 01:27:13 localhost.localdomain runuser[6489]: pam_unix(runuser:ses...
Jun 03 01:27:17 localhost.localdomain runuser[6489]: pam_unix(runuser:ses...
Jun 03 01:27:17 localhost.localdomain jenkins[6488]: Starting Jenkins [  ...
Jun 03 01:27:17 localhost.localdomain systemd[1]: Started LSB: Jenkins Co...
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]#

现在我们可以使用以下网址访问 Jenkins 网页:http://服务器的 IP 地址:8080 或 http://localhost:8080

您可以在 /var/lib/jenkins/secrets/initialAdminpassword 找到密码

登录后可以看到如下页面。

单击开始使用 Jenkins 按钮后。

通过使用 Manage Jenkin 选项,我们可以设置配置系统、配置全局安全性、全局工具配置、管理插件等选项

选择“配置全局安全性”(第二个选项),选中“启用安全性”框。该页面将展开以提供访问控制的选择。

选择 Jenkins 自己的用户数据库 在“允许用户注册”旁边打勾(如果您想允许用户注册) 在“授权”的子部分中,我们有“任何人都可以做任何事情”、“传统模式”、“登录用户可以”等选项做任何事情并允许匿名读取访问。完成所有更改后,请不要忘记按页面底部的“保存”按钮。

管理插件

在管理 Jenkins 页面上选择管理插件选项,它会打开插件管理器。

这里我们有一些选项,比如安装而不重新启动、下载和重新启动后立即安装。通过使用它,我们可以安装可用的新软件包或已安装插件的更新。

在下一篇文章中我们将详细了解 Jenkin 插件。

了解更多关于 Jenkins 的官方网站在这里

©2015-2025 Norria support@norria.com