April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

Categories

April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

Tomcat+Nginx+Memcached

?Tomcat+Nginx+Memcached

??Ubuntu 16.04 64 bit test pass

??Movement classification, load balancing, clustering, Javolution serialized, high-performance, high availability

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

EDITORIAL:

??Originally intended configuration kryo serialization framework, but also how to get unsuccessful, with only a Javolution
??If the last unsuccessful general problems will find out in Tomcat, look at the log resolved
??under tomcat can deploy multiple projects, and the movement is still classified
??nginx configured to jsp, servlet, do the file extension to the Tomcat process, can be added according to the situation
??if you do not use the root account, then run nginx, nginx is useless to the user to configure
??Tomcat, nginx are optimized configuration, without modifying the original project Nothing, directly into the Tomcat / webapps where you can

process:

??Long process, carefully

# Sudo passwd
# Use administrator to configure
Sudo Su
# Update software list
apt-get update
# Install the required dependencies
apt-get install gcc zlib1g zlib1g-dev openssl libssl-dev libpcre3 libpcre3-dev libevent-dev
# Reboot (recommended)
reboot

sudo su
http://www.Oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
tar -zxvf jdk-8u131-linux-x64.tar.gz
mv jdk1.8.0_131 /usr/local/jdk

# Configure JDK environment variables
sed -i ‘$a ulimit -n 65535’ /etc/profile
sed -i ‘$a export JAVA_HOME=/usr/local/jdk’ /etc/profile
sed -i ‘$a export JRE_HOME=$JAVA_HOME/jre’ /etc/profile
sed -i ‘$a export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH’ /etc/profile
sed -i ‘$a export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH’ /etc/profile
source /etc/profile

rm jdk-8u131-linux-x64.tar.gz

# Installation configuration memcached
wget http://www.memcached.org/files/memcached-1.4.36.tar.gz
tar -zxvf memcached-1.4.36.tar.gz
cd memcached-1.4.36
./configure –prefix=/usr/local/memcached
make && make install
cd .. && rm -rf memcached-1.4.36 && rm memcached-1.4.36.tar.gz

# Configure Tomcat installation
wget http://apache.fayea.com/tomcat/tomcat-8/v8.5.14/bin/apache-tomcat-8.5.14.tar.gz
tar -zxvf apache-tomcat-8.5.14.tar.gz

# Download the added lib file to support the sharing session
cd apache-tomcat-8.5.14/lib
wget http://central.maven.org/maven2/de/javakaffee/msm/memcached-session-manager/2.1.1/memcached-session-manager-2.1.1.jar
wget http://central.maven.org/maven2/de/javakaffee/msm/memcached-session-manager-tc8/2.1.1/memcached-session-manager-tc8-2.1.1.jar
wget http://central.maven.org/maven2/net/spy/spymemcached/2.11.1/spymemcached-2.11.1.jar
wget http://central.maven.org/maven2/de/javakaffee/msm/msm-javolution-serializer/2.1.1/msm-javolution-serializer-2.1.1.jar
wget http://central.maven.org/maven2/javolution/javolution/5.4.5/javolution-5.4.5.jar
cd .. && cd ..

# Disable scan for new TLDs added to the jar package
sed -i ‘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’ apache-tomcat-8.5.14/conf/catalina.properties
Optimization of #tomcat, an insert in the line at 102
sed -i ‘102c export JAVA_OPTS=”-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”‘ apache-tomcat-8.5.14/bin/catalina.sh

rm -rf apache-tomcat-8.5.14/webapps
mkdir -vp apache-tomcat-8.5.14/webapps/ROOT
cp -r apache-tomcat-8.5.14 /usr/local/tomcat
mv apache-tomcat-8.5.14 /usr/local/tomcat2
chown ubuntu.ubuntu -R /usr/local/tomcat
chown ubuntu.ubuntu -R /usr/local/tomcat2
rm apache-tomcat-8.5.14.tar.gz

# Create a test page
touch /usr/local/tomcat/webapps/ROOT/index.jsp
echo ‘<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>Tomcat1<%=session.getId()%>‘ >/usr/local/tomcat/webapps/ROOT/index.jsp
touch /usr/local/tomcat2/webapps/ROOT/index.jsp
echo ‘<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>Tomcat2<%=session.getId()%>‘ >/usr/local/tomcat2/webapps/ROOT/index.jsp

# Configure sharing session
# Since we handed over static files nginx process, so no configuration requestUriIgnorePattern
# We configured to use Javolution serialization framework
vim /usr/local/tomcat/conf/context.xml
# In was added the following content within the tag
##################################################

##################################################

# Tomcat2 also need to add the same content, the only difference is that instead n2 failoverNodes
vim /usr/local/tomcat2/conf/context.xml
##################################################

##################################################

# Modify port configuration, modify the following content
vim /usr/local/tomcat/conf/server.xml
##################################################
# Since our tomcat is running on a single server, so you need to add in jvmRoute Engine node respectively = ” tomcat ” and = jvmRoute ” tomcat2 ”
# Still optimized configuration, and does not turn gzip, has opened because nginx

……..

##################################################

# The same port configuration modifications tomcat2
vim /usr/local/tomcat2/conf/server.xml
##################################################

……..

##################################################
# 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

