实现有价值的IT服务
全部博文(709)
分类: Java
2006-08-10 10:49:32
1 Command Line
2 Sample Configurations
3 Topics
4 General Configuration
5 Environment Configuration
6 Server Configuration
7 Port Configuration
8 Virtual Host Configuration
9 Application Configuration
10 Deployment
11 Security Configuration
12 Clustering and Load Balancing
13 Cache Configuration
1.Command Line
Option Description -classpath xxx Adds to the system classpath, default is determined from environment variable CLASSPATH -conf conf/resin.conf specifies the resin.conf file -Dfoo=bar sets the JVM system property `foo' to the value `bar' -install (windows) install Resin as a service with a default name (but doesn't automatically start) -install-as name (windows) install Resin as a named service (but doesn't automatically start) -Jxxx passes xxx to the JVM -J-verbosegc turns on JVM garbage collection information (recommended) -java_home xxx sets the JDK, default is determined from environment variable JAVA_HOME or a heuristic search. -jvm-log file (unix) sets the file to put output that cannot be captured by stdout-log and stderr-log, relative to -server-root, default is log/jvm.log -no-auto-restart disables the automatic restart of the JVM if it exits abnormally -nojit disables the Just-In-Time compiler, useful for debugging with some JDK's -pid file (unix) sets the pid file, default is based on the -server-id -pid-dir dir (unix) sets the directory to store pid files in -remove (windows) remove Resin as a service with a default name -remove-as (windows) remove Resin as a named service -resin-home dir sets the resin.home value, default is determined from RESIN_HOME environment variable or a heuristic search. restart (unix) restarts Resin as a daemon using the pid in the file specfied with -pid -server id sets the resin.server_id value and limits http and srun activation to those with a matching server-id -server-root dir establishes the root directory for server files and sets the resin.root value start (unix) starts Resin as a daemon saving the pid in the file specfied with -pid stop (unix) stops Resin as a daemon using the pid in the file specfied with -pid -verbose show the Java environment before starting Resin -Xxxx passes the -Xxxx configuration to the JVM -Xdebug enable HotSwap class reloading (recommended) [edit]Memory Options Option Description -J-verbosegc turns on JVM garbage collection information (recommended) -Xmx256m set the maximum heap size (recommended) -XX:MaxPermSize=256m the maximum size of the permanent space (recommended) -Xss the stack size, default is 1m The default values for -Xmx and -XX:MaxPermSize are generally too low for a normal deployment. |
2 Sample Configurations
1) minimal.conf
<> <> <> <> <> <> <> <> <document-directory> minimal resin.conf xmlns:resin=""> command line and -server-root unix> bin/httpd.sh -server-root /var/www -conf conf/resin.conf The argument specifies the main directory for the Resin instance. In this example, the document directory is in _/var/www/docs_. As an alternative, either the <> or the <> can specify the actual <>, e.g. . Using the command line adds some flexibility, but also makes the resin.conf more difficult to read as a standalone file. description <> The <> directive is the top-level directive for the resin.conf. xmlns and xmlns:resin The xmlns and xmlns:resin directives define the XML namespaces for the resin.conf. These namespaces are important for the configuration file validation. <> The <> configures a Resin server. Each <> listens to TCP ports (usually HTTP) and defines a number of [virtual hosts]. Although it is possible to have multiple <> items, most sites will only use a single <>. <> The <> directive tells Resin to listen to a HTTP port and interface. <> The <> imports a secondary XML file into the current configuration. In this case, the is a critical import file which defines the JSP servlet, the file servlet, and defines WEB-INF/classes, WEB-INF/lib, WEB-INF/ and WEB-INF/. Without the import of , most of the expected behavior will not occur. <> The <> directive defines a . The <> directive is required, otherwise Resin will simply return messages. The <> of a <> specifies the virtual host's directory. If the path is relative, the root-directory will be relative to the <> root-directory. (If the <> root-directory is unspecified, it defaults to .) <> The <> directive defines a . |
2) development.conf
xmlns:resin="">
|
3) Sample resin.conf
xmlns:core=""> format='%h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"' rollover-period="1W"/>
|
4) fine.conf
xmlns:resin="">
|
Topics
1) Logging
Access logging An access log receives output describing each request received by the server. It is commonly used in conjunction with analysis tools to determine statistics and patterns of use for a website. Examples format='%h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"' rollover-period="1W"/> stdout-log and stderr-log The stdout-log and stderr-log directives capture and redirect the output of and . Examples configuration to capture and output to log files. xmlns:resin=""> rollover-period='1W'/> rollover-period='1W'/> ... log Java programs (including Resin) can use the logging facilities included in the JDK. Log messages have a name and and a level. Logging can be used to enable and to enable application specific logging that utilizes the JDK logging facilities. Examples resin.conf configuration to capture finer logging and display it on the console, useful during development: xmlns:resin=""> ... ... resin.conf configuration to capture finer request and response related logging from Resin, and all logging from the com.hogwarts application under development: xmlns:resin=""> ... Archiving All log directives support archiving, when the log reaches a certain size or age a rollover occurs and the existing log is saved away while a new log is started. path-format and archive-format are two mutually exclusive methods for archiving logs. Rollover determines the frequency at which the archive files are created. path-format path-format specifies the name of a file. The name contains escape sequences that are replaced with the current date and time. When the rollover occurs, a new file is started with the appropriate date and time. Thus path-format results in archive files that are named with the date and time of the first entry in the log. ... rollover-period="1D"/> ... ... archive-format and path Log messages are written to the file specified by . When a rollover occurs the contents of the file are copied to the archive-path. The archive-path contains escape sequences that are replaced with the current date and time. Thus archive-format results in log files that are named with the date and time of the last entry in the log. archive-format can use a *.gz or *.zip extension to indicate that the archived log should be compressed. archive-path="/var/www/log/access.log.%Y%m%d.gz" rollover-period="1D"/> Rollover The fequency of the rollover is is specified with or . rollover-period is a time based specification of a in days (15D), weeks (2W), months (1M), or hours (1h). When the specified time period has elapsed the rollover occurs. rollover-size is a size based specification of a in bytes (50000), kb (128kb), or megabytes (10mb). When the log reaches the specified size the rollover occurs. Disabling rollover To completely disable rollovers, set the rollover-size to such a high number that it will never occur: |
General Configuration
1)EL Configuration Variables
Globally Available Variables
Globally Available Functions
The java object has the following methods
The resin object has the following methods
The server variable has a number of fields/methods available (defined in com.caucho.server.resin.ServerController$Var)
|
2)Configuration EL Library
Resin 3.0.14 has added the capability of adding functions to the resin.conf EL expressions. The builtin functions are: 1. class_exists - test if the class is loadable 2. jndi_lookup - perform a jndi lookup of the name 3. jndi - shorthand for jndi_lookup The standard configuration library is com.caucho.config.lib.ResinConfigLibrary. Libraries are configured using the standard META-INF/services convention. First, create a Java class with static methods you'd like to create as a library. Then create a META-INF/services/com.caucho.config.ConfigLibrary file: com.caucho.config.ConfigLibrary file com.foo.MyLibrary For example, you could create an add method: package com.foo; public class MyLibrary { public static int add(int a, int b) { return a + b; } } Then, in your resin.conf you could use EL expressions like "${add(3, 17)}" |
3)Control directives
The directives in the namespace provide general configuration abilities like conditional configuration. In general, we recommend avoiding the use of resin:if and resin:choose when possible, in order to keep configuration files manageable.
resin:import imports a configuration file into the current tag. The configuration file will match the current context, the a resin:import file in a
The web.xml and resin-web.xml files are loaded with a resin:import tag in the conf/app-default.xml file. [] app-default.xml ...
...
...
|
4)resin:import
resin:import imports a configuration file into the current tag. The configuration file will match the current context, the a resin:import file in a
The web.xml and resin-web.xml files are loaded with a resin:import tag in the conf/app-default.xml file. app-default.xml ...
...
... |
5)Custom Configuration
Overview
Resin provides a configuration API to populate application beans from an XML file. Resin's configuration machinery supports Inversion of Control and allows the use of EL expressions. Using Resin to parse XML
Resin's configuration API is the easiest method to parse XML. Create Java classes mirroring the XML file. Call Resin's configuration with an instance of the classes and the XML file. Calling the Configuration import com.caucho.config.*; ...
Config config = new Config(); MovieListing movies = new MovieList(); InputStream is = ...; config.configure(bean, is);
Sample XML Parsing
Sample XML File
To model the XML file, you'll use a Movie class and a MovieListener class: Movie.java public class Movie { private String _director; private String _title; public void setDirector(String director) { _director = director; } public void setTitle(String title) { _title = title; } }
The movie listing encapsulates a list of movies MovieListing.java public class MovieListing { private ArrayList _movies = new ArrayList(); public void addMovie(Movie movie) { _movies.add(movie); } } |
Environment Configuration
1)Environment
Environment
|
2) Database Configuration
Connection Configuration
The JDBC connections can be initialized with specified values of the transaction-isolation, catalog, and read-only values. The resin.conf
...
Transaction (XA) Configuration
The If true, connections automatically participate in any , i.e. a .begin() will enlist the connection into the new transaction and commit() will commit the transactions. The default value is true. Non-transactional data sources
In some cases, it is convenient to have a transactional (xa) data source and a non-transactional data source to the same database. For example, a connection that only selects data from read-only tables does not need to participate in a transaction. In that case, it is more efficient to mark the read-only connection as non-transactional by setting |
Server Configuration
1)
The
resin.conf
xmlns:resin=""> ... ...
|
2)
Server The <server> directive occurs in the <resin> top-level directive. It allows any Environment configuration. Multiple <server> directives are allowed as long as they have different id values.
|
3)Security Configuration
<>
As part of the HTTP response, Resin sends its name and version number in a server header, e.g. To enable this, in the resin.conf ...
... ...
|
4)Log Configuration
Access logging An access log receives output describing each request received by the server. It is commonly used in conjunction with analysis tools to determine statistics and patterns of use for a website. Examples format='%h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"' rollover-period="1W"/> stdout-log and stderr-log The stdout-log and stderr-log directives capture and redirect the output of System.out and System.err. Examples resin.conf configuration to capture System.out and System.err output to log files. xmlns:resin=""> rollover-period='1W'/> rollover-period='1W'/> ... log Java programs (including Resin) can use the logging facilities included in the JDK. Log messages have a name and and a level. Logging can be used to enable Resin logging names and to enable application specific logging that utilizes the JDK logging facilities. Examples resin.conf configuration to capture finer logging and display it on the console, useful during development: xmlns:resin=""> ... ... resin.conf configuration to capture finer request and response related logging from Resin, and all logging from the com.hogwarts application under development: xmlns:resin=""> ... Archiving All log directives support archiving, when the log reaches a certain size or age a rollover occurs and the existing log is saved away while a new log is started. path-format and archive-format are two mutually exclusive methods for archiving logs. Rollover determines the frequency at which the archive files are created. path-format path-format specifies the name of a file. The name contains date format escape sequences that are replaced with the current date and time. When the rollover occurs, a new file is started with the appropriate date and time. Thus path-format results in archive files that are named with the date and time of the first entry in the log. ... rollover-period="1D"/> ... ... archive-format and path Log messages are written to the file specified by path. When a rollover occurs the contents of the file are copied to the archive-path. The archive-path contains date format escape sequences that are replaced with the current date and time. Thus archive-format results in log files that are named with the date and time of the last entry in the log. archive-format can use a *.gz or *.zip extension to indicate that the archived log should be compressed. archive-path="/var/www/log/access.log.%Y%m%d.gz" rollover-period="1D"/> Rollover The fequency of the rollover is is specified with rollover-period or rollover-size. rollover-period is a time based specification of a period in days (15D), weeks (2W), months (1M), or hours (1h). When the specified time period has elapsed the rollover occurs. rollover-size is a size based specification of a size in bytes (50000), kb (128kb), or megabytes (10mb). When the log reaches the specified size the rollover occurs. Disabling rollover To completely disable rollovers, set the rollover-size to such a high number that it will never occur: |
Port Configuration
1)
|
2)
Port It is possible to configure Resin to listen to custom protocols using the In fact, <http> and <srun> are specializations of port: Configuring a HTTP port xmlns:resin=""> ... ... Configuring a Srun port outside of a cluster xmlns:resin=""> ... ... |
3)
A srun is a backend port listing to requests from a load balancer. configuration directives
|
Virtual Host Configuration
1)
The
xmlns:resin=""> ... ... root-directory="/var/www/foo.com"> ... |
2)
Host-default
Contains default <host> configuration for all virtual hosts in a <server> (or in a <host-deploy>.) host-default can be useful for configuring all virtual hosts with a common directory structure or access logging. For example, to configure all virtual hosts to use a directory and have a separate root web-app in docs, you could use: resin.conf ...
...
..
|
3)
Host-deploy The Essentially, it's an automatic directory for For example, in the default resin.conf, if you drop a foo.jar in /hosts, it will expand to hosts/foo and be browseable at . It's also possible to create a without a .jar file by creating a directory in the hosts. ... ...
|
Application Configuration
1)
Web-app The
|
2)
Web-app-default
The The The best example of app-default.xml
...
|
3)
Web-app-deploy The Essentially, it's an automatic directory for For example, in the default resin.conf, if you drop a foo.war in /webapps, it will expand to webapps/foo and be browseable at . It's also possible to create a Web Application without a .war files by creating a directory in the webapps without ... ...
|
4)
Rewrite-dispatch The Overview The Starting with Resin 3.0.19, Escaping Since the rewrite rules are written in Resin's XML configuration files, XML escaping rules apply. In particular a & character must be escaped with & 302 Redirecting a URL To redirect a URL with a HTTP 302 redirect use: 301 Permanently Move a URL To redirect a URL with a HTTP 301 moved-permanently use: (requires Resin 3.0.18) Forwarding a URL To internally forward a URL to a target using the Servlet forward() call use: 403 Forbidden To send a HTTP 403 forbidden message for a URL, use: 404 Not Found To send a HTTP 404 Not Found message for a URL, use: 410 Gone To send a HTTP 410 Gone message for a URL, use: |
5)resin-web.xml
Since most applications will only be deploying to a single web server, they will typically just create a resin-web.xml as the configuration file in WEB-INF. Applications which expect to deploy in multiple web servers will generally create a web.xml with servlet-standard configuration and a separate resin-web.xml for additional configuration for databases and other resources. For validation, the resin-web.xml should declare the Resin validation namespace: . This will let Resin catch XML configuration errors early and give information about the errors. resin-web.xml
... ...
Since Resin 3.0 tries to avoid defaults, the import of web.xml and resin-web.xml is defined in the conf/app-default.xml file as follows: app-default.xml
xmlns:resin="">
...
|