tar xf jdk-8u60-linux-x64.tar.gz -C /application/
ln -s /application/jdk1.8.0_60 /application/jdk
sed -i.ori ‘$a export JAVA_HOME=/application/jdk\nexport PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH\nexport CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar‘ /etc/profile
source /etc/profile
java -version
ar xf apache-tomcat-8.0.27.tar.gz -C /application/
ln -s /application/apache-tomcat-8.0.27 /application/tomcat
echo ‘export TOMCAT_HOME=/application/tomcat‘>>/etc/profile
source /etc/profile
chown -R root.root /application/jdk/ /application/tomcat/
chmod +x /application/tomcat/bin/*
/application/tomcat/bin/version.sh
启动关闭tomcat
/application/tomcat/bin/startup.sh
/application/tomcat/bin/shutdown.sh
netstat -tunlp|grep java
http://10.0.0.17:8080/
查看日志,读懂日志
/application/tomcat/logs
catalina.out # 实时记录tomcat运行信息,文件会越来越大,需要定时清空
catalina.时间.log # catalina.out文件每天的日志切割文件
#每个站点访问日志
host-manager.时间.log
localhost_access_log.时间.txt 访问日志
localhost.时间.log
manager.时间.log web页面上操作,会记录到这里
[root@web03 webapps]# tail -4 /application/tomcat/conf/tomcat-users.xml
<role rolename="manager-gui"/>
<role rolename="admin-gui"/>
<user username="tomcat" password="tomcat" roles="manager-gui,admin-gui"/>
</tomcat-users>
/application/tomcat/bin/shutdown.sh
/application/tomcat/bin/startup.sh
类似wordpess博客站点
环境:Linux Tomcat JDK MySQL(Mariadb)
yum -y install mariadb-server
systemctl start mariadb.service
mysql
create database jpress DEFAULT CHARACTER SET utf8;
grant all on jpress.* to jpress@‘%‘ identified by ‘123456‘;
上传jpress-web-newest.war到webapps目录
http://10.0.0.17:8080/jpress-web-newest/
网页安装
/application/tomcat/conf/server.xml
<Server port="8005" shutdown="SHUTDOWN">
......
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
......
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
详细说明:http://blog.oldboyedu.com/java-tomcat/
访问jpress地址为:http://10.0.0.200:8080/
访问jpress地址为:http://10.0.0.200:8080/jpress
把下面的内容加到<Host下
<Context path="/jpress" docBase="/application/tomcat/webapps/jpress-web-newest" debug="0" reloadable="false" crossContext="true"/>
[root@web03 tools]# cp -r apache-tomcat-7.0.93 tomcat_1
[root@web03 tools]# cp -r apache-tomcat-7.0.93 tomcat_2
[root@web03 tools]# sed -i ‘s#8005#8006#g‘ tomcat_1/conf/server.xml
[root@web03 tools]# sed -i ‘s#8080#8081#g‘ tomcat_1/conf/server.xml
[root@web03 tools]# sed -i ‘s#8009#8010#g‘ tomcat_1/conf/server.xml
[root@web03 tools]# sed -i ‘s#8005#8007#g‘ tomcat_2/conf/server.xml
[root@web03 tools]# sed -i ‘s#8080#8082#g‘ tomcat_2/conf/server.xml
[root@web03 tools]# sed -i ‘s#8009#8011#g‘ tomcat_2/conf/server.xml
[root@web03 tools]# mv tomcat_* /application/
[root@web03 application]# /application/tomcat_1/bin/startup.sh
[root@web03 application]# /application/tomcat_2/bin/startup.sh
[root@web03 application]# echo default-8080>/application/tomcat/webapps/ROOT/index.jsp
[root@web03 application]# echo default-8081>/application/tomcat_1/webapps/ROOT/index.jsp
[root@web03 application]# echo default-8082>/application/tomcat_2/webapps/ROOT/index.jsp
第一步:zabbix server 端安装zabbix_java_gateway(java程序),也需要jdk(openjdk) (做1次)
rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
yum -y install zabbix-java-gateway
systemctl start zabbix-java-gateway.service
netstat -tunlp|grep java
第二步:Zabbix Server 需要开启java监控功能(做1次)
sed -i -e ‘220a JavaGateway=127.0.0.1‘ -e ‘236a StartJavaPollers=5‘ /etc/zabbix/zabbix_server.conf
systemctl restart zabbix-server.service
第三步:web服务器上,Tomcat需要开启远程监控功能 (每一个实例都要做)
vim /application/tomcat8_1/bin/catalina.sh +97
CATALINA_OPTS="$CATALINA_OPTS
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=12345
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Djava.rmi.server.hostname=10.0.0.17"
#主机名解析
echo "10.0.0.17 web03" >>/etc/hosts
/application/tomcat8_1/bin/shutdown.sh
/application/tomcat8_1/bin/startup.sh
netstat -tunlp|grep 12345
第四步:zabbix页面配置
1.Tomcat自带函数检测:meminfo.jsp
2.jps命令:jdk包带的命令,jps主要用来输出JVM中运行的进程状态信息。
语法格式:jps [options] [hostid]
如果不指定hostid就默认为当前主机或服务器。
参数说明:
-q 不输出类名、Jar名和传入main方法的参数
-m 输出传入main方法的参数
-l 输出main类或Jar的全名
-v 输出传入JVM的参数
jps -lvm #→快速获取Java进程的pid,不用ps和grep
3.jstack:主要用来查看某个Java进程内的线程堆栈信息。
jstack可以定位到线程堆栈,根据堆栈信息我们可以定位到具体代码,所以它在JVM性能调优中使用得非常多。
排除tomcat故障步骤
a. 查看catalina.out
b. sh show-busy-java-threads.sh
c.jstack PID
[root@web03 application]# sh show-busy-java-threads.sh
[1] Busy(0.0%) thread(1784/0x6f8) stack of java process(1784) under user(root):
[2] Busy(0.0%) thread(1785/0x6f9) stack of java process(1784) under user(root):
"DestroyJavaVM" prio=10 tid=0x00007f2ec8009000 nid=0x6f9 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
[3] Busy(0.0%) thread(1786/0x6fa) stack of java process(1784) under user(root):
"VM Thread" prio=10 tid=0x00007f2ec805f000 nid=0x6fa runnable
[4] Busy(0.0%) thread(1787/0x6fb) stack of java process(1784) under user(root):
"Reference Handler" daemon prio=10 tid=0x00007f2ec8063800 nid=0x6fb in Object.wait() [0x00007f2ec4841000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000000f0a64608> (a java.lang.ref.ReferenceLock)atjava.lang.Object.wait(Object.java:503)atjava.lang.ref.ReferenceReferenceHandler.run(Reference.java:133)
- locked <0x00000000f0a64608> (a java.lang.ref.Reference$Lock)
[5] Busy(0.0%) thread(1788/0x6fc) stack of java process(1784) under user(root):
"Finalizer" daemon prio=10 tid=0x00007f2ec8065800 nid=0x6fc in Object.wait() [0x00007f2ec4740000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000000f0a64560> (a java.lang.ref.ReferenceQueueLock)atjava.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135)?locked<0x00000000f0a64560>(ajava.lang.ref.ReferenceQueueLock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:151)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:209)
[root@web03 application]# jstack 1784
4.jconsole和jvisualvm
这是windows安装完jdk后的图形监控工具。
C:\Program Files\Java\jdk1.8.0_31\bin
tomcat性能取决于你的内存大小。
上策:优化代码
中策:jvm优化机制--垃圾回收机制,把不需要的内存回收
优化jvm--优化垃圾回收策略
优化catalina.sh配置文件。在catalina.sh配置文件中添加以下代码:
#tomcat分配1G内存模板
JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms1024m -Xmx1024m -XX:NewSize=512m -XX:MaxNewSize=512m -XX:PermSize=512m -XX:MaxPermSize=512m"
原文:https://blog.51cto.com/10983441/2426113