Tomcat服务器配置文件的详细说明
YPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
æ们é½ç¥éTomcatæ¯éè¦çé ç½®æ件ï¼Tomcatåæ¶ä¹æ¯è½»é级çåºç¨æå¡å¨ï¼å®çåºç°ä¹å¨å¼åä¸ä¹å¾å°äºå¹¿æ³çåºç¨ï¼ä¸é¢è®©ç±ç«ææ¯é¢éå°ç¼å¸¦å¤§å®¶ççTomcatæå¡å¨é ç½®æ件ç详ç»è¯´æå§ã
1. å ¥é¨ç¤ºä¾ï¼èæ主æºæä¾webæå¡
该示ä¾éè¿è®¾ç½®èæ主æºæ¥æä¾webæå¡ï¼å 为æ¯å ¥é¨ç¤ºä¾ï¼æ以设置æå ¶ç®åï¼åªéä¿®æ¹$CATALINA_HOME/conf/server.xmlæ件为å¦ä¸å 容å³å¯ãå ¶ä¸å¤§é¨åé½éç¨äºé»è®¤è®¾ç½®ï¼åªæ¯å¨engine容å¨ä¸æ·»å äºä¸¤ä¸ªHost容å¨ã
é¤äºengineä¸å®ä¹çé»è®¤localhostèæ主æºï¼å¦å¤å¸ç½®äºä¸¤ä¸ªèæ主æºwww.longshuai.comåwww.xiaofang.comï¼å®ä»¬çç¨åºç®å½åå«ä¸º/www/longshuaiå/www/xiaofangï¼æ以éè¦æå建ç«å¥½è¿ä¸¤ä¸ªç®å½ãå¦å¤ï¼å¨contextä¸å®ä¹äºdocBaseï¼å¯¹äºuriè·¯å¾/xuexiï¼å®çæ件系ç»è·¯å¾ä¸º/www/{longshuai,xiaofang}/xuexiç®å½ï¼æ以ä¹è¦å¨ä¸é¢ä¸¤ä¸ªç¨åºæ ¹ç®å½ä¸å®ä¹å¥½xuexiç®å½ãé¤æ¤ä¹å¤ï¼è¿åå«ä¸ºè¿3个èæ主æºå®ä¹äºæ¥å¿ï¼å®ä»¬çè·¯å¾ä¸ºç¸å¯¹è·¯å¾logsï¼ç¸å¯¹äº$CATALINA_HOMEã
åæä¾appBaseç®å½ådocBaseç®å½ã
mkdir -p /www/{longshuai,xiaofang}/xuexi
åæä¾æµè¯ç¨çindex.jspæ件ãå 容大è´å¦ä¸ï¼åå«å¤å¶å°/www/{longshuai,xiaofang}/å/www/{longshuai,xiaofang}/xuexi/ä¸ï¼å¹¶å°out.printlnçè¾åºå 容åå«ç¨ä½ä¿®æ¹ï¼ä½¿è½å¤åºå读åçæ¯åªä¸ªindex.jspã
æåéå¯catalinaã
catalina.sh stop catalina.sh start
åæµè¯ä¸»æºä¸æ·»å www.{longshuai,xiaofang}.comçhostè®°å½ãä¾å¦å¨windowsä¸ï¼å¨C:\Windows\System32\drivers\etc\hostsä¸æ·»å å¦ä¸è®°å½ï¼
192.168.100.22 www.longshuai.com www.xiaofang.com
å¨æµè§å¨ä¸è¿è¡æµè¯ï¼ç»æå¦ä¸ï¼
2. tomcatä½ç³»ç»æåºæ¬è¯´æ
å¦ä¸å¾ï¼
tomcaté«åº¦æ¨¡ååï¼å个模åä¹é´æåµå¥çç¶åå ³ç³»ãå¦æ使ç¨é ç½®æ件æ¥æè¿°ï¼å¯ä»¥å¤§è´ç®å为å¦ä¸ï¼
å ¶ä¸serverç»ä»¶æ¯å·¥ä½å¨åå°ç®¡çtomcatå®ä¾çç»ä»¶ï¼å¯ä»¥çå¬ä¸ä¸ªç«¯å£ï¼ä»æ¤ç«¯å£ä¸å¯ä»¥è¿ç¨å该å®ä¾åéshutdownå ³éå½ä»¤ã
serviceç»ä»¶æ¯ä¸ä¸ªé»è¾ç»ä»¶ï¼ç»å®connectoråcontainorï¼æäºservice表示å¯ä»¥åå¤æä¾æå¡ï¼å°±åæ¯ä¸è¬çdaemonç±»æå¡çserviceã
connectorç»ä»¶æ¯æå¡çå¬ç»ä»¶ï¼ç¨äºçå¬å¤ç请æ±å¹¶å»ºç«TCPè¿æ¥ï¼ç¶åå°è¿æ¥äº¤ç»containorï¼ä¹åå¯ä»¥ä»æ¤è¿æ¥ä¼ è¾æ°æ®ï¼ä¾å¦æ¥æ¶http请æ±ï¼åéhttpååºçã
containoræ¯å®¹å¨ï¼å¨é ç½®æ件ä¸æ²¡æä½ç°åºæ¥ï¼å®å å«4个容å¨ç±»ç»ä»¶ï¼engine容å¨ãhost容å¨ãcontext容å¨åwrapper容å¨ã
engine容å¨ç¨äºä»connectorç»ä»¶å¤æ¥æ¶å·²å»ºç«çTCPè¿æ¥ï¼è¿ç¨äºæ¥æ¶å®¢æ·ç«¯åéçhttp请æ±å¹¶åæ请æ±ï¼ç¶åæç §åæçç»æå°ç¸å ³åæ°ä¼ éç»å¹é åºçèæ主æºãengineè¿ç¨äºæå®é»è®¤çèæ主æºã
host容å¨å®ä¹èæ主æºï¼ç±äºtomcat主è¦æ¯ä½ä¸ºservlet容å¨çï¼æ以为æ¯ä¸ªwebåºç¨ç¨åºæå®äºå®ä»¬çæ ¹ç®å½appBaseã
context容å¨å¯¹åºservlet容å¨çå¤çè¿ç¨ãè¿å¯ä»¥æå®ç¸å ³çwrapper容å¨ç±»ï¼å½ç¶ä¸è¬é½éç¨é»è®¤çæ åwrapperç±»ã
æåå½è¯·æ±å¤çå®æ¯åï¼contextå°ååºæ°æ®è¿åç»hostï¼åè¿åç»engineï¼åè¿åç»connectorï¼æåè¿åç»å®¢æ·ç«¯ã
æå¼tomcatä½ä¸ºservlet容å¨çè¡ä¸ºãå®åapacheãnginxçåè½å¤§è´é½è½å¯¹åºä¸ãä¾å¦ä»¥nginx为ä¾ï¼ä»¥ä¸æ¯nginxæä¾webæå¡æ¶çé ç½®ç»æï¼
server { listen PORT; server_name www.a.com; # 对åºäºlocation / { # 对åºäºcontext path="" root html; # 对åºäºdocBase } location /xuexi { # 对åºäºcontext path="/xuexi" root html/xuexi; } }
connetcorç»ä»¶ç±»ä¼¼äºnginxçlistenæ令ãhost容å¨ç±»ä¼¼äºnginxçserveræ令ï¼host容å¨ä¸çnameå±æ§ç¸å½äºnginxçserver_nameæ令ãengineç»ä»¶å没æ对åºé 置项ï¼ä¸è¿å¨nginxåæ ·æengineçåè½ï¼ä¾å¦é»è®¤çèæ主æºï¼åæURLæ¥å¤æ请æ±äº¤ç»åªä¸ªèæ主æºå¤ççãcontext容å¨ç¸å½äºlocationæ令ï¼context容å¨çpathå±æ§ç¸å½äºlocationçuriå¹é è·¯å¾ï¼docBaseç¸å½äºlocationçä¸çrootæ令ï¼å³DocumentRootã
tomcatä½ä¸ºç®åçwebæå¡ç¨åºå¤§è´å¦æ¤ï¼ä½å®çæ ¸å¿æ¯ç«æ¯å¤çservletåjspï¼å®å¿ é¡»å¾ç®¡ç好æ¯ä¸ªwebappãå æ¤ï¼å¯¹äºtomcatæ¥è¯´ï¼å¿ é¡»è¦ææ¡é¨ç½²webappçæ¹å¼ãå¨tomcatä¸é¨ç½²webappæ¶ï¼å¿ é¡»è¦ç解contextçæ¦å¿µï¼å¯¹äºtomcatèè¨ï¼æ¯ä¸ªcontexté½åºè¯¥ç®æ¯ä¸ä¸ªwebappï¼å ¶è·¯å¾ç±docBaseå³å®ï¼è¯¥ç®å½åæ¾çæ¯å½æ¡£çwaræ件ææªå½æ¡£çwebappç¸å ³æ件ï¼èhost容å¨ä¸çappBaseåæ¯èæ主æºæ´çwebappçå°æ¹ï¼ä¸ä¸ªappBaseä¸å¯ä»¥æå¤ä¸ªwebappï¼å³å¤ä¸ªcontextã
3. tomcatçappBaseådocBase详ç»è¯´æ
è¿ä¸¤è´§è½ç¶æä¹å¾æç¡®ï¼ä½"æ½è§å"å¾ä¸¥éã以ä¸é¢çé 置为ä¾ã
appBaseæ¯èæ主æºåæ¾webappçç®å½ï¼å®å¯ä»¥æ¯ç¸å¯¹è·¯å¾ï¼ä¹å¯ä»¥æ¯ç»å¯¹è·¯å¾ãå¦ææ¯ç¸å¯¹è·¯å¾ï¼åç¸å¯¹äº$CATALINA_HOMEï¼ä¸¥æ ¼å°è¯´æ¯$CATALINA_BASEã
pathæ¯URIçå¹é è·¯å¾ï¼ç¸å½äºnginxçlocationåçè·¯å¾ãtomcatè¦æ±æ¯ä¸ªèæ主æºå¿ é¡»é ç½®ä¸ä¸ªç©ºå符串çpathï¼è¯¥æ¡contextä½ä¸ºURIæ æ³è¢«æç¡®å¹é æ¶çé»è®¤contextï¼å®ç¸å½äºnginxä¸location / {}çä½ç¨ã
docBaseåæ¯æ¯ä¸ªwebappçåæ¾ç®å½(æè æ¯å·²å½æ¡£çwaræ件)ï¼å®å¯ä»¥æ¯ç¸å¯¹è·¯å¾ï¼ä¹å¯ä»¥æ¯ç»å¯¹è·¯å¾ï¼æä¾ç¸å¯¹è·¯å¾æ¶å®ç¸å¯¹äºappBaseã该ç®å½ä¸è¬å¨appBaseçç®å½ä¸ï¼ä½å¹¶ä¸è§å®ä¸å®è¦æ¾å¨appBaseä¸ã对äºwebæå¡æ¥è¯´ï¼å®ç¸å½äºnginxçrootæ令ï¼ä½å¯¹äºwebappæ¥è¯´ï¼ä¸ä¸ªcontextå°±ç¸å½äºä¸ä¸ªwebappï¼èdocBaseæ£æ¯webappçè·¯å¾ã
"æ½è§å"å¨äºé»è®¤çcontextå¦ä½æä¾ãæ以ä¸å ç§æ åµï¼
1.æç¡®å®ä¹äº
2.æç¡®å®ä¹äº
3.å®å ¨æ²¡æå®ä¹path=""çcontextæ¶ï¼å³host容å¨ä¸æ²¡ææç¡®çpath=""ï¼æ¤æ¶å°éå¼å®ä¹ä¸ä¸ªé»è®¤contextï¼å¤çè·¯å¾ä¸ºappBase/ROOTç®å½ã
4.å®ä¹äºpathä½æ²¡æå®ä¹docBaseå±æ§æ¶ï¼docBaseå°æ ¹æ®pathæ¨æåºå®çè·¯å¾ãæ¨æçè§åå¦ä¸ï¼
context path context name æ¨æåºçdocBaseè·¯å¾ -------------------------------------------------- /foo /foo foo /foo/bar /foo/bar foo/bar Empty String Empty String ROOT
以ä¸æ¯å 个å®ä¹ç¤ºä¾ï¼
# èæ主æºä¸æ²¡æå®ä¹ä»»ä½contextï¼å°ä»¥appBaseä¸çROOTä½ä¸ºé»è®¤å¤çè·¯å¾# 没æå®ä¹path=""çcontextï¼ä½å®ä¹äºpathé空çcontextï¼ä¹å°ä»¥ROOTä½ä¸ºé»è®¤å¤çè·¯å¾ # å¦æä¸é¢çContext容å¨ä¸çç¥docBaseå±æ§ï¼åæ¨æåºå ¶docBaseè·¯å¾ä¸ºappBase/xuexi # æ个contextå®ä¹äºpath=""ï¼è¯¥contextå°ä½ä¸ºé»è®¤context # ä½è¯¥é»è®¤context没æå®ä¹docBaseï¼å°æ¨æåºå ¶docBaseè·¯å¾ä¸ºappBase/ROOT # æ个contextå®ä¹äºpath=""ï¼è¯¥contextå°ä½ä¸ºé»è®¤context # ä¸é¢çé»è®¤contextæç¡®å®ä¹äºdocBase
4. tomcaté ç½®æ件server.xml详解
tomcaté ç½®æ件ä¸é ç½®çæ¯å个ç»ä»¶çå±æ§ï¼å ¨å±é ç½®æ件为$CATALINA_HOME/conf/server.xmlï¼ä¸»è¦çç»ä»¶æ以ä¸å 项ï¼Server,Service,Connector,Engine,Host,Alias,Context,Valveçãé ç½®å®é ç½®æ件åéè¦éå¯tomcatï¼ä½å¨å¯å¨åä¸å®è¦æ£æ¥tomcatæ¯å¦å¯å¨æåï¼å 为å³ä½¿åºéï¼å¾å¤æ¶åå®é½ä¸ä¼æ¥éï¼å¯ä»çå¬ç«¯å£å¤æã
é ç½®æ¹æ³è§å®æ¹æåï¼å¨é¡µé¢ç左边æå个ç»ä»¶çé¾æ¥ã
tomcatçé ç½®æ件é½æ¯xmlæ件ï¼ä»¥ä¸æ¯xmlæ件ç常è§è§åï¼
1.æ件第ä¸è¡è®¾ç½®xmlæ è¯ï¼è¡¨ç¤ºè¯¥æ件æ¯xmlæ ¼å¼çæ件ãä¾å¦ã
2.xmlæ件ç注éæ¹æ³ä¸ºï¼è¿å¯ä»¥æ¯åè¡æ³¨éï¼ä¹å¯ä»¥å¤è¡æ³¨éï¼åªè¦åå注é符å·è½å¯¹åºä¸ï¼ä¸é´çå 容é½æ¯æ³¨éã
3.å®ä¹å±æ§æ¶æ两ç§æ¹å¼ï¼åè¡å®ä¹åå¤è¡å®ä¹ãä¾å¦ï¼
ä¸é¢ä¸ªç»ä»¶çé ç½®ä¸æäºå°æ¹ä½¿ç¨äºç¸å¯¹äº$CATALINA_BASEçç¸å¯¹è·¯å¾ï¼å®å$CATALINA_HOMEå°æåºå«ï¼å¦æåªæä¸ä¸ªtomcatå®ä¾ï¼åå®ä»¬æ¯çä»·çï¼é½æ¯tomcatçå®è£ è·¯å¾ãå¦ææå¤ä¸ªtomcatå®ä¾ï¼å$CATALINA_HOME表示çæ¯å®è£ è·¯å¾ï¼è$CATALINA_BASE表示çæ¯åå®ä¾æå¨æ ¹ç®å½ãå ³äºtomcatå¤å®ä¾ï¼è§running.txtä¸å¯¹åºç说æã
4.1 顶级å ç´ server
serverç»ä»¶å®ä¹çæ¯ä¸ä¸ªtomcatå®ä¾ãé»è®¤å®ä¹å¦ä¸ï¼
å®é»è®¤çå¬å¨8005端å£ä»¥æ¥æ¶shutdownå½ä»¤ãè¦å¯ç¨å¤ä¸ªtomcatå®ä¾ï¼å°å®ä»¬çå¬å¨ä¸åç端å£å³å¯ãè¿ä¸ªç«¯å£çå®ä¹ä¸ºç®¡çåæä¾ä¸ä¸ªå ³éå®ä¾ç便æ·éå¾ï¼å¯ä»¥ç´æ¥telnetè³æ¤ç«¯å£ä½¿ç¨SHUTDOWNå½ä»¤å ³éæ¤å®ä¾ãä¸è¿åºäºå®å ¨è§åº¦çèèï¼é常ä¸å 许è¿ç¨è¿è¡ã
Serverçç¸å ³å±æ§ï¼
â¢classNameï¼ç¨äºå®ç°æ¤ç»ä»¶çjavaç±»çå称ï¼è¿ä¸ªç±»å¿ é¡»å®ç°æ¥å£org.apache.catalina.Serverãä¸ç»å®è¯¥å±æ§æ¶å°éç¨é»è®¤çæ åç±»org.apache.catalina.core.StandardServerï¼
â¢addressï¼çå¬ç«¯å£ç»å®çå°åãå¦ä¸æå®ï¼åé»è®¤ä¸ºLocalhostï¼å³åªè½å¨localhostä¸åéSHUTDOWNå½ä»¤ï¼
â¢portï¼æ¥æ¶shutdownæ令ç端å£ï¼é»è®¤ä» å 许éè¿æ¬æºè®¿é®ï¼é»è®¤ä¸º8005ï¼
â¢shutdownï¼éè¿TCP/IPè¿æ¥åå¾æ¤Serverç¨äºå®ç°å ³étomcatå®ä¾çå½ä»¤å符串ã
å¨serverç»ä»¶ä¸å¯åµå¥ä¸ä¸ªæå¤ä¸ªserviceç»ä»¶ã
4.2 顶级å ç´ service
å®ä¹äºserviceå°±è½æä¾æå¡äºãserviceç»ä»¶ä¸å°è£ connectoråcontainorï¼å®åæ¶ä¹è¡¨ç¤ºå°æ¤serviceä¸çconnectoråcontainorç»å®èµ·æ¥ï¼å³ç±å®ä»¬ç»æä¸ä¸ªserviceåå¤æä¾æå¡ãé»è®¤å®ä¹å¦ä¸ï¼
Serviceç¸å ³çå±æ§ï¼
â¢classNameï¼ç¨äºå®ç°serviceçç±»åï¼è¿ä¸ªç±»å¿ é¡»å®ç°org.apache.catalina.Serviceæ¥å£ãä¸ç»å®è¯¥å±æ§æ¶å°éç¨é»è®¤çæ åç±»org.apache.catalina.core.StandardServiceã
â¢nameï¼æ¤serviceçæ¾ç¤ºå称ï¼è¯¥å称主è¦ç¨äºå¨æ¥å¿ä¸è¿è¡æ è¯serviceãä¸è¬æ¥è¯´æ å ³ç´§è¦ï¼é»è®¤ä¸ºCatalinaã
4.3 æ§è¡å¨executor
æ§è¡å¨å®ä¹tomcatåç»ä»¶ä¹é´å ±äº«ç线ç¨æ± ãå¨ä»¥åï¼æ¯ä¸ªconnectoré½ä¼ç¬èªå建èªå·±ç线ç¨æ± ï¼ä½ç°å¨ï¼å¯ä»¥å®ä¹ä¸ä¸ªçº¿ç¨æ± ï¼åç»ä»¶é½å¯ä»¥å ±äº«è¯¥çº¿ç¨æ± ï¼ä¸è¿ä¸»è¦æ¯ä¸ºåconnectorä¹é´æä¾å ±äº«ã注æï¼executorå建çæ¯å ±äº«çº¿ç¨æ± ï¼å¦ææ个connectorä¸å¼ç¨executorå建ç线ç¨æ± ï¼é£ä¹è¯¥connectorä»ä¼æ ¹æ®èªå·±æå®çå±æ§å建å®ä»¬èªå·±ç线ç¨æ± ã
è¿æ¥å¨å¿ é¡»è¦å®ç°org.apache.catalina.Executoræ¥å£ãå®æ¯ä¸ä¸ªåµå¥å¨serviceç»ä»¶ä¸çå ç´ ï¼ä¸ºäºæéæ使ç¨çconnectorï¼è¯¥å ç´ è¿å¿ é¡»å®ä¹å¨connectorå ç´ ä¹åã
é»è®¤çå®ä¹å¦ä¸ï¼
å ¶ä¸è¯¥ç»ä»¶çå±æ§æï¼
â¢classNameï¼ç¨äºå®ç°æ¤ç»ä»¶çjavaç±»çå称ï¼è¿ä¸ªç±»å¿ é¡»å®ç°æ¥å£org.apache.catalina.Executorãä¸ç»å®è¯¥å±æ§æ¶å°éç¨é»è®¤çæ åç±»org.apache.catalina.core.StandardThreadExecutorï¼
â¢nameï¼è¯¥çº¿ç¨æ± çå称ï¼å ¶ä»ç»ä»¶éè¦ä½¿ç¨è¯¥å称å¼ç¨è¯¥çº¿ç¨æ± ã
æ åç±»çå±æ§å æ¬ï¼
â¢threadPriorityï¼çº¿ç¨ä¼å 级ï¼é»è®¤å¼ä¸º5ã
â¢daemonï¼çº¿ç¨æ¯å¦ä»¥daemonçæ¹å¼è¿è¡ï¼é»è®¤å¼ä¸ºtrueã
â¢namePrefixï¼æ§è¡å¨å建æ¯ä¸ªçº¿ç¨æ¶çå称åç¼ï¼æç»çº¿ç¨çå称为:namePrefix+threadNumberã
â¢maxThreadsï¼çº¿ç¨æ± æ¿æ´»çæ大线ç¨æ°éãé»è®¤å¼ä¸º200ã
â¢minSpareThreadsï¼çº¿ç¨æ± ä¸æå°ç©ºé²ç线ç¨æ°éãé»è®¤å¼ä¸º25ã
â¢maxIdleTimeï¼å¨ç©ºé²çº¿ç¨å ³éåç毫ç§æ°ãé¤éæ¿æ´»ç线ç¨æ°éå°äºæçäºminSpareThreadsçå¼ï¼å¦åä¼æ空é²çº¿ç¨çåºç°ãé»è®¤å¼ä¸º60000ï¼å³ç©ºé²çº¿ç¨éè¦ä¿ç1åéç空é²æ¶é´æ被ææã
â¢maxQueueSizeï¼å¯æ§è¡ä»»å¡çæ大éåæ°ï¼è¾¾å°éåä¸éæ¶çè¿æ¥è¯·æ±å°è¢«æç»ã
â¢prestartminSpareThreadsï¼å¨å¯å¨executoræ¶æ¯å¦ç«å³å建minSpareThreads个线ç¨æ°ï¼é»è®¤ä¸ºfalseï¼å³å¨éè¦æ¶æå建线ç¨ã
ä¾å¦å¨connectorä¸æå®æ使ç¨ç线ç¨æ± ï¼æ¹å¼å¦ä¸ï¼
4.4 è¿æ¥å¨connector
è¿æ¥å¨ç¨äºæ¥æ¶å®¢æ·ç«¯åéç请æ±å¹¶è¿åååºç»å®¢æ·ç«¯ãä¸ä¸ªserviceä¸å¯ä»¥æå¤ä¸ªconnectorãæå¤ç§connectorï¼å¸¸è§ç为http/1.1,http/2åajp(apache jserv protocol)ãå¨tomcatä¸ï¼ajpè¿æ¥å议类åä¸ç¨äºtomcatå端æ¯apacheåå代ççæ åµä¸ã
å æ¤tomcatå¯ä»¥æ®æ¼ä¸¤ç§è§è²ï¼
1.Tomcatä» ä½ä¸ºåºç¨ç¨åºæå¡å¨ï¼è¯·æ±æ¥èªäºå端çwebæå¡å¨ï¼è¿å¯è½æ¯Apache, IIS, Nginxçï¼
2.Tomcatæ¢ä½ä¸ºwebæå¡å¨ï¼ä¹ä½ä¸ºåºç¨ç¨åºæå¡å¨ï¼è¯·æ±æ¥èªäºæµè§å¨ã
Tomcatåºè¯¥èèå·¥ä½æ 形并为ç¸åºæ å½¢ä¸ç请æ±åå«å®ä¹å¥½éè¦çè¿æ¥å¨æè½æ£ç¡®æ¥æ¶æ¥èªäºå®¢æ·ç«¯ç请æ±ã
æ¤å¤æå ä»ç»HTTP/1.1è¿æ¥å¨çå±æ§è®¾ç½®ãajpåæååä»ç»ã
HTTPè¿æ¥å¨è¡¨ç¤ºæ¯æHTTP/1.1åè®®çç»ä»¶ã设置äºè¯¥è¿æ¥å¨å°±è¡¨ç¤ºcatalinaå¯ç¨å®çç¬ç«webæå¡åè½ï¼å½ç¶ï¼è¯å®ä¹æä¾å®å¿ é¡»çservletsåjspæ§è¡åè½ãå¨ä¸ä¸ªserviceä¸å¯ä»¥é ç½®ä¸ä¸ªæå¤ä¸ªè¿æ¥å¨ï¼æ¯ä¸ªè¿æ¥å¨é½å¯ä»¥å°è¯·æ±è½¬åç»å®ä»¬ç¸å ³èçengine以å¤ç请æ±ãå建ååºã
å¦ææ³è¦é ç½®æ个web serverçè¿æ¥å¨ï¼å使ç¨AJPåè®®ã
æ¯ä¸ªæµå ¥ç请æ±é½éè¦ä¸ä¸ªç¬ç«ç线ç¨æ¥æ¥æ¶ãå½å¹¶å请æ±æ°éè¶ åºmaxThreadsæå®çå¼æ¶ï¼å¤åºç请æ±å°è¢«å å å¨å¥æ¥åä¸ï¼ç´å°è¶ åºacceptCountæå®çå¼ãè¶ åºaccpetCountç请æ±å°ä»¥"connection refused"é误è¿è¡æç»ã
é»è®¤çå®ä¹å¦ä¸ï¼
HTTPè¿æ¥å¨çå±æ§å®å¨å¤ªå¤ï¼è¯¦ç»é ç½®æ¹æ³è§å®æ¹æåãé常å®ä¹HTTPè¿æ¥å¨æ¶å¿ é¡»å®ä¹çå±æ§åªæ"port"ã
â¢addressï¼æå®è¿æ¥å¨çå¬çå°åï¼é»è®¤ä¸ºææå°åï¼å³0.0.0.0ã
â¢maxThreadsï¼æ¯æçæ大并åè¿æ¥æ°ï¼é»è®¤ä¸º200ï¼å¦æå¼ç¨äºexecutorå建çå ±äº«çº¿ç¨æ± ï¼å该å±æ§è¢«å¿½ç¥ã
â¢acceptCountï¼è®¾ç½®çå¾ éåçæ大é¿åº¦ï¼é常å¨tomcatææå¤ç线ç¨åå¤äºç¹å¿ç¶ææ¶ï¼æ°åæ¥ç请æ±å°è¢«æ¾ç½®äºçå¾ éåä¸ï¼
â¢maxConnectionsï¼å 许建ç«çæ大è¿æ¥æ°ãacceptCountåmaxThreadsæ¯æ¥åè¿æ¥çæ大线ç¨æ°ãåå¨ä¸ç§æ åµï¼maxConnectionså°äºacceptCountæ¶ï¼è¶ åºmaxConnectionsçè¿æ¥è¯·æ±å°è¢«æ¥æ¶ï¼ä½ä¸ä¼ä¸ä¹å»ºç«è¿æ¥ã
â¢portï¼çå¬ç端å£ï¼é»è®¤ä¸º0ï¼æ¤æ¶è¡¨ç¤ºéæºéä¸ä¸ªç«¯å£ï¼é常é½åºè¯¥æ¾å¼æå®çå¬ç«¯å£ã
â¢protocolï¼è¿æ¥å¨ä½¿ç¨çåè®®ï¼ç¨äºå¤ç对åºç请æ±ãé»è®¤ä¸ºHTTP/1.1ï¼æ¤æ¶å®ä¼èªå¨å¨åºäºJava NIOæAPR/nativeè¿æ¥å¨ä¹é´è¿è¡åæ¢ãå®ä¹AJPåè®®æ¶é常为AJP/1.3ã
â¢redirectPortï¼å¦ææè¿æ¥å¨æ¯æçåè®®æ¯HTTPï¼å½æ¥æ¶å®¢æ·ç«¯åæ¥çHTTPS请æ±æ¶ï¼å转åè³æ¤å±æ§å®ä¹ç端å£ã
â¢connectionTimeoutï¼çå¾ å®¢æ·ç«¯åé请æ±çè¶ æ¶æ¶é´ï¼åä½ä¸ºæ¯«ç§ï¼é»è®¤ä¸º60000ï¼å³1åéï¼æ³¨æï¼è¿æ¶åè¿æ¥å·²ç»å»ºç«ã
â¢keepAliveTimeoutï¼é¿è¿æ¥ç¶æçè¶ æ¶æ¶é´ãè¶ åºè¯¥å¼æ¶ï¼é¿è¿æ¥å°å ³éã
â¢enableLookupsï¼æ¯å¦éè¿request.getRemoteHost()è¿è¡DNSæ¥è¯¢ä»¥è·å客æ·ç«¯ç主æºåï¼é»è®¤ä¸ºtrueï¼åºè®¾ç½®ä¸ºfalseé²æ¢å解客æ·ç«¯ä¸»æºï¼
â¢compressionï¼æ¯å¦å缩æ°æ®ãé»è®¤ä¸ºoffã设置为onæ¶è¡¨ç¤ºåªå缩textææ¬ï¼è®¾ç½®ä¸ºforceæ¶è¡¨ç¤ºå缩ææå 容ãåºè¯¥å¨å缩åsendfileä¹é´å个æè¡¡ã
â¢useSendfileï¼è¯¥å±æ§ä¸ºNIOçå±æ§ï¼è¡¨ç¤ºæ¯å¦å¯ç¨sendfileçåè½ãé»è®¤ä¸ºtrueï¼å¯ç¨è¯¥å±æ§å°ä¼ç¦æ¢compressionå±æ§ã
å½åè®®æå®ä¸ºHTTP/1.1æ¶ï¼é»è®¤ä¼èªå¨å¨NIO/APRåè®®å¤çæ¹å¼ä¸è¿è¡æéåæ¢ï¼å¦è¦æ¾å¼æå®åè®®ï¼æ¹å¼å¦ä¸ï¼
å ¶ä¸NIOæ¯C/C++çéé»å¡IOå¤ç¨æ¨¡åå¨JAVAä¸çIOå®ç°ï¼NIO2å³AIOæ¯å¼æ¥NIOï¼å³å¼æ¥éé»å¡IOï¼
NioProtocol ï¼non blocking Java NIO connector Nio2Protocolï¼non blocking Java NIO2 connector AprProtocol ï¼the APR/native connector
å®ä»¬ä¹é´çå¼åç¹å¦ä¸è¡¨æ示ï¼
Â
 | Java Nio Connector | Java Nio2 Connector | APR/native Connector |
---|---|---|---|
Classname | Http11NioProtocol | Http11Nio2Protocol | Http11AprProtocol |
Tomcat Version | 6.x onwards | 8.x onwards | 5.5.x onwards |
Support Polling | YES | YES | YES |
Polling Size | maxConnections | maxConnections | maxConnections |
Read Request Headers | Non Blocking | Non Blocking | Non Blocking |
Read Request Body | Blocking | Blocking | Blocking |
Write Response Headers and Body | Blocking | Blocking | Blocking |
Wait for next Request | Non Blocking | Non Blocking | Non Blocking |
SSL Support | Java SSL or OpenSSL | Java SSL or OpenSSL | OpenSSL |
SSL Handshake | Non blocking | Non blocking | Blocking |
Max Connections | maxConnections | maxConnections | maxConnections |
ä¸é¢æ¯ä¸ä¸ªå®ä¹äºå¤ä¸ªå±æ§çSSLè¿æ¥å¨ï¼
4.5 容å¨ç±»engine
engineæ¯serviceç»ä»¶ä¸ç¨æ¥åæåè®®çå¼ææºå¨ï¼å®ä»ä¸ä¸ªæå¤ä¸ªconnectorä¸æ¥æ¶è¯·æ±ï¼å¹¶å°è¯·æ±äº¤ç»å¯¹åºçèæ主æºè¿è¡å¤çï¼æåè¿åå®æ´çååºæ°æ®ç»connectorï¼éè¿connectorå°ååºæ°æ®è¿åç»å®¢æ·ç«¯ã
åªæä¸ä¸ªengineå ç´ å¿ é¡»åµå¥å¨æ¯ä¸ªserviceä¸ï¼ä¸engineå¿ é¡»å¨å ¶æéè¦å ³èçconnectorä¹åï¼è¿æ ·å¨engineåé¢çconnectoré½å¯ä»¥è¢«æ¤engineå ³èï¼èå¨engineåé¢çconnectorå被忽ç¥ï¼å 为ä¸ä¸ªserviceä¸åªå 许æä¸ä¸ªengineã
å®ä¹æ¹å¼å¤§è´å¦ä¸ï¼
常ç¨çengineå±æ§æï¼
â¢classNameï¼å®ç°engineçç±»ï¼è¯¥ç±»å¿ é¡»å®ç°org.apache.catalina.Engineæ¥å£ãä¸ç»å®è¯¥å±æ§æ¶å°éç¨é»è®¤çæ åç±»org.apache.catalina.core.StandardEngineã
â¢defaultHostï¼æå®å¤ç请æ±çé»è®¤èæ主æºãå¨Engineä¸å®ä¹çå¤ä¸ªèæ主æºç主æºå称ä¸è³å°æä¸ä¸ªè·defaultHostå®ä¹ç主æºå称ååã
â¢nameï¼Engineç»ä»¶çå称ï¼ç¨äºè®°å½æ¥å¿åé误信æ¯ï¼æ å ³ç´§è¦çå±æ§ï¼å¯éæç»å®ã
â¢jvmRouteï¼å¨å¯ç¨sessionç²æ§æ¶æå®ä½¿ç¨åªç§è´è½½åè¡¡çæ è¯ç¬¦ãææçtomcat serverå®ä¾ä¸è¯¥æ è¯ç¬¦å¿ é¡»å¯ä¸ï¼å®ä¼è¿½å å¨sessionæ è¯ç¬¦çå°¾é¨ï¼å æ¤è½è®©å端代çæ»æ¯å°ç¹å®çsession转åè³åä¸ä¸ªtomcatå®ä¾ä¸ã
注æï¼jvmRouteåæ ·å¯ä»¥ä½¿ç¨jvmRouteçç³»ç»å±æ§æ¥è®¾ç½®ãå¦ææ¤å¤è®¾ç½®äºjvmRouteï¼åè¦çjvmRouteç³»ç»å±æ§ãå ³äºjvmRouteç使ç¨ï¼å¨åé¢tomcat ajpè´è½½åè¡¡çæç« ä¸ä»ç»ã
engineæ¯å®¹å¨ä¸ç顶级å容å¨ï¼å ¶å å¯ä»¥åµå¥ä¸ä¸ªæå¤ä¸ªHostä½ä¸ºèæ主æºï¼ä¸è³å°ä¸ä¸ªhostè¦åengineä¸çé»è®¤èæ主æºå称对åºãé¤äºhostï¼è¿å¯ä»¥åµå¥releamåvalveç»ä»¶ã
4.6 容å¨ç±»host
host容å¨ç¨æ¥å®ä¹èæ主æºãengineä»connectoræ¥æ¶å°è¯·æ±è¿è¡åæåï¼ä¼å°ç¸å ³çå±æ§åæ°ä¼ éç»å¯¹åºç(çéæ¹å¼æ¯ä»è¯·æ±é¦é¨çhostå段åèæ主æºå称è¿è¡å¹é )èæhostè¿è¡å¤çãå¦æ没æåéçèæ主æºï¼åä¼ éç»é»è®¤èæ主æºãå æ¤æ¯ä¸ªå®¹å¨ä¸å¿ é¡»è³å°å®ä¹ä¸ä¸ªèæ主æºï¼ä¸å¿ é¡»æä¸ä¸ªèæ主æºåengine容å¨ä¸å®ä¹çé»è®¤èæ主æºå称ç¸åã
大è´å®ä¹æ¹å¼å¦ä¸ï¼
常ç¨å±æ§è¯´æï¼
â¢classNameï¼å®ç°host容å¨çç±»ï¼è¯¥ç±»å¿ é¡»å®ç°org.apache.catalina.Hostæ¥å£ãä¸ç»å®è¯¥å±æ§æ¶å°éç¨é»è®¤çæ åç±»org.apache.catalina.core.StandardHostã
â¢nameï¼èæ主æºç主æºåï¼å¿½ç¥å¤§å°å(åå§åæ¶ä¼èªå¨è½¬æ¢ä¸ºå°å)ãå¯ä»¥ä½¿ç¨åç¼æå·éé 符ï¼å¦"*.a.com"ã使ç¨äºæå·åç¼çèæ主æºçå¹é ä¼å 级ä½äºç²¾ç¡®å称çèæ主æºã
â¢appBaseï¼æ¤Hostçwebappsç®å½ï¼å³webappé¨ç½²å¨æ¤èæ主æºä¸æ¶çåæ¾ç®å½ãå æ¬éå½æ¡£çwebåºç¨ç¨åºç®å½åå½æ¡£åçWARæ件çç®å½ã使ç¨ç¸å¯¹è·¯å¾æ¶åºäº$CATALINA_BASEã
â¢xmlBaseï¼é¨ç½²å¨æ¤èæ主æºä¸çcontext xmlç®å½ã
â¢startStopThreadsï¼å¯å¨context容å¨æ¶ç并è¡çº¿ç¨æ°ãå¦æ使ç¨äºèªå¨é¨ç½²åè½ï¼åå次é¨ç½²ææ´æ°æ¶ä½¿ç¨ç¸åç线ç¨æ± ã
â¢autoDeployï¼å¨Tomcatå¤äºè¿è¡ç¶ææ¶æ¾ç½®äºappBaseç®å½ä¸çåºç¨ç¨åºæ件æ¯å¦èªå¨è¿è¡deployæèªå¨æ´æ°é¨ç½²ç¶æãè¿çäºåæ¶å¼å¯äºdeployOnStartupå±æ§åreload/redeploy webappçåè½ã触åèªå¨æ´æ°æ¶å°é»è®¤é载该webappãé»è®¤ä¸ºtrueã
â¢unpackWarsï¼å¨æ§è¡æ¤webappsæ¶æ¯å¦å 对å½æ¡£æ ¼å¼çWARæ件解ååè¿è¡ï¼è®¾ç½®ä¸ºfalseæ¶åç´æ¥æ§è¡WARæ件ï¼é»è®¤ä¸ºtrueã设置为falseæ¶ä¼æèæ§è½ã
â¢workDirï¼è¯¥èæ主æºçå·¥ä½ç®å½ãæ¯ä¸ªwebappé½æèªå·±ç临æ¶IOç®å½ï¼é»è®¤è¯¥å·¥ä½ç®å½ä¸º$CATALINA_BASE/workã
大å¤æ°æ¶åé½åªé设置èæ主æºå称nameåwebBaseå±æ§å³å¯ï¼å ¶ä½éç¨é»è®¤ï¼é»è®¤æ¶ä¼èªå¨é¨ç½²webappãææ¶åè¿éè¦ç®¡çå¤ä¸ªç«ç¹å称ï¼å³ä¸»æºå«åãå¯ä»¥ä½¿ç¨Alias为Hostæå®ç主æºåå®ä¹ä¸»æºå«åãå¦ï¼
www.a.com
èªå¨é¨ç½²æçæ¯èªå¨è£ è½½webapp以æä¾ç¸å ³webappçæå¡ã
4.7 容å¨ç±»context
connectoråcontainoræ¯æ´ä¸ªtomcatçå¿èï¼ècontextåæ¯containorçå¿èï¼æ´æ¯tomcatå¿èçå¿èãå®æ¯çæ£ç®¡çservletçå°æ¹ï¼å®çé 置影åäºservletçå·¥ä½æ¹å¼ã
ä¸ä¸ªcontext代表ä¸ä¸ªwebappãservletä¸è§å®ï¼æ¯ä¸ªwebappé½å¿ é¡»åºäºå·²å½æ¡£çWAR(WEB application archive)æ件æåºäºéå½æ¡£ç¸å ³å 容æå¨ç®å½ã
catalinaåºäºå¯¹è¯·æ±URIä¸contextä¸å®ä¹çpathè¿è¡æ大å¹é åç¼çè§åè¿è¡æéï¼ä»ä¸éåºä½¿ç¨åªä¸ªcontextæ¥å¤ç该HTTP请æ±ãè¿ç¸å½äºnginxçlocation容å¨ï¼catalinaçpathå°±ç¸å½äºlocationçpathï¼å®ä»¬çä½ç¨æ¯ç¸åçã
æ¯ä¸ªcontexté½å¿
é¡»å¨èæ主æºå®¹å¨hostä¸æä¸ä¸ªå¯ä¸çcontext nameãcontextçpathä¸éè¦å¯ä¸ï¼å 为å
许åä¸ä¸ªwebappä¸åçæ¬çå
±åé¨ç½²ãæ¤å¤ï¼å¿
é¡»è¦æä¸ä¸ªcontextçpath为0é¿åº¦çå符串(å³
å ³äºcontext nameï¼å®æ¯ä»context pathæ¨æåºæ¥çï¼ä¸ä» å¦æ¤ï¼å ¶ä½å 个å±æ§å¦context basefile nameä¹æ¯ç±æ¤æ¨æåºæ¥çãè§åå¦ä¸ï¼
â¢å¦æpathä¸ä¸ºç©ºï¼åcontext nameçäºcontext pathï¼basefile nameåpathä¸å»é¤åç¼"/"åçè·¯å¾ï¼ä¸ææ"/"æ¿æ¢ä¸º"#"ã
â¢å¦æpath为空ï¼åcontext nameä¹ä¸ºç©ºï¼èbasefile为ROOT(注ææ¯å¤§å)ã
ä¾å¦ï¼
context path context name basefile name deploy examples ----------------------------------------------------------------- /foo /foo foo foo.xml,foo.war,foo /foo/bar /foo/bar foo#bar foo#bar.xml,foo#bar.war,foo#bar Empty String Empty String ROOT ROOT.xml,ROOT.war,ROOT
é ç½®contextæ¶ï¼å¼ºç建议ä¸è¦å®ä¹å¨server.xmlä¸ï¼å 为å®ä¹conf/server.xmlä¸æ¶ï¼åªè½éè¿éå¯tomcatæ¥éè½½çæï¼ä¹å°±æ¯è¯´æ æ³èªå¨é¨ç½²åºç¨ç¨åºäºãè½è¯´å®æ¹å¦æ¤æ¨èï¼ä½å¤§å¤æ°äººåºäºä¹ æ¯åæ¹ä¾¿ï¼è¿æ¯ä¼ç´æ¥åå¨server.xmlä¸ï¼è¿å¹¶æ²¡æä»ä¹é®é¢ï¼æ éæ¯éå¯ä¸ä¸èå·²ã
å¯ä»¥èèå®ä¹å¨/META-INF/context.xmlä¸ï¼å¦ææ¤æ¶è®¾ç½®äºcopyXMLå±æ§ï¼å¨é¨ç½²æ¶ä¼å°æ¤context.xmlå¤å¶å°$CATALINA_BASE/conf/enginename/hostname/ä¸ï¼å¹¶éå½å为"basefile name.xml"ãä¹å¯ä»¥ç´æ¥å®ä¹å¨$CATALINA_BASE/conf/enginename/hostname/ä¸ç.xmlæ件ä¸ï¼è¯¥è·¯å¾çxmlä¼å 级é«äº/META-INF/context.xmlã
è¿å¯ä»¥å®ä¹é»è®¤çcontext.xmlæ件ï¼å æ¬ä¸¤ç§ï¼(1)å®ä¹å¨$CATALINA_BASE/conf/context.xmlä¸ï¼è¯¥é»è®¤context对ææwebappé½çæï¼(2)å®ä¹å¨$CATALINA_BASE/conf/[enginename]/[hostname]/context.xml.defaultä¸ï¼è¯¥é»è®¤contextåªå¯¹è¯¥èæ主æºä¸çææwebappçæã
å®ä¹æ¹å¼å¤§è´å¦ä¸ï¼
å ¶ä¸ç¬¬ä¸ä¸ªcontextçpath为空å符串ï¼è¡¨ç¤ºå®æ¯é»è®¤çcontextãå½æµè§å¨ä¸è¾å ¥www.a.comæ¶ï¼ç±äºæ æ³å¹é 第äºä¸ªcontextï¼æ以被é»è®¤å³ç¬¬ä¸ä¸ªcontextå¤çï¼å½æµè§å¨ä¸è¾å ¥www.a.com/bbsæ¶ï¼å°è¢«ç¬¬äºä¸ªcontextå¤çï¼å®å°æ§è¡web/bbsæ对åºçwebappï¼å¹¶è¿åç¸å ³å 容ã
å¨context容å¨ä¸å¯ä»¥å®ä¹é常å¤çå±æ§ï¼è¯¦ç»å 容è§å®æ¹æåï¼ä»¥ä¸æ¯å¸¸è§çå 个å±æ§ï¼
â¢classNameï¼å®ç°host容å¨çç±»ï¼è¯¥ç±»å¿ é¡»å®ç°org.apache.catalina.Contextæ¥å£ãä¸ç»å®è¯¥å±æ§æ¶å°éç¨é»è®¤çæ åç±»org.apache.catalina.core.StandardContextã
â¢cookiesï¼é»è®¤ä¸ºtrueï¼è¡¨ç¤ºå¯ç¨cookieæ¥æ è¯sessionã
â¢docBaseï¼å³DocumentRootï¼æ¯è¯¥webappçcontext rootï¼å³å½æ¡£WARæ件æå¨ç®å½æéå½æ¡£å 容æå¨ç®å½ãå¯ä»¥æ¯ç»å¯¹è·¯å¾ï¼ä¹å¯ä»¥æ¯ç¸å¯¹äºè¯¥webapp appBaseçç¸å¯¹è·¯å¾ã
â¢pathï¼å®ä¹webapp pathã注æï¼å½path=""æ¶ï¼è¡¨ç¤ºé»è®¤çcontextï¼å¦å¤åªæå¨server.xmlä¸æéè¦å®ä¹è¯¥å±æ§ï¼å ¶ä»æææ åµä¸é½ä¸è½å®ä¹è¯¥å±æ§ï¼å 为ä¼æ ¹æ®docBaseåcontextçxmlæ件åæ¨æåºpathã
â¢reloadableï¼æ¯å¦çæ§/WEB-INF/classå/WEB-INF/lib两个ç®å½ä¸æ件çååï¼ååæ¶å°èªå¨éè½½ãå¨æµè¯ç¯å¢ä¸è¯¥å±æ§å¾å¥½ï¼ä½å¨çå®ç产ç¯å¢é¨ç½²åºç¨æ¶ä¸åºè¯¥è®¾ç½®è¯¥å±æ§ï¼å 为çæ§ä¼å¤§å¹ å¢å è´è½½ï¼å æ¤è¯¥å±æ§çé»è®¤å¼ä¸ºfalseã
â¢wrapperClassï¼å®ç°wrapper容å¨çç±»ï¼wrapperç¨äºç®¡ç该contextä¸çservletï¼è¯¥ç±»å¿ é¡»å®ç°org.apache.catalina.Wrapperæ¥å£ï¼å¦æä¸æå®è¯¥å±æ§åéç¨é»è®¤çæ åç±»ã
â¢xmlNamespaceAwareï¼åweb.xmlç解ææ¹å¼æå ³ãé»è®¤ä¸ºtrueï¼è®¾ç½®ä¸ºfalseå¯ä»¥æåæ§è½ã
â¢xmlValidationï¼åweb.xmlç解ææ¹å¼æå ³ãé»è®¤ä¸ºtrueï¼è®¾ç½®ä¸ºfalseå¯ä»¥æåæ§è½ã
4.8 被åµå¥ç±»realm
realmå®ä¹çæ¯ä¸ä¸ªå®å ¨ä¸ä¸æï¼å°±åæ¯ä»¥åªç§æ¹å¼åå¨è®¤è¯æ¶çç¨æ·åç»ç¸å ³çæ°æ®åºãæå¤ç§æ¹å¼å¯ä»¥å®ç°æ°æ®åæ¾ï¼
â¢JAASRealmï¼åºäºJava Authintication and Authorization Serviceå®ç°ç¨æ·è®¤è¯ï¼
â¢JDBCRealmï¼éè¿JDBC访é®æå ³ç³»åæ°æ®åºè¡¨å®ç°ç¨æ·è®¤è¯ï¼
â¢JNDIRealmï¼åºäºJNDI使ç¨ç®å½æå¡å®ç°è®¤è¯ä¿¡æ¯çè·åï¼
â¢MemoryRealmï¼æ¥æ¾tomcat-user.xmlæ件å®ç°ç¨æ·ä¿¡æ¯çè·åï¼
â¢UserDatabaseRealmï¼åºäºUserDatabaseæ件(é常æ¯tomcat-user.xml)å®ç°ç¨æ·è®¤è¯ï¼å®å®ç°æ¯ä¸ä¸ªå®å ¨å¯æ´æ°åæä¹ ææçMemoryRealmï¼å æ¤è½å¤è·æ åçMemoryRealmå ¼å®¹ï¼å®éè¿JNDIå®ç°ï¼
ä¸é¢æ¯ä¸ä¸ªå¸¸è§ç使ç¨UserDatabaseçé ç½®ï¼
ä¸é¢æ¯ä¸ä¸ªä½¿ç¨JDBCæ¹å¼è·åç¨æ·è®¤è¯ä¿¡æ¯çé ç½®ï¼
4.9 被åµå¥ç±»valve
Valveä¸ææææ¯éé¨ï¼ç±»ä¼¼äºè¿æ»¤å¨ï¼å®å¯ä»¥å·¥ä½äºEngineåHost/Contextä¹é´ãHoståContextä¹é´ä»¥åContextåWebåºç¨ç¨åºçæèµæºä¹é´ãä¸ä¸ªå®¹å¨å å¯ä»¥å»ºç«å¤ä¸ªValveï¼èä¸Valveå®ä¹ç次åºä¹å³å®äºå®ä»¬çæç次åºã
æå¤ç§ä¸åçValveï¼
â¢AccessLogValveï¼è®¿é®æ¥å¿Valveï¼
â¢ExtendedAccessValveï¼æ©å±åè½ç访é®æ¥å¿Valveï¼
â¢JDBCAccessLogValveï¼éè¿JDBCå°è®¿é®æ¥å¿ä¿¡æ¯åéå°æ°æ®åºä¸ï¼
â¢RequestDumperValveï¼è¯·æ±è½¬å¨Valveï¼
â¢RemoteAddrValveï¼åºäºè¿ç¨å°åç访é®æ§å¶ï¼
â¢RemoteHostValveï¼åºäºè¿ç¨ä¸»æºå称ç访é®æ§å¶ï¼
â¢SemaphoreValveï¼ç¨äºæ§å¶Tomcat主æºä¸ä»»ä½å®¹å¨ä¸ç并å访é®æ°éï¼
â¢JvmRouteBinderValveï¼å¨é ç½®å¤ä¸ªTomcat为以Apacheéè¿mod_proxyæmod_jkä½ä¸ºå端çé群æ¶æä¸ï¼å½ææåæ¢æèç¹æ¶ï¼å¯ä»¥éè¿æ¤Valveå°ç¨è®°è¯·æ±å®åè³å¤ç¨èç¹ï¼ä½¿ç¨æ¤Valveï¼å¿ 须使ç¨JvmRouteSessionIDBinderListenerï¼
â¢ReplicationValveï¼ä¸ç¨äºTomcaté群æ¶æä¸ï¼å¯ä»¥å¨æ个请æ±çsessionä¿¡æ¯åçæ´æ¹æ¶è§¦åsessionæ°æ®å¨åèç¹é´è¿è¡å¤å¶ï¼
â¢SingleSignOnï¼å°ä¸¤ä¸ªæå¤ä¸ªéè¦å¯¹ç¨æ·è¿è¡è®¤è¯webappå¨è®¤è¯ç¨æ·æ¶è¿æ¥å¨ä¸èµ·ï¼å³ä¸æ¬¡è®¤è¯å³å¯è®¿é®ææè¿æ¥å¨ä¸èµ·çwebappï¼
â¢ClusterSingleSingOnï¼å¯¹SingleSignOnçæ©å±ï¼ä¸ç¨äºTomcaté群å½ä¸ï¼éè¦ç»åClusterSingleSignOnListenerè¿è¡å·¥ä½ï¼
å ¶ä¸RemoteHostValveåRemoteAddrValveå¯ä»¥åå«ç¨æ¥å®ç°åºäºä¸»æºå称ååºäºIPå°åç访é®æ§å¶ï¼æ§å¶æ¬èº«å¯ä»¥éè¿allowædenyæ¥è¿è¡å®ä¹ï¼è¿æç¹ç±»ä¼¼äºApacheç访é®æ§å¶åè½ãå¦ä¸é¢çValveå®ç°äºä» å 许æ¬æºè®¿é®/probeï¼
å ¶ä¸ç¸å ³å±æ§å®ä¹æ:
â¢classNameï¼å¨å¯¹åºä½ç½®çåç¼ä¸å ä¸".valves.RemoteHostValve"æ".valves.RemoteAddrValve"ï¼
â¢allowï¼ä»¥éå·åå¼çå 许访é®çIPå°åå表ï¼æ¯ææ£åï¼ç¹å·â.âç¨äºIPå°åæ¶éè¦è½¬ä¹ï¼ä» å®ä¹allow项æ¶ï¼éæç¡®allowçå°åå被denyï¼
â¢deny: 以éå·åå¼çç¦æ¢è®¿é®çIPå°åå表ï¼æ¯ææ£åï¼ä½¿ç¨æ¹å¼åallowï¼ä» å®ä¹deny项æ¶ï¼éæç¡®denyçå°åå被allowï¼
å¦å¤ä¸ä¸ªå¸¸ç¨çValve为AccessLogValveï¼å®ä¹æ¹å¼å¤§è´å¦ä¸ï¼
å ¶ä¸prefixåsuffix表示æ¥å¿æ件çåç¼å称ååç¼å称ãpattern表示记å½æ¥å¿æ¶çä¿¡æ¯åæ ¼å¼ã
çå®ç±ç«ææ¯é¢éå°ç¼ä»ç»çTomcatæå¡å¨é ç½®æ件ç详ç»è¯´æï¼æ们åºè¯¥ç¸ä¿¡èªå·±ï¼ä¸ä¸æ²¡æè¿ä¸å»çæ§ï¼ä¸è¦å®³æï¼é¼èµ·åæ°å»é¢å¯¹å°é¾å§ã
上一篇:apache重定向的实现