1024programmer Nginx Nginx+tomcat server environment load balancing configuration

Nginx+tomcat server environment load balancing configuration

NGINX_TOMCAT LoadBalanceConfiguration

This configuration is already running in production.

software:

Nginx-1.0.8

Download address: http://nginx.org/download/nginx-1.0.8.tar.gz

apache-tomcat-6.0.18

Download address: http://archive.apache.org/dist/tomcat/tomcat-6/v6.0.18/bin/apache-tomcat-6.0.18.tar.gz

jdk-6u27-linux-i586.bin

Download address: http://download.oracle.com/auth/otn-pub/java/jdk/6u27-b07/jdk-6u27-linux-i586.bin?e=131891933

Pcre-8.00

Download link: http://nchc.dl.sourceforge.net/project/pcre/pcre/8.00/pcre-8.00.tar.gz

Nginx-upstream-jvm-route-0.2

Download address: http://nginx-upstream-jvm-route.googlecode.com/files/nginx-upstream-jvm-route-0.2.tar.gz

Configuration environment:

Nginx server address: 192.168.1.20

Apache_tomcat1 server: 192.168.1.21

Apache_tomcat2 server: 192.168.1.22

One: Software installation steps

Download all packages to: /usr/src path

Configure nginx server:

1: Compile and install pcre-8.00

[root@mysql2 ~]# cd /usr/src/

[root@mysql2 src]# tar xf pcre-8.00.tar.gz

[root@mysql2 src]# cd pcre-8.00/

[root@mysql2 pcre-8.00]# ./configure ;make;make install

2: Compile and install nginx-1.0.8

[root@mysql2 src]# tar xf
nginx-upstream-jvm-route-0.1.tar.gz

[root@mysql2 src]# tar xf nginx-1.0.8.tar.gz

[root@mysql2 src]# cd nginx-1.0.8/

[root@mysql2 nginx-1.0.8]# patch -p0 <
/usr/src/nginx_upstream_jvm_route/jvm_route.patch

[root@mysql2 nginx-1.0.8]# ./configure –prefix=/usr/local/nginx
–with-pcre=/usr/src/pcre-8.00/ –with-http_stub_status_module
–with-http_sub_module
–add-module=/usr/src/nginx_upstream_jvm_route

3: Modify the Nginx configuration file

[root@mysql2 ~]# cd /usr/local/nginx/conf/

[root@mysql2 conf]# cp nginx.conf nginx.conf.back

[root@mysql2 conf]# vi nginx.conf

user nginx nginx;


worker_processes 8;


error_log logs/error.log;


#error_log logs/error.log notice;


#error_log logs/error.log info;


pid logs/nginx.pid;

worker_rlimit_nofile
65535;

events {

use
epoll;

“ “
worker_connections 10240;

}

http {

“ “
include mime.types;

“ “
default_type application/octet-stream;

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

“ “
server_names_hash_bucket_size 128;

“ “
client_header_buffer_size 32k;

“ “
large_client_header_buffers 4 32k;

“ “
client_max_body_size 8m;

“ “
#keepalive_timeout 0;

“ “
keepalive_timeout 60;

“ “
gzip on;

“ “
gzip_min_length 1k;

“ “
gzip_buffers 4 1nbsp;
# if this happens, d_start will fail (and dpkg
will break if
# the package is being upgraded). Change the
timeout if needed
# be, or change d_stop to have start-stop-daemon
use –retry.
# Notice that using –retry slows down the
shutdown process somewhat.
sleep 3
d_start
echo “done.”
;;
‘list’)
ps auxf | egrep ‘(PID|nginx)’ | grep -v
grep
;;
‘test’)
$DAEMON -t -c $CONFIGFILE
;;
*)
echo “Usage: $SCRIPTNAME {reload|list|test|start|stop|restart}”
>&2
exit 3
;;
esac
exit 0

[root@mysql2 conf]# chmod 755 /etc/init.d/nginx

[root@mysql2 conf]# /etc/init.d/nginx start

[root@mysql2 conf]# /etc/init.d/nginx stop

