CloudBees Jenkins运营中心的水平扩展

tech2023-03-02  103

This article was sponsored by CloudBees. Thank you for supporting the sponsors who make SitePoint possible!

本文由 CloudBees 赞助 。 感谢您支持使SitePoint成为可能的赞助商!

Picture this: You start using Jenkins, probably with one machine. As both the number of projects and the size of the projects themselves start to grow, you start to add slaves. Slowly, your cluster of Jenkins servers grows, and you slowly start to lose your grip. What if your Jenkins master crashes? If you recognize this feeling or you want to avoid this, you definitely should read on.

想象一下:您可能在一台机器上开始使用Jenkins。 随着项目数量和项目本身大小的增长,您开始添加从站。 慢慢地,您的Jenkins服务器集群增长了,并且您开始逐渐失去控制力。 如果您的詹金斯大师崩溃了怎么办? 如果您认识到这种感觉或想要避免这种感觉,则绝对应该继续阅读。

In this article we’ll take a small peak at CloudBees Jenkins Operation Center. CloudBees Jenkins Operation Center, created by CloudBees, offers you a lot of additional functionality to take your Jenkins cluster to the next level. The key features for CloudBees Jenkins Operation Center are:

在本文中,我们将在CloudBees Jenkins运营中心占据一个小高峰。 由CloudBees创建的CloudBees Jenkins操作中心为您提供了许多附加功能,可将您的Jenkins集群提升到一个新的水平。 CloudBees Jenkins操作中心的主要功能是:

Consolidated navigation experience across all the client masters.

跨所有客户端主站的合并导航体验。 Shared build slave resources that can be used by any client masters.

可以由任何客户端主服务器使用的共享构建从属资源。 Control of authentication and authorization schemes used by client masters. This enables features such as: single sign-on and consolidated permission schemes.

控制客户端主机使用的身份验证和授权方案。 这样可以启用以下功能:单点登录和合并权限方案。 Management of update centers used by client masters.

客户主使用的更新中心的管理。 Consolidated management of Jenkins Enterprise licenses.

统一管理Jenkins Enterprise许可证。 Management and enforcement of certain key security settings on client masters.

在客户端主服务器上管理和实施某些密钥安全设置。

Within this article we’ll just use a small amount of the available features. We’ll be creating a client master and a shared slave. For this we will be using three separate servers. The first one will run CloudBees Jenkins Operation Center, the second one will run Jenkins Enterprise and the third will be used as a shared slave. We will be explaining everything in the next couple of chapters.

在本文中,我们将仅使用少量可用功能。 我们将创建一个客户端主服务器和一个共享从服务​​器。 为此,我们将使用三个单独的服务器。 第一个将运行CloudBees Jenkins Operations Center,第二个将运行Jenkins Enterprise,第三个将用作共享从属。 在接下来的几章中,我们将解释所有内容。

制备 (Preparation)

I’ll be using three virtual machines on my local computer. If you want to follow along, you might want to make sure your own computer is powerful enough. If you happen to have three spare servers somewhere, you can also try it directly on those servers.

我将在本地计算机上使用三个虚拟机。 如果要继续学习,可能需要确保自己的计算机功能强大。 如果您恰好在某处有三个备用服务器,则也可以直接在这些服务器上尝试。

The three servers will be managed through Vagrant. I created a multi-machine Vagrant file which will boot all three servers. If you’re not familiar with Vagrant yet, you might want to read this article.

这三台服务器将通过Vagrant进行管理。 我创建了一个多计算机 Vagrant文​​件,它将引导所有三个服务器。 如果您还不熟悉Vagrant,则可能需要阅读这篇文章 。

Let’s start off with our Vagrant file. You can find the content here

让我们从我们的Vagrant文​​件开始。 您可以在这里找到内容

Note: All three boxes are running CentOS 7. You can easily replace them with Ubuntu boxes if you prefer, but do note that all commands below are meant for CentOS.

注意:所有这三个盒子都在运行CentOS7。如果愿意,您可以轻松地用Ubuntu盒子替换它们,但请注意,以下所有命令均适用于CentOS。

