nginx负载均衡toncat服务搭建
(1).tomcat部署
包名:
apache-tomcat-7.0.56.tar.gz
jdk-7u71-linux-x64.rpm
JDK安装:
rpm -qa | grep -i java | xargs yum -y remove
rpm -ivh jdk-7u71-linux-x64.rpm
vim /etc/profile:
JAVA_HOME=/usr/java/jdk1.7.0_71^M
JRE_HOME=/usr/java/jdk1.7.0_71/jre^M
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin^M
CLASSPATH=$CLASSPATH:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib^M
export JAVA_HOME JRE_HOME PATH CLASSPATH
tomcat安装:
find / -name tomcat|xargs rm -rf
tar -zxvf apache-tomcat-7.0.56.tar.gz
mv apache-tomcat-7.0.56 tomcat1
cp -r tomcat1 tomcat2
tomcat启动脚本:
cp tomcat /etc/init.d/
mv tomcat tomcat1
cp tomcat1 tomcat2
修改配置文件里的tomcat为相应的tomcat服务编号
chmod 755 tomcat1
chmod 755 tomcat2
chkconfig --add tomcat1
chkconfig --add tomcat2
1.服务端口更改
server默认:
8080 HTTP服务端口
8005 为远程停服务端口
8009 为AJP端口,APACHE能过AJP协议访问TOMCAT的8009端口。
8443 默认的HTTPS端口
2.系统环境变量增加
环境变量:
etc/profile
91 #tomcat2
92 CATALINA_2_BASE=/opt/tomcat2
93 CATALINA_2_HOME=/opt/tomcat2
94 TOMCAT_2_HOME=/opt/tomcat2
95 export CATALINA_2_BASE CATALINA_2_HOME TOMCAT_2_HOME
source /etc/profile
3.服务配置
shutdown.sh startup.sh增加下面配置
24 export JAVA_HOME=/usr/java/jdk1.7.0_71
25 export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
26 export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
27 export CATALINA_HOME=$CATALINA_2_HOME
28 export CATALINA_BASE=$CATALINA_2_BASE
./bin/startup.sh ;tail -f logs/catalina.out
(2)nginx部署
/usr/local/src
nginx-1.10.2.tar.gz
yum -y install gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl openssl-devel
tar -zxvf nginx-1.10.2.tar.gz
cd nginx-1.10.2
./configure --prefix=/usr/local/nginx
make && make install
防火墙设置
/usr/local/nginx/sbin/nginx -t 检查nginx配置文件是否正确
/usr/local/nginx/sbin/nginx
/usr/local/nginx/sbin/nginx -s stop
/usr/local/nginx/sbin/nginx -s reload
开机自启
vi /etc/rc.local
/usr/local/nginx/sbin/nginx
(3)负载均衡设置
/opt/tomcat1/webapps/ROOT/index.jsp
配置nginx负载均衡,添加在http模块里
34 ##qa-web-pay-api(双机负载均衡)
35 upstream qa_web_pay_api {
36 server 172.11.30.134:8081 weight=3;
37 server 172.11.30.134:8082 weight=3;
38 }
39
40 server {
41 listen 80;
42 server_name localhost;
43 location / {
44 proxy_pass http://qa_web_pay_api/;
45 }