目标:同一台Linux主机上 安装 Nginx 和 两个 Tomcat 的集群
1. 下载安装 Nginx
地址:http://nginx.org/download/nginx-1.0.4.tar.gz
cd /usr/local/src/nginx
wget http://nginx.org/download/nginx-1.0.4.tar.gz
tar zxvf nginx-1.0.4.tar.gz
cd nginx-1.0.4
./configure
make
make install
2. Tomcat的下载安装配置,请参照 http://pengranxiang.iteye.com/admin/blogs/1135072
3. 配置 Nginx 负载均衡 来集成 两个Tomcat
修改配置文件:$NGNINX_HOME/conf/nginx.conf
#Nginx所用用户和组,window下不指定
user nobody;
#工作的子进程数量(通常等于CPU数量或者2倍于CPU)
worker_processes 1;
#错误日志存放路径
#error_log logs/error.log;
#error_log logs/error.log notice;
error_log logs/error.log info;
#指定pid存放文件
pid logs/nginx.pid;
events {
#使用网络IO模型linux建议epoll,FreeBSD建议采用kqueue,window下不指定。
use epoll;
#允许最大连接数
worker_connections 1024;
}
http {
#mine.types内定义各文件类型映像
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 tomcats {
server localhost:8080 weight=1;
server localhost:9080 weight=1;
#根据ip计算将请求分配各那个后端tomcat,许多人误认为可以解决session问题,其实并不能。
#同一机器在多网情况下,路由切换,ip可能不同
ip_hash;
}
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
index index.shtml;
proxy_pass http://tomcats;
proxy_set_header X-Real-IP $remote_addr;
client_max_body_size 100m;
}
#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;
# server_name localhost;
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_timeout 5m;
# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
安装以上配置即可实现集群。
关于Nginx启动
直接执行: $NGINX_HOME/sbin/nginx 即可
为了方便,可以自定义一个脚本文件
vim nginx.sh
#!/bin/bash
case $1 in
start)
/usr/local/nginx/sbin/nginx;
;;
stop)
kill -2 `ps -ef|grep "/usr/local/nginx/sbin/nginx" | grep -v "grep"|awk '{print $2}'`
;;
restart)
$0 stop
$0 start
;;
*)
echo $"Usage; $0{start|stop|restart}"
exit 1
esac
exit 0
分享到:
相关推荐
Nginx Tomcat 集群的Session 复制,解决了,集群情况下的session复制问题。
一份不错的Nginx Tomcat集群部署说明
nginx,tomcat集群,session共享,基于memcache 包含nginx配置,tomcat配置,以及tomcat所需要的jar 不包含nginx,tomcat,jdk,memcache的安装
nginx-1.0.11.tar.gz、pcre-8.21.tar.gz、nginx-upstream-jvm-route-0.2 apache-tomcat-6.0.35.tar.gz、tomcat-native-1.1.20-src.tar.gz apr-1.4.6.tar.gz、apr-iconv-1.2.1.tar.gz、apr-util-1.4.1.tar.gz jdk-1_5...
基于ssm+shiro+redis+nginx tomcat服务器集群管理项目 基于ssm+shiro+redis+nginx tomcat服务器集群管理项目 基于ssm+shiro+redis+nginx tomcat服务器集群管理项目 基于ssm+shiro+redis+nginx tomcat服务器集群管理...
关于nginx和tomcat在window下的下载安装和使用等。仅供参考。
linux下nginx-tomcat集群及session共享,亲测成功,下载的文件包含了所有需要的jar包及nginx,memcached安装,配置,由于试了很多种方法,下了很多包,有些也需要积分,所以这里下载要些积分留着用,不好意思了,...
NULL 博文链接:https://yiyiboy2010.iteye.com/blog/2083123
部署Nginx+Tomcat负载均衡集群部署思路: 1、Tomcat服务器设置 关闭防火墙 //两台保持一致 安装JDK //两台保持一致 安装Tomcat //两台保持一致 创建站点/www/test目录,修改server.xml文件 //两台保持一致 创建...
windowXP下搭建nginx-1.7.10和apache-tomcat-8.0.18的集群 已经配置好,下载后直接启动三个tomcat和nginx,然后访问http://localhost/即可。
Nginx+tomcat负载均衡集群session复制 windos
nginx+tomcat 负载、集群简单搭建,适合新手。
Nginx+tomcat配置集群负载均衡实现动静分离实例
nginx+tomcat集群的jar包,实现session共享
这篇文档是介绍Nginx tomcat mybatis 集群部署的文档,对tomcat集群干兴趣的同学可以研究一下
NULL 博文链接:https://dws.iteye.com/blog/999036
nginx tomcat 配置完整,只需要把项目放到tomcat下。 tomcat端口是8081,8082;nginx端口是8080
NULL 博文链接:https://ajita.iteye.com/blog/1715312
nginx 配置tomcat8集群