当前位置: 首页>移动开发>正文

综合架构tomcat

涓€.鏈熸湯鏋舵瀯鏈嶅姟tomcat

1.jre-jdk-jvm浠嬬粛
jre
java runtime enviroment java杩愯鐜
jdk
java delelopment kit java寮€鍙戠幆澧?寰堝鍐呭) = jre + 棰濆java宸ュ叿
jvm
 java virtual machine java铏氭嫙鏈?
**1浠戒唬鐮?鎯冲湪涓嶅悓鐨勭郴缁熶娇鐢?
**java 绋嬪簭浠g爜 杩愯鍦╦ava铏氭嫙鏈轰腑 鍙绯荤粺鑳芥湁java鐜(java铏氭嫙鏈? 灏卞彲浠ヨ繍琛屼唬鐮?
**1浠戒唬鐮?澶勫浣跨敤闂 浠g爜鍙Щ妞嶆€?
**瀵逛簬 java铏氭嫙鏈?涓€鑸叧娉?鍐呭瓨浣跨敤鎯呭喌

浜?鍑嗗鐜涓庨儴缃?/h2>
1.web03
##jdk
#鍚勭鐗堟湰锛?
https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/
2.閮ㄧ讲 jdk
[root@oldboy-tomcat ~]# tar xf /app/tools/jdk-8u241-linux-x64.tar.gz  -C  /app/
[root@oldboy-tomcat ~]# ln -s /app/jdk1.8.0_241/       /app/jdk
3.java jdk 鐜鍙橀噺
cat >>/etc/profile<<'EOF'
export JAVA_HOME=/app/jdk
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export
CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar
export TOMCAT_HOME=/app/tomcat
EOF
[root@oldboy-tomcat ~]# . /etc/profile   杩愯
4.妫€鏌?jdk鏄惁閮ㄧ讲瀹屾垚
[root@oldboy-tomcat ~]# java -version
java version "1.8.0_241"
Java(TM) SE Runtime Environment (build 1.8.0_241-b07)
Java HotSpot(TM) 64-Bit Server VM (build 25.241-b07,mixed mode)
5.閮ㄧ讲 tomcat
[root@oldboy-tomcat ~]# tar xf /app/tools/apache锟絫omcat-8.5.50.tar.gz -C /app/
[root@oldboy-tomcat ~]# ln -s /app/apache-tomcat锟?.5.50/ /app/tomcat
6.妫€鏌dk+tomcat
[root@oldboy-tomcat ~]#
/app/tomcat/bin/version.sh
Using CATALINA_BASE: /app/tomcat
Using CATALINA_HOME: /app/tomcat
Using CATALINA_TMPDIR: /app/tomcat/temp
Using JRE_HOME: /app/jdk
澶浜嗕笉鍐欎簡

1.tomcat鏈嶅姟绠$悊

综合架构tomcat,第1张
鍚姩tomcat
[root@web01tools]#/application/tomcat/bin/startup.sh
Using CATALINA_BASE: /application/tomcat
Using CATALINA_HOME: /application/tomcat
Using CATALINA_TMPDIR: /application/tomcat/temp
Using JRE_HOME: /application/jdk
鍚姩鎴愬姛鎻愮ず澶浜嗕笉鍐欎簡
妫€鏌ョ鍙d笌鏈嶅姟
[root@web01 tools]# ss -lntup|grep java
[root@web01 tools]#ps  -ef  |grep   java

web璁块棶10.0.0.7:8080

2.tomcat鐩綍缁撴瀯

综合架构tomcat,第2张

3.tomcat绠$悊绔?/h2>
综合架构tomcat,第3张
*娉ㄦ剰锛歵omcat 8.5 瀵圭鐞嗙闄愬埗鏇翠弗鏍?
*瑕侀厤缃畉omcat-user.xml涔嬪
*杩橀檺鍒?鍙兘鍦ㄦ湰鍦颁娇鐢?27.0.0.1 璁块棶绠$悊鐨?
*浠巘omcat8.5寮€濮?绠$悊绔粯璁ゅ彧鑳介€氳繃 鏈湴浣跨敤 127.0.0.1 璁块棶 (绫讳技浜巒ginx all 127.0.0.1 ; deny all; )
*榛樿鎯呭喌涓嬶紝鍙兘浠庝笌Tomcat杩愯鍦ㄥ悓涓€鍙拌绠楁満涓婄殑娴忚鍣ㄨ闂鐞嗗櫒銆傚鏋滆淇敼姝ら檺鍒讹紝鍒欓渶瑕佺紪杈戠鐞嗗櫒鐨刢ontext.xml鏂?
浠躲€?

3.1鏌ョ湅鐧婚檰闄愬埗淇敼
鍘熸枃涓?
[root@web03 /app/tomcat]# find -type f -name 
"context.xml" |xargs grep 127
./webapps/host-manager/META-INF/context.xml:         
allow="127\d.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
./webapps/manager/META-INF/context.xml:         
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
./webapps/host-manager/WEB-INF/manager.xml:         
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
淇敼涓?
[root@web03 /app/tomcat]# find -type f -name 
"context.xml" |xargs grep allow
./webapps/host-manager/META-INF/context.xml:         
allow="\d+\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
./webapps/manager/META-INF/context.xml:         
allow="\d+\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
allow="\d+\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1"
/>
3.2淇敼鐧婚檰璐﹀彿瀵嗙爜conf/tomcat-user.xml
综合架构tomcat,第4张
淇敼涓?/h5>
[root@web03 ~]# cat  /app/tomcat/conf/tomcat-users.xml |grep  role
  NOTE:  By default, no user is included in the "manager-gui" role required
  NOTE:  The sample user and role entries below are intended for use with the
  <role rolename="admin-gui"/>
  <role rolename="manager-gui"/>
  <role rolename="host-gui"/>
  <user username="oldboy" password="oldboy" roles="admin-gui,manager-gui,host-gui"/>
3.3鍥犱负鏄慨鏀圭殑閰嶇疆鏂囦欢鎵€浠ラ渶瑕侀噸鍚?/h5>
鍏抽棴
[root@web03 ~]#  # /app/tomcat/bin/shutdown.sh 
閲嶅惎
[root@web03 ~]#  # /app/tomcat/bin/startsh 

3.4鎻愮ず鐧婚檰鐘舵€?/h4>
综合架构tomcat,第5张

3.5鐧诲綍鎴愬姛鏄剧ず鐨勪俊鎭?/h5>
综合架构tomcat,第6张

综合架构tomcat,第7张

综合架构tomcat,第8张

4.tomcat鏃ュ織涓庤繘绋嬩俊鎭?/h2>

4.1 杩涚▼淇℃伅
#ps鍛戒护鏌ヨ java杩涚▼淇℃伅
[root@web03 ~]# ps  -ef  |grep  java
root      27620      1  0 10:01        00:00:53 /app/jdk/bin/java -Djava.util.logging.config.file=/app/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /app/tomcat/bin/bootstrap.jar:/app/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/app/tomcat -Dcatalina.home=/app/tomcat -Djava.io.tmpdir=/app/tomcat/temp org.apache.catalina.startup.Bootstrap start
root      28705  27620  0 12:10        00:00:49 /app/jdk1.8.0_60/jre/bin/jav -Xms8m -Xmx32m -Dfile.encoding=UTF-8 -Duser.dir=/app/tomcat/webapps/zrlog/WEB-INF/plugins -jar /app/tomcat/webapps/zrlog/WEB-INF/plugins/plugin-core.jar 21913 41913 /app/tomcat/webapps/zrlog/WEB-INF/db.properties /app/tomcat/webapps/zrlog/WEB-INF/plugins/jars 51913 /app/tomcat/webapps/zrlog 2.1.14
root      29617  29411  0 15:35 pts/2    00:00:00 grep --color=auto java
 
jps鏌ョ湅   jps   -lvm 鏄剧ず鏈€璇︾粏鐨勪俊鎭? 涔熷彲鍒嗗紑鏌ョ湅
*[root@web03 ~]# jps
28705 plugin-core.jar
27620 Bootstrap
29662 Jps
*[root@web03 ~]# jps  -lvm
28705 /app/tomcat/webapps/zrlog/WEB-INF/plugins/plugin-core.jar 21913 41913 /app/tomcat/webapps/zrlog/WEB-INF/db.properties /app/tomcat/webapps/zrlog/WEB-INF/plugins/jars 51913 /app/tomcat/webapps/zrlog 2.1.14 -Xms8m -Xmx32m -Dfile.encoding=UTF-8 -Duser.dir=/app/tomcat/webapps/zrlog/WEB-INF/plugins
29682 sun.tools.jps.Jps -lvm -Denv.class.path=.:/app/jdk/lib:/app/jdk/jre/lib:/app/jdk/lib/tools.jar -Dapplication.home=/app/jdk1.8.0_60 -Xms8m
27620 org.apache.catalina.startup.Bootstrap start -Djava.util.logging.config.file=/app/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -Dcatalina.base=/app/tomcat -Dcatalina.home=/app/tomcat -Djava.io.tmpdir=/app/tomcat/temp

浣跨敤jps   -lvm   |grep   -V   jps
[root@web03 ~]# jps  -lvm  |grep   jps
29698 sun.tools.jps.Jps -lvm -Denv.class.path=.:/app/jdk/lib:/app/jdk/jre/lib:/app/jdk/lib/tools.jar -Dapplication.home=/app/jdk1.8.0_60 -Xms8m


## java 楂樼骇鍛戒护 Troubleshooting Tools
##jmap 鍙栧嚭 java杩涚▼淇℃伅 jvm鍐呭瓨淇℃伅 heap memory
details for a process, core file
##瀵煎嚭 淇℃伅  jmap  -heap   java_pid 锛坧id灏辨槸涓婇潰鐨勮繃婊ゅ嚭鏉ョ殑鏁板瓧锛?
[root@web03 ~]#  jps -lvm |grep -v jps |cut -d" "  -f1
[root@web03 ~]# jmap  -heap  28705
浼氬嚭缁撴灉

鏄剧ずjava鐪熷疄鐨勮繘绋嬩俊鎭?
#jstack    鍔爌id    Java process   鏄剧ずjava杩涚▼鎵ц娴佺▼ 璋冪敤淇℃伅 Troubleshooting Tools
4.2tomcat鏃ュ織
综合架构tomcat,第9张
catalina.out   鏃ュ織涓昏鐪?
#error 閿欒
#startup 鎴?finished 鍚姩鎵€闇€鐨勬椂闂?

5.tomcat閰嶇疆鏂囦欢

综合架构tomcat,第10张
#server.xml
#绔彛閮ㄥ垎
###8005 shutdown绔彛
22 琛? <Server port="8005" shutdown="SHUTDOWN">
###tomcat shutdown绔彛 telnet/nc 杩炴帴鍒拌繖涓鍙?杈撳叆鏆楀彿tomcat灏嗕細鍏抽棴

###8080 http鍗忚绔彛
69     <Connector port="8080" protocol="HTTP/1.1"
70                connectionTimeout="20000"     
71                redirectPort="8443" />

###8009 ajp鍗忚绔彛 涓巃pache杩炴帴浣跨敤
115     <!-- Define an AJP 1.3 Connector on port 8009
-->
116     <!--
117     <Connector protocol="AJP/1.3"
118                address="::1"
119                port="8009"
120                redirectPort="8443" />
121     -->

#8009绔彛 鏄敤鏉ョ粰 apache涓巘omcat杩涜杩炴帴浣跨敤
#鐜板湪 tomcat+nginx 鍙互鎶?杩欎竴琛?009娉ㄩ噴 鎻愰珮tomcat鎬ц兘
        <Connector port="8009" protocol="AJP/1.3"
redirectPort="8443" />

#tomcat绠$悊绔?鐩稿簲鐨勯厤缃?
##绠$悊绔?瀹為檯鐢熶骇鐜 鍏抽棴
37   <GlobalNamingResources>
38     <!-- Editable user database that can also be 
used by
39         UserDatabaseRealm to authenticate users
40     -->
41     <Resource name="UserDatabase"
auth="Container"
42               
type="org.apache.catalina.UserDatabase"
43               description="User database that can 
be updated and saved"
44               
factory="org.apache.catalina.users.MemoryUserDatabase
Factory"
                  #鎸囧畾绠$悊绔?瀵嗙爜鏂囦欢
45               pathname="conf/tomcat-users.xml" />
46   </GlobalNamingResources>

#閰嶇疆 tomcat 铏氭嫙涓绘満鐨勫唴瀹?
Nginx           tomcat 
Server_name     Host name 鍩熷悕
root           appBase   绔欑偣鐩綍

#unpackWARs #鑷姩瑙e帇war鍖? 
#autoDeploy 鑷姩閮ㄧ讲 鎶婁唬鐮佸姞杞藉埌jvm鍐呭瓨涓?
148       <Host name="localhost"  appBase="webapps"
149             unpackWARs="true" autoDeploy="true">
150
151         <!-- SingleSignOn valve, share 
authentication between web applications
152             Documentation at: 
/docs/config/valve.html -->
153         <!--
154         <Valve 
className="org.apache.catalina.authenticator.SingleSi
gnOn" />
155         -->
156
157         <!-- Access log processes all example.
158             Documentation at: 
/docs/config/valve.html
159             Note: The pattern used is equivalent 
to using pattern="common" -->

#閰嶇疆 鏃ュ織
160         <Valve 
className="org.apache.catalina.valves.AccessLogValve"
                   directory="logs"
                   #鏃ュ織鏂囦欢 鍓嶇紑鏄痩ocalhost_access_log 

 #鏃ュ織鍚庣紑
161                prefix="access" suffix=".log"
  #鏃ュ織 閲岄潰鐨勬牸寮?  &quot html璇█涓殑 
鍙屽紩鍙?
       #鏃ュ織鍐呭 绫讳技浜?log_format  
162                pattern="%h %l %u %t 
&quot;%r&quot; %s %b" />
163
164       </Host>
#%h   瀹㈡埛绔痠p鍦板潃鎴栬€呮槸鍩熷悕
#%l   (灏忓啓L) 杩滅▼鐢ㄦ埛  
#%u   鐢ㄦ埛 Remote user that was authenticated (if 
any), else '-' (escaped if required)
#%t 鏃堕棿 鏃ユ湡鍜屾椂闂?
#&quot 鍙屽紩鍙?
#%r 璇锋眰璧峰琛?$request 
#%s   $status 鐘舵€佺爜
#%b   澶у皬

