今天在centos上安装了两个tomcat和nginx,进行配置。今天记录的只是最基本的实现测试。(不包含使用redis进行session共享)

Nginx 是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行。  其特点是占有内存少,并发能力强。

直接开始主题:

1,首先jdk应该是配好了我就不写了,安装nginx(我使用的rmp安装) ,安装 pcre 让nginx支持rewrite,我使用的是pcre2-10.00.tar.gz;

PCRE下载地址:ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/

tar zxvf  pcre-8.01.tar.gz

cd pcre-8.01

./configure

make

make install

ps:(网上说没有安装openssl还要安装openssl。)

2,安装nginx:

rpm -ivh nginx-release-centos-6-0.el6.ngx.noarch.rpm

yum install nginx   (我是一路的[y/n]  选择y,最后出现complete!)

nginx的几个默认目录:

whereis nginx
 nginx: /usr/sbin/nginx /etc/nginx /usr/share/nginx

其中

配置所在目录:/etc/nginx/

错误日志:/var/log/nginx/error.log

默认站点目录:/usr/share/nginx/html

3.可能CentOS的防火墙把80端口拦住了,打开80端口

iptables -I INPUT -p tcp --dport 80 -j ACCEPT

/etc/init.d/iptables status 查看

出现这个就哦了。

4,配置nginx:

配置文件在/etc/nginx/