[root@mysql2 conf]# chkconfig –add
nginx #Boot self-start

Check if the server port is up:

[root@mysql2 conf]# lsof ?i:80

View service status:

http://192.168.1.20/nginx

Apache-tomcat server configuration

1: jdk-6u27-linux-i586.bin installation

[root@web usr]# cd /usr/src/

[root@web src]# ./jdk-6u27-linux-i586.bin

[root@web src]# mv jdk1.6.0_27/ /usr/local/

[root@web src]# vi /etc/profile

JAVA_HOME=/usr/local/jdk1.6.0_27

CLASSPATH=”.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar”

PATH=$JAVA_HOME/bin:$PATH

TOMCAT_HOME=/usr/local/tomcat

export JAVA_HOME CLASSPATH PATH TOMCAT_HOME

Make configuration take effect:

[root@web src]# source /etc/profile

View the current java version number:

[root@web src]# java -version

java version “1.6.0_27”

2: apache-tomcat-6.0.18 installation

[root@web src]# tar xf apache-tomcat-6.0.18.tar.gz

[root@web src]# mv apache-tomcat-6.0.18 /usr/local/tomcat1

[root@web tomcat]# cd /usr/local/tomcat/conf/

Modify the configuration file:

[root@web conf]# vi server.xml

[root@web conf]# vi tomcat-users.xml

[root@web conf]# cd /usr/local/tomcat/bin/

[root@web bin]# vi catalina.sh

74 JAVA_HOME=/usr/local/jdk1.6.0_27

JAVA_OPTS=”-server -Xms256m -Xmx512m”

Start the service:

[root@web bin]# /usr/local/tomcat/bin/startup.sh

Close the service:

[root@web bin]# /usr/local/tomcat/bin/shutdown.sh

Check the service port:

[root@web bin]# lsof -i:8080

COMMAND PID USER FD TYPE DEVICE
SIZE NODE NAME

java 6414 root
29u IPv4 24953 TCP
*:webcache (LISTEN)

Create a test page in the directory

[root@web ~]# mkdir /usr/local/tomcat/webapps/opps

[root@web ~]# vi /usr/local/tomcat/webapps/opps/mem.jsp

<%

Runtime lRuntime = Runtime. getRuntime();

out.println(“*** BEGIN MEMORY STATISTICS ***
“);

out.println(“Free Memory:
“+lRuntime. freeMemory()+”
“);

out.println(“Max Memory:
“+lRuntime.maxMemory()+”
“);

out.println(“Total Memory:
“+lRuntime. totalMemory()+”
“);

out.println(“Available Processors :
“+lRuntime.availableProcessors()+”
“);

out.println(“*** END MEMORY STATISTICS ***”);

%>

Access test:

http://192.168.1.20/mem.jsp

It can be accessed, which proves that the configuration is successful. OK

In the configuration step of another server in TOMCAT, just repeat the steps of the first one, so I won’t write it here.

System kernel optimization parameters: (add on three)

[root@web bin]# /etc/sysctl.conf

# Use TCP synCOOKIEs when needed

net.ipv4.tcp_synCOOKIEs = 1

# Enable TCP window scaling

net.ipv4.tcp_window_scaling := 1

# Increase TCP max buffer size

net.core.rmem_max = 16777216

net.core.wmem_max = 16777216

# Increase Linux autotuning TCP buffer limits

net.ipv4.tcp_rmem = 4096 87380 16777216

net.ipv4.tcp_wmem = 4096 65536 16777216

# Increase number of ports available

net.ipv4.ip_local_port_range = 1024 65000

Make configuration take effect immediately:

[root@web bin]# /sbin/sysctl -p

max = 16777216

# Increase Linux autotuning TCP buffer limits

net.ipv4.tcp_rmem = 4096 87380 16777216

net.ipv4.tcp_wmem = 4096 65536 16777216

# Increase number of ports available

net.ipv4.ip_local_port_range = 1024 65000

Make configuration take effect immediately:

[root@web bin]# /sbin/sysctl -p

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/nginxtomcat-server-environment-load-balancing-configuration/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索