6.tomcat 閮ㄧ讲搴旂敤鍙婃柟寮?/h2>

6.1 閮ㄧ讲搴旂敤鏂瑰紡
(1)濡傛灉寮€鍙戠粰浣犵殑鏄痺ar鍖?鍒欐妸war鍖呮斁鍏ュ埌 tomcat webapps 鑷姩瑙e帇 鑷姩閮ㄧ讲
(2)濡傛灉寮€鍙戠粰浣犵殑鏄痡ar鍖?鐩稿綋浜巎ar鍖呴噷闈㈠凡缁忛泦鎴愪簡tomcat java -jar xxxx.jar 閫夐」
综合架构tomcat,第11张

6.2 java寮€婧愯蒋浠?/h2>

锛?锛塲press java wordpress
锛?锛墇rlog java blog

6.3閮ㄧ讲搴旂敤-zrlog

#鍑嗗鏁版嵁搴?
鐧婚檰鏁版嵁搴撳垱寤簔rlog   鍔犲瓧绗﹂泦
create database zrlog charset utf8;

#web03 瀹夎搴旂敤 璁╁簲鐢ㄨ繛鎺?鏁版嵁搴?
cd  /app/tools
鎶妟rlog鍘嬬缉鍖呯┛鍒?app/tools鐩綍涓?
鏀瑰悕
mv  zrlog-2.1.14-5537197-release.war   zrlog.war
澶嶅埗鍒?app/tomcat/webapps
cp          zrlog.war      /app/tomcat/webapps
澶嶅埗杩涘幓鍚庝細鑷姩瑙e帇

