首页 > 代码库 > Tomcat配置
Tomcat配置
1、Tomcat内存参数调整。
[root@localhost ~]# vim /usr/local/tomcat/bin/catalina.sh JAVA_OPTS="$JAVA_OPTS -server -Xmn1024M -Xms2096M -Xmx2096M -Djava.net.preferIPv4Stack=true -Djava.awt.headless=true -Dorg.apache.catalina.connector.RECYCLE_FACADES=false -XX:PermSize=512M -XX:MaxPermSize=512M -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:CMSFullGCsBeforeCompaction=0 -XX:+CMSClassUnloadingEnabled -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:SurvivorRatio=65536 -XX:MaxTenuringThreshold=0 -XX:CMSInitiatingOccupancyFraction=81 -XX:SoftRefLRUPolicyMSPerMB=0 -Xloggc:gc.log -XX:+PrintGCDetails
2、安装tomcat-native以提升tomcat性能
apr下载地址:http://apache.org/
[root@localhost~]#tar -zxvf apr-1.5.1.tar.gz [root@localhost~]#cd apr-1.5.1 [root@localhostapr-1.5.1]#./configure --prefix=/usr/local/apr #安装apr可移植运行库 [root@localhostapr-1.5.1]# make [root@localhostapr-1.5.1]# make install [root@localhost~]# cd /usr/local/tomcat/bin/ [root@localhostbin]# tar xf tomcat-native.tar.gz [root@localhostbin]# cd tomcat-native-1.1.29-src/jni/native/ [root@localhostnative]# ./configure --with-apr=/usr/local/apr --with-java-home=/usr/local/java [root@localhostnative]# make && make install [root@localhost ~]# vim /etc/profile #声明环境变量 LD_LIBRARY_PATH=/usr/local/apr/lib
3、配置多实例Tomcat。
Tomcat下载地址:http://tomcat.apache.org/
[root@localhost~]# tar xf apache-tomcat-7.0.47.tar.gz -C /usr/local #解压tomcat到/usr/local目录 [root@localhost~]# cp -r /usr/local/apache-tomcat-7.0.47/ /usr/local/apache-tomcat-7.0.47-2 #配置Tomcat多实例 [root@localhost~]# mv /usr/local/apache-tomcat-7.0.47/ /usr/local/apache-tomcat-7.0.47-1 [root@localhost~]# ln -sv /usr/local/apache-tomcat-7.0.47-1/ /usr/local/tomcat1 #创建软连接,方便管理 [root@localhost~]# ln -sv /usr/local/apache-tomcat-7.0.47-2/ /usr/local/tomcat2 [root@localhost ~]# vim /etc/profile.d/custom.sh #声明环境变量 CATALINA_HOME_1=/usr/local/tomcat1 CATALINA_HOME_2=/usr/local/tomcat2 JAVA_HOME=/usr/local/java LD_LIBRARY_PATH=/usr/local/apr/lib export CATALINA_HOME_1 CATALINA_HOME_2 JAVA_HOME LD_LIBRARY_PATH export PATH=$PATH:$JAVA_HOME/bin [root@localhost ~]# . /etc/profile.d/custom.sh #执行自定义变量脚本,使之生效 [root@localhost~]# vim /usr/local/tomcat1/bin/startup.sh #修改tomcat的启动和关闭脚本,分别指定tomcat实例家目录 export CATALINA_HOME=$CATALINA_HOME_1 [root@localhost ~]# vim/usr/local/tomcat1/bin/shutdown.sh exportCATALINA_HOME=$CATALINA_HOME_1 [root@localhost ~]# vim/usr/local/tomcat2/bin/startup.sh exportCATALINA_HOME=$CATALINA_HOME_2 [root@localhost ~]# vim /usr/local/tomcat2/bin/shutdown.sh exportCATALINA_HOME=$CATALINA_HOME_2 [root@localhost ~]# vim /etc/init.d/tomcat1 #!/bin/sh # Tomcat init script for Linux. # # chkconfig: 2345 96 14 # description: The Apache Tomcat servlet/JSP container. JAVA_HOME=/usr/local/java CATALINA_HOME=/usr/local/tomcat1 LD_LIBRARY_PATH=/usr/local/apr/lib export JAVA_HOME CATALINA_HOME LD_LIBRARY_PATH exec $CATALINA_HOME/bin/catalina.sh $* [root@localhost ~]# vim /etc/init.d/tomcat2 #!/bin/sh # Tomcat init script for Linux. # # chkconfig: 2345 96 14 # description: The Apache Tomcat servlet/JSP container. JAVA_HOME=/usr/local/java CATALINA_HOME=/usr/local/tomcat2 LD_LIBRARY_PATH=/usr/local/apr/lib export JAVA_HOME CATALINA_HOME LD_LIBRARY_PATH exec $CATALINA_HOME/bin/catalina.sh $* [root@localhost~]# vim /usr/local/tomcat2/conf/server.xml #修改tomcat2默认端口号 ………… <Server port="8006"shutdown="SHUTDOWN"> ………… <Connectorport="8081" protocol="HTTP/1.1" ………… <Connectorport="8010" protocol="AJP/1.3" redirectPort="8443"/>
4、配置redis session共享。
配置redis session共享,把以下3个jar包放到2个tomcat实例的库$CATALINA_HOME_1/lib/ $CATALINA_HOME_2/lib/ commons-pool-1.6.jar jedis-2.1.0.jar tomcat-redis-session-manager-1.1.jar 然后修改$CATALINA_HOME/conf/context.xml指定redis服务器路径 <ValveclassName="com.radiadesign.catalina.session.RedisSessionHandlerValve"/> <ManagerclassName="com.radiadesign.catalina.session.RedisSessionManager"database="0" host="192.168.1.1"maxInactiveInterval="1800" port="1234"/>
5、日志分割。
[root@localhost ~]# tar xf cronolog-1.6.2.tar.gz #安装cron日志分割工具 [root@localhost ~]# cd cronolog-1.6.2 [root@localhost cronolog-1.6.2]# ./configure [root@localhost cronolog-1.6.2]# make && make install
Tomcat配置
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。