GlassFish Administration
上QQ阅读APP看书,第一时间看更新

Performing administrative tasks

In this section, we will introduce the utilities that help us perform these tasks. Two administrative utilities are shipped with the GlassFish Server:

  • The Admin Console: A browser-based tool that allows you to perform administrative tasks using the web interface.
  • The asadmin utility: A command-line tool that allows you to perform most administrative tasks from a command terminal.

Both tools can perform similar configuration changes, with the asadmin utility incorporating slightly more functionality. In this chapter, we discuss both of these tools.

Using the GlassFish Admin Console

You have seen the Admin Console in Chapter 1. The user interface of the Admin Console is very intuitive. In this section, we will provide you with a short guided tour around the Admin Console to help you get familiar with its operation features.

Complete the following steps:

  1. After starting the GlassFish Server, view the Admin Console by accessing the following URL: http://localhost:4848 in a browser. Enter admin as the username and adminadmin as the password.

    The Admin Console should appear in your browser, as shown in the following screenshot. The Admin Console user interface is composed of the information panel on the top, the navigation panel to the left, and the main content panel. The default content panel displays a page with links to common administrative tasks.

    Using the GlassFish Admin Console
  2. Click the Help button on the top-right corner of the information panel.

    The context-sensitive help information of the Admin Console should appear in a separate browser window. The help content is also indexed with searching capability.

    This figure displays a screenshot of the Admin Console's help information. The help content contains a lot of helpful information. However, not many people are aware of this.

  3. Close the help page browser window, and click the Application Server node in the navigation panel of the Admin Console.

    The content panel displays the general information of the GlassFish Server instance, such as the open ports, and the installation directory. You can also click the Stop Instance button to shut down the server

  4. Click the JVM Settings tab in the content panel. Within the General sub-tab, delete -g in the javac options field, and click Save button in the content panel.

    As the task you just performed changes the settings of the underlying JVM running the GlassFish Server, the GlassFish Server needs to be restarted to make this change effective. Whenever the server needs to be restarted, the Admin Console will display a visual cue to remind you.

    This screenshot illustrates the situation when the Admin Console reminds the administrator that the server needs to be restarted.

  5. Restart the GlassFish Server and then reload the Admin Console in the browser.

The server restart indicator should disappear.

Even though this short tour in the GlassFish Admin Console is very straightforward, it does describe how you typically use the Admin Console to manage the server: Navigate to the right place, make necessary changes in the content panel, save the changes; and finally, restart the server if necessary. In GlassFish, the following configuration changes require the server to be restarted:

  • Changing JVM options
  • Managing HTTP services
  • Modifying thread pool settings
  • Modifying the following JDBC connection pool properties:
    • datasource-classname
    • associate-with-thread
    • lazy-connection-association
    • lazy-connection-enlistment
    • JDBC driver vendor-specific properties
  • Modifying the following connector connection pool properties:
    • resource-adapter-name
    • connection-definition-name
    • transaction-support
    • associate-with-thread
    • lazy-connection-association
    • lazy-connection-enlistment
    • Vendor-specific properties

Using the administration Command Line Utility (CLI) — asadmin

It is not always desirable to use the Admin Console to manage the GlassFish Server. For example, you may want to create some scripts to run routine maintenance and monitoring, or perform some other repetitive administrative tasks. In this case, using the Admin Console could be fairly time consuming. GlassFish provides a command-line utility—asadmin—that is particularly suitable for these tasks. The asadmin utility is located in the $AS_INSTALL/bin directory. In this section, let's get familiar with the syntax of the utility, and then try to perform some simple administrative tasks.

The syntax of the asadmin utility

You can enter the following command to view the help page of the asadmin utility:

# cd $AS_INSTALL/bin # ./asadmin help | more

On Windows, you can run the command asadmin help | help.txt to redirect the help page out to a file and then read the file.

The syntax of running the asadmin utility is as follows:

# cd $AS_INSTALL/bin # ./asadmin <subcommand> <options>* <operand>*

By then end of this book, you should be familiar with most, if not all of these commands.

Different commands may have different options and operands, the best way to learn the syntax of each subcommand is by running the following command:

# cd $AS_INSTALL/bin # ./asadmin <subcommand> --help

This command displays detailed help information for the subcommand. For example, if you want to know how to run the list-commands subcommand, you can enter the following commands from a terminal:

# cd $AS_INSTALL/bin # ./asadmin list-commands –help |more

This output explains the options the subcommand accepts. Many options have a long form and a short form. For example, the long option – –terse can be written in the form of -t.

The – –passwordfile option does not have a short form. We will discuss this option when we configure security for the GlassFish Server.

Finally, the operand of the asadmin command depends on the subcommand you want to run.

Examples of running the asadmin utility

Now, we will go through an example to get more familiar with the asadmin utility. Let's create a new domain for our GlassFish installation.

First, try to view the help page of the create-domain subcommand:

# cd $AS_INSTALL/bin # ./asadmin create-domain --help | more

When you create a new domain, you should specify the admin server port number (default 4848) and the HTTP service port number (default 8080). Otherwise, if your default domain was not running when the new domain was created, the new domain will use the same default ports, and a port conflict will occur when you try to start both domains.

You can also specify a port base, such as 18080, in the create-domain command to force all the ports allocated to the new domain to have a port number higher than the base number.

Now enter the following command:

# cd $AS_INSTALL/bin # ./asadmin create-domain --adminport 5858 --instanceport 9090 domain2

The command asks you for the admin username. Type ENTER to accept the default admin user (anonymous user), and the asadmin command should print the following output, indicating the new domain is successfully created:

Enter admin user name[Enter to accept default]> Using port 5858 for Admin. Using port 9090 for HTTP Instance. Using default port 7676 for JMS. Using default port 3700 for IIOP. Using default port 8181 for HTTP_SSL. Using default port 3820 for IIOP_SSL. Using default port 3920 for IIOP_MUTUALAUTH. Default port 8686 for JMX_ADMIN is in use. Using 2672 Distinguished Name of the self-signed X.509 Server Certificate is: [CN=panda.programming-stuff.com,OU=GlassFish,O=Sun Microsystems,L=Santa Clara,ST=California,C=US] Domain domain2 created. 

By default, the new domain, domain2 is created under the domain root directory $AS_INSTALL/glassfish/domains. You can create the new domain in a different domain root directory by providing a domaindir option in the create-domain command.

After domain2 is created, you can start it by entering the following command:

# cd $AS_INSTALL/bin # ./asadmin start-domain --adminport 5858 --instanceport 9090 domain2

If there are multiple domains within a domain root directory, when you start/stop one of them, you must provide the domain name as the operand in the asadmin command.