6.4鍘荤櫨搴﹀畨瑁?0.0.0.9:8080/zrlog

综合架构tomcat,第12张

综合架构tomcat,第13张
瀹夎瀹屾垚鍚?
ip:8080/zrlog 棣栭〉
http://10.0.0.9:8080/zrlog/admin 绠$悊椤甸潰
综合架构tomcat,第14张

6.5妫€鏌?鏁版嵁搴撹繛鎺ユ枃浠?鍜?鐢ㄦ埛涓婁紶 鐨勭洰褰?/h2>
#鏁版嵁搴撹繛鎺?
[root@web03 /app/tomcat/webapps/zrlog]# cat ./WEB锟絀NF/db.properties 
#This is a database configuration file
#Wed Jun 02 11:14:44 CST 2021
driverClass=com.mysql.cj.jdbc.Driver
user=all
password=123456
jdbcUrl=jdbc\:mysql\://172.16.1.51\:3306/zrlog?
characterEncoding\=UTF锟?&allowPublicKeyRetrieval\=true&useSSL\=false&serverTim
ezone\=GMT
#鐢ㄦ埛涓婁紶
http://10.0.0.9:8080/zrlog/attached/image/20210602/2021
0602111945_677.png

7. tomcat 3绉嶅伐浣滄ā寮? bio , nio , apr

