Deploying Tomcat application + configuration optimization in Linux

Source: Internet
Author: User
Http://blog.csdn.net/gaoligaoli/archive/2007/06/10/1646877.aspx

Configure tomcat in Linux
I. JDK Installation
1. Log On As the root user
2. Open a terminal
3. Enter the LS-l command to view the permissions of the installed files.
# Cd/home
# Cp jdk1.4.2.rpm. bin/usr/local
# Cd/usr/local
Add executable permissions to all users
# Chmod A + x jdk1.4.2.rpm. Bin
#./Jdk1.4.2.rpm. Bin
The jdk1.4.2.rpm file is generated.
Add executable permissions to all users.
Chmod A + x jdk1.4.2.rpm
InstallProgramRpm-IVH jdk1.4.2.rpm
Accept the protocol and press Enter.
Use the default installation directory under/usr/Java /.

Ii. install Tomcat

Tar-xvzf jakarta-tomcat-5.5.9.tar.gz

Music jakarta-tomcat-5.5.9 tomcat5.9

After completion, the Tomcat 5.9 directory appears in/usr/tomcat, which contains the Tomcat file.

3. Configure Environment Variables
Vi. bash_profile

Add the following content:
Java_home =/usr/Java/jdk1.5.0 _ 04

Export java_home

Catalina_home =/yewu/tomcat/tomcat5.9

Export catalina_home

Classpath =.: $ java_home/lib: $ catalina_home/common/lib

Export classpath

Path = $ path: $ home/bin: $ java_home/bin

Export path

Save and exit.
4. Configure to start Tomcat
1. Start the file manually. Put the file under the root/bin and name it 100 class.
#! /Bin/sh
Catalina_home =/usr/tomcat-5.0.28
Export catalina_home

$ Catalina_home/bin/startup. Sh
# Case "$1" in
# Start)
# $ Catalina_home/bin/startup. Sh
#;;
# Stop)
# $ Catalina_home/bin/shutdown. Sh
#;;
# Esac
2. automatically start. Put the file under/etc/init. d and name it 100 classserver.
#! /Bin/sh

Case "$1" in
Start)
Catalina_home =/usr/tomcat-5.0.28
Export catalina_home
Java_home =/usr/Java/jdk1.5.0 _ 12
Export java_home
Echo $ java_home
Path = $ java_home/bin: $ path
CD $ catalina_home/bin
$ Catalina_home/bin/startup. Sh
CD-
;;
Stop)
Catalina_home =/usr/tomcat-5.0.28
Export catalina_home
Java_home =/usr/Java/jdk1.5.0 _ 12
Export java_home
Echo $ java_home
Path = $ java_home/bin: $ path
Echo $ path
$ Catalina_home/bin/shutdown. Sh
;;
*)
Echo "Usage: 100 classserver {START | stop }"
Exit 1
Esac

Exit 0
Note: you must go to the ETC/rc2.d directory from RC1 ~ 6. Add the s99100class link. The system automatically loads the Tomcat service at startup.

3. Copy % java_home %/lib/tools. jar to % catalina_home %/common/lib. You can select
4. Add the user name 100class password 100 class under the tomcat-users.xml and add the corresponding role

You can solve it by using the following method: Find the tomcat-users.xml content in the conf folder of the tomcat installation directory and modify it to the following: <? XML version = '1. 0' encoding = 'utf-8'?>
<Tomcat-users>
<Role rolename = "Tomcat"/>
<Role rolename = "role1"/>
<Role rolename = "manager"/>
<Role rolename = "admin"/>
<User Username = "Tomcat" Password = "Tomcat" roles = "Tomcat"/>
<User Username = "both" Password = "Tomcat" roles = "tomcat, role1"/>
<User Username = "role1" Password = "Tomcat" roles = "role1"/>
<User Username = "admin" Password = "admin" roles = "Admin, Manager"/>
</Tomcat-users> 5. Modify the default Tomcat path in Unpackwars = "true" autodeploy = "true"
Xmlvalidation = "false" xmlnamespaceaware = "false"> Add the following: <context Path = "" docbase = "yying" DEBUG = "0" reloadable = "true"/>
5. Call htt: // localhost: 8080/manager to deploy the war file. 6. The system automatically starts the Tomcat service. In Linux, Tomcat can be started and stopped as a daemon, the jsvc tool in the project commons-Daemon must be used. After Tomcat is installed, the source code of this tool {Tomcat}/bin/jsvc.tar.gz is provided. Run the following command to install the tool: Decompress tar zxvf jsvc.tar.gz
Configuration: CD jsvc-Src
Chmod + x configure
./Configure -- With-Java =/usr/JDK
Compile: Make
Test :. the/jsvc-helpjsvc tool contains a script (under the Native directory) to start and stop the Tomcat daemon. However, during the test, the script cannot be set to automatic start, the error message is: the Tomcat service does not support chkconfig, so the script is modified.
Program Code :#! /Bin/sh
#
# STARTUP script for tomcat5
#
# Chkconfig: 345 87 13
# Description: Tomcat daemon
# Processname: jsvc
# Pidfile:/var/run/jsvc. PID
# Config:
#
# Source function library.
./Etc/rc. d/init. d/functions
#
Prog = Tomcat
#
# Small shell script to show how to start/stop Tomcat using jsvc
# If you want to have Tomcat running on port 80 Please modify the server. xml
# File:
#
# <! -- Define a non-ssl http/1.1 Connector on port 80 -->
# <Connector classname = "org. Apache. Catalina. connector. http. httpconnector"
# Port = "80" minprocessors = "5" maxprocessors = "75"
# Enablelookups = "true" redirectport = "8443"
# Acceptcount = "10" DEBUG = "0" connectiontimeout = "60000" type = "codeph" text = "codeph"/>
#
# You need a developement version of Tomcat (Apache Tomcat/4.1-dev)
#
# Adapt the following lines to your configuration java_home =/usr/jdk1.5.0
Catalina_home =/Apache/tomcat
Daemon_home = $ catalina_home/bin/jsvc-Src
Tomcat_user = root
Tmp_dir =/var/tmp
Catalina_opts =
Classpath = $ java_home/lib/tools. jar: $ catalina_home/bin/commons-daemon.jar: $ catalina_home/bin/Bootstrap. jarstart (){
Echo-N $ "Starting $ prog :"
#
# Start Tomcat
#
$ Daemon_home/jsvc \
-User $ tomcat_user \
-Home $ java_home \
-Dcatalina. Home = $ catalina_home \
-Djava. Io. tmpdir = $ tmp_dir \
-OUTFILE $ catalina_home/logs/Catalina. Out \
-Errfile '& 1 '\
$ Catalina_opts \
-CP $ classpath \
Org. Apache. Catalina. startup. Bootstrap
#
# To get a verbose JVM
#-Verbose \
# To get a debug of jsvc.
#-Debug \
Retval =$?
[$ Retval = 0] & Touch/var/lock/subsys/jsvc
[$ Retval = 0] & echo_success | echo_failure
Echo
Return $ retval
}
Stop (){
Echo-N $ "Stopping $ prog :"
#
# Stop Tomcat
#
PID = 'cat/var/run/jsvc. PID'
Kill $ PID
Retval =$?
[$ Retval = 0] & RM/var/lock/subsys/jsvc
[$ Retval = 0] & echo_success | echo_failure
Echo
Return $ retval
} Case "$1" in
Start)
Start
; Stop)
Stop
; Restart | RELOAD)
Stop
Start
;;*)
Echo "usage $0 start/stop"
Exit 1 ;;
Esac modifies the path information in the downloaded script and the user who wants to start Tomcat (the user must already exist)
Copy the script to the Tomcat file in the/etc/rc. d/init. d directory and grant the script executable permission chmod + x Tomcat
You can run the/etc/rc. d/init. d/tomcat START | Stop command to verify whether the daemon can be started and stopped properly. Next, set the script to automatically run when the system starts and stop automatically when the system is turned off. Run the following command:
Chkconfig -- add Tomcat
After the system is restarted, you can view the information of starting tomcat... [OK] During the startup process. This completes the setup process.

