今天在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. Taro踩坑记录一: swiper组件pagestate定制,swiperChange中setState导致组件不能滚动。

    import Taro, { Component } from '@tarojs/taro'; import { Swiper, SwiperItem, Image, View } from '@ta ...

  2. Extjs4 似bug非bug的东西修改

    /** hzm modify * method: Ext.panel.Table.hasLockedColumns: function(columns) {} * function:支持extjs g ...

  3. Python使用微信接入图灵机器人

    1.wxpy库介绍 wxpy 在 itchat 的基础上,通过大量接口优化提升了模块的易用性,并进行丰富的功能扩展. 文档地址:https://wxpy.readthedocs.io 从 PYPI 官 ...

  4. NTP时钟同步学习记录

    --1 要点回顾 . 1. NTP唯一配置文件:/etc/ntp.conf . 2. NTP系统日志记录:/var/log/ntp . 3. ntp.conf简要介绍 - 利用 restrict 来管 ...

  5. DROOLS通过URL访问changset

    package droolsRule; import java.net.Authenticator; import java.net.PasswordAuthentication; import ka ...

  6. base64,AES,RSA,SHA和MD5等加密方式(jdk)

    import sun.misc.BASE64Decoder; import sun.misc.BASE64Encoder; import javax.crypto.Cipher; import jav ...

  7. 主从复制系列B

    从服务器靠中继日志来接收从主服务器上传回来的日志.并依靠状态文件来记录已经从主服务器接收了哪些日志,已经恢复了哪些日志. 中继日志与二进制日志的格式相同,并且可以用mysqlbinlog读取.SQL线 ...

  8. LOJ#3119 随机立方体

    解:极大值至少为1.我们尝试把最大那个数的影响去掉. 最大那个数所在的一层(指一个三维十字架)都是不可能成为最大值的. 考虑容斥.我们试图求除了最大值以外至少有k个极大值的概率. 我们钦定某k个位置是 ...

  9. CSS 滤镜效果

    本文所描述的滤镜,指的是 CSS3 出来后的滤镜,不是 IE 系列时代的滤镜,语法如下,还未接触过这个属性的可以先简单到 MDN -- filter 了解下: { filter: blur(5px); ...

  10. 关于CSS3 animation 属性在ie edge浏览器中不能工作

    我想要给div边框加一个闪烁,所以我将css中设置如下 给想要闪烁的div加上blink类  这样在firefox,chrome下是正常显示的,但是在ie下box-shadow属性不能被正常的展现 后 ...