7.1 io妯″瀷鍖哄埆
综合架构tomcat,第15张
7.2淇敼io妯″瀷
###nio
protocol="org.apache.coyote.http11.Http11Nio2Protocol"
#server.xml 涓?淇敼 8080
   <Connector port="8080"
protocol="org.apache.coyote.http11.Http11Nio2Protocol"
               connectionTimeout="20000"
               redirectPort="8443" />
[root@web03 /app/tomcat]# grep -ni nio2   
conf/server.xml
69:   <Connector port="8080"
protocol="org.apache.coyote.http11.Http11Nio2Protocol"
鏌ョ湅淇敼缁撴灉-catalina.out鏃ュ織
17-Dec-2019 10:46:33.106 INFO [main] 
org.apache.coyote.AbstractProtocol.start Starting 
ProtocolHandler ["http-nio2-8080"]

8. tomcat 澶氬疄渚?/h2>

8.1澶氬疄渚?鍦ㄥ悓涓€鍙版湇鍔″櫒涓婇潰杩愯澶氫釜tomcat
搴旂敤鍦烘櫙: 璁╂湇鍔″櫒璧勬簮鍏呭垎鍒╃敤 浣跨敤澶氬疄渚?E7(閾傞噾CPU) 鍐呭瓨 512G 纭洏 1tb pci-e ssd * 8 raid 10 nginx
娉ㄦ剰浜嬮」: 绔彛涓嶅悓涓庤矾寰勪笉鍚?
/app/tomcat 8005
/app/tomcat_8081 8006
/app/tomcat_8082 8007
8.2閰嶇疆tomcat澶氬疄渚?tomcat_8081 tomcat_8082
cp -r /app/tomcat/ /app/tomcat_8081
cp -r /app/tomcat/ /app/tomcat_8082

[root@web03 /app/tomcat]# sed -i 's#8080#8081#g' 
/app/tomcat_8081/conf/server.xml 
[root@web03 /app/tomcat]# sed -i 's#8005#8006#g' 
/app/tomcat_8081/conf/server.xml 
[root@web03 /app/tomcat]# 
[root@web03 /app/tomcat]# sed -i 's#8080#8082#g' 
/app/tomcat_8082/conf/server.xml 
[root@web03 /app/tomcat]# sed -i 's#8005#8007#g' 
/app/tomcat_8082/conf/server.xml

鏌ョ湅绔彛
[root@oldboy-tomcat ~]# ss -lntup |grep java

鍚姩tomcat澶氬疄渚嬩笌妫€鏌?
[root@oldboy-tomcat ~]# /app/tomcat_8081/bin/startup.sh
[root@oldboy-tomcat ~]# 
/app/tomcat_8082/bin/startup.sh

鏌ョ湅绔彛
[root@oldboy-tomcat ~]# ss -lntup |grep java