Three servers will be created when you run vagrant up. They each have a different IP:

当您运行vagrant up时,将创建三个服务器。 它们各自具有不同的IP:

192.168.56.105: CloudBees Jenkins Operation Center

192.168.56.105:CloudBees Jenkins运营中心 192.168.56.106: Jenkins Enterprise – Client Master (master)

192.168.56.106:Jenkins Enterprise –客户端管理员(管理员) 192.168.56.107: Shared Slave (slave)

192.168.56.107:共享从站(从站)

安装CloudBees Jenkins操作中心 (Installing CloudBees Jenkins Operation Center)

We start by installing CloudBees Jenkins Operation Center on our first server. CloudBees Jenkins Operation Center is our main control hub to manage all Jenkins instances. We’ll be using it to create our client master and shared slave. After logging in to the first Vagrant machine by running vagrant ssh CloudBees Jenkins Operation Center in your terminal, you can perform the following commands to install CloudBees Jenkins Operation Center.

我们首先在第一台服务器上安装CloudBees Jenkins Operation Center。 CloudBees Jenkins运营中心是我们管理所有Jenkins实例的主要控制中心。 我们将使用它来创建客户端主服务器和共享从服务​​器。 通过在终端中运行vagrant ssh CloudBees Jenkins Operation Center登录到第一台Vagrant计算机后,可以执行以下命令来安装CloudBees Jenkins Operation Center。

sudo rpm --import http://nectar-downloads.cloudbees.com/jenkins-operations-center/latest/rpm/jenkins-ci.org.key sudo wget -O /etc/yum.repos.d/jenkins-oc.repo http://nectar-downloads.cloudbees.com/jenkins-operations-center/latest/rpm/jenkins-oc.repo sudo yum update sudo yum install java jenkins-oc sudo chkconfig jenkins-oc on sudo service jenkins-oc start

You will receive an ok message to indicate CloudBees Jenkins Operation Center has been successfully installed and started.

您将收到一条ok消息,指示CloudBees Jenkins Operation Center已成功安装并启动。

Before we can actually start using CloudBees Jenkins Operation Center, we’ll have to open the web service port to allow access as well as allow our other servers to access this server. We can do this by changing the firewall by running the following commands.

在实际开始使用CloudBees Jenkins Operation Center之前,我们必须打开Web服务端口以允许访问以及允许我们的其他服务器访问该服务器。 我们可以通过运行以下命令来更改防火墙来做到这一点。

sudo firewall-cmd --zone=public --permanent --add-port=8888/tcp --permanent sudo firewall-cmd --zone=public --permanent --add-rich-rule='rule family="ipv4" source address="192.168.56.105/32" accept' sudo firewall-cmd --zone=public --permanent --add-rich-rule='rule family="ipv4" source address="192.168.56.106/31" accept' sudo firewall-cmd --reload

By now, you should be able to reach CloudBees Jenkins Operation Center with the following URL: http://192.168.56.105:8888/. After entering the above URL, a registration form will show up. You can register for an evaluation license if you haven’t bought the product yet from CloudBees. Just fill in your details and press Next.

现在,您应该可以使用以下URL访问CloudBees Jenkins运营中心: http://192.168.56.105:8888/ : http://192.168.56.105:8888/ : http://192.168.56.105:8888/ 。 输入上述URL后,将显示注册表格。 如果尚未从CloudBees购买产品,则可以注册评估许可证。 只需填写您的详细信息,然后按Next 。

When you’ve registered yourself, I recommend you update all the plugins. CloudBees Jenkins Operation Center requires some specific versions of plugins so we want to make sure we have these. Generally, it’s not recommended to update plugins when it’s not needed, as indicated in this article, 7 ways to improve Jenkins.

注册自己后,建议您更新所有插件。 CloudBees Jenkins操作中心需要某些特定版本的插件,因此我们希望确保拥有这些版本。 通常,不建议在不需要时更新插件,如本文所述,这是改善Jenkins的7种方法 。

Note: Problems installing CloudBees Jenkins Operation Center, or using a different server setup? Have a look at the official manual_ for troubleshooting._

