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同步的问题折腾了几个小时才搞 ...
随机推荐
- https,http和ssl的关系
https,http和ssl这三者是什么关系呢? http是超文本传输协议,浏览器利用这一协议就可以访问各种网站了. ssl指Secure Sockets Layer 安全套接层,是一种保证网络数据传 ...
- UICollectionView入门--使用系统UICollectionViewFlowLayout布局类
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://rainbownight.blog.51cto.com/1336585/13237 ...
- Redis深度历险——核心原理与应用实践
高可用架构」的各位老铁们,你们好!你是否还记得上个月发布的文章中,有两篇深入讲解Redis的文章,分别是和,广大粉丝读者们对这两篇文章整体评价颇高.而我就是这两篇文章的原创作者「老钱」(钱文品),我是 ...
- 转:linux中select()函数分析
源地址:http://blog.csdn.net/zi_jin/article/details/4214359 Select在Socket编程中还是比较重要的,可是对于初学Socket的人来说都不太爱 ...
- ORA-01790: 表达式必须具有与对应表达式相同的数据类型
出现这种错误,要先看一下是不是sql中有用到连接:union,unio all之类的,如果有,需要注意相同名称字段的数据类型一定要相同.
- 根据url的属性名来取属性值赋值给js
1.方法一:js的正则表达式:请求路径:http://127.0.0.1/pec/jsp/member/refundOrder.jsp?status=4 <script> var stat ...
- 使用springmvc实现文件上传
该配置在javaweb上传文件篇中的基础上进行配置:https://www.cnblogs.com/flypig666/p/11745182.html 1.配置文件解析器,在springmvc.xml ...
- Android中Activity和AppcompatActivity的区别(详细解析)
转载 https://blog.csdn.net/today_work/article/details/79300181 继承AppCompatActivity的界面. 如下图所示: copy界面代码 ...
- 攻防世界wp--web新手1
https://adworld.xctf.org.cn/task/answer?type=web&number=3&grade=0&id=5061 打开是一个网页 知识点: 根 ...
- java锁_IO_NIO_AIO_BIO_GC_Jvm
如何保证线程安全,线程锁有哪些? 同步方法和同步代码块常见的锁:ReentrantLock与synchronized二者区别: (1) 线程A和B都要获取对象O的锁定,假设A获 ...