centos 安装nginx + 多个tomcat负载均衡
今天在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负载均衡的更多相关文章
- 使用apache和nginx代理实现tomcat负载均衡及集群配置详解
实验环境: 1.nginx的代理功能 nginx proxy: eth0: 192.168.8.48 vmnet2 eth1: 192.168.10.10 tomcat server1: vmnet2 ...
- Linux下nginx+多个Tomcat负载均衡的实现
博主原创,转载请注明. 由于项目需要,共创建了10个Tomcat端,由nginx负责转发.9个Tomcat端口分别是8080,11000,12000,13000,14000,15000,16000,1 ...
- nginx+tomcat负载均衡
最近练习nginx+tomcat负载均衡.根据一些资料整理了大体思路,最终实现了1个nginx+2个tomcat负载均衡. 安装JDK 1>进入安装目录,给所有用户添加可执行的权限 #chmod ...
- Nginx+tomcat负载均衡时静态页面报404
百度到的问题解决BLOG http://os.51cto.com/art/201204/326843.htm nginx+2台tomcat负载均衡,应用程序已部署,单独访问tomcat时,可以访问到所 ...
- Linux下Nginx+Tomcat负载均衡和动静分离配置要点
本文使用的Linux发行版:CentOS6.7 下载地址:https://wiki.centos.org/Download 一.安装Nginx 下载源:wget http://nginx.org/pa ...
- Nginx+keepalived做双机热备加tomcat负载均衡
Nginx+keepalived做双机热备加tomcat负载均衡 环境说明: nginx1:192.168.2.47 nginx2:192.168.2.48 tomcat1:192.168.2.49 ...
- Nginx+Tomcat 负载均衡集群
案例分析 通常情况下,一台Tomcat站点由于可能出现单点故障及无法应对多客户复杂多样性的请求等问题,不能单独应用于生产环境下,所以我们需要一套更可靠的解决方案来完善Web站点架构. Nginx是一款 ...
- 基于nginx的tomcat负载均衡和集群
要集群tomcat主要是解决SESSION共享的问题,因此我利用memcached来保存session,多台TOMCAT服务器即可共享SESSION了. 你可以自己写tomcat的扩展来保存SESSI ...
- linux+nginx+tomcat负载均衡,实现session同步
linux+nginx+tomcat负载均衡,实现session同步 花了一个上午的时间研究nginx+tomcat的负载均衡测试,集群环境搭建比较顺利,但是session同步的问题折腾了几个小时才搞 ...
随机推荐
- SpringBoot_02_SpringBoot的配置文件
1.SpringBoot配置文件 SpringBoot是基于约定的,所以很多配置都有默认值,但如果想使用自己的配置替换默认配置的话,就可以使用application.properties或者appli ...
- v-bind:class
<!DOCTYPE html> <html lang="zh"> <head> <title></title> < ...
- PAT甲级——A1092 To Buy or Not to Buy【20】
Eva would like to make a string of beads with her favorite colors so she went to a small shop to buy ...
- Ajax之json返回结果是集合的处理
Jquery实现ajax: $.ajax({ type //数据的提交方式:get和post url //数据的提交路径 async //是否支持 ...
- ps命令详解-转
名称:ps使用权限:所有使用者使用方式:ps [options] [--help]说明:显示瞬间行程 (process) 的动态参数:ps的参数非常多, 在此仅列出几个常用的参数并大略介绍含义-A ...
- 使用Log4net把日志写入到SqlServer数据库
1.官网URL: http://logging.apache.org/log4net/ 2.配置文件参照URL: http://logging.apache.org/log4net/release/c ...
- Python基础——使用with结构打开多个文件
考虑如下的案例: 同时打开三个文件,文件行数一样,要求实现每个文件依次读取一行,然后输出,我们先来看比较容易想到的写法: with open(filename1, 'rb') as fp1: with ...
- Odoo Documentation : Recordsets
Other recordset operations Recordsets are iterable(可迭代的) so the usual Python tools are available for ...
- 模板:数位DP
第一次听说dp还有模板的... 当然你要是记忆化搜索的话,就可以有一些套路 这是一个伪代码: LL Dfs(LL now,限制,LL top){ if(!now) return 判断条件; if(!t ...
- 我认为最节省时间的CSS命名规范
CSS命名规范一 js中对变量的命名最好使用camel case驼峰式命名法,但CSS中更适用于red-box命名规范. CSS命名规范二 BEM命名规范 B=>block E=>elem ...