Chapter 1. Getting Started with Data Grid CLI
The command line interface (CLI) lets you remotely connect to Data Grid Server to access data and perform administrative functions. Complete the following procedures to learn basic CLI usage such as creating users, connecting to Data Grid, and navigating resources.
1.1. Creating Data Grid users Copy linkLink copied to clipboard!
Add credentials to authenticate with Data Grid Server deployments through Hot Rod and REST endpoints. Before you can access the Data Grid Console or perform cache operations you must create at least one user with the Data Grid command line interface (CLI).
Data Grid enforces security authorization with role-based access control (RBAC). Create an admin user the first time you add credentials to gain full ADMIN permissions to your Data Grid deployment.
Prerequisites
- Download and install Data Grid Server.
Procedure
-
Open a terminal in
$RHDG_HOME. Create an
adminuser with theuser createcommand.bin/cli.sh user create admin -p changeme
bin/cli.sh user create admin -p changemeCopy to Clipboard Copied! Toggle word wrap Toggle overflow TipRun
help userfrom a CLI session to get complete command details.
Verification
Open user.properties and confirm the user exists.
cat server/conf/users.properties admin=scram-sha-1\:BYGcIAwvf6b...
cat server/conf/users.properties
admin=scram-sha-1\:BYGcIAwvf6b...
Adding credentials to a properties realm with the CLI creates the user only on the server instance to which you are connected. You must manually synchronize credentials in a properties realm to each node in the cluster.
1.1.1. Granting roles to users Copy linkLink copied to clipboard!
Assign roles to users and grant them permissions to perform cache operations and interact with Data Grid resources.
Grant roles to groups instead of users if you want to assign the same role to multiple users and centrally maintain their permissions.
Prerequisites
-
Have
ADMINpermissions for Data Grid. - Create Data Grid users.
Procedure
- Create a CLI connection to Data Grid.
Assign roles to users with the
user roles grantcommand, for example:user roles grant --roles=deployer katie
user roles grant --roles=deployer katieCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
List roles that you grant to users with the user roles ls command.
user roles ls katie ["deployer"]
user roles ls katie
["deployer"]
1.1.2. Adding users to groups Copy linkLink copied to clipboard!
Groups let you change permissions for multiple users. You assign a role to a group and then add users to that group. Users inherit permissions from the group role.
You use groups as part of a property realm in the Data Grid Server configuration. Each group is a special type of user that also requires a username and password.
Prerequisites
-
Have
ADMINpermissions for Data Grid. - Create Data Grid users.
Procedure
- Create a CLI connection to Data Grid.
Use the
user createcommand to create a group.-
Specify a group name with the
--groupsargument. Set a username and password for the group.
user create --groups=developers developers -p changeme
user create --groups=developers developers -p changemeCopy to Clipboard Copied! Toggle word wrap Toggle overflow
-
Specify a group name with the
List groups.
user ls --groups
user ls --groupsCopy to Clipboard Copied! Toggle word wrap Toggle overflow Grant a role to the group.
user roles grant --roles=application developers
user roles grant --roles=application developersCopy to Clipboard Copied! Toggle word wrap Toggle overflow List roles for the group.
user roles ls developers
user roles ls developersCopy to Clipboard Copied! Toggle word wrap Toggle overflow Add users to the group one at a time.
user groups john --groups=developers
user groups john --groups=developersCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Open groups.properties and confirm the group exists.
cat server/conf/groups.properties
cat server/conf/groups.properties
1.1.3. Data Grid user roles and permissions Copy linkLink copied to clipboard!
Data Grid includes several roles that provide users with permissions to access caches and Data Grid resources.
| Role | Permissions | Description |
|---|---|---|
|
| ALL | Superuser with all permissions including control of the Cache Manager lifecycle. |
|
| ALL_READ, ALL_WRITE, LISTEN, EXEC, MONITOR, CREATE |
Can create and delete Data Grid resources in addition to |
|
| ALL_READ, ALL_WRITE, LISTEN, EXEC, MONITOR |
Has read and write access to Data Grid resources in addition to |
|
| ALL_READ, MONITOR |
Has read access to Data Grid resources in addition to |
|
| MONITOR |
Can view statistics via JMX and the |
1.2. Connecting to Data Grid Servers Copy linkLink copied to clipboard!
Establish CLI connections to Data Grid.
Prerequisites
Add user credentials and have at least one running Data Grid server instance.
Procedure
-
Open a terminal in
$RHDG_HOME. Start the CLI.
Linux:
bin/cli.sh
bin/cli.shCopy to Clipboard Copied! Toggle word wrap Toggle overflow Microsoft Windows:
bin\cli.bat
bin\cli.batCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Run the
connectcommand and enter your username and password when prompted.Data Grid Server on the default port of
11222:[disconnected]> connect
[disconnected]> connectCopy to Clipboard Copied! Toggle word wrap Toggle overflow Data Grid Server with a port offset of
100:[disconnected]> connect 127.0.0.1:11322
[disconnected]> connect 127.0.0.1:11322Copy to Clipboard Copied! Toggle word wrap Toggle overflow
1.4. Shutting down Data Grid Server Copy linkLink copied to clipboard!
Stop individually running servers or bring down clusters gracefully.
Procedure
- Create a CLI connection to Data Grid.
Shut down Data Grid Server in one of the following ways:
Stop all nodes in a cluster with the
shutdown clustercommand, for example:shutdown cluster
shutdown clusterCopy to Clipboard Copied! Toggle word wrap Toggle overflow This command saves cluster state to the
datafolder for each node in the cluster. If you use a cache store, theshutdown clustercommand also persists all data in the cache.Stop individual server instances with the
shutdown servercommand and the server hostname, for example:shutdown server <my_server01>
shutdown server <my_server01>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
The shutdown server command does not wait for rebalancing operations to complete, which can lead to data loss if you specify multiple hostnames at the same time.
Run help shutdown for more details about using the command.
Verification
Data Grid logs the following messages when you shut down servers:
ISPN080002: Data Grid Server stopping ISPN000080: Disconnecting JGroups channel cluster ISPN000390: Persisted state, version=<$version> timestamp=YYYY-MM-DDTHH:MM:SS ISPN080003: Data Grid Server stopped
ISPN080002: Data Grid Server stopping
ISPN000080: Disconnecting JGroups channel cluster
ISPN000390: Persisted state, version=<$version> timestamp=YYYY-MM-DDTHH:MM:SS
ISPN080003: Data Grid Server stopped
1.4.1. Shutdown and restart of Data Grid clusters Copy linkLink copied to clipboard!
Prevent data loss and ensure consistency of your cluster by properly shutting down and restarting nodes.
Cluster shutdown
Data Grid recommends using the shutdown cluster command to stop all nodes in a cluster while saving cluster state and persisting all data in the cache. You can use the shutdown cluster command also for clusters with a single node.
When you bring Data Grid clusters back online, all nodes and caches in the cluster will be unavailable until all nodes rejoin. To prevent inconsistencies or data loss, Data Grid restricts access to the data stored in the cluster and modifications of the cluster state until the cluster is fully operational again. Additionally, Data Grid disables cluster rebalancing and prevents local cache stores purging on startup.
During the cluster recovery process, the coordinator node logs messages for each new node joining, indicating which nodes are available and which are still missing. Other nodes in the Data Grid cluster have the view from the time they join. You can monitor availability of caches using the Data Grid Console or REST API.
However, in cases where waiting for all nodes is not necessary nor desired, it is possible to set a cache available with the current topology. This approach is possible through the CLI, see below, or the REST API.
Manually installing a topology can lead to data loss, only perform this operation if the initial topology cannot be recreated.
Server shutdown
After using the shutdown server command to bring nodes down, the first node to come back online will be available immediately without waiting for other members. The remaining nodes join the cluster immediately, triggering state transfer but loading the local persistence first, which might lead to stale entries. Local cache stores configured to purge on startup will be emptied when the server starts. Local cache stores marked as purge=false will be available after a server restarts but might contain stale entries.
If you shutdown clustered nodes with the shutdown server command, you must restart each server in reverse order to avoid potential issues related to data loss and stale entries in the cache.
For example, if you shutdown server1 and then shutdown server2, you should first start server2 and then start server1. However, restarting clustered nodes in reverse order does not completely prevent data loss and stale entries.