#curl鎴栨祻瑙堝櫒璁块棶tomcat澶氬疄渚?
###娉ㄦ剰浜嬮」
#10.0.0.7:8080/index.jsp 鐩存帴璁块棶棣栭〉鏂囦欢 鎴?灞曠ず棣栭〉鏂囦欢
#杩欎釜棣栭〉鏂囦欢瀛樻斁鍦╳ebapps/ROOT涓嬮潰 
/app//tomcat/webapps/ROOT/index.jsp 
#10.0.0.7:8080/odboy/index.jsp
#/app//tomcat/webapps/oldboy/index.jsp 
#tomcat璁块棶棣栭〉鏂囦欢 娉ㄦ剰浜嬮」
鍔犲叆鍐呭
[root@web03 /app/tomcat]# echo tomcat_8080 
>/app/tomcat/webapps/ROOT/oldboy.jsp 
[root@web03 /app/tomcat]# echo tomcat_8081 
>/app/tomcat_8081/webapps/ROOT/oldboy.jsp 
[root@web03 /app/tomcat]# echo tomcat_8082 
>/app/tomcat_8082/webapps/ROOT/oldboy.jsp
娴嬭瘯
[root@web03 /app/tomcat]# curl 
10.0.0.9:8080/oldboy.jsp 
tomcat_8080
[root@web03 /app/tomcat]# curl 
10.0.0.9:8081/oldboy.jsp 
tomcat_8081
[root@web03 /app/tomcat]# curl 
10.0.0.9:8082/oldboy.jsp

9tomcat鐨剆ystemctl绠$悊閰嶇疆

1.缂栧啓閰嶇疆鏂囦欢
[root@web03 local]# cat   /usr/lib/systemd/system/tomcat.service 
[Unit]
Description=tomcat 8080 system cmd 
After=network.target remote-fs.target nss-lookup.target


[Service]
Type=forking
ExecStart=/app/tomcat/bin/startup.sh
ExecStop=/app/tomcat/bin/shutdown.sh

[Install]
WantedBy=multi-user.target



2.鎵ц涓€姝?
systemctl  daemon-reload 
3.鏇挎崲鍐呭
sed  -i  '2a source /etc/profile'  /app/tomcat*/bin/startup.sh   /app/tomcat*/bin/shutdown.sh
4.鎵ц
systemctl  daemon-reload 
5.浣跨敤systemctl寮€鍚?
systemctl   start  tomcat
6.鏌ョ湅鍚姩鐘舵€?
systemctl   status  tomcat




鍏朵粬妗堝垪淇敼閲岄潰鐨勬暟瀛?
浠ュ強sed  -i  '2a source /etc/profile'  /app/tomcat*/bin/startup.sh   /app/tomcat*/bin/shutdown.sh

[root@web03 ~]# cat/usr/lib/systemd/system/tomcat_8082.service
[Unit]
Description=tomcat 8082 system cmd 
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/app/tomcat_8082/bin/startup.sh
ExecStop=/app/tomcat_8082/bin/shutdown.sh
[Install]
WantedBy=multi-user.target
systemctl daemon-reload

10.tomcat鐩戞帶鍔熻兘

10.1Tomcat杩滅▼鐩戞帶 搴旂敤:
寮€鍙? 缁欏紑鍙戠暀涓悗闂?寮€鍙?杩愮淮 閫氳繃闂ㄦ煡鐪?tomcat(jvm)
杩愮淮: 閫氳繃鍛戒护妫€鏌omcat淇℃伅 閫氳繃鐩戞帶杞欢妫€鏌ヨ幏鍙杢omcat淇℃伅
10.2閫氳繃鐩戞帶杞欢 鍙互鐩戞帶 tomcat鐘舵€?jvm鐘舵€?
1. 閫氳繃鍛戒护/鑴氭湰鏌ョ湅
2. 寮€鍚痶omcat鐩戞帶鍔熻兘 jmx 鍐嶈zabbix鐩戞帶
10.3閫氳繃鍛戒护琛屾煡鐪?/h5>
*jps
*jmap
*jstack
*ps  jps  -lvm
*sh show-busy-java-threads.sh
涓婁紶show-busy-java-threads.sh鍒發绯荤粺涓洿鎺h鎵ц
[root@web03 ~]# ./show-busy-java-threads.sh
[1] Busy(0.0%) thread(21615/0x546f) stack of java process(21219) under user(root):