注意:在安装CloudBees Jenkins Operation Center或使用其他服务器设置时遇到问题? 请参阅 官方手册 _进行故障排除。_

准备客户主管 (Preparing a Client Master)

On the client master server, we’ll install Jenkins Enterprise. Jenkins Enterprise is a commercial product like CloudBees Jenkins Operation Center by CloudBees. It’ll enhance your Jenkins experience by installing several plugins.

在客户端主服务器上,我们将安装Jenkins Enterprise。 詹金斯企业是一个商业产品一样CloudBees的詹金斯运营中心由CloudBees的 。 通过安装几个插件,它将增强您的Jenkins体验。

You can enter the client master server by running vagrant ssh master on the command line. Now you can run the following commands to install Jenkins.

您可以通过在命令行上运行vagrant ssh master来进入客户端主服务器。 现在,您可以运行以下命令来安装Jenkins。

sudo rpm –import http://nectar-downloads.cloudbees.com/jenkins-enterprise/1.580/rpm/jenkins-ci.org.key

sudo rpm –导入http://nectar-downloads.cloudbees.com/jenkins-enterprise/1.580/rpm/jenkins-ci.org.key

sudo wget -O /etc/yum.repos.d/jenkins.repo http://nectar-downloads.cloudbees.com/nectar/rpm/jenkins.repo

须藤wget -O /etc/yum.repos.d/jenkins.repo http://nectar-downloads.cloudbees.com/nectar/rpm/jenkins.repo

sudo rpm --import http://nectar-downloads.cloudbees.com/jenkins-enterprise/1.580/rpm/jenkins-ci.org.key sudo wget -O /etc/yum.repos.d/jenkins.repo http://nectar-downloads.cloudbees.com/nectar/rpm/jenkins.repo sudo yum update sudo yum install java jenkins sudo chkconfig jenkins on sudo service jenkins start

Just as we did when installing CloudBees Jenkins Operation Center, we have to configure our firewall again.

就像安装CloudBees Jenkins Operation Center一样,我们必须再次配置防火墙。

sudo firewall-cmd --zone=public --permanent --add-port=8080/tcp --permanent sudo firewall-cmd --zone=public --permanent --add-rich-rule='rule family="ipv4" source address="192.168.56.105/32" accept' sudo firewall-cmd --zone=public --permanent --add-rich-rule='rule family="ipv4" source address="192.168.56.106/31" accept' sudo firewall-cmd --reload

When you’ve performed these steps on the server, you can enter the Jenkins instance by entering http://192.168.56.106:8080/ in your favorite web browser. Once again, you’ll receive the option to register yourself. Fill in your details for an evaluation version of Jenkins Enterprise.

在服务器上执行了这些步骤后,可以在您喜欢的Web浏览器中输入http://192.168.56.106:8080/来输入Jenkins实例。 再一次,您将获得注册自己的选项。 填写您的详细信息,以获得Jenkins Enterprise的评估版。

When completed, make sure you go to Manage Jenkins -> Configure System and set the number of executors to 0. By setting it to 0, we make sure that later on this client master uses any of the available shared slaves instead of building on the server itself.

完成后,确保您转到Manage Jenkins-> Configure System并将执行程序的数量设置为0 。 通过将其设置为0 ,我们确保稍后在此客户端主服务器上使用任何可用的共享从服务​​器,而不是在服务器本身上进行构建。

将客户端主机添加到CloudBees Jenkins Operations Center (Adding a Client Master to CloudBees Jenkins Operation Center)

Install Jenkins Enterprise is one step. To create a client master out of it, we have to configure it in CloudBees Jenkins Operation Center. After entering CloudBees Jenkins Operation Center again, we click on new item in the menu and choose client master as our option on the CloudBees Jenkins Operation Center instance.

安装Jenkins Enterprise是一个步骤。 要从中创建客户端主服务器,我们必须在CloudBees Jenkins Operations Center中对其进行配置。 再次进入CloudBees Jenkins Operation Center后,我们在菜单中单击new item ,然后在CloudBees Jenkins Operation Center实例上选择client master节点作为我们的选项。

