{"id":6770,"date":"2017-06-09T16:00:26","date_gmt":"2017-06-09T08:00:26","guid":{"rendered":"http:\/\/rmohan.com\/?p=6770"},"modified":"2017-06-09T16:00:26","modified_gmt":"2017-06-09T08:00:26","slug":"tomcatnginxmemcached-2","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=6770","title":{"rendered":"Tomcat+Nginx+Memcached"},"content":{"rendered":"<p><strong>?Tomcat+Nginx+Memcached<\/strong><\/p>\n<p>??Ubuntu 16.04 64 bit test pass<\/p>\n<p>??Movement classification, load balancing, clustering, Javolution serialized, high-performance, high availability<\/p>\n<p>Configuration environment (both current latest stable version):<br \/>\n??the JDK-Linux-x64-8u131<br \/>\n??the Apache-Tomcat-8.5.14<br \/>\n??nginx-1.12.0<br \/>\n??memcached-1.4.36<\/p>\n<p>EDITORIAL:<\/p>\n<p>??Originally intended configuration kryo serialization framework, but also how to get unsuccessful, with only a Javolution<br \/>\n??If the last unsuccessful general problems will find out in Tomcat, look at the log resolved<br \/>\n??under tomcat can deploy multiple projects, and the movement is still classified<br \/>\n??nginx configured to jsp, servlet, do the file extension to the Tomcat process, can be added according to the situation<br \/>\n??if you do not use the root account, then run nginx, nginx is useless to the user to configure<br \/>\n??Tomcat, nginx are optimized configuration, without modifying the original project Nothing, directly into the Tomcat \/ webapps where you can<\/p>\n<p>process:<\/p>\n<p>??Long process, carefully<\/p>\n<p># Sudo  passwd<br \/>\n# Use administrator to configure<br \/>\nSudo  Su<br \/>\n# Update software list<br \/>\napt-get update<br \/>\n# Install the required dependencies<br \/>\napt-get install gcc zlib1g zlib1g-dev openssl libssl-dev libpcre3 libpcre3-dev libevent-dev<br \/>\n# Reboot (recommended)<br \/>\nreboot<\/p>\n<p>sudo su<br \/>\nhttp:\/\/www.Oracle.com\/technetwork\/java\/javase\/downloads\/jdk8-downloads-2133151.html<br \/>\ntar -zxvf jdk-8u131-linux-x64.tar.gz<br \/>\nmv jdk1.8.0_131 \/usr\/local\/jdk<\/p>\n<p># Configure JDK environment variables<br \/>\nsed -i &#8216;$a ulimit -n 65535&#8217; \/etc\/profile<br \/>\nsed -i &#8216;$a export JAVA_HOME=\/usr\/local\/jdk&#8217; \/etc\/profile<br \/>\nsed -i &#8216;$a export JRE_HOME=$JAVA_HOME\/jre&#8217; \/etc\/profile<br \/>\nsed -i &#8216;$a export CLASSPATH=.:$JAVA_HOME\/lib:$JRE_HOME\/lib:$CLASSPATH&#8217; \/etc\/profile<br \/>\nsed -i &#8216;$a export PATH=$JAVA_HOME\/bin:$JRE_HOME\/bin:$PATH&#8217; \/etc\/profile<br \/>\nsource \/etc\/profile<\/p>\n<p>rm jdk-8u131-linux-x64.tar.gz<\/p>\n<p># Installation configuration memcached<br \/>\nwget http:\/\/www.memcached.org\/files\/memcached-1.4.36.tar.gz<br \/>\ntar -zxvf memcached-1.4.36.tar.gz<br \/>\ncd memcached-1.4.36<br \/>\n.\/configure &#8211;prefix=\/usr\/local\/memcached<br \/>\nmake &#038;&#038; make install<br \/>\ncd .. &#038;&#038; rm -rf memcached-1.4.36 &#038;&#038; rm memcached-1.4.36.tar.gz<\/p>\n<p># Configure Tomcat installation<br \/>\nwget http:\/\/apache.fayea.com\/tomcat\/tomcat-8\/v8.5.14\/bin\/apache-tomcat-8.5.14.tar.gz<br \/>\ntar -zxvf apache-tomcat-8.5.14.tar.gz<\/p>\n<p># Download the added lib file to support the sharing session<br \/>\ncd apache-tomcat-8.5.14\/lib<br \/>\nwget http:\/\/central.maven.org\/maven2\/de\/javakaffee\/msm\/memcached-session-manager\/2.1.1\/memcached-session-manager-2.1.1.jar<br \/>\nwget http:\/\/central.maven.org\/maven2\/de\/javakaffee\/msm\/memcached-session-manager-tc8\/2.1.1\/memcached-session-manager-tc8-2.1.1.jar<br \/>\nwget http:\/\/central.maven.org\/maven2\/net\/spy\/spymemcached\/2.11.1\/spymemcached-2.11.1.jar<br \/>\nwget http:\/\/central.maven.org\/maven2\/de\/javakaffee\/msm\/msm-javolution-serializer\/2.1.1\/msm-javolution-serializer-2.1.1.jar<br \/>\nwget http:\/\/central.maven.org\/maven2\/javolution\/javolution\/5.4.5\/javolution-5.4.5.jar<br \/>\ncd .. &#038;&#038; cd ..<\/p>\n<p># Disable scan for new TLDs added to the jar package<br \/>\nsed -i &#8216;134c xom-*.jar,javolution-5.4.5.jar,memcached-session-manager-2.1.1.jar,memcached-session-manager-tc8-2.1.1.jar,msm-javolution-serializer-2.1.1.jar,spymemcached-2.11.1.jar&#8217; apache-tomcat-8.5.14\/conf\/catalina.properties<br \/>\nOptimization of #tomcat, an insert in the line at 102<br \/>\nsed -i &#8216;102c export JAVA_OPTS=&#8221;-server -Xms1000M -Xmx1000M -Xss512k -XX:+AggressiveOpts -XX:+UseBiasedLocking -XX:+DisableExplicitGC -XX:MaxTenuringThreshold=15 -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -Djava.awt.headless=true&#8221;&#8216; apache-tomcat-8.5.14\/bin\/catalina.sh<\/p>\n<p>rm -rf apache-tomcat-8.5.14\/webapps<br \/>\nmkdir -vp apache-tomcat-8.5.14\/webapps\/ROOT<br \/>\ncp -r apache-tomcat-8.5.14 \/usr\/local\/tomcat<br \/>\nmv apache-tomcat-8.5.14 \/usr\/local\/tomcat2<br \/>\nchown ubuntu.ubuntu -R \/usr\/local\/tomcat<br \/>\nchown ubuntu.ubuntu -R \/usr\/local\/tomcat2<br \/>\nrm apache-tomcat-8.5.14.tar.gz<\/p>\n<p># Create a test page<br \/>\ntouch \/usr\/local\/tomcat\/webapps\/ROOT\/index.jsp<br \/>\necho &#8216;<%@ page language=\"java\" contentType=\"text\/html; charset=UTF-8\" pageEncoding=\"UTF-8\"%><html><head><title>Tomcat1<\/title><\/head><body><%=session.getId()%><\/body><\/html>&#8216; >\/usr\/local\/tomcat\/webapps\/ROOT\/index.jsp<br \/>\ntouch \/usr\/local\/tomcat2\/webapps\/ROOT\/index.jsp<br \/>\necho &#8216;<%@ page language=\"java\" contentType=\"text\/html; charset=UTF-8\" pageEncoding=\"UTF-8\"%><html><head><title>Tomcat2<\/title><\/head><body><%=session.getId()%><\/body><\/html>&#8216; >\/usr\/local\/tomcat2\/webapps\/ROOT\/index.jsp<\/p>\n<p># Configure sharing session<br \/>\n# Since we handed over static files nginx process, so no configuration requestUriIgnorePattern<br \/>\n# We configured to use Javolution serialization framework<br \/>\nvim \/usr\/local\/tomcat\/conf\/context.xml<br \/>\n# In <Context> was added the following content within the tag<br \/>\n##################################################<br \/>\n    <Manager className=\"de.javakaffee.web.msm.MemcachedBackupSessionManager\"\n        memcachedNodes=\"n1:127.0.0.1:11211,n2:127.0.0.1:11311\"\n        failoverNodes=\"n1\"\n        transcoderFactoryClass=\"de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory\"\n    \/><br \/>\n##################################################<\/p>\n<p># Tomcat2 also need to add the same content, the only difference is that instead n2 failoverNodes<br \/>\nvim \/usr\/local\/tomcat2\/conf\/context.xml<br \/>\n##################################################<br \/>\n    <Manager className=\"de.javakaffee.web.msm.MemcachedBackupSessionManager\"\n        memcachedNodes=\"n1:127.0.0.1:11211,n2:127.0.0.1:11311\"\n        failoverNodes=\"n2\"\n        transcoderFactoryClass=\"de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory\"\n    \/><br \/>\n##################################################<\/p>\n<p># Modify port configuration, modify the following content<br \/>\nvim \/usr\/local\/tomcat\/conf\/server.xml<br \/>\n##################################################<br \/>\n# Since our tomcat is running on a single server, so you need to add in jvmRoute Engine node respectively = &#8221; tomcat &#8221; and = jvmRoute &#8221; tomcat2 &#8221;<br \/>\n# Still optimized configuration, and does not turn gzip, has opened because nginx<br \/>\n    <Connector port=\"8080\" protocol=\"org.apache.coyote.http11.Http11AprProtocol\" URIEncoding=\"UTF-8\"\n               maxHttpHeaderSize=\"8192\" maxThreads=\"1000\"\n               minSpareThreads=\"100\" maxSpareThreads=\"1000\"\n               minProcessors=\"100\" maxProcessors=\"1000\"\n               connectionTimeout=\"25000\" acceptCount=\"1000\"\n               enableLookups=\"false\" disableUploadTimeout=\"true\" redirectPort=\"8443\" \/><br \/>\n    &#8230;&#8230;..<br \/>\n    <Engine name=\"Catalina\" defaultHost=\"localhost\" jvmRoute=\"tomcat\"><br \/>\n##################################################<\/p>\n<p># The same port configuration modifications tomcat2<br \/>\nvim \/usr\/local\/tomcat2\/conf\/server.xml<br \/>\n##################################################<br \/>\n    <Connector port=\"8180\" protocol=\"org.apache.coyote.http11.Http11AprProtocol\" URIEncoding=\"UTF-8\"\n               maxHttpHeaderSize=\"8192\" maxThreads=\"1000\"\n               minSpareThreads=\"100\" maxSpareThreads=\"1000\"\n               minProcessors=\"100\" maxProcessors=\"1000\"\n               connectionTimeout=\"25000\" acceptCount=\"1000\"\n               enableLookups=\"false\" disableUploadTimeout=\"true\" redirectPort=\"8443\" \/><br \/>\n    &#8230;&#8230;..<br \/>\n    <Engine name=\"Catalina\" defaultHost=\"localhost\" jvmRoute=\"tomcat2\"><br \/>\n##################################################<br \/>\n# While Tomcat2 profile all changed 8105,8009 8180,8005 8080 port to 8109 instead, because it is interactive and so do not configure SSL nginx<\/p>\n<p># Configure the following content to optimize tomcat<br \/>\n# Installation configuration apr<br \/>\nwget http:\/\/mirror.bit.edu.cn\/apache\/\/apr\/apr-1.5.2.tar.gz<br \/>\ntar -zxvf apr-1.5.2.tar.gz<br \/>\ncd apr-1.5.2 &#038;&#038; .\/configure &#8211;prefix=\/usr\/local\/apr<br \/>\nmake &#038;&#038; make install<br \/>\ncd .. &#038;&#038; rm -rf apr-1.5.2 &#038;&#038; rm apr-1.5.2.tar.gz<\/p>\n<p>apr-util<br \/>\nwget http:\/\/mirror.bit.edu.cn\/apache\/\/apr\/apr-util-1.5.4.tar.gz<br \/>\ntar -zxvf apr-util-1.5.4.tar.gz<br \/>\ncd apr-util-1.5.4 &#038;&#038; .\/configure &#8211;prefix=\/usr\/local\/apr-util &#8211;with-apr=\/usr\/local\/apr<br \/>\nmake &#038;&#038; make install<br \/>\ncd .. &#038;&#038; rm -rf apr-util-1.5.4 &#038;&#038; rm apr-util-1.5.4.tar.gz<\/p>\n<p>tomcat-native<br \/>\nwget https:\/\/mirrors.tuna.tsinghua.edu.cn\/apache\/tomcat\/tomcat-connectors\/native\/1.2.12\/source\/tomcat-native-1.2.12-src.tar.gz<br \/>\ntar -zxvf tomcat-native-1.2.12-src.tar.gz<br \/>\ncd tomcat-native-1.2.12-src\/native &#038;&#038; .\/configure &#8211;with-apr=\/usr\/local\/apr<br \/>\nmake &#038;&#038; make install<br \/>\ncd .. &#038;&#038; cd .. &#038;&#038; rm -rf tomcat-native-1.2.12-src &#038;&#038; rm tomcat-native-1.2.12-src.tar.gz<\/p>\n<p>tomcat-native<br \/>\nsed -i &#8216;$a export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:\/usr\/local\/apr\/lib&#8217; \/etc\/profile<br \/>\nsource \/etc\/profile<\/p>\n<p># The last installation configuration Nginx<br \/>\nwget http:\/\/nginx.org\/download\/nginx-1.12.0.tar.gz<br \/>\ntar -zxvf nginx-1.12.0.tar.gz<br \/>\ncd nginx-1.12.0 &#038;&#038; .\/configure &#8211;user=ubuntu &#8211;group=ubuntu &#8211;prefix=\/usr\/local\/nginx &#8211;with-http_ssl_module &#8211;with-http_gzip_static_module<br \/>\nmake &#038;&#038; make install<br \/>\nchown ubuntu.ubuntu -R \/usr\/local\/nginx<br \/>\ncd .. &#038;&#038; rm -rf nginx-1.12.0 &#038;&#038; rm nginx-1.12.0.tar.gz<\/p>\n<p># First ssl certificates in the \/ usr \/ local \/ nginx \/ conf \/ directory, respectively cert.crt and cert.key file, if you do not configure SSL skip<br \/>\nvim \/usr\/local\/nginx\/conf\/nginx.conf<br \/>\n# Set nginx.conf, configuration optimization has been done, if you do not need to change the corresponding configuration to SSL<br \/>\n##################################################<br \/>\nuser ubuntu ubuntu;<br \/>\nworker_processes auto;<br \/>\nworker_rlimit_nofile 65535 ;<br \/>\nerror_log logs\/error.log warn;<br \/>\npid logs\/nginx.pid;<\/p>\n<p>events {<br \/>\n    use epoll;<br \/>\n    worker_connections 65500;<br \/>\n}<\/p>\n<p>http {<br \/>\n    server_tokens off;<br \/>\n    include mime.types;<br \/>\n    default_type application\/octet-stream;<br \/>\n    charset utf-8;<\/p>\n<p>    log_format main &#8216;$remote_addr &#8211; $remote_user [$time_local] &#8220;$request&#8221; &#8216;<br \/>\n                    &#8216;$status $body_bytes_sent &#8220;$http_referer&#8221; &#8216;<br \/>\n                    &#8216;&#8221;$http_user_agent&#8221; &#8220;$http_x_forwarded_for&#8221;&#8216;;<br \/>\n    access_log logs\/access.log main;<\/p>\n<p>    sendfile on;<br \/>\n    tcp_nopush on;<br \/>\n    reset_timedout_connection on;<br \/>\n    keepalive_timeout 30;<\/p>\n<p>    open_file_cache max=65535 inactive=20s;<br \/>\n    open_file_cache_min_uses 1;<br \/>\n    open_file_cache_valid 30s;<\/p>\n<p>    gzip on;<br \/>\n    gzip_comp_level 5;<br \/>\n    gzip_min_length 256;<br \/>\n    gzip_proxied any;<br \/>\n    gzip_vary on;<br \/>\n    gzip_http_version 1.0;<br \/>\n    gzip_buffers 4 16k;<br \/>\n    gzip_types<br \/>\n            text\/plain text\/css text\/xml application\/xml text\/x-json application\/json<br \/>\n            image\/svg+xml image\/png image\/jpeg image\/x-icon image\/gif<br \/>\n            text\/javascript application\/javascript application\/x-javascript<br \/>\n            application\/x-font-truetype application\/x-font-woff application\/vnd.ms-fontobject;<br \/>\n    gzip_disable &#8220;MSIE [1-6]\\.&#8221;;<\/p>\n<p>    proxy_redirect off;<br \/>\n    proxy_set_header Host $host;<br \/>\n    proxy_set_header X-Real-IP $remote_addr;<br \/>\n    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br \/>\n    proxy_connect_timeout 90;<br \/>\n    proxy_send_timeout 90;<br \/>\n    proxy_read_timeout 90;<br \/>\n    proxy_buffer_size 32k;<br \/>\n    proxy_buffers 4 32k;<br \/>\n    proxy_busy_buffers_size 64k;<br \/>\n    proxy_temp_file_write_size 64k;<\/p>\n<p>    upstream tomcat_server {<br \/>\n        server localhost:8080 weight=1;<br \/>\n        server localhost:8180 weight=1;<br \/>\n    }<\/p>\n<p>    server {<br \/>\n        listen 80;<br \/>\n        server_name localhost;<br \/>\n        return 301 https:\/\/$host$request_uri;<br \/>\n    }<\/p>\n<p>    server {<br \/>\n        listen 443 ssl;<br \/>\n        server_name localhost;<br \/>\n        ssl_certificate cert.crt;<br \/>\n        ssl_certificate_key cert.key;<br \/>\n        ssl_session_cache shared:SSL:1m;<br \/>\n        ssl_session_timeout 5m;<br \/>\n        ssl_ciphers HIGH: ! Anull :! MD5;<br \/>\n        ssl_prefer_server_ciphers on;<br \/>\n        location \/ {<br \/>\n            root \/usr\/local\/tomcat\/webapps\/ROOT;<br \/>\n            index index.html index.jsp index.htm;<br \/>\n            expires 30d;<br \/>\n        }<br \/>\n        location ~ \\.(jsp|servlet|do)$ {<br \/>\n            index index.html index.jsp index.htm;<br \/>\n            proxy_pass http:\/\/tomcat_server;<br \/>\n        }<br \/>\n        error_page 400 404 414 500 502 503 504 \/error.html;<br \/>\n    }<br \/>\n}<br \/>\n##################################################<br \/>\nAre you the type of need does not exist # recommended to check the type gzip<br \/>\n# If your tomcat is configured with multiple projects, only you need to add the following content to the nginx.conf<br \/>\n        LOCATION \/ your project name {<br \/>\n            root \/usr\/local\/tomcat\/webapps;<br \/>\n            index index.html index.jsp index.htm;<br \/>\n            expires 30d;<br \/>\n        }<br \/>\n##################################################<br \/>\nAfter # Save, enter the following command to check the configuration<br \/>\n\/usr\/local\/nginx\/sbin\/nginx -t<br \/>\nnginx ?sudo \/usr\/local\/nginx\/sbin\/nginx -s reload<\/p>\n<p>Switching to the normal user #<br \/>\nyour ubuntu<\/p>\n<p>memcached?ps -ef | grep memcached<br \/>\n\/usr\/local\/memcached\/bin\/memcached -d -m 64M -u ubuntu -l 127.0.0.1 -p 11211 -c 32750 -P \/tmp\/memcached-n1.pid<br \/>\n\/usr\/local\/memcached\/bin\/memcached -d -m 64M -u ubuntu -l 127.0.0.1 -p 11311 -c 32750 -P \/tmp\/memcached-n2.pid<\/p>\n<p># Start Tomcat, be sure to use ordinary users to run Tomcat<br \/>\n\/usr\/local\/tomcat\/bin\/startup.sh &#038;&#038; \/usr\/local\/tomcat2\/bin\/startup.sh<\/p>\n<p># Start nginx, be sure to use administrator privileges to run nginx<br \/>\nsudo \/usr\/local\/nginx\/sbin\/nginx<\/p>\n","protected":false},"excerpt":{"rendered":"<p>?Tomcat+Nginx+Memcached<\/p>\n<p>??Ubuntu 16.04 64 bit test pass<\/p>\n<p>??Movement classification, load balancing, clustering, Javolution serialized, high-performance, high availability<\/p>\n<p>Configuration environment (both current latest stable version): ??the JDK-Linux-x64-8u131 ??the Apache-Tomcat-8.5.14 ??nginx-1.12.0 ??memcached-1.4.36<\/p>\n<p>EDITORIAL:<\/p>\n<p>??Originally intended configuration kryo serialization framework, but also how to get unsuccessful, with only a Javolution ??If the last unsuccessful general problems will find [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6770"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6770"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6770\/revisions"}],"predecessor-version":[{"id":6771,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6770\/revisions\/6771"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6770"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6770"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6770"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}