1.环境准备

在前面的博客中我已经安装好nginx和一台tomcat了。现在就在加一台tomcat

tomcat1:  /apps/tomcat/tomcat1/apache-tomcat-7.0.69/

tomcat2: /apps/tomcat/tomcat2/apache-tomcat-7.0.69/

jdk:java7

nginx:nginx-1.4.2

给tomcat添加权限

chmod +775 -R /apps/tomcat/tomcat1

chmod +775 -R /apps/tomcat/tomcat2

tomcat下载地址: http://pan.baidu.com/s/1gf7gcVL

2.修改 server.xml 给tomcat配置不同的端口

cd /apps/tomcat/tomcat1/apache-tomcat-7.0.69/conf/

vi server.xml

tomcat1  8080

tomcat2 8081

3.给tomcat编写不同的测试页,用来测试nginx是否能分发请求

vi /apps/tomcat/tomcat1/apache-tomcat-7.0.69/webapps/ROOT/index.jsp

vi /apps/tomcat/tomcat2/apache-tomcat-7.0.69/webapps/ROOT/index.jsp

4.配置nginx

进入安装目录

cd /apps/install/nginx/conf/

编辑配置文件

vi /apps/install/nginx/conf/nginx.conf

添加如下部分

upstream的负载均衡,weight是权重,可以根据机器配置定义权重。weigth参数表示权值,权值越高被分配到的几率越大。

user  root;
worker_processes 1; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections 1024;
} http {
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 tomcat_server{
server localhost:8080 weight=1;
server localhost:8081 weight=1;
} server {
listen 80;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / {
root html;
index index.html index.htm;
proxy_pass http://tomcat_server;
} # error_page 403 /html/index.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 ssl;
# server_name localhost; # ssl_certificate cert.pem;
# ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on; # location / {
# root html;
# index index.html index.htm;
# }
#} }

  

5.启动测试

tomcat1

tomcat2

启动nginx

/apps/install/nginx/sbin/nginx

访问nginx

再次访问

ok 成功路由到了2台tomcat

6.nginx 常用命令

cd /apps/install/nginx/

启动

./sbin/nginx

停止

./sbin/nginx -s stop

重载配置

./sbin/nginx -s reload

指定配置文件启动

./sbin/nginx -c /usr/local/nginx/conf/nginx.conf

查看 Nginx 版本

./sbin/nginx -v

检查配置文件是否正确

./sbin/nginx -t

显示帮助信息

./sbin/nginx -h

tomcat+nginx简单实现负载均衡的更多相关文章

  1. Nginx 简单的负载均衡配置示例(转载)

    原文地址:Nginx 简单的负载均衡配置示例(转载) 作者:水中游于 www.s135.com 和 blog.s135.com 域名均指向 Nginx 所在的服务器IP. 用户访问http://www ...

  2. Windows下nginx+tomcat实现简单的负载均衡

    Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器.反向代理(Reverse Proxy)方式是指以代理服务器来接受internet上的连接请求,然后将请 ...

  3. Nginx 简单的负载均衡配置示例

    http://www.cnblogs.com/xiaogangqq123/archive/2011/03/02/1969006.html 在此记录下Nginx服务器nginx.conf的配置文件说明, ...

  4. Nginx 简单的负载均衡配置演示样例

    近期在做开放查询应用的时候,因为数据两天特别多,两千多万条呢,用户訪问需求也比較大,所以就用nginx做了 负载均衡,以下是改动之后的相关内容. http://www.cnblogs.com/xiao ...

  5. 使用nginx简单实现负载均衡

    只是简单使用nginx玩玩而已,知道能这么用,但是在实际项目中并没有实践过,在项目不大的时候用不到,但是对于理解负载均衡来说还是可以的. 利用虚拟机安装了三个centOS系统,然后顺便装了环境. 这里 ...

  6. Nginx简单的负载均衡(一)

    Nginx是一个高性能的http和反向代理服务器,官方测试nginx能够支支撑5万并发链接,并且cpu.内存等资源消耗却非常低,运行非常稳定. 1.应用场景 1.http服务器.Nginx是一个htt ...

  7. nginx+tomcat实现简单的负载均衡

    host1:10.0.0.10(部署nginx和tomcat) host2:10.0.0.11(部署tomcat) 平台环境(2主机一样) [root@smp ~]# uname -r3.10.0-8 ...

  8. Nginx简单的负载均衡入门

    nginx是用来管理tomcat的,只管理tomcat,并没有管理具体tomcat里面的项目,这里实现了简单的nginx管理两个tomcat的配置,注意upstream节点应该配置到service节点 ...

  9. Nginx + Tomcat Windows下的负载均衡配置

     Nginx + Tomcat Windows下的负载均衡配置 一.为什么需要对Tomcat服务器做负载均衡?    Tomcat服务器作为一个Web服务器,其并发数在300-500之间,如果超过50 ...

随机推荐

  1. CentOS 安装 lamp(转)

    一般情况下,安装的都是最新的正式版,除非你有特殊需求,要安装指定的版本,本文暂不讨论.从最基础的开始,一点点完成一个可用的 Linux 主机.这里就开始介绍如何在 CentOS 6.0 上安装 LAM ...

  2. php: 不能嵌套try-catch-fnally,否则执行时间过长

    php不能try-catch-fnally里面在嵌套try-catch-fnall,否则本来执行时间不长的程序,会被执行更长时间,这是php的bug吗? 如: try{ 代码块 }catch (\Ex ...

  3. 样本、文库、重复、lane、run - 二代测序原理及名词解释

    参考: 独占鳌头的Illumina仪器(二代测序篇) HiSeq2000测序原理.流程与仪器 NGS文库制备的方法比较[心得点评] 各种测序文库构建方式 样本:就是待测的DNA.RNA或蛋白序列,样本 ...

  4. [讨论] 这几天来封装Win7用户配置文件丢失的解决方法个人心得

    [讨论] 这几天来封装Win7用户配置文件丢失的解决方法个人心得 prerouting 发表于 2010-5-9 16:50:46 https://www.itsk.com/thread-36634- ...

  5. python3 购物程序

    要求: 一.启动程序后,选择是商家还是用户 1.选择商家用户 输入用户名,密码进入 选择增加商品及价格:格式:  商品名称 价格 选择编辑商品及价格:根据提示进行操作 2.选择用户 输入用户名,密码进 ...

  6. 利用node来下载图片到本地

      本文是针对于知道图片地址的下载图片方法. 同时也是我的处男作(额,怪怪的〜);不要在意这些细节. 最近在弄项目迁移,需要把http的链接全换成https的:以前的cms不支持http的协议,然后就 ...

  7. AxureRP8实战手册(基础21-30)

    AxureRP8实战手册(基础21-30) 本文目录 基础21.     设置元件默认选中/禁用 基础22.     设置单选按钮唯一选中 基础23.     设置元件不同状态时的样式 基础24.   ...

  8. 改善C#程序,提高程序运行效率的50种方法

    改善C#程序,提高程序运行效率的50种方法   转自:http://blog.sina.com.cn/s/blog_6f7a7fb501017p8a.html 一.用属性代替可访问的字段 1..NET ...

  9. C# DateTime 格式化 奇怪问题!

    使用 DateTime.Now.ToString("MM/dd") 本地显示 06/16 window sevcie 2003  显示是 06-16 解决方法: DateTime. ...

  10. MyBatis总结(一)

    一.创建测试项目工程 二.导包(一个myBatis所需的包,以及一个数据库操作的包) 三.创建实体类 四.配置文件的建立(最佳命名为(SqlMapConfig.xml)) <?xml versi ...