如何在Ubuntu 20.04上安装Jenkins

介绍 (Introduction)

When faced with repetitive technical tasks, finding automation solutions that work can be a chore. With Jenkins, an open-source automation server, you can efficiently manage tasks from building to deploying software. Jenkins is Java-based, 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 we’ll install Jenkins on Ubuntu 20.04, start the development server and create an administrative user to get you started in exploring what Jenkins can do. While you’ll have a development-level server ready for use at the conclusion of this tutorial, to secure this installation for production, follow the guide How to Configure Jenkins with SSL Using an Nginx Reverse Proxy on Ubuntu 18.04.

在本教程中,我们将在Ubuntu 20.04上安装Jenkins,启动开发服务器并创建一个管理用户,以使您开始探索Jenkins可以做什么。 虽然在本教程结束时您将准备使用开发级服务器,但是要确保该安装用于生产环境,请遵循指南如何在Ubuntu 18.04上使用Nginx反向代理使用SSL配置Jenkins

先决条件 (Prerequisites)

To follow this tutorial, you will need:

要遵循本教程,您将需要:

第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 ensure you have the latest fixes and features, use the project-maintained packages to install Jenkins.

默认Ubuntu软件包中包含的Jenkins版本通常落后于项目本身的最新可用版本。 为确保您具有最新的修补程序和功能,请使用项目维护的软件包来安装Jenkins。

First, add the repository key to the system:

首先,将存储库密钥添加到系统:

  • wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -

    wget -q -O-https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt键添加-

After the key is added the system will return with OK.

添加密钥后,系统将返回OK

Next, let’s append the Debian package repository address to the server’s sources.list:

接下来,让我们将Debian软件包存储库地址附加到服务器的sources.list

  • sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'

    sudo sh -c'echo deb http://pkg.jenkins.io/debian-stable binary /> /etc/apt/sources.list.d/jenkins.list'

After both commands have been entered, we’ll run update so that apt will use the new repository.

输入两个命令后,我们将运行update以便apt将使用新的存储库。

  • sudo apt update

    sudo apt更新

Finally, we’ll 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 by using systemctl:

让我们通过使用systemctl启动Jenkins:

sudo systemctl start jenkins

Since systemctl doesn’t display status output, we’ll use the 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 status output shows 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 Fri 2020-06-05 21:21:46 UTC; 45s ago Docs: man:systemd-sysv-generator(8) Tasks: 0 (limit: 1137) CGroup: /system.slice/jenkins.service

Now that Jenkins is up and 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)

To set up a UFW firewall, visit Initial Server Setup with Ubuntu 20.04, Step 4- Setting up a Basic Firewall. By default, Jenkins runs on port 8080. We’ll open that port using ufw:

要设置UFW防火墙,请访问Ubuntu 20.04的初始服务器设置,第4步,设置基本防火墙 。 默认情况下,Jenkins在端口8080上运行。 我们将使用ufw打开该端口:

  • sudo ufw allow 8080

    sudo ufw允许8080

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启用

Check ufw’s status to confirm the new rules:

检查ufw的状态以确认新规则:

  • sudo ufw status

    sudo ufw状态

You’ll notice 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)

With Jenkins installed and our firewall configured, we can complete the installation stage and dive into Jenkins setup.

安装了Jenkins并配置了防火墙之后,我们可以完成安装阶段并深入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 receive 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’ll 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. Refer to How to Configure Jenkins with SSL Using an Nginx Reverse Proxy on Ubuntu 20.04 to protect user credentials and information about builds that are transmitted via the web interface.

注意:默认的Jenkins服务器未加密,因此使用此表单提交的数据不受保护。 请参阅如何在Ubuntu 20.04上使用Nginx反向代理使用SSL配置Jenkins,以保护用户凭据和有关通过Web界面传输的内部版本的信息。

Enter the name and password for your user:

输入您的用户名和密码:

You’ll receive 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’ll receive 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 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, follow the guide How to Configure Jenkins with SSL Using an Nginx Reverse Proxy on Ubuntu 20.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 to continue using Jenkins.

完成探索之后,请遵循指南如何在Ubuntu 20.04上使用Nginx反向代理使用SSL配置Jenkins,以保护密码以及将在计算机和服务器之间发送的任何敏感系统或产品信息。纯文本以继续使用Jenkins。

To learn more about what you can do using Jenkins, check out other tutorials on the subject:

要了解有关使用Jenkins可以做什么的更多信息,请查看有关此主题的其他教程:

翻译自: https://www.digitalocean.com/community/tutorials/how-to-install-jenkins-on-ubuntu-20-04

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值