Abstract
| Goal |
Configure JBoss EAP by using the management Command Line Interface (CLI), and deploy Jakarta EE applications. |
| Objectives |
|
| Sections |
|
| Lab |
|
Connect to an instance of JBoss EAP standalone with the management CLI and execute general commands.
In Red Hat JBoss Enterprise Application Platform (JBoss EAP) the configuration values reside in XML files. There are three different options for configuring for JBoss EAP servers:
A web application that modifies the underlying XML configuration files.
A command-line tool to manage and configure JBoss EAP instances remotely from the operating system terminal, including writing scripts for repetitive tasks.
The action of manually editing XML configuration files. Red Hat does not recommend manually editing configuration files.
Some of the benefits of using the management CLI include:
Managing servers without the need of a GUI.
Writing commands in a separate file and execute them as a batch. This capability enables you to write scripts for common tasks.
The management console has limitations, but the management CLI configures almost every aspect of the XML configuration files.
JBoss EAP 7 embeds a JBoss EAP server instance inside the management CLI process. By using the embedded JBoss EAP 7 server, you can access the management CLI remote administration without connecting to a running server.
The main goal of using this approach is to enable the local administration of JBoss EAP without requiring a socket-based connection.
This can be very useful when, for example, for security reasons, the 9990 management port is not available.
Another example of how this is useful is that you can perform some configuration offline and apply in production only when the update can be made.
To use this feature, it is necessary to start the management CLI without providing the connection parameter:
# $JBOSS_HOME/bin/jboss-cli.shThen, you can start the embedded server:
[disconnected /] embed-server --server-config=standalone-ha.xmlIn the previous example, every change made by the management CLI persists on the standalone-ha.xml file, which is available in the JBOSS_HOME/standalone/configuration directory.
If you do not specify the --server-config parameter, then the standalone.xml contains the changes.
It is possible to start with an empty configuration using the parameter --empty-config
[disconnected /] embed-server --server-config=production-ha.xml --empty-configThe production-ha.xml file is created in the JBOSS_HOME/standalone/configuration directory.
This file only contains the XML tags related to configurations performed in the management CLI.
If the file already exists, then the command fails.
This condition prevents the accidental deletion of the configuration file.
If the --empty-config parameter is not specified, then the file specified in the --server-config parameter must exist on the JBOSS_HOME/standalone/configuration directory.
JBoss EAP uses a new, de-typed syntax for representing the underlying Java objects that are used by both the management console and the management CLI.
The syntax name is Dynamic Model Representation (DMR).
The DMR syntax is a way of inspecting the JBoss EAP settings. You need to understand the DMR syntax to work with the management CLI. The DMR syntax is intuitive and less verbose than XML.
To compare DMR and XML syntax from JBoss EAP, consider the following excerpt, which is part of the standalone.xml file, configuring the logging subsystem:
<subsystem xmlns="urn:jboss:domain:logging:8.0">
<console-handler name="CONSOLE">
<level name="INFO"/>
<formatter>
<named-formatter name="COLOR-PATTERN"/>
</formatter>
</console-handler>
...remainder of the logging subsystem
</subsystem>The same settings in DMR syntax:
"logging" => {
"console-handler" => {"CONSOLE" => {
"autoflush" => true,
"enabled" => true,
"encoding" => undefined,
"filter" => undefined,
"filter-spec" => undefined,
"formatter" => "%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n",
"level" => "INFO",
"name" => "CONSOLE",
"named-formatter" => "COLOR-PATTERN",
"target" => "System.out"
}},
...remainder of the logging subsystem
}One of the advantages of seeing the DMR syntax is that it is possible to see all the attributes, including those that have a default value.
For example, in the XML syntax it is not clear that the autoflush attribute has the true value.
However, this is clear in the DMR syntax.
Notice that the DMR is "flatter" than the XML.
In DMR, most settings belong to the same level, as opposed to XML, where settings can be attributes or nested within elements.
For example, the formatter pattern in XML is several levels deep.
But in the DMR syntax it is a property of the CONSOLE handler.
As the progress through this course increases, the configurations and examples discussed gradually shift from XML to the DMR syntax. The management CLI is an important tool designed for both the casual user of JBoss EAP and the more expert user.
The management CLI is started by running the jboss-cli.sh script, which is in the bin directory of the JBoss EAP installation.
This script does not require any arguments and if arguments are not provided, then it runs in disconnected mode:
# $JBOSS_HOME/bin/jboss-cli.sh
[disconnected /]The connect command is responsible for connecting to the server.
If no argument is provided, then the command tries to connect to the default host,localhost, using the default port, 9990.
[disconnected /] connect localhost:9990To automatically connect using the jboss-cli.sh
script, use the --connect argument:
# $JBOSS_HOME/bin/jboss-cli.sh --connectThe OS user that runs the management CLI must be the same as the one that started JBoss EAP. The authentication is based on creating a file to pass a one-time token. The JBoss EAP instance creates the file. If the management CLI can read the file, then it sends the token to JBoss EAP to authenticate.
If JBoss EAP and the management CLI are started by different OS users, then the management CLI cannot read the file and the local authentication fails. Then, authentication falls back, and the management CLI requests for a username and a password.
You can use a shortcut to connect to a server:
# $JBOSS_HOME/bin/jboss-cli.sh -cTo connect to a different host machine, use the --controller argument:
# $JBOSS_HOME/bin/jboss-cli.sh --connect --controller=ip:portBy default, the management CLI does not request credentials if it is running in the same host that started the server.
The credentials can be passed with the --user and --password arguments.
Operations are a low level way to manage the JBoss EAP server.
An operation in the management CLI has the following format:
[node] : operation_name [ parameters ] [ headers ]
The node represents the target resource address or the node where the operation is invoked.
It is a key/value pair with the node type and the node name.
An example of a node is /subsystem=datasources.
After specifying the desired node, you must define the operation name with an optional list of parameters. The colon is required before the operation name because it serves as a separator between the node and the operation. A colon is required even if the node is empty. In this case, the operation is executed in the current node level.
The following operations are very common:
:read-resource
Reads a model resource attribute value.
:read-operation-names
Gets the names of all the operations for the given resource.
:read-operation-description
Gets the description of given operation.
:reload
Reloads the server by shutting down all its services and starting them again. The java process is not restarted.
:read-attribute
Gets the value of an attribute for the selected resource.
:write-attribute
Sets the value of an attribute for the selected resource.
:remove
Removes the node.
The commands contains a user friendly syntax and translate into operation requests.
The following commands are the basic supported commands for the management CLI:
cn or cd: Change the current node path to the argument.
connect: Connect to the server or domain controller.
data-source: Used to manage resources of the /subsystem=datasources/data-source type .
deploy: Deploy an application.
help: Display the help page.
history: Print, disable, enable, or clear the history expansion.
ls: list the contents of the node path.
pwn or pwd: Prints the current working node.
exit or quit: Quit the management CLI.
undeploy: Undeploy an application.
version: Prints the version and environment information.
Tab completion shows all possible commands available at any point in a current command.
For example, enter /.
Then, press Tab to view all possible values after the / character.
[standalone@localhost:9990 /] /
core-service deployment-overlay interface socket-binding-group system-property
deployment extension path subsystemStart typing interface after the / character, and press Tab.
The management CLI not only completes the interface sub-level, but it adds an equals sign, because an equals sign is the only possible value after /interface.
Press Tab again and all the interfaces display:
[standalone@localhost:9990 /] /interface=
management publicJBoss EAP supports using a text file for the management CLI as a script. Using this approach, you can create scripts for repetitive tasks. For example, you can create a script file that configures a data source and test a connection from the pool:
/subsystem=datasources/data-source=appDs:add\ (jndi-name=java:jboss/datasources/appDS,driver-name=h2,user-name=jb248, \ password=jb248,connection-url="jdbc:h2:mem:app;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE") /subsystem=datasources/data-source=appDs:test-connection-in-pool
You can execute the previous content from a /home/student/create-datasource.cli text file:
#$JBOSS_HOME/jboss-cli.sh --connect --controller=localhost:9990 \--file=/home/student/create-datasource.cli
The management CLI provides a batch command that supports multiple commands in one atomic unit.
If one of the commands or operations fails, then all the other successfully commands and operations in the batch are rolled back.
In the previous example, it as good idea to create the data source using the batch command.
If testing a connection from the pool fails, then the data source creation is rolled back.
To execute a batch, use the run-batch command:
batch /subsystem=datasources/data-source=appDs:add\ (jndi-name=java:jboss/datasources/appDS,driver-name=h2,user-name=jb248,\ password=jb248,connection-url="jdbc:h2:mem:app;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE") /subsystem=datasources/data-source=appDs:test-connection-in-pool run-batch
The management CLI enables integration with external scripts.
You can pass a command or an operation to the CLI by using the --command
attribute:
#$JBOSS_HOME/jboss-cli.sh -c --controller=localhost:9990 \--command="/subsystem=datasources:read-resource"
The result of the operation returns, in DMR syntax, to the script that invoked the CLI.
You can specify a set of commands by using the commands attribute.
This attribute specifies a comma-separated list (the list must not contain whitespace) of commands and operations that should be executed in the management CLI session.
# ./jboss-cli.sh -c --controller=localhost:9990 --commands="cd /subsystem=datasources,ls"For more information about the JBoss EAP management CLI, refer to the Management CLI Guide in the Red Hat JBoss EAP 7 documentation at https://access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/7.4/html-single/management_cli_guide/index
For more examples about common operations with the management CLI, refer to the How to… chapter in the Management CLI Guide in the Red Hat JBoss EAP 7 documentation at https://access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/7.4/html-single/management_cli_guide/index#how_to_cli