Appendix: Operations of the VI Editor

Open File: VI file name

Switch from command mode to input mode:

Switch the input mode to the command mode: ESC

Last line mode ::

Save: W

Save and exit: WQ

Force exit without saving: Q!

Save and force Exit: WQ!

Move the cursor to the beginning of the file :[[

Move the cursor to the end of the file:]

Down the page: Ctrl + F

Flip: Ctrl + B

Optimization:Tomcat5. Common optimization and Configuration

========================================================== ======================================
1. JDK memory optimization:
Tomcat The default memory used is 128 MB. In Windows, the file {tomcat_home}/bin/Catalina. in bat and UNIX, in {tomcat_home}/bin/Catalina. before SH, add the following Configuration:
Java_opts = '-XMS [initial memory size]-xmx [maximum memory available]
Generally, you should use 80% of the physical memory as the heap size.
2. connector optimization:
In Tomcat In the configuration file server. XML, the connection-related parameters include:
Maxthreads:
Tomcat Use a thread to process each received request. This value indicates Tomcat The maximum number of threads that can be created. The default value is 200.
Acceptcount:
Specify the number of threads that can be used to process requests, and the number of requests that can be placed in the processing queue. Requests that exceed this number will not be processed. The default value is 10.
Minsparethreads:
Tomcat The number of threads created during initialization. The default value is 4.
Maxsparethreads:
Once the created thread exceeds this value, Tomcat The socket thread that is no longer needed will be closed. The default value is 50.
Enablelookups:
Whether to reverse query the domain name. The default value is true. Set to false to improve processing capability.
Connnectiontimeout:
Network Connection timeout. The default value is 60000. Unit: milliseconds. If the value is set to 0, the timeout is never reached. This poses a risk. Generally, it can be set to 30000 ms.
Maxkeepaliverequests:
Number of requests to be retained. The default value is 100.
Buffersize:
The input stream buffer size. The default value is 2048 bytes.
Compression:
Compression and transmission. Optional values: On, off, and force. Default Value: off.
The parameters related to the maximum number of connections are maxthreads and acceptcount. To increase the number of concurrent connections, increase the two parameters at the same time. The maximum number of connections allowed by the Web server is also subject to the kernel parameter configuration of the operating system. Generally, Windows has about 2000 connections and Linux has about 1000 connections.
3, Tomcat How to disable and allow documents in the column directory
In {tomcat_home}/CONF/Web. XML, set the listings parameter to false, as shown below:
<Servlet>
...
<Init-param>
<Param-Name> listings </param-Name>
<Param-value> false </param-value>
</Init-param>
...
</Servlet>
4, Tomcat How to disable and allow access from hosts or IP addresses
<Host name = "localhost"...>
...
<Valve classname = "org. Apache. Catalina. Valves. remotehostvalve"
Allow = "* .mycompany.com, www.yourcompany.com"/>
<Valve classname = "org. Apache. Catalina. Valves. remoteaddrvalve"
Deny = "192.168.1. *"/>
...
</Host>
This is the configuration of our server. The specific document cannot be provided to you, because it involves company secrets, so I will give it to you, And I copied it.
Java_opts = '-server-xms512m-xmx768m-XX: newsize = 128 M-XX: maxnewsize = 192 m-XX: Export vorratio = 8'

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.