#Nginx所用用户和组
user root;
worker_processes ; error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid; events {
#使用网络IO模型linux建议epoll,FreeBSD建议采用kqueue
use epoll; #允许最大连接数
worker_connections 2048;
} http {
include /etc/nginx/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 /var/log/nginx/access.log main; sendfile on;
#tcp_nopush on; keepalive_timeout 65; #gzip on;
upstream localhost {
#ip_hash
server localhost:8081;
server localhost:8080;
} #这里还包含另外的cong文件
include /etc/nginx/conf.d/*.conf; }

主要是upstream 所以一会将要把两个tomcat端口设置成8080和8081.

另一个配置文件就是那个包含的/etc/nginx/conf.d/*.conf; (也就是default.conf):

#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
#修改就是这一段代理
location / {
proxy_connect_timeout 3;
proxy_send_timeout 30;
proxy_read_timeout 30;
proxy_pass http://localhost;
} #error_page 404 /404.html; # redirect server error pages to the static page /50x.html
#

5.启动nginx(我是先配置好两个tomcat,然后再测试的,继续往下)

nginx

测试nginx配置:nginx -t

6,开始配置tomcat

tomcat都很熟悉,这次只需要修改server.xml配置文件即可。修改3处:

a:

<!-- 修改port端口:18080 两个tomcat不能重复-->
<Server port="18080" shutdown="SHUTDOWN">

b:

<!-- port="8080" tomcat监听端口 -->
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />

c:  Engine元素增加jvmRoute属性:(我是 tomcat1 和 tomcat2 )

<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">

另一个也是改这三处,但是端口要和nginx一致。我的是8080和8081

7.测试:启动两个tomcat和nginx。

验证配置负载均衡设置,http://localhost/   多次访问测试:

我为了方便看。这两个tomcat的首页我添加了一个小标识。说明访问了不同的tomcat。

8.后续还需要加上redis缓存实现session共享,根据自己情况进行测试。

												

centos 安装nginx + 多个tomcat负载均衡的更多相关文章

  1. 使用apache和nginx代理实现tomcat负载均衡及集群配置详解

    实验环境: 1.nginx的代理功能 nginx proxy: eth0: 192.168.8.48 vmnet2 eth1: 192.168.10.10 tomcat server1: vmnet2 ...

  2. Linux下nginx+多个Tomcat负载均衡的实现

    博主原创,转载请注明. 由于项目需要,共创建了10个Tomcat端,由nginx负责转发.9个Tomcat端口分别是8080,11000,12000,13000,14000,15000,16000,1 ...

  3. nginx+tomcat负载均衡

    最近练习nginx+tomcat负载均衡.根据一些资料整理了大体思路,最终实现了1个nginx+2个tomcat负载均衡. 安装JDK 1>进入安装目录,给所有用户添加可执行的权限 #chmod ...

  4. Nginx+tomcat负载均衡时静态页面报404

    百度到的问题解决BLOG http://os.51cto.com/art/201204/326843.htm nginx+2台tomcat负载均衡,应用程序已部署,单独访问tomcat时,可以访问到所 ...

  5. Linux下Nginx+Tomcat负载均衡和动静分离配置要点

    本文使用的Linux发行版:CentOS6.7 下载地址:https://wiki.centos.org/Download 一.安装Nginx 下载源:wget http://nginx.org/pa ...

  6. Nginx+keepalived做双机热备加tomcat负载均衡

    Nginx+keepalived做双机热备加tomcat负载均衡 环境说明: nginx1:192.168.2.47 nginx2:192.168.2.48 tomcat1:192.168.2.49 ...

  7. Nginx+Tomcat 负载均衡集群

    案例分析 通常情况下,一台Tomcat站点由于可能出现单点故障及无法应对多客户复杂多样性的请求等问题,不能单独应用于生产环境下,所以我们需要一套更可靠的解决方案来完善Web站点架构. Nginx是一款 ...

  8. 基于nginx的tomcat负载均衡和集群

    要集群tomcat主要是解决SESSION共享的问题,因此我利用memcached来保存session,多台TOMCAT服务器即可共享SESSION了. 你可以自己写tomcat的扩展来保存SESSI ...

  9. linux+nginx+tomcat负载均衡,实现session同步

    linux+nginx+tomcat负载均衡,实现session同步 花了一个上午的时间研究nginx+tomcat的负载均衡测试,集群环境搭建比较顺利,但是session同步的问题折腾了几个小时才搞 ...

随机推荐

  1. 莫烦PyTorch学习笔记(四)——回归

    下面的代码说明个整个神经网络模拟回归的过程,代码含有详细注释,直接贴下来了 import torch from torch.autograd import Variable import torch. ...

  2. 转:Eclipse中设置编码的方式

    来源:http://blog.csdn.net/jianw2007/article/details/3930915 如果要使插件开发应用能有更好的国际化支持,能够最大程度的支持中文输出,则最好使 Ja ...

  3. LintCode_1 单例模式

    从今天开始我的LintCode之旅,由于C/C++好久没有使用了,语法生疏不说,低级错误频繁出现,因此在做题之后,还会有部分时间复习语法项目. ---------------------------- ...

  4. 【JEECG-Boot 技术文档】新手入门教程

    Jeecg-Boot入门教程必看(新手学习) 1.开发环境搭建 http://jeecg-boot.mydoc.io/?t=345670 开发工具 :https://pan.baidu.com/sha ...

  5. SpringCloud学习笔记(三):Rest微服务构建案例工程模块

    需要具备的知识 1 springmvc+mybatis+mysql 2 Consumer消费者(Client)通过REST调用Provider提供者(Server)提供的服务 3 Maven的分包分模 ...

  6. Python2.7版本:定义类时为什么要继承object类?

    ********此答案摘自知乎,且经过自己实际运行后得出******** 继承 object 类的是新式类,不继承 object 类的是经典类 例子: 新式类: 经典类: B.C 是 A 的子类,D ...

  7. STL与泛型编程-练习2-GeekBand

    练习题目: struct Programmer{ Programmer(const int id, const std::wstring name): Id(id), Name(name){ } vo ...

  8. Luogu P3558 [POI2013]BAJ-Bytecomputer(线性dp)

    P3558 [POI2013]BAJ-Bytecomputer 题意 给一个只包含\(-1,0,1\)的数列,每次操作可以让a[i]+=a[i-1],求最少操作次数使得序列单调不降.若无解则输出BRA ...

  9. mysql5.7基于gtid进行搭建主从复制过程

    gtid_mode = onenforce-gtid-consistency = onskip_name_resolve # 去掉域名解析二进制日志必须开启,且格式为ROWserver-id必须配置成 ...

  10. 快速体验 Sentinel 集群限流功能,只需简单几步

    ️ Pic by Alibaba Tech on Facebook 集群限流 可以限制某个资源调用在集群内的总 QPS,并且可以解决单机流量不均导致总的流控效果不佳的问题,是保障服务稳定性的利器. S ...