# Configure the following content to optimize tomcat
# Installation configuration apr
wget http://mirror.bit.edu.cn/apache//apr/apr-1.5.2.tar.gz
tar -zxvf apr-1.5.2.tar.gz
cd apr-1.5.2 && ./configure –prefix=/usr/local/apr
make && make install
cd .. && rm -rf apr-1.5.2 && rm apr-1.5.2.tar.gz

apr-util
wget http://mirror.bit.edu.cn/apache//apr/apr-util-1.5.4.tar.gz
tar -zxvf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4 && ./configure –prefix=/usr/local/apr-util –with-apr=/usr/local/apr
make && make install
cd .. && rm -rf apr-util-1.5.4 && rm apr-util-1.5.4.tar.gz

tomcat-native
wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-connectors/native/1.2.12/source/tomcat-native-1.2.12-src.tar.gz
tar -zxvf tomcat-native-1.2.12-src.tar.gz
cd tomcat-native-1.2.12-src/native && ./configure –with-apr=/usr/local/apr
make && make install
cd .. && cd .. && rm -rf tomcat-native-1.2.12-src && rm tomcat-native-1.2.12-src.tar.gz

tomcat-native
sed -i ‘$a export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/apr/lib’ /etc/profile
source /etc/profile

# The last installation configuration Nginx
wget http://nginx.org/download/nginx-1.12.0.tar.gz
tar -zxvf nginx-1.12.0.tar.gz
cd nginx-1.12.0 && ./configure –user=ubuntu –group=ubuntu –prefix=/usr/local/nginx –with-http_ssl_module –with-http_gzip_static_module
make && make install
chown ubuntu.ubuntu -R /usr/local/nginx
cd .. && rm -rf nginx-1.12.0 && rm nginx-1.12.0.tar.gz

# First ssl certificates in the / usr / local / nginx / conf / directory, respectively cert.crt and cert.key file, if you do not configure SSL skip
vim /usr/local/nginx/conf/nginx.conf
# Set nginx.conf, configuration optimization has been done, if you do not need to change the corresponding configuration to SSL
##################################################
user ubuntu ubuntu;
worker_processes auto;
worker_rlimit_nofile 65535 ;
error_log logs/error.log warn;
pid logs/nginx.pid;

events {
use epoll;
worker_connections 65500;
}

http {
server_tokens off;
include mime.types;
default_type application/octet-stream;
charset utf-8;

log_format main ‘$remote_addr – $remote_user [$time_local] “$request” ‘
‘$status $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” “$http_x_forwarded_for”‘;
access_log logs/access.log main;

sendfile on;
tcp_nopush on;
reset_timedout_connection on;
keepalive_timeout 30;

open_file_cache max=65535 inactive=20s;
open_file_cache_min_uses 1;
open_file_cache_valid 30s;

gzip on;
gzip_comp_level 5;
gzip_min_length 256;
gzip_proxied any;
gzip_vary on;
gzip_http_version 1.0;
gzip_buffers 4 16k;
gzip_types
text/plain text/css text/xml application/xml text/x-json application/json
image/svg+xml image/png image/jpeg image/x-icon image/gif
text/javascript application/javascript application/x-javascript
application/x-font-truetype application/x-font-woff application/vnd.ms-fontobject;
gzip_disable “MSIE [1-6]\.”;

proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 32k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;

upstream tomcat_server {
server localhost:8080 weight=1;
server localhost:8180 weight=1;
}

server {
listen 80;
server_name localhost;
return 301 https://$host$request_uri;
}

server {
listen 443 ssl;
server_name localhost;
ssl_certificate cert.crt;
ssl_certificate_key cert.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH: ! Anull :! MD5;
ssl_prefer_server_ciphers on;
location / {
root /usr/local/tomcat/webapps/ROOT;
index index.html index.jsp index.htm;
expires 30d;
}
location ~ \.(jsp|servlet|do)$ {
index index.html index.jsp index.htm;
proxy_pass http://tomcat_server;
}
error_page 400 404 414 500 502 503 504 /error.html;
}
}
##################################################
Are you the type of need does not exist # recommended to check the type gzip
# If your tomcat is configured with multiple projects, only you need to add the following content to the nginx.conf
LOCATION / your project name {
root /usr/local/tomcat/webapps;
index index.html index.jsp index.htm;
expires 30d;
}
##################################################
After # Save, enter the following command to check the configuration
/usr/local/nginx/sbin/nginx -t
nginx???sudo /usr/local/nginx/sbin/nginx -s reload

Switching to the normal user #
your ubuntu

memcached?ps -ef | grep memcached
/usr/local/memcached/bin/memcached -d -m 64M -u ubuntu -l 127.0.0.1 -p 11211 -c 32750 -P /tmp/memcached-n1.pid
/usr/local/memcached/bin/memcached -d -m 64M -u ubuntu -l 127.0.0.1 -p 11311 -c 32750 -P /tmp/memcached-n2.pid

# Start Tomcat, be sure to use ordinary users to run Tomcat
/usr/local/tomcat/bin/startup.sh && /usr/local/tomcat2/bin/startup.sh

# Start nginx, be sure to use administrator privileges to run nginx
sudo /usr/local/nginx/sbin/nginx

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>