【高可用HA】Nginx (1) —— Mac下配置Nginx Http负载均衡(Load Balancer)之101实例


nginx版本: nginx-1.9.8

参考来源:

nginx.org

【高可用HA】Apache (2) —— Mac下安装多个Apache Tomcat实例

Nginx on Mac OS X Snow Leopard in 2 Minutes

51cto:Nginx+Tomcat负载均衡配置

csdn:Nginx+Tomcat负载均衡配置

iteye:图文解说:Nginx+tomcat配置集群负载均衡

安装

首先

从nginx官方网站下载

编译配置

  1. 执行命令

     $ ./configure --prefix=/Users/Richard/Documents/Dev/servers/cluster/nginx/node-a --with-http_ssl_module

    执行结果末尾几行

     ...
    nginx error log file: "/Users/Richard/Documents/Dev/servers/cluster/nginx/node-a/logs/error.log"
    nginx http access log file: "/Users/Richard/Documents/Dev/servers/cluster/nginx/node-a/logs/access.log"
    nginx http client request body temporary files: "client_body_temp"
    nginx http proxy temporary files: "proxy_temp"
    nginx http fastcgi temporary files: "fastcgi_temp"
    nginx http uwsgi temporary files: "uwsgi_temp"
    nginx http scgi temporary files: "scgi_temp"
  2. 执行命令

     $ make

    执行结果末尾几行

     ...
    objs/src/http/modules/ngx_http_upstream_zone_module.o \
    objs/ngx_modules.o \
    -lpcre -lssl -lcrypto -lz
    /Library/Developer/CommandLineTools/usr/bin/make -f objs/Makefile manpage
    sed -e "s|%%PREFIX%%|/Users/Richard/Documents/Dev/servers/cluster/nginx/node-a|" \
    -e "s|%%PID_PATH%%|/Users/Richard/Documents/Dev/servers/cluster/nginx/node-a/logs/nginx.pid|" \
    -e "s|%%CONF_PATH%%|/Users/Richard/Documents/Dev/servers/cluster/nginx/node-a/conf/nginx.conf|" \
    -e "s|%%ERROR_LOG_PATH%%|/Users/Richard/Documents/Dev/servers/cluster/nginx/node-a/logs/error.log|" \
    < man/nginx.8 > objs/nginx.8
  3. 执行命令

     $ sudo make install

    执行结果末尾几行

     test -d '/Users/Richard/Documents/Dev/servers/cluster/nginx/node-a/logs' 		|| mkdir -p '/Users/Richard/Documents/Dev/servers/cluster/nginx/node-a/logs'
    test -d '/Users/Richard/Documents/Dev/servers/cluster/nginx/node-a/logs' || mkdir -p '/Users/Richard/Documents/Dev/servers/cluster/nginx/node-a/logs'
    test -d '/Users/Richard/Documents/Dev/servers/cluster/nginx/node-a/html' || cp -R html '/Users/Richard/Documents/Dev/servers/cluster/nginx/node-a'
    test -d '/Users/Richard/Documents/Dev/servers/cluster/nginx/node-a/logs' || mkdir -p '/Users/Richard/Documents/Dev/servers/cluster/nginx/node-a/logs'
  4. 修改服务器启动配置

    • 将端口修改成85(与其他文章中httpd的端口区分),并修改location配置Proxy

      server {

      listen 85;

      server_name localhost;

        #charset koi8-r;
      
        #access_log  logs/host.access.log  main;
      
        # location / {
      # root html;
      # index index.html index.htm;
      # } location / {
      proxy_connect_timeout 3;
      proxy_send_timeout 30;
      proxy_read_timeout 30;
      proxy_pass http://localhost;
      }

      ...

    • 增加转发路由的配置,并指向之前配好的两台Tomcat服务器

        upstream localhost {
      #根据ip计算将请求分配各那个后端tomcat,许多人误认为可以解决session问题,其实并不能。
      #同一机器在多网情况下,路由切换,ip可能不同
      #ip_hash;
      server localhost:8081;
      server localhost:8082;
      }

运行

执行命令

$ ./sbin/nginx

提示错误

nginx: [alert] could not open error log file: open() "/Users/Richard/Documents/Dev/servers/cluster/nginx/node-a/logs/error.log" failed (13: Permission denied)
2015/12/09 16:26:55 [emerg] 16550#0: mkdir() "/Users/Richard/Documents/Dev/servers/cluster/nginx/node-a/client_body_temp" failed (13: Permission denied)
*这是因为nginx没有相应的权限

运行命令授权或者以sudo运行

$ sudo ./sbin/nginx

启动

$ sudo ./sbin/nginx -s stop

测试

用浏览器访问localhost:85,页面中会交替出现"Node-A!!"和"Node-B!!"

结束

【高可用HA】Nginx (1) —— Mac下配置Nginx Http负载均衡(Load Balancer)之101实例的更多相关文章

  1. 【高可用HA】Apache (4) —— Mac下配置Apache Httpd负载均衡(Load Balancer)之mod_jk

    Mac下配置Apache Httpd负载均衡(Load Balancer)之mod_jk httpd版本: httpd-2.4.17 jk版本: tomcat-connectors-1.2.41 参考 ...

  2. 【高可用HA】Apache (3) —— Mac下配置Apache Httpd负载均衡(Load Balancer)之mod_proxy

    Mac下配置Apache Httpd负载均衡(Load Balancer)之mod_proxy httpd版本: httpd-2.4.17 参考来源: Apache (1) -- Mac下安装Apac ...

  3. Hadoop 高可用(HA)的自动容灾配置

    参考链接 Hadoop 完全分布式安装 ZooKeeper 集群的安装部署 0. 说明 在 Hadoop 完全分布式安装 & ZooKeeper 集群的安装部署的基础之上进行 Hadoop 高 ...

  4. Mac下配置Nginx负载均衡

    1.首先在Mac下安装Nginx(可参考我的另一篇随笔http://www.cnblogs.com/malcolmfeng/p/6896703.html). 2.安装Tomcat,下载后,解压,bin ...

  5. mac下配置nginx

    nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器,下面我们来了解下nginx的用法. 安装nginx 使用brew安装nginx brew install ...

  6. mysql高可用架构方案之二(keepalived+lvs+读写分离+负载均衡)

    mysql主从复制与lvs+keepalived实现负载高可用 文件夹 1.前言    4 2.原理    4 2.1.概要介绍    4 2.2.工作原理    4 2.3.实际作用    4 3方 ...

  7. Nginx 在windows下配合iis搭建负载均衡过程 [转]

    因为项目遇到大量图片存储问题,虽然现在我们图片还不是很多(目前在1T上下,预计增长速度每年1.3倍的增长速度),自己在思考如何有效地存储大量图片时,查找一些资料,看到了,有人使用 Nginx搭建服务器 ...

  8. Mac 下配置Nginx安装环境配置详细说明

    环境信息: Mac OS X 10.11.1 Homebrew  0.9.5 正文 一.安装 Nginx 1.终端执行: ? 1 2 brew search nginx brew install ng ...

  9. mac下配置nginx php

    修改 php-fpm 文件 1.执行命令: sudo cp /private/etc/php-fpm.conf.default /private/etc/php-fpm.conf 2.找到目录下的 p ...

随机推荐

  1. [CXF REST标准实战系列] 二、Spring4.0 整合 CXF3.0,实现测试接口(转)

    转自:[CXF REST标准实战系列] 二.Spring4.0 整合 CXF3.0,实现测试接口 文章Points: 1.介绍RESTful架构风格 2.Spring配置CXF 3.三层初设计,实现W ...

  2. Ubuntu用户root密码设置

    我们在安装Ubuntu后发现个问题,就是不像Linux系统那样会在安装过程中设置root的密码,那以后如果需要root的权限时该如何操作呢? Ubuntu里有个命令叫sudo,是以管理员的身份运行命令 ...

  3. SQL Server因为数据库正在使用,所以无法获得对数据库的独占访问权

    恢复数据库: 恢复数据库之前,先执行下面这句话 ALTER DATABASE [mpn_stat] SET OFFLINE WITH ROLLBACK IMMEDIATE 执行恢复数据库SQL语句 R ...

  4. Python sqrt() 函数

    描述 sqrt() 方法返回数字x的平方根. 语法 以下是 sqrt() 方法的语法: import math math.sqrt( x ) 注意:sqrt()是不能直接访问的,需要导入 math 模 ...

  5. C#实现相似QQ的隐藏浮动窗口、消息闪动

    功能简单介绍 当语音客服系统登录成功进入主界面时,本聊天工具将会自己主动隐藏在左下角位置,当鼠标移动到左下角时,自己主动弹出,当鼠标移开聊天窗口时,自己主动隐藏.假设想让聊天窗口固定在桌面.仅仅要拖动 ...

  6. Mac 下的矢量图设计工具

    Mac 下的矢量图设计工具 一图胜千言.一张清晰的示意图无论对于系统设计,流程梳理,还是其他的方方面面,都非常重要. 曾经亲见一位老同事把 FreeHand 这个矢量绘图工具用得出神入化,并且非常成功 ...

  7. C#操作txt文件并清空添加操作

    C#操作txt文件,进行清空添加操作的例子.代码: //把txt清空 FileStream stream = File.Open(Adr,FileMode.OpenOrCreate,FileAcces ...

  8. hdu 1532 最大流

    #include <cstdio> #include <iostream> #include <algorithm> #include <queue> ...

  9. Python标准库:内置函数getattr(object, name[, default])

    本函数实现获取对象object的属性.属性由name来表示,就是属性名称的字符串.參数default是可选的參数,当获取对象的属性不存在时,就返回此值.假设没有提供此參数.同一时候在对象属性里也找不到 ...

  10. ios笔记一(面向对象编程)

    #import <Foundation/Foundation.h> #import "Person.h" int main (int argc, const char ...