After creating the client master, you can define several settings like which license type to use and whether there’s a specific user who manages this master. The latter option can come in handy when different people manage certain Jenkins instances. You can find more information about the available settings in the official manual. The default license is License (no dedicated executors).

创建客户端主机后,您可以定义几个设置,例如要使用的许可证类型以及是否有特定用户来管理该主机。 当不同的人管理某些Jenkins实例时,后一种方法会派上用场。 您可以在以下位置找到有关可用设置的更多信息: 官方手册 。 默认许可证是License (no dedicated executors) 。

We can now connect this client master with the actual server. By filling in http://192.168.56.106:8080/ in Client Master URL and clicking Push Notification, we can connect our master instance with CloudBees Jenkins Operation Center.

现在,我们可以将此客户端主服务器与实际服务器连接。 通过在Client Master URL填写http://192.168.56.106:8080/并单击Push Notification ,我们可以将我们的主实例与CloudBees Jenkins Operations Center连接。

After confirming this connection, you’ll find a connected client master in the overview in CloudBees Jenkins Operation Center.

确认此连接后,您将在CloudBees Jenkins操作中心的概述中找到已连接的客户端主服务器。

添加共享从站 (Adding a Shared Slave)

The third server is our shared slave. A shared slave is, as the name implies, a slave which can be shared across multiple client masters. Whenever a client master needs a slave, it will retrieve a slave from the pool in CloudBees Jenkins Operation Center. Whichever slave is available and connected to the client master will be attached to the client master.

第三个服务器是我们的共享从站。 顾名思义,共享从站是可以在多个客户端主站之间共享的从站。 每当客户端主服务器需要一个从服务器时,它将从CloudBees Jenkins Operations Center中的池中检索一个从服务器。 无论哪个可用的从属服务器都已连接并连接到客户端主服务器,它将被附加到客户端主服务器。

A shared slave doesn’t necessarily need its own server. It can run on the same servers as our other instances (CloudBees Jenkins Operation Center & Client Master) or even multiple slaves can be run on one server. However, best practices mandate spreading the load by using a separate instance like we’re doing now.

共享从站不一定需要自己的服务器。 它可以与其他实例在同一服务器上运行(CloudBees Jenkins运营中心和客户端主服务器),甚至可以在一台服务器上运行多个从服务器。 但是,最佳实践要求像现在这样使用单独的实例来分散负载。

You can enter the slave server by running vagrant ssh slave on the command line. Now you can run the following commands to install Java.

您可以通过在命令行上运行vagrant ssh slave来进入从服务器。 现在,您可以运行以下命令来安装Java。

sudo yum update sudo yum install java

Now we have to make sure that we have a writable directory for our slave. We do so by running the following commands on the slave.

现在,我们必须确保我们的从服务器具有可写目录。 为此,我们在从站上运行以下命令。

sudo mkdir /var/jenkins sudo chown vagrant:vagrant /var/jenkins

To add a shared slave to CloudBees Jenkins Operation Center click new item in the menu and chose shared slave as your option on CloudBees Jenkins Operation Center.

要将共享的从服务器添加到CloudBees Jenkins运营中心,请单击菜单中的新项目,然后在CloudBees Jenkins运营中心上选择共享的从服务器作为您的选项。

Change the following settings:

更改以下设置:

Number of executors: 1

执行人数量:1 Remote FS root: /var/jenkins

远程FS根目录:/ var / jenkins

Launch method: Launch slave agents on Unix machines via SSH

启动方法:通过SSH在Unix机器上启动从属代理

Launch method: Launch slave agents on Unix machines via SSH

启动方法:通过SSH在Unix机器上启动从属代理

Host: 192.168.56.107

主机:192.168.56.107

We are going to set up an SSH connection between the servers. For security reasons, it’s advised to communicate through SSH with a separate user.

我们将在服务器之间建立SSH连接。 出于安全原因,建议通过SSH与单独的用户进行通信。

For now, we will be using the already existing vagrant user. If you would like to create your own user, check out this article. Here you can find out how to set up a public private key pair.

