Nginx
搭建集群
建立三台Tomcat 修改3台tomcat配置文件
vi /opt/bdp/apache-tomcat-8.5.47/webapps/ROOT/index.jsp
<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<%
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy");
request.setAttribute("year", sdf.format(new java.util.Date()));
request.setAttribute("tomcatUrl", "https://tomcat.apache.org/");
request.setAttribute("tomcatDocUrl", "/docs/");
request.setAttribute("tomcatExamplesUrl", "/examples/");
%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title><%=request.getServletContext().getServerInfo() %></title>
<link href="favicon.ico" rel="icon" type="image/x-icon" />
<link href="favicon.ico" rel="shortcut icon" type="image/x-icon" />
<link href="tomcat.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>welcome to tomcat lzj</h1>
<h1>Server:<%=request.getLocalAddr() %></h1>
<h1>Client:<%=request.getRemoteAddr() %></h1>
<h1>Session:<%=session.getId() %></h1>
<hr/>
<img src = 'https://img1.baidu.com/it/u=3989847751,3083795632&fm=253&fmt=auto&app=138&f=PNG?w=1153&h=500' height="200px" />
</body>
</html>
vim /opt/bdp/nginx-1.8.1/conf
#user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 0;
upstream bdp {
server 192.168.88.101:8080;
server 192.168.88.102:8080;
server 192.168.88.103:8080;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://bdp;
}
}
}
cd /opt/bdp/nginx-1.8.1/sbin
启动Nginx
./nginx -s reload
创建多个Tomcat
修改配置文件
vim /etc/profile 加入以下代码
#tomcat8080
export CATALINA_HOME=/opt/bdp/apache-tomcat-8080
export CATALINA_BASE=/opt/bdp/apache-tomcat-8080
export TOMCAT_HOME=/opt/bdp/apache-tomcat-8080
#tomcat18080
export CATALINA_HOME18080=/opt/bdp/apache-tomcat-18080
export CATALINA_BASE18080=/opt/bdp/apache-tomcat-18080
export TOMCAT_HOME18080=/opt/bdp/apache-tomcat-18080
修改18080配置文件
apache-tomcat-18080/conf/server.xml
22--默认为8005--》修改为18005
<Server port="18005" shutdown="SHUTDOWN">
69--默认为8080--》修改为18080
<Connector port="18080" protocol="HTTP/1.1" connectionTimeout="20000"
redirectPort="8443" />
116-默认为8009--》修改为18009
<Connector port="18009" protocol="AJP/1.3" redirectPort="8443" />
vim apache-tomcat-18080/bin/catalina.sh
113行以后加入
export CATALINA_BASE=$CATALINA_BASE18080
export CATALINA_HOME=$CATALINA_HOME18080
export TOMCAT_HOME=$TOMCAT_HOME18080
重启
reboot
进入两个tomcat启动
修改配置文件
#user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream bdp {
server 192.168.88.101:8080;
server 192.168.88.102:8080;
server 192.168.88.103:8080;
}
upstream bdpweight {
server 192.168.88.101:8080 weight=4;
server 192.168.88.102:8080 weight=1;
server 192.168.88.103:8080 weight=1;
}
upstream miaosha {
server 192.168.88.101:8080;
server 192.168.88.102:8080;
server 192.168.88.103:8080;
}
upstream fxhh {
server 192.168.88.101:18080;
server 192.168.88.102:18080;
server 192.168.88.103:18080;
}
upstream port12345 {
server 192.168.88.101:8080;
server 192.168.88.102:8080;
server 192.168.88.103:8080;
}
upstream port54321 {
server 192.168.88.101:18080;
server 192.168.88.102:18080;
server 192.168.88.103:18080;
}
server {
listen 12345;
server_name www.bdp.com;
location / {
proxy_pass http://port12345;
}
}
server {
listen 54321;
server_name www.bdp.com;
location / {
proxy_pass http://port54321;
}
}
server {
listen 80;
server_name www.miaosha.bdp.com;
location / {
proxy_pass http://miaosha;
}
}
server {
listen 80;
server_name www.fxhh.bdp.com;
location / {
proxy_pass http://fxhh;
}
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://bdpweight;
}
location ^~ /static/ {
root html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
修改win host文件
192.168.88.100 www.miaosha.bdp.com
192.168.88.100 www.fxhh.bdp.com
www.miaosha.bdp.com 进入8080端口
www.fxhh.bdp.com 进入18080端口