process 杩涚▼    鍦ㄥ唴瀛樹腑鍒涘缓绌洪棿
thread 绾跨▼       瀹為檯澶勭悊鐢ㄦ埛璇锋眰
10.4杩涚▼涓庣嚎绋?/h5>
绾跨▼鏄寚杩涚▼鍐呯殑涓€涓墽琛屽崟鍏冿紝
#杩涚▼
杩涚▼鎷ユ湁鑷凡鐙珛鐨勫爢鍜屾爤锛屾棦涓嶅叡浜爢锛屼害涓嶅叡浜爤锛岃繘绋嬬敱鎿嶄綔绯荤粺璋?
搴︺€?
#绾跨▼
绾跨▼鎷ユ湁鑷繁鐙珛鐨勬爤鍜屽叡浜殑鍫嗭紝鍏变韩鍫嗭紝涓嶅叡浜爤锛岀嚎绋嬩害鐢辨搷浣滅郴缁熻皟
搴?
#鍗忕▼鍜岀嚎绋?
鍗忕▼閬垮厤浜嗘棤鎰忎箟鐨勮皟搴︼紝鐢辨鍙互鎻愰珮鎬ц兘:浣嗗悓鏃跺崗绋嬩篃澶卞幓浜嗙嚎绋嬩娇鐢?
澶欳PU鐨勮兘鍔?
杩涚▼涓庣嚎绋嬬殑鍖哄埆
(1)鍦板潃绌洪棿:绾跨▼鏄繘绋嬪唴鐨勪竴涓墽琛屽崟浣嶏紝杩涚▼鍐呰嚦灏戞湁涓€涓嚎绋嬶紝浠栦滑
鍏变韩杩涚▼鐨勫湴鍧€绌洪棿锛岃€岃繘绋嬫湁鐧藉繁鐙珛
鐨勫湴鍧€绌洪棿
(2)璧勬簮鎷ユ湁:杩涚▼鏄祫婧愬垎閰嶅拰鎷ユ湁鐨勫崟浣嶏紝鍚屼竴涓繘绋嬪唴绾跨▼鍏变韩杩涚▼鐨?
璧勬簮
(3)绾跨▼鏄鐞嗗櫒璋冨害鐨勫熀鏈崟浣嶏紝浣嗚繘绋嬩笉鏄?
(4)浜岃€呭潎鍙苟鍙戞墽琛?
(5)姣忎釜鐙珛鐨勭嚎绋嬫湁涓€涓▼搴忚繍琛岀殑鍏ュ彛
10.4linux涓嬮厤缃畉omcat鐩戞帶
#寮€鍚痶omcat杩滅▼鐩戞帶 鍔熻兘  
#淇敼 tomcat/bin/catalina.sh   
#CATALINA_OPTS java鍐呯疆鍙橀噺 淇敼java鍚姩鍙傛暟(tomcat) 
# CATALINA_OPTS java鍚姩鍙傛暟 
CATALINA_OPTS="$CATALINA_OPTS                 
-Dcom.sun.management.jmxremote               #jmx remote 
  寮€鍚痶omcat杩滅▼鐩戞帶鍔熻兘
-Dcom.sun.management.jmxremote.port=12345    #鎸囧畾绔彛
12345 杩樻湁2涓殢鏈虹鍙?
-Dcom.sun.management.jmxremote.authenticate=false  #auth 
璁よ瘉 鏄惁寮€鍚繙绋嬬洃鎺ц璇?鐢ㄦ埛鍚?瀵嗙爜)
-Dcom.sun.management.jmxremote.ssl=false           #鏄惁寮€
鍚痟ttps 
-Djava.rmi.server.hostname=10.0.0.7"             #tomcat
鐩戝惉鐨刬p鍦板潃  
                      #杩欓噷鎴戜滑
涔﹀啓鍏綉ip鍦板潃
                      #鐢熶骇鐜
涔﹀啓鍐呯綉ip 
                      #鏈湴ip 
10.0.0.7 172.16.1.7


[root@web03 ~]# grep -A5 '^CATALINA_OPT' 
/app/tomcat/bin/catalina.sh 
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.9"
鍚姩鏌ョ湅杩涚▼
systemctl   start    tomcat
[root@web03 ~]# ps  -ef  |grep  java
root      22059      1  0 20:29        00:00:06 /app/jdk/bin/java -Djava.util.logging.config.file=/app/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -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.9 -Dignore.endorsed.dirs= -classpath /app/tomcat/bin/bootstrap.jar:/app/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/app/tomcat -Dcatalina.home=/app/tomcat -Djava.io.tmpdir=/app/tomcat/temp org.apache.catalina.startup.Bootstrap start
root      22363  20814  0 21:01 pts/0    00:00:00 grep --color=auto java
閫氳繃绔彛鏌ヨss  -lntup  |grep  java
[root@web03 ~]# ss  -lntip  |grep  java
LISTEN     0      50        [::]:12345                 [::]:*                   users:(("java",pid=22059,fd=20))
LISTEN     0      50        [::]:45178                 [::]:*                   users:(("java",pid=22059,fd=21))
LISTEN     0      1       [::ffff:127.0.0.1]:8005                  [::]:*                   users:(("java",pid=22059,fd=67))
LISTEN     0      50        [::]:34604                 [::]:*                   users:(("java",pid=22059,fd=19))
LISTEN     0      100       [::]:8080                  [::]:*                   users:(("java",pid=22059,fd=56))
澧炲姞浜?2345绔彛
10.5閫氳繃windows jconsole 杩炴帴(妯℃嫙zabbix杩炴帴) linux tomcat
综合架构tomcat,第16张

综合架构tomcat,第17张
10.6jvisualvm
综合架构tomcat,第18张

综合架构tomcat,第19张

综合架构tomcat,第20张

综合架构tomcat,第21张

综合架构tomcat,第22张
10.7tomcat杩滅▼鐩戞帶鍔熻兘灏忕粨
鍛戒护/鑴氭湰: jps -lvm / pstree / show_busy_java_threads.sh 
杩滅▼鐩戞帶鍔熻兘: jmxremote / jmx
灏忓潙: 鍦?tomcat 8.5.x 閰嶇疆寮€鍚姛鑳?淇敼 catalina.sh 鍐欐垚涓€琛?鎴?鍔犱笂
\ (缁)

