介绍 (Introduction)
Jenkins is an open-source automation server that automates the repetitive technical tasks involved in the continuous integration and delivery of software. Jenkins is Java-based and can be installed from Ubuntu packages or by downloading and running its web application archive (WAR) file — a collection of files that make up a complete web application to run on a server.
Jenkins是一个开源自动化服务器,可自动执行软件的持续集成和交付中涉及的重复性技术任务。 Jenkins是基于Java的,可以从Ubuntu软件包中安装,也可以通过下载并运行其Web应用程序存档(WAR)文件来安装,该文件是组成要在服务器上运行的完整Web应用程序的文件的集合。
In this tutorial, you will install Jenkins by adding its Debian package repository, and using that repository to install the package with apt
.
在本教程中,您将通过添加Jenkins的Debian软件包存储库并使用该存储库通过apt
安装软件包来安装Jenkins。
先决条件 (Prerequisites)
To follow this tutorial, you will need:
要遵循本教程,您将需要:
One Ubuntu 18.04 server configured with a non-root sudo user and firewall by following the Ubuntu 18.04 initial server setup guide. We recommend starting with at least 1 GB of RAM. See Choosing the Right Hardware for Masters for guidance in planning the capacity of a production Jenkins installation.
按照Ubuntu 18.04初始服务器设置指南 ,使用非root用户sudo用户和防火墙配置一台Ubuntu 18.04服务器。 我们建议至少从1 GB RAM开始。 请参阅为母版选择合适的硬件,以计划生产Jenkins生产设备的容量。
Java 8 installed, following our guidelines on installing specific versions of OpenJDK on Ubuntu 18.04.
遵循我们在Ubuntu 18.04上安装特定版本的OpenJDK的准则,已安装 Java 8。
第1步-安装Jenkins (Step 1 — Installing Jenkins)
The version of Jenkins included with the default Ubuntu packages is often behind the latest available version from the project itself. To take advantage of the latest fixes and features, you can use the project-maintained packages to install Jenkins.
默认Ubuntu软件包中包含的Jenkins版本通常落后于项目本身的最新可用版本。 要利用最新的修补程序和功能,您可以使用项目维护的软件包来安装Jenkins。
First, add the repository key to the system:
首先,将存储库密钥添加到系统:
- wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add - wget -q -O-http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt键添加-
When the key is added, the system will return OK
. Next, append the Debian package repository address to the server’s sources.list
:
添加密钥后,系统将返回OK
。 接下来,将Debian软件包存储库地址附加到服务器的sources.list
:
- sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list' sudo sh -c'回显deb http://pkg.jenkins-ci.org/debian-stable binary /> /etc/apt/sources.list.d/jenkins.list'
When both of these are in place, run update
so that apt
will use the new repository:
当这两个都到位时,运行update
以便apt
将使用新的存储库:
- sudo apt update sudo apt更新
Finally, install Jenkins and its dependencies:
最后,安装Jenkins及其依赖项:
- sudo apt install jenkins sudo apt安装詹金斯
Now that Jenkins and its dependencies are in place, we’ll start the Jenkins server.
既然Jenkins及其依赖项已经到位,我们将启动Jenkins服务器。
第2步-启动詹金斯 (Step 2 — Starting Jenkins)
Let’s start Jenkins using systemctl
:
让我们使用systemctl
启动Jenkins:
sudo systemctl start jenkins
Since systemctl
doesn’t display output, you can use its status
command to verify that Jenkins started successfully:
由于systemctl
不显示输出,因此可以使用其status
命令来验证Jenkins是否成功启动:
- sudo systemctl status jenkins sudo systemctl状态詹金斯
If everything went well, the beginning of the output should show that the service is active and configured to start at boot:
如果一切顺利,则输出的开头应显示该服务处于活动状态并配置为在引导时启动:
Output
● jenkins.service - LSB: Start Jenkins at boot time
Loaded: loaded (/etc/init.d/jenkins; generated)
Active: active (exited) since Mon 2018-07-09 17:22:08 UTC; 6min ago
Docs: man:systemd-sysv-generator(8)
Tasks: 0 (limit: 1153)
CGroup: /system.slice/jenkins.service
Now that Jenkins is running, let’s adjust our firewall rules so that we can reach it from a web browser to complete the initial setup.
现在,Jenkins正在运行,让我们调整防火墙规则,以便我们可以从Web浏览器访问它以完成初始设置。
步骤3 —打开防火墙 (Step 3 — Opening the Firewall)
By default, Jenkins runs on port 8080
, so let’s open that port using ufw
:
默认情况下,Jenkins在端口8080
上运行,因此让我们使用ufw
打开该端口:
- sudo ufw allow 8080 sudo ufw允许8080
Check ufw
’s status to confirm the new rules:
检查ufw
的状态以确认新规则:
- sudo ufw status sudo ufw状态
You will see that traffic is allowed to port 8080
from anywhere:
您将看到允许从任何地方向8080
端口发送流量:
Output
Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
8080 ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
8080 (v6) ALLOW Anywhere (v6)
Note: If the firewall is inactive, the following commands will allow OpenSSH and enable the firewall:
注意:如果防火墙处于非活动状态,则以下命令将允许OpenSSH并启用防火墙:
- sudo ufw allow OpenSSH sudo ufw允许OpenSSH
- sudo ufw enable sudo ufw启用
With Jenkins installed and our firewall configured, we can complete the initial setup.
安装了Jenkins并配置了防火墙之后,我们就可以完成初始设置。
第4步-设置詹金斯 (Step 4 — Setting Up Jenkins)
To set up your installation, visit Jenkins on its default port, 8080
, using your server domain name or IP address: http://your_server_ip_or_domain:8080
要设置安装,请使用服务器域名或IP地址通过其默认端口8080
访问Jenkins: http:// your_server_ip_or_domain :8080
You should see the Unlock Jenkins screen, which displays the location of the initial password:
您应该看到Unlock Jenkins屏幕,其中显示初始密码的位置:
In the terminal window, use the cat
command to display the password:
在终端窗口中,使用cat
命令显示密码:
- sudo cat /var/lib/jenkins/secrets/initialAdminPassword 须藤猫/ var / lib / jenkins / secrets / initialAdminPassword
Copy the 32-character alphanumeric password from the terminal and paste it into the Administrator password field, then click Continue.
从终端复制32个字符的字母数字密码,并将其粘贴到管理员密码字段,然后单击继续 。
The next screen presents the option of installing suggested plugins or selecting specific plugins:
下一个屏幕显示安装建议的插件或选择特定插件的选项:
We’ll click the Install suggested plugins option, which will immediately begin the installation process:
我们将单击“ 安装建议的插件”选项,该选项将立即开始安装过程:
When the installation is complete, you will be prompted to set up the first administrative user. It’s possible to skip this step and continue as admin
using the initial password we used above, but we’ll take a moment to create the user.
安装完成后,系统将提示您设置第一个管理用户。 可以跳过此步骤,并使用我们上面使用的初始密码以admin
身份继续,但是我们将花一些时间来创建用户。
Note: The default Jenkins server is NOT encrypted, so the data submitted with this form is not protected. When you’re ready to use this installation, follow the guide How to Configure Jenkins with SSL Using an Nginx Reverse Proxy on Ubuntu 18.04. This will protect user credentials and information about builds that are transmitted via the web interface.
注意:默认的Jenkins服务器未加密,因此使用此表单提交的数据不受保护。 准备好使用此安装时,请遵循指南如何在Ubuntu 18.04上使用Nginx反向代理使用SSL配置Jenkins 。 这将保护用户凭据以及有关通过Web界面传输的内部版本的信息。
Enter the name and password for your user:
输入您的用户名和密码:
You will see an Instance Configuration page that will ask you to confirm the preferred URL for your Jenkins instance. Confirm either the domain name for your server or your server’s IP address:
您将看到一个“ 实例配置”页面,该页面将要求您确认Jenkins实例的首选URL。 确认服务器的域名或服务器的IP地址:
After confirming the appropriate information, click Save and Finish. You will see a confirmation page confirming that “Jenkins is Ready!”:
确认适当的信息后,点击保存并完成 。 您将看到一个确认页面,确认“ Jenkins准备就绪!” :
Click Start using Jenkins to visit the main Jenkins dashboard:
单击开始使用Jenkins访问Jenkins主仪表板:
At this point, you have completed a successful installation of Jenkins.
至此,您已经成功安装了Jenkins。
结论 (Conclusion)
In this tutorial, you have installed Jenkins using the project-provided packages, started the server, opened the firewall, and created an administrative user. At this point, you can start exploring Jenkins.
在本教程中,您已经使用项目提供的软件包安装了Jenkins,启动了服务器,打开了防火墙,并创建了一个管理用户。 此时,您可以开始探索詹金斯。
When you’ve completed your exploration, if you decide to continue using Jenkins, follow the guide How to Configure Jenkins with SSL Using an Nginx Reverse Proxy on Ubuntu 18.04 to protect your passwords, as well as any sensitive system or product information that will be sent between your machine and the server in plain text.
完成探索之后,如果您决定继续使用Jenkins,请遵循指南如何在Ubuntu 18.04上使用Nginx反向代理使用SSL配置Jenkins,以保护密码以及将要使用的任何敏感系统或产品信息。以纯文本格式在您的计算机和服务器之间发送。
翻译自: https://www.digitalocean.com/community/tutorials/how-to-install-jenkins-on-ubuntu-18-04