目前,我们将使用现有的无业游民用户。 如果你想创建自己的用户,请查看此文章。 在这里,您可以了解如何设置公共私钥对。

On our own machine, we first run the following command on the command line.

在我们自己的机器上,我们首先在命令行上运行以下命令。

cat ~/.vagrant.d/insecure_private_key

Copy the output that you get back. Now head back into your browser. In the last step, you filled in the host. Now click the “add” button for adding a credential.

复制您返回的输出。 现在返回浏览器。 在最后一步中,您填写了主机。 现在,单击“添加”按钮以添加证书。

Choose ‘SSH username with private key’ in the drop down. Fill in ‘vagrant’ as username choose ‘enter directly’ for private key. Within the text box that appears, you can paste the content you copied earlier.

在下拉菜单中选择“带有私钥的SSH用户名”。 填写“ vagrant”作为用户名,然后选择“直接输入”作为私钥。 在出现的文本框中,您可以粘贴先前复制的内容。

Click on add when done. Next you can click on save to save this slave. The slave should now state that it is ready for lease.

完成后单击add 。 接下来,您可以单击save以保存该从站。 现在,从服务器应声明已准备好出租。

创建一个项目 (Creating a Project)

Until now, we’ve only been preparing our servers. We can now actually start to run a project and see the use of a shared slave. Log into our client master and create a new freestyle job by clicking on new item and then choosing freestyle project.

到目前为止,我们仅在准备服务器。 现在,我们实际上可以开始运行项目,并查看共享从站的使用。 登录我们的客户主站点,然后通过单击new item然后选择freestyle project来创建新的自由样式作业。

We add a new shell build step with the following content.

我们添加一个新的Shell构建步骤,内容如下。

sleep 10 date

When you start building this project, you’ll notice two things. In the client master, you’ll notice that the project is being build on the shared slave. In CloudBees Jenkins Operation Center you will notice that the slave is being marked as ‘in use’.

当您开始构建此项目时,您会注意到两件事。 在客户端主机中,您会注意到该项目是在共享从机上构建的。 在CloudBees Jenkins操作中心中,您会注意到从站被标记为“使用中”。

Of course this project is not realistic, but you can imagine your own project is now being built. The next step you probably want to do is add more shared slaves, so your client master has more slaves to choose from. Also, you want to create more client masters and assign your colleagues to a client master to manage. This way you can keep control using CloudBees Jenkins Operation Center while having multiple Jenkins servers dealing with your projects.

当然,这个项目是不现实的,但是您可以想象现在正在构建自己的项目。 下一步可能要添加更多共享从属,因此您的客户端主服务器将有更多从属可供选择。 另外,您想创建更多的客户主文件并将您的同事分配给客户主文件进行管理。 这样,您可以使用CloudBees Jenkins Operation Center进行控制,同时让多个Jenkins服务器处理您的项目。

结论 (Conclusion)

Unfortunately, we’re at the end of the article. As you can imagine, we’re not quite production ready. To get to that stage, you’ll probably want to secure all your Jenkins instances with a single sign on and configure multiple shared slaves or perhaps a shared cloud. Also you could dive into generating analytics or configure the update centers.

不幸的是,我们在本文结尾。 可以想象,我们还没有准备好生产。 为了达到这个阶段,您可能需要通过单点登录来保护所有Jenkins实例并配置多个共享的从属服务器或共享的云 。 您也可以深入研究生成分析或配置更新中心 。

As you can see, Jenkins Operations Center is a great tool to manage your Jenkins instances and this article just showed you a small part of horizontal scaling your Jenkins cluster.

如您所见,Jenkins Operations Center是管理Jenkins实例的出色工具,本文仅向您展示了水平扩展Jenkins集群的一小部分。

Have you tried CloudBees Jenkins Operation Center yet? What did you think?

您是否尝试过CloudBees Jenkins运营中心? 你觉得呢?

翻译自: https://www.sitepoint.com/horizontal-scaling-with-cloudbees-jenkins-operation-center/

相关资源:jdk-8u281-windows-x64.exe
最新回复(0)