11. Tomcat鐩稿叧鏁呴殰鍙婃帓閿?/h2>

1. tomcat 寮€鏈鸿嚜鍚姩鏁呴殰
#鑳屾櫙: 
##1.tomcat鐜浣跨敤鐨刯dk 鏄簩杩涘埗
##2. 璁剧疆tomcat寮€鏈鸿嚜鍚姩
#浣跨敤浜岃繘鍒跺畨瑁卝dk鐨勬椂鍊?鐜鍙橀噺涓嶅湪 /bin /sbin 
/usr/local/bin   /usr/local/sbin 
#鍦ㄩ噸鍚氨娌℃湁鎵惧埌杩欎釜鍛戒护
#鍗充娇鍦?/etc/profile 涓篃鏄?鏃犳硶璇嗗埆
闇€瑕佸湪 /etc/rc.local  
.   /etc/profile 
##/etc/rc.local 
. /etc/profile
/app/tomcat/bin/startup.sh
tomcat(java) 鏈嶅姟鍣?杩愯鍗犵敤澶ч噺swap 鐗╃悊鍐呭瓨鍗犵敤杈冨皯
#java浠g爜闂
## 澧炲姞swap 
##Linux鍐呮牳鍙傛暟:
/etc/sysctl.conf   
vm.swappiness=0
sysctl -p  #鍐呮牳鍙傛暟鐢熸晥
vm.swappiness=0     #鎺у埗绯荤粺鏄惁浼樺厛浣跨敤鐗╃悊鍐呭瓨 鏁拌秺灏?瓒婁紭鍏堜娇
鐢ㄧ墿鐞嗗唴瀛?
3.:tomcat璐熻浇楂?15k-20k
鎺掓煡娴佺▼
1. 馃専鏁翠綋鎺掓煡: vmstat /top/ps aux 鎵惧嚭鍝釜杩涚▼鐨勯棶棰?
2. 馃専鎵惧嚭杩涚▼瀵瑰簲绾跨▼id :
1. 閫氳繃top -Hp java杩涚▼id 鎵惧嚭鏄摢涓猨ava绾跨▼鐨勯棶棰?
2. 鎴栬€?show_busy_java_threads.sh 
3. 馃専杞崲:绾跨▼id--->16杩涘埗:闂绾跨▼鐨刬d 杞崲涓?6杩涘埗 绾跨▼id
4. 馃専鎵惧嚭绾跨▼鐨勮缁嗕俊鎭? jstack (鏄剧ずjava 杩涚▼淇℃伅) jstack 
java杩涚▼id 杩囨护 java绾跨▼鐨?6杩涘埗id 涓庡紑鍙戞矡閫?
5. 鏄剧ずjvm淇℃伅: jmap (鏄剧ずjava jvm淇℃伅) jmap -heap java杩涚▼id 
鏄剧ずjvm鐨勫唴瀛樹娇鐢ㄦ儏鍐?
6. jvm鍐呭瓨鍐呭瀵煎嚭:jmap (瀵煎嚭 jvm鍐呭瓨鐨勫唴瀹?) jmap -
dump:format=b,file=/root/tomcat.bin pid
7. 缁欏紑鍙戝垎鏋恓vm瀵煎嚭鏂囦欢:閫氳繃 mat(Eclipse Memory Analyzer 
Tool )鍒嗘瀽 windows
vmstat /top/ps aux
tomcat: 鎵惧嚭杩欎釜tomcat鐨刾id top -Hp 10789 绮剧‘鐨勬壘鍑烘煇涓嚎绋?
瀵艰嚧鐨?
骞朵笖鑳芥壘鍑虹嚎绋嬬殑id 10802 (10杩涘埗)杞崲涓?6杩涘埗

12.https

12.1闆嗙兢
综合架构tomcat,第23张
12.1web绔厤缃?/h5>
web03鍜寃eb04鎵€鏈夌殑閰嶇疆涓€鏍疯繖閲屽氨鍙啓涓€涓簡
1.<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="443" />
 <Engine name="Catalina" defaultHost="zrlog.oldboylinux.cn">
Host name="zrlog.oldboylinux.cn"  appBase="/code/zrlog"
            unpackWARs="true" autoDeploy="true">

鍦ㄨ繖閲屼富瑕佷慨鏀圭綉绔欏悕绉帮紝浠ュ強绔欑偣鐩綍
2.鍒涘缓瀵瑰簲鐨勭珯鐐圭洰褰?
mkdir  -p  /code/zrlog
3.绉诲姩zrlog鐨勬墍鏈夐厤缃枃浠跺埌绔欑偣鐩綍
mv   /app/tomcat/webapps/zrlog*   /code/zrlog

