一、端口规划
IP:127.0.0.1
Tomcat端口:
远程关闭服务的端口:8005;8105;8205
HTTP请求监听的端口:8080;8181;8282
和其它的HTTP服务器建立连接的端口:8009;8109;8209
nginx端口:80
二、安装 Tomcat 服务器
(1)解压 apache-tomcat-7.0.88.tar.gz 到 D:\clustering-space\apache-tomcat-7.0.88 目录
(2)分别修改 conf 目录下的 server.xml 文件
D:\clustering-space\apache-tomcat-7.0.88\apache-tomcat-7.0.88-8080-8005-8009\conf\server.xml
<?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN">
...省略代码...
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
...省略代码...
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
...省略代码...
</Server>
D:\clustering-space\apache-tomcat-7.0.88\apache-tomcat-7.0.88-8181-8105-8109\conf\server.xml
<?xml version='1.0' encoding='utf-8'?>
<Server port="8105" shutdown="SHUTDOWN">
...省略代码...
<Connector port="8180" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
...省略代码...
<Connector port="8109" protocol="AJP/1.3" redirectPort="8443" />
...省略代码...
</Server>
D:\clustering-space\apache-tomcat-7.0.88\apache-tomcat-7.0.88-8282-8205-8209\conf\server.xml
<?xml version='1.0' encoding='utf-8'?>
<Server port="8205" shutdown="SHUTDOWN">
...省略代码...
<Connector port="8280" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
...省略代码...
<Connector port="8209" protocol="AJP/1.3" redirectPort="8443" />
...省略代码...
</Server>
三、安装 nginx 反向代理服务器
(1)解压 nginx-1.14.0.zip 到 D:\clustering-space\apache-tomcat-7.0.88 目录
(2)修改 D:\clustering-space\apache-tomcat-7.0.88\nginx-1.14.0\conf\nginx.conf 配置文件
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
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;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
#默认轮询
upstream tomcatCluster{
server 127.0.0.1:8181;
server 127.0.0.1:8282;
}
#加权轮询
#upstream tomcatCluster{
# server 127.0.0.1:8181 weight=1;
# server 127.0.0.1:8282 weight=2;
#}
#IP HASH
#upstream tomcatCluster{
# ip_hash;
# server 127.0.0.1:8181;
# server 127.0.0.1:8282;
#}
server {
listen 80;
server_name 127.0.0.1;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#反向代理 8080 服务器
location /tomcat/ {
proxy_pass http://127.0.0.1:8080/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
#反向代理 8181、8282 服务器集群
location /tomcat-cluster/ {
proxy_pass http://tomcatCluster/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_connect_timeout 1;
proxy_read_timeout 1;
proxy_send_timeout 1;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# 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 html;
# index index.html index.htm;
# }
#}
}
四、Tomcat 启动脚本
tomcat1.bat
title apache-tomcat-7.0.88-8080-8005-8009
D:
cd D:\clustering-space\apache-tomcat-7.0.88\apache-tomcat-7.0.88-8080-8005-8009\bin
startup.bat
tomcat2.bat
title apache-tomcat-7.0.88-8180-8105-8109
D:
cd D:\clustering-space\apache-tomcat-7.0.88\apache-tomcat-7.0.88-8180-8105-8109\bin
startup.bat
tomcat3.bat
title apache-tomcat-7.0.88-8280-8205-8209
D:
cd D:\clustering-space\apache-tomcat-7.0.88\apache-tomcat-7.0.88-8280-8205-8209\bin
startup.bat
tomcat-cluster.bat
@echo off
color 0A
@echo on
start tomcat1.bat
start tomcat2.bat
start tomcat3.bat
@echo off
echo.
pause
@echo on
五、nginx 管理脚本
nginx 启动脚本:nginx-start.bat
@echo off
D:
cd D:\clustering-space\apache-tomcat-7.0.88\nginx-1.14.0
@echo on
start nginx
nginx 启动重新加载配置文件:nginx-reload.bat
@echo off
D:
cd D:\clustering-space\apache-tomcat-7.0.88\nginx-1.14.0
@echo on
nginx -s reload
nginx 退出脚本:nginx-quit.bat
@echo off
D:
cd D:\clustering-space\apache-tomcat-7.0.88\nginx-1.14.0
@echo on
nginx -s stop
nginx 强制退出脚本:nginx-stop.bat
@echo off
D:
cd D:\clustering-space\apache-tomcat-7.0.88\nginx-1.14.0
@echo on
nginx -s quit