Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to add KVM hosts to CloudStack

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to add a KVM host to CloudStack". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to add KVM hosts to CloudStack.

Main process

1. The code entry for adding a host is the execute method of AddHostCmd

Then call the find method of the LibvirtServerDiscoverer class

In the find method, first connect to the corresponding host through SSH (here agentIp is 172.16.65.135) sshConnection = new com.trilead.ssh3.Connection (agentIp, 22)

Then execute the agent command SSHCmdHelper.sshExecuteCmd (sshConnection, setupAgentCommand + parameters, 3) on the host using the connection you just established

SetupAgentCommand = "cloudstack-setup-agent"

After the command is executed on the host computer, a corresponding JAVA process will be started.

Second, a little analysis of the start-up command of the process: for jsvc.exec, please refer to the official explanation http://commons.apache.org/proper/commons-daemon/jsvc.html

In a word, jsvc allows you to start JAVA applications in a very convenient and simple Linux environment, which is the same as we usually use java xxx to start applications, and the latter-cp is easy to associate with the meaning of classpath.

Take a closer look at the jar package in classpath that contains cloud-agent-4.3.2.jar, so the startup entry for the process is the main method of com.cloud.agent.AgentShell

Third, let's leave what happened on the mainframe and go back to the management node.

After starting the agent command through SSH, CS executes HostVO connectedHost = waitForHostConnect (dcId, podId, clusterId, guid)

Note that there is no record of the host in the host table of the database at this time

In the waitForHostConnect method, there is a _ waitTime*2, that is, a loop of 10 times, which allows the thread to sleep30 seconds in the middle of each loop.

That is, wait for a total of 5 minutes for other threads to insert the records of the host into the host table, and return Null directly if you don't get the connectedHost for more than 5 minutes.

The next thing we care about is how the data is inserted into the host table

Let's go back to the host agent and see what happens after the JAVA process starts.

By looking at the log file / var/log/cloudstack/agent/agent.log (here is the file on host 172.16.65.135)

Combined with the code of the class AgentShell, the running process of the agent process after startup is summarized as follows:

Create an Agent object Agent agent = new Agent (this, localAgentId, resource); notice that a NioConnection _ connection; in Agent is instantiated as a NioClient

Then there is the initialization init method of NioClient

The NIO of JAVA is used to communicate here. For a specific explanation, please refer to my other article, https://my.oschina.net/abelgroup/blog/849680.

The first step is to establish a connection to the management node, 172.16.60.197, as shown in the log

After connecting, create a Task of ServerHandler and put it into the thread pool to execute

Then execute the sendStartup (link) method, which mainly uses link to send a StartupRoutingCommand to the management node

Now let's go back to the management node and continue to process the StartupRoutingCommand command that has just been sent from agent

We know that there is an instance object of AgentManagerImpl in CS, which holds a NioServer, and the listening port 8250 happens to be the port on which agent establishes a connection.

NioServer listens for events through an endless loop. When agent sends data, it executes NioConnect's read method protected void read (final SelectionKey key).

Then create a Task for AgentHandler, and then execute its processRequest method

one

two

three

four

five

six

seven

eight

nine

ten

eleven

twelve

thirteen

fourteen

fifteen

sixteen

Protected void processRequest (final Link link, final Request request) {

Final AgentAttache attache = (AgentAttache) link.attachment ()

Final Command [] cmds = request.getCommands ()

Command cmd = cmds [0]

Boolean logD = true

If (attache = = null) {

If (! (cmd instanceof StartupCommand)) {

S_logger.warn ("Throwing away a request because it came through as the first command on a connect:" + request)

} else {

/ / submit the task for execution

Request.logD ("Scheduling the first command")

ConnectAgent (link, cmds, request)

}

Return

}

Then execute the handleConnectedAgent method through a Task of HandleAgentConnectTask

one

two

three

four

five

six

seven

eight

nine

ten

eleven

twelve

thirteen

fourteen

fifteen

sixteen

seventeen

eighteen

nineteen

Private AgentAttache handleConnectedAgent (final Link link, final StartupCommand [] startup, final Request request) {

AgentAttache attache = null

ReadyCommand ready = null

Try {

Final HostVO host = _ resourceMgr.createHostVOForConnectedAgent (startup)

If (host! = null) {

Ready = new ReadyCommand (host.getDataCenterId (), host.getId ())

Attache = createAttacheForConnect (host, link)

Attache = notifyMonitorsOfConnection (attache, startup, false)

}

} catch (final Exception e) {

S_logger.debug ("Failed to handle host connection:" + e.toString ())

Ready = new ReadyCommand (null)

Ready.setDetails (e.toString ())

} finally {

If (ready = = null) {

Ready = new ReadyCommand (null)

}

}

The main things this method does include: createHostVOForConnectedAgent creates an HostVo,host data insertion that is also performed in this method.

Then createAttacheForConnect creates an attach for this host and gives it to attachManagerImpl to manage.

Then there is the method notifyMonitorsOfConnection, which notifies the host of all the Monitor to processConnect

This includes StoragePoolMonitor, which handles connecting all the storage pools available to the new host to the host, which is not expanded here

After all this processing, execute agentStatusTransitTo (host, Event.Ready, _ nodeId); change the host state to UP

When the host status is UP, the waitForHostConnect method in the previous step 3 can get the data smoothly.

The task of adding hosts here is basically a success.

At this point, I believe you have a deeper understanding of "how to add a KVM host to CloudStack". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report