12.2lb绔厤缃?/h2>
1.閰嶇疆鏂囦欢
[root@lb01 ~]# cat  /etc/nginx/conf.d/zrlog.oldboy.com.conf
upstream zrlog {
server 10.0.0.9:8080;
server 10.0.0.10:8080;
}
server {
   listen 80;
   server_name zrlog.oldboylinux.cn;
   return 302 https://zrlog.oldboylinux.cn$request_uri;
}
server {
   listen 443 ssl;
   server_name zrlog.oldboylinux.cn;
   ssl_certificate ssl_key/server.crt;
   ssl_certificate_key ssl_key/server.key;
   location / {
    proxy_pass http://zrlog;
    include  proxy_params;
   }
}
2.鍒涘缓鏀綾a璇佷功鐨勭洰褰?
mkdir  -p  /etc/nginx/ssl_key
涓婁紶璇佷功鍒板垱寤虹殑鐩綍涓?
3.缁欒瘉涔︽敼鍚?
mv 5745132_zrlog.oldboylinux.cn.key  server.key
mv 5745132_zrlog.oldboylinux.cn.pem   server.crt
[root@lb01 ssl_key]# ll 
total 8
-rw-r--r-- 1 root root 3818 Jun  4 08:55 server.crt
-rw-r--r-- 1 root root 1675 Jun  4 08:55 server.key
5.妫€鏌ginx閰嶇疆鏂囦欢鍚姩nginx

12.3娉ㄦ剰浜嬮」
####涔嬪悗鎶婃湰鍦拌В鏋愮殑 zrlog.oldboylinux.cn  瑙f瀽鍒?0.0.0.5   鍘昏闂竴涓?  
####濡傛灉澶辫触妫€鏌ラ厤缃枃浠?
####杩樻湁涓€涓姤閿欏氨鏄祻瑙堝櫒涓€鐩村湪璁╀綘瀹夎  鎴戜滑鍘绘鏌omcat鐨勬暟鎹簱鏂囦欢鏈夋病鏈夎繃鏉?
####绉诲姩鏁版嵁搴撴枃浠剁殑璇濇槸瑕佸叧鎺塼omcat鐨?
####杩欐牱鎴戜滑鐨勯泦缇よ烦杞氨瀹屾垚浜?
1.鍏抽敭鐐癸紝鍦╳eb绔簰浼犵殑鏃跺€欎竴瀹氳鍏抽棴tomcat
2.tomcat鐨勭鍙?涓嶆敼鍙樹竴鐩存槸8080
3.鏈€鍚庡鏋滄姤閿欑殑璇濆崟鍙板崟鍙版祴璇曞鏋滄垚鍔熼偅灏辨槸nginx璐熻浇鐨勯棶棰?

13.tomcat nginx 鍔ㄩ潤鎬佸垎绂?/h2>
综合架构tomcat,第24张

13.1web绔厤缃?/h5>
鍦╳eb04涓婅瀹屼箣鍚? 瑕佸惎鍔╪ginx  棣栧厛瑕佹妸web03涓婄殑tomcat鍏抽棴 涓嶇劧绔彛鍙蜂細鍐茬獊
鍦╳eb04瀹夎nginx
##鐜板湪鎴戜滑鍘婚厤缃畐eb04涓婄殑闈欐€侀〉闈?
[root@web04 conf.d]# vim /etc/nginx/conf.d/zrlog.oldboylinux.cn.conf 
server {
  listen 80;
  server_name zrlog.oldboylinux.cn;
  root /code/zrlog;
}
13.2lb绔厤缃?/h5>
[root@lb01 ~]# vim  /etc/nginx/conf.d/zrlog.oldboy.com.conf 

upstream zrlog {
server 10.0.0.9:80;
}
upstream zrlog_static {
server 10.0.0.10:80;
}
server {
   listen 80;
   server_name zrlog.oldboylinux.cn;
   return 302 https://zrlog.oldboylinux.cn$request_uri;
}
server {
   listen 443 ssl;
   server_name zrlog.oldboylinux.cn;
   ssl_certificate ssl_key/server.crt;
   ssl_certificate_key ssl_key/server.key;
   location / {
    proxy_pass http://zrlog;
    include  proxy_params;
   }
   location ~* \.(jpg|png|jpeg|bmp|gif|js|css)$ {
    proxy_pass http://zrlog_static;
    include  proxy_params;
   }
}
妫€鏌ュ惎鍔╪ginx
鍘荤綉椤垫祴璇?
13.3娉ㄦ剰浜嬮」
web椤甸潰鏄剧ず 502鐨勮瘽  鍘绘鏌eb03 tomcat鐨勯厤缃枃浠?  
鍙兘鏄鍙g殑闂
鐒跺悗灏辨槸妫€鏌ユ瘡涓湇鍔″櫒鐨則omcat   鎴栬€呮槸lb01涓婄殑 nginx
鍚勭鏈嶅姟閮借捣鏉ヤ箣鍚庡憿  鍐嶅幓web椤甸潰璁块棶  


[root@web04 conf]# chown -R nginx.nginx /code/zrlog/
[root@web04 conf]# chmod 755 /code/
[root@web04 conf]# ll -d /code/
drwxr-xr-x 4 root root 33 Jun  4 23:37 /code/
nginx閲岄潰鏉冮檺鑷磋閲嶈

https://www.xamrdz.com/mobile/4mz1996105.html

相关文章: