美文网首页
Nginx学习笔记一:基础用法

Nginx学习笔记一:基础用法

作者: 哪吒小子 | 来源:发表于2018-12-25 14:45 被阅读14次

负载均衡想必不用我跟大家解释了吧。其中主要的负载均衡器主要有四种:

-硬件级别:
F5

-软件级别:
Nginx
LVS
HAProxy

Nginx/LVS/HAProxy是目前使用最广泛的三种负载均衡软件
目前关于网站架构一般比较合理流行的架构方案:Web前端采用Nginx/HAProxy+Keepalived作负载均衡器;后端采用MySQL数据库一主多从和读写分离,采用LVS+Keepalived的架构。

Nginx常见配置

worker_processes  5;
worker_rlimit_nofile 10000;

events {
    use epoll;
    worker_connections  10240;
    multi_accept on;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    #tcp_nopush     on;
    keepalive_timeout  0;
    gzip  on;
    upstream myapp {
        ip_hash;
        server 127.0.0.1:8080;
        server 127.0.0.1:8081;
    }
    server {
        listen       80;
        server_name  myapp;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            #root   html;
            #index  index.html index.htm;
            proxy_pass http://myapp;
            proxy_redirect             off;
            proxy_set_header           Host $host;
            proxy_set_header           X-Real-IP $remote_addr;
            proxy_set_header           X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }
}

压测实验

  • 命令:

这表示并发量为500,然后一共发5000条请求。

ab -c 500 -n 5000 -k http://47.101.xx.xx:80/

结果为:

This is ApacheBench, Version 2.3 <$Revision: 1826891 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 47.101.xx.xx (be patient)
Completed 500 requests
Completed 1000 requests
Completed 1500 requests
Completed 2000 requests
Completed 2500 requests
Completed 3000 requests
Completed 3500 requests
Completed 4000 requests
Completed 4500 requests
Completed 5000 requests
Finished 5000 requests


Server Software:        nginx/1.14.0
Server Hostname:        47.101.xx.xx
Server Port:            80

Document Path:          /
Document Length:        612 bytes

Concurrency Level:      500
Time taken for tests:   65.457 seconds
Complete requests:      5000
Failed requests:        8
   (Connect: 0, Receive: 0, Length: 8, Exceptions: 0)
Keep-Alive requests:    4992
Total transferred:      4245104 bytes
HTML transferred:       3055104 bytes
Requests per second:    76.39 [#/sec] (mean)
Time per request:       6545.663 [ms] (mean)
Time per request:       13.091 [ms] (mean, across all concurrent requests)
Transfer rate:          63.33 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0  103 501.1      0   11813
Processing:     8 3885 7624.5   1072   63399
Waiting:        7 1153 2298.8    449   37516
Total:          8 3989 7708.1   1145   63622

Percentage of the requests served within a certain time (ms)
  50%   1145
  66%   2322
  75%   3880
  80%   4997
  90%  10773
  95%  17623
  98%  32100
  99%  41291
 100%  63622 (longest request)

参考文献

Nginx从听说到学会: https://www.jianshu.com/p/630e2e1ca57f

相关文章

  • Nginx学习笔记一:基础用法

    负载均衡想必不用我跟大家解释了吧。其中主要的负载均衡器主要有四种: Nginx/LVS/HAProxy是目前使用最...

  • 21天E战到底学习笔记Day11

    21天E战到底学习笔记Day11-认识函数,进阶用法 今天的学习内容继续是函数的基础知识,进阶用法, 一、绝对引用...

  • 基础-NGINX学习笔记

    Nginx概述 Nginx (engine x) 是一款自由的、开源的、高性能的HTTP服务器和反向代理服务器软件...

  • RobotFramework学习02-基础关键字

    RobotFramework学习笔记目录 本文包含内容: 基础关键字 基础关键字(高级用法) 内置关键字查询 关键...

  • [架] nginx常见问题(29)

    获取全套nginx教程,请访问瓦力博客 在前面那些章节记录了nginx基础用法、模块等。这小节会记录nginx在配...

  • Git学习笔记(一)基础用法

    原文链接:https://zhang35.coding.me/2018-git-5-5.html (补上周文章) ...

  • nginx学习笔记一基础配置

    Nginx简介ApacheApache仍然是时长占用量最高的web服务器,据最新数据统计,市场占有率目前是50%左...

  • Dart学习笔记-基础篇

    声明 本笔记是我自己在学习Dart语言基础的时候做的笔记。有些代码只是为了演示用法,不要纠结逻辑。 本笔记是站在一...

  • Canvas学习笔记之形状

    canvas学习笔记--by Damon 基础用法 默认宽高300x150 标签 渲染上下文 绘制形状 矩形 re...

  • Nginx学习笔记-基本操作

    title: Nginx学习笔记-基本操作date: 2018-07-08tags: [nginx]categor...

网友评论

      本文标题:Nginx学习笔记一:基础用法

      本文链接:https://www.haomeiwen.com/subject/vgjflqtx.html