查看linux系统编码:vi /etc/sysconfig/i18n
1.jdk的安装
tomcat7需要使用jdk6
wget http://download.oracle.com/otn-pub/java/jdk/6u25-b06/jdk-6u25-linux-i586.bin
cd /opt
cp jdk-6u25-linux-i586.bin ./
./jdk-6u25-linux-i586.bin
vi /etc/profile 在最后添加如下行
export JAVA_HOME=/opt/jdk1.6.0_25
export JRE_HOME=$JAVA_HOME/jre
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=./:/opt/jdk1.6.0_25/lib:/opt/jdk1.6.0_25/jre/lib
如果要是设置立刻生效运行如下命令
source /etc/profile
2.tomcat的安装设置
wget http://labs.renren.com/apache-mirror/tomcat/tomcat-7/v7.0.14/bin/apache-tomcat-7.0.14-deployer.tar.gz
tar -xzvf apache-tomcat-7.0.14-deployer.tar.gz
mv apache-tomcat-7.0.14-deployer tomcat
setup
Tomcat can be run as a daemon using the jsvc tool from the commons-daemon project.
cd ./bin
tar -xzvf commons-daemon-native.tar.gz
cd commons-daemon-1.0.5-native-src/unix
./configure
如果出现如下报错:
configure: error: Java Home not defined. Rerun with --with-java=... parameter
solution:
export JAVA_HOME=/opt/jdk1.6.0_25
cp jsvc ../..
cd ../..
Tomcat can then be run as a daemon using the following commands.
cd $CATALINA_HOME
./bin/jsvc -cp ./bin/bootstrap.jar:./bin/tomcat-juli.jar \
-outfile ./logs/catalina.out -errfile ./logs/catalina.err \
org.apache.catalina.startup.Bootstrap
#################################################################
tomcat开机自启
cd /opt/tomcat/bin/commons-daemon-1.0.5-native-src/unix/samples
cp Tomcat7.sh /etc/init.d/tomcat.sh
vi tomcat.sh 添加如下:
JAVA_HOME=/opt/jdk1.6.0_25
TOMCAT_HOME=/opt/tomcat
JRE_HOME=$JAVA_HOME/jre
CATALINA_HOME=/opt/tomcat
CATALINA_BASE=$CATALINA_HOME
报错:tomcat 服务不支持 chkconfig
在tomat添加如下
#chkconfig: 345 80 90
#description:auto_run
#########cp Tomcat7.sh ./bin 可以直接使用#######
#################################################################
Once you have configured the catalina.policy file for use with a SecurityManager, Tomcat can be started with a SecurityManager in place by using the "-security" option:
$CATALINA_HOME/bin/catalina.sh start -security (Unix)
%CATALINA_HOME%\bin\catalina start -security (Windows)
4.代理设置
Apache 1.3 Proxy Support
确保 apache的proxy模块安装
1.Configure your copy of Apache so that it includes the mod_proxy module. If you are building from source,
the easiest way to do this is to include the --enable-module=proxy directive on the ./configure command line.
2.If not already added for you, make sure that you are loading the mod_proxy module at Apache startup time, by using the following directives in your httpd.conf file:
LoadModule proxy_module {path-to-modules}/mod_proxy.so
AddModule mod_proxy.c
3.Include two directives in your httpd.conf file for each web application that you wish to forward to Tomcat.
For example, to forward an application at context path /myapp:
ProxyPass /myapp http://localhost:8081/myapp
ProxyPassReverse /myapp http://localhost:8081/myapp
which tells Apache to forward URLs of the form http://localhost/myapp/* to the Tomcat connector listening on port 8081.
4.Configure your copy of Tomcat to include a special <Connector> element, with appropriate proxy settings, for example:
<Connector port="8081" ...
proxyName=" www.mycompany.com"
proxyPort="80"/>
which will cause servlets inside this web application to think that all proxied requests were directed to www.mycompany.com on port 80.
5.It is legal to omit the proxyName attribute from the <Connector> element. If you do so, the value returned by request.getServerName()
will by the host name on which Tomcat is running. In the example above, it would be localhost.
6.If you also have a <Connector> listening on port 8080 (nested within the same Service element), the requests to either port will share the same set of virtual hosts and web applications.
虚拟主机的配置
vi server.xml 在</host>下一行添加如下
<Engine name="Catalina" defaultHost="ren">
<Host name=" www.test.com" appBase="testnapps"/>
<Host name=" www.abc.com" appBase="abcapps"/>
</Engine>
<Connector port="8080" address="192.168.1.123" redirectPort="8443" acceptCount="100" disableUploadTimeout="true"/>
mkdir $CATALINA_HOME/abcapps
vi /etc/hosts
添加如下:
yourserverip www.test.com
yourserverip www.abc.com
修改本地host文件
在运行中输入 drivers 然后打开etc目录在hosts文件添加如下
yourserverip www.test.com
yourserverip www.abc.com
注:如果在运营环境不需要修改hosts文件dns会提供解析,这里为了测试方便,作此修改。
新修改的目录下默认须建ROOT目录,原因如下:
Contexts are normally located underneath the appBase directory. For example, to deploy the foobar context as a war file in the ren host,
use $CATALINA_HOME/renapps/foobar.war. Note that the default or ROOT context for ren would be deployed as $CATALINA_HOME/renapps/ROOT.war (WAR) or $CATALINA_HOME/renapps/ROOT (directory).
修改默认根路径:
在 <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">下添加如下
<Context path="" docBase="/mnt/vivimob/" debug="0" reloadable="true" />
<Context path="/xyz" docBase="/mnt/test/" debug="0" reloadable="true" />
第一个Context用了path="", 如果path=""(注意不是path="/"),则相当于是这个Host的虚拟根目录,docBase则指出了物理目录的位置(可以是绝对也可以是相对于Host的appBase的位置),如果你访问 http://localhost/ 则会使用/mnt/vivimob/里的内容。
第二个Context用了path="/xyz",如果你访问 http://localhost/xyz/ 则会使用/mnt/test/里的内容。
<Context path="/DBTest" docBase="DBTest"
reloadable="true" crossContext="true">
configure your mysqld max_connections large enough to handle
all of your db connections. Set to -1 for no limit.
-->
Set to -1 for no limit. See also the DBCP documentation on this
and the minEvictableIdleTimeMillis configuration parameter.
-->
in ms, in this example 10 seconds. An Exception is thrown if
this timeout is exceeded. Set to -1 to wait indefinitely.
-->
org.gjt.mm.mysql.Driver - we recommend using Connector/J though.
Class name for the official MySQL Connector/J driver is com.mysql.jdbc.Driver.
-->
<!-- url: The JDBC connection url for connecting to your MySQL dB.
-->
maxActive="100" maxIdle="30" maxWait="10000"
username="javauser" password="javadude" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/javatest"/>
<web-app xmlns=" http://java.sun.com/xml/ns/j2ee"
xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<description>MySQL Test App</description>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/TestDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
vi ./conf/web.xml 在文件最后修改如下,修改默认网页。
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>