|
Working with Terracotta Configuration FilesIntroductionTerracotta XML configuration files set the characteristics and behavior of Terracotta servers and clients. The easiest way to create your own Terracotta configuration file is by editing a copy of one of the sample configuration files available in /config-examples directory, located in the Terracotta home directory. Where you locate the Terracotta configuration file, or how your Terracotta server and client configurations are loaded, depends on the stage your project is at and on its architecture. This document covers the following cases:
For more information on configuration, including definitions of configuration elements, see More Information. How Terracotta Servers Get ConfiguredAt startup, Terracotta servers should fetch their configuration from one of the following sources:
These sources are explored below. Default ConfigurationIf no configuration file is specified and no tc-config.xml exists in the directory in which the Terracotta instance is started, then default configuration values are used. Local XML File (Default)The file tc-config.xml is used by default if it is located in the directory in which a Terracotta instance is started and no configuration file is explicitly specified. Local or Remote Configuration FileYou can explicitly specify a configuration file by passing the -f option to the script used to start a Terracotta server. For example, to start a Terracotta server on UNIX/Linux using the provided script, enter: start-tc-server.sh -f <path_to_configuration_file> where <path_to_configuration_file> can be a URL or a relative directory path. How Terracotta Clients Get ConfiguredAt startup, Terracotta clients should fetch their configuration from one of the following sources:
These sources are explored below. Local XML File (Default)See the discussion for local XML file (default) in How Terracotta Servers Get Configured. Local or Remote Configuration FileTo specify a configuration file for a Terracotta client, see Clients in Development. Terracotta ServerTerracotta clients can load configuration from a running Terracotta server by specifying its hostname and DSO port (see Clients in Production). Configuration in a Development EnvironmentIn a development environment, using a different configuration file for each Terracotta client facilitates the testing and tuning of configuration options. This is an efficient and effective way to gain valuable insight on best practices for clustering your application with Terracotta DSO. One-Server Setup in DevelopmentFor one Terracotta server, the default configuration is adequate.
![]() To use the default configuration settings, simply start your Terracotta server using the start-tc-server.sh or start-tc-server.bat script in a directory that does not contain the file tc-config.xml: start-tc-server.sh If you want to specify a configuration file, use one of the approaches discussed in How Terracotta Servers Get Configured. Active-Passive Setup in DevelopmentAn active-passive setup uses at least two servers that should load the same configuration file. ![]() The configuration file loaded by the Terracotta servers must define each server separately using <server> elements. For example: ... <server host="%i" name="Server1"> ... <server host="%i" name="Server2"> ... By using the same configuration, Server2 can maintain the environment in the case of failover. Using the same configuration file simplifies maintenance and coordination between the Terracotta servers.
With multiple <server> elements, the name attribute is required to avoid ambiguity when starting a server: start-tc-server.sh -n Server1 -f <path_to_configuration_file> Clients in DevelopmentYou can explicitly specify a client's Terracotta configuration file by passing -Dtc.config when you start the client using the dso-java.sh script (or dso-java.bat for Windows): dso-java.sh -Dtc.config=path/to/my-tc-config.xml -cp classes myApp.class.Main where myApp.class.Main is the class used to launch the application you want to cluster with Terracotta.
If tc-config.xml exists in the directory in which you run dso-java, it can be loaded without -Dtc.config: dso-java.sh -cp classes myApp.class.Main
Configuration in a Production EnvironmentFor an efficient production environment, it's recommended that you maintain one Terracotta configuration file. That file can be loaded by the Terracotta server (or servers) and pushed out to clients. While this is an optional approach, it's an effective way to centralize and decrease maintenance. ![]() If your Terracotta configuration file uses "%i" for the hostname attribute in its server element, change it to the actual hostname in production. For example, if in development you used the following: <server host="%i" name="Server1"> and the production host's hostname is myHostName, then change the host attribute to the myHostName: <server host="myHostName" name="Server1"> Clients in ProductionFor clients in production, you can set up the Terracotta environment before launching your application, or you can use the dso-java script. Setting Up the Terracotta EnvironmentTo start your application with the Terracotta client using your own scripts, first set the following environment variables:
where <server_host>:<dso-port> points to the running Terracotta Server. The specified Terracotta server will push its configuration to the client Terracotta client. If more than one Terracotta server is available, enter them in a comma-separated list: TC_CONFIG_PATH=<server_host1>:<dso-port>,<server_host2>:<dso-port> If <server_host1> is unavailable, <server_host2> is used. To complete setting up the Terracotta client's environment, run the following in UNIX/Linux: . ${TC_INSTALL_DIR}/bin/dso-env.sh -q
export JAVA_OPTS="$TC_JAVA_OPTS $JAVA_OPTS"
In Windows, run the following: %TC_INSTALL_DIR%\bin\dso-env.bat -q set JAVA_OPTS=%TC_JAVA_OPTS%;%JAVA_OPTS% Before starting up your application, confirm that the value of JAVA_OPTS is correct. terracotta.xmlThe file terracotta.xml, which contains a fragment of Terracotta configuration, can be part of a Terracotta integration module (TIM). When the TIM is loaded at runtime, terracotta.xml is inserted into the client configuration. For more information on TIMs and terracotta.xml, see the Terracotta Integration Modules Manual.
Which Configuration?Each server and client must maintain separate log directories. By default, server logs are written to %(user.home)/terracotta/server-logs and client logs to %(user.home)/terracotta/client-logs. To find out which configuration a server or client is using, search its logs for an INFO message containing the text "Configuration loaded from". More Information
|
About Terracotta Configuration Files
(None)



