您的位置:首页 > 运维架构 > Tomcat

linux企业常用服务---部署Nginx+Tomcat负载均衡集群

2016-05-15 14:08 609 查看
部署前准备:

iptables和selinux不做配置,关掉系统光盘作为yum源,配置yum文件源码包准备jdk-7u65-linux-x64.gz apache-tomcat-7.0.54.tar.gz注意源码包存放位置要与脚本中相互对应环境介绍:一台nginx,两台tomcat
分别在后端tomcat1和tomcat2上配置:
[root@localhost ~]# vi install_tomcat.sh
#!/bin/bash
##by linuxfan
#################解压######################
tar zxvf /usr/src/jdk-7u65-linux-x64.gz -C /usr/src/
tar zxvf /usr/src/apache-tomcat-7.0.54.tar.gz -C /usr/src/
###############config java env#############
yum -y remove java
mv /usr/src/jdk1.7.0_65/ /usr/local/java
cat <<END >>/etc/profile ##设置JAVA的环境变量
export JAVA_HOME=/usr/local/java
export PATH=\$PATH:\$JAVA_HOME/bin
END
source /etc/profile
java -version
################config tomcat7 #############
mv /usr/src/apache-tomcat-7.0.54 /usr/local/tomcat7
reboot
:wq
sh -x install_tomcat.sh
等待重启后,启动服务:
/usr/local/tomcat7/bin/startup.sh &&netstat -utpln |grep 8080
cd /usr/local/tomcat7/webapps/ROOT/
[root@localhost ROOT]# rm -rf ./*
[root@localhost ROOT]# vi index.jsp ##这里注意tomcat1和2服务器的网页不同,分别设为test1,test2
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head>
<title>JSP TEST PAGE1 </title>
</head>
<body>
<% out.println("Welcome to test site;http://www.test1.com");%>
</body>
</html>
:wq
分别访问测试:
http://ip地址:8080/

配置前端nginx:
yum -y install pcre-devel zlib-devel openssl-devel
useradd -s /bin/false nginx
tar axvf nginx-1.6.2.tar.gz
cd nginx-1.6.2
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-file-aio --with-http_stub_status_module --with-http_gzip_static_module --with-http_flv_module \
--with-http_ssl_module &&make &&make install

vim nginx.conf
upstream tomcat_server { ##在http{}中
server tomcat1的ip地址:8080 weight=1; ##weight表权重,根据实际情况可设置
server tomcat2的ip地址:8080 weight=1;
}
location / { ##在server{}中
root html;
index index.html index.htm;
proxy_pass http://tomcat_server; }
:wq

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

多次访问测试:最终实现负载均衡本文出自 “LP-linux” 博客,请务必保留此出处http://linuxlp.blog.51cto.com/11463376/1773579
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: