1,內存調優javascript
在bin/catalina.sh中(大概97行)加入以下配置:css
2,併發調優html
在conf/server.xml文件中加入:java
<Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol" URIEncoding="UTF-8" maxConnections="10000" maxThreads="2000" acceptCount="2000" minSpareThreads="100" compression="no" compressionMinSize="2048" compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain" enableLookups="false" disableUploadTimeout="true" connectionTimeout="20000" redirectPort="8443" />
此處的protocol默認爲protocol="HTTP/1.1",即nio模式。linux
參數解釋:git
apr下載地址:github
http://apr.apache.org/download.cgi
下載APR,APR-util,APR iconvapache
安裝apr:ubuntu
在解壓目錄下執行tomcat
./configure --prefix=/usr/local/apr
分別執行 make,make install
安裝apr-iconv:
在解壓目錄下執行
./configure --prefix=/usr/local/apr-iconv --with-apr=/usr/local/apr
分別執行 make,make install
安裝apr-util:
在解壓目錄下執行
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr --with-apr-iconv=/usr/local/apr-iconv/bin/apriconv
分別執行 make,make install
這時可能會報錯:expat.h: No such file or directory,需安裝libexpat1-dev:apt-get install libexpat1-dev
接下來從新編譯安裝tomcat-native:
在tomcat目錄下/bin下解壓 tar -zxvf tomcat-native.tar.gz
進入bin/tomcat-native-1.2.23-src/native下執行:
./configure --with-apr=/usr/local/apr
而後make make install
在bin/catalina.sh中添加:
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/apr/lib export LD_LIBRARY_PATH
將conf/server.xml中讀協議改成APR:
<Connector port="8080" protocol="org.apache.coyote.http11.Http11AprProtocol"
安裝openssl:
在安裝以前須要確認openssl的版本,最好先卸載掉原有的,安裝最新的,不然在./configure時會報錯too old(版本太低)。能夠在github上下載最新版本,在解壓目錄下執行:
./configure --prefix=/usr/local/openssl
以後make,make install
查看版本信息:
openssl version
會報錯:
openssl version openssl: /usr/lib/x86_64-linux-gnu/libssl.so.1.1: version `OPENSSL_1_1_1' not found (required by openssl) openssl: /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1: version `OPENSSL_1_1_1' not found (required by openssl)
更改環境變量:
echo "export LD_LIBRARY_PATH=/usr/local/openssl/lib" >> ~/.bashrc export LD_LIBRARY_PATH=/usr/local/openssl/lib
安裝ab壓測工具httpd:
下載httpd:
http://www.apache.org/dist/httpd/
在./configure時不能指定安裝好讀apr以及apr-util路徑,make時會報錯:
Makefile:48: recipe for target 'htpasswd' failed make[2]: *** [htpasswd] Error 1 make[2]: Leaving directory '/etc/httpd-2.4.27/support' /etc/httpd-2.4.27/build/rules.mk:75: recipe for target 'all-recursive' failed make[1]: *** [all-recursive] Error 1 make[1]: Leaving directory '/etc/httpd-2.4.27/support' /etc/httpd-2.4.27/build/rules.mk:75: recipe for target 'all-recursive' failed make: *** [all-recursive] Error 1
須要把以前下載好的apr以及apr-util壓縮包解壓到httpd解壓目錄下讀srclib下,而後在解壓目錄下執行:
./configure --prefix=/usr/local/httpd --sysconfdir=/usr/local/httpd --enable-so --enable-ssl --with-ssl=/usr/local/openssl --enable-rewrite --enable-modules=most --enable-mpms-shared=all --with-zlib --with-pcre --with-mpm=prefork --with-included-apr
接着執行make和make install
進入httpd/bin目錄,執行:
./ab -c1000 -n10 http://localhost:8080/
進行壓測
四,一些問題
ubuntu開放8080端口:iptables -I INPUT -p tcp --dport 8080 -j ACCEPT