【高可用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. HDUOJ---2642Stars(二维树状数组)

    Stars Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/65536 K (Java/Others)Total Submi ...

  2. SpringBoot启动

    一.启动时加载数据,就用CommandLineRunner 只需要将类实现CommandLineRunner,并且加上Component注解,还可以通过Order来控制启动顺序. @Component ...

  3. POJ 2965 The Pilots Brothers' refrigerator (DFS)

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15136 ...

  4. JSP开发中对jstl的引用方式(标签库引用)

    创建标签库引用文件taglibs.inc 一 采用本地标签库的taglibs.inc文件 <%--struts库标签 --%> <%@ taglib uri="/WEB-I ...

  5. oracle中的一些基本概念

    Oracle数据库的物理文件是存储在磁盘上的数据文件.控制文件和日志文件的总称.数据文件和日志文件是数据库中最重要的文件.数据库由若干个表空间组成,表空间由表组成,表由段组成,段由区间组成,区间由数据 ...

  6. python学习笔记011——函数式编程

    1 函数式编程 面向对象 ,面向过程 ,函数式编程 侧重函数的作用,注重函数结果的传递 函数可以被赋值,也可以接受其他的值 2 函数式编程特点 1.函数是一等公民 与其他变量一样,可以赋值和被赋值,可 ...

  7. android LinearLayout设置selector不起作用解决

    设置方法 : android:background="@drawable/fen_selector" 如果只有这个的话,是不起作用的.还必须加上: android:clickabl ...

  8. jmeter ---常用字符串相关函数

    主要的函数如下: 1.将字符串转为大写或小写: ${__lowercase(Hello,)}  ${__uppercase(Hello,)}2.生成字符串:  __RandomString函数 3.取 ...

  9. C语言07指针高级

    01内存四区 接口封装和设计思想引导 接口封装设计思想引导 Sckclient客户端api模型设计 第一套api函数 #ifndef _SCK_CLINT_H_ #define _SCK_CLINT_ ...

  10. 总结Codeigniter的一些优秀特性

    总结Codeigniter的一些优秀特性 近期准备接手改进一个别人用Codeigniter写的项目.尽管之前也实用过CI,可是是全然按着自己的意思写的,没按CI的一些套路.用在公众的项目,不妨按框架规 ...