编译安装openresty

简介

OpenResty 是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库、第三方模块以及大多数的依赖项。用于方便地搭建能够处理超高并发、扩展性极高的动态 Web 应用、Web 服务和动态网关。

OpenResty 通过汇聚各种设计精良的 Nginx 模块(主要由 OpenResty 团队自主开发),从而将 Nginx 有效地变成一个强大的通用 Web 应用平台。这样,Web 开发人员和系统工程师可以使用 Lua 脚本语言调动 Nginx 支持的各种 C 以及 Lua 模块,快速构造出足以胜任 10K 乃至 1000K 以上单机并发连接的高性能 Web 应用系统。

OpenResty 的目标是让你的Web服务直接跑在 Nginx 服务内部,充分利用 Nginx 的非阻塞 I/O 模型,不仅仅对 HTTP 客户端请求,甚至于对远程后端诸如 MySQL、PostgreSQL、Memcached 以及 Redis 等都进行一致的高性能响应。

环境

  • 操作系统:Centos7.2

准备工作

因为我当前安装是在LNMP环境下安装的,所以需要将原有的nginx做一个备份操作,以确保openresty安装出错的时候能立马回退到nginx可用状态。

[root@niaoyun /]# cd /usr/local/
[root@niaoyun local]# mv nginx nginxold/

安装依赖包

Centos

[root@niaoyun /]# yum -y install readline-devel pcre-devel openssl-devel gcc postgresql-devel luajit luajit-devel libxml2 libxml2-dev libxslt-devel gd-devel geoip geoip-devel

Debian

* 稍后补充

编译安装openresty

下载openresty安装包

[root@niaoyun down]# wget https://openresty.org/download/openresty-1.11.2.1.tar.gz
--2016-10-29 16:52:54--  https://openresty.org/download/openresty-1.11.2.1.tar.gz
Resolving openresty.org (openresty.org)... 61.132.13.169
Connecting to openresty.org (openresty.org)|61.132.13.169|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3930804 (3.7M) [application/x-gzip]
Saving to: ‘openresty-1.11.2.1.tar.gz’

100%[=================================================================================================>] 3,930,804   1.32MB/s   in 2.8s   

2016-10-29 16:52:57 (1.32 MB/s) - ‘openresty-1.11.2.1.tar.gz’ saved [3930804/3930804]

编译安装

[root@niaoyun down]# tar -zxvf openresty-1.11.2.1.tar.gz
[root@niaoyun down]# cd openresty-1.11.2.1/
[root@niaoyun openresty-1.11.2.1]# ./configure --prefix=/usr/local --with-luajit --without-http_redis2_module --with-http_iconv_module --with-http_postgres_module --with-http_stub_status_module --with-http_ssl_module --with-http_stub_status_module
[root@niaoyun openresty-1.11.2.1]# gmake
[root@niaoyun openresty-1.11.2.1]# gmake install

测试openresty

查看server类型

[root@niaoyun openresty-1.11.2.1]# curl -I http://127.0.0.1
HTTP/1.1 200 OK
Server: openresty
Date: Sat, 29 Oct 2016 08:57:04 GMT
Content-Type: text/html
Content-Length: 2502
Last-Modified: Fri, 28 Oct 2016 18:51:49 GMT
Connection: keep-alive
Vary: Accept-Encoding
ETag: "58139e45-9c6"
Accept-Ranges: bytes

ab压测工具测试

[root@niaoyun openresty-1.11.2.1]# ab -c10 -n50000 http://127.0.0.1:80/
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 5000 requests
Completed 10000 requests
Completed 15000 requests
Completed 20000 requests
Completed 25000 requests
Completed 30000 requests
Completed 35000 requests
Completed 40000 requests
Completed 45000 requests
Completed 50000 requests
Finished 50000 requests


Server Software:        openresty
Server Hostname:        127.0.0.1
Server Port:            80

Document Path:          /
Document Length:        2502 bytes

Concurrency Level:      10
Time taken for tests:   8.210 seconds
Complete requests:      50000
Failed requests:        0
Write errors:           0
Total transferred:      137800000 bytes
HTML transferred:       125100000 bytes
Requests per second:    6090.44 [#/sec] (mean)
Time per request:       1.642 [ms] (mean)
Time per request:       0.164 [ms] (mean, across all concurrent requests)
Transfer rate:          16391.85 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       1
Processing:     0    2   0.6      1      11
Waiting:        0    1   0.6      1      11
Total:          0    2   0.7      1      11
WARNING: The median and mean for the processing time are not within a normal deviation
        These results are probably not that reliable.
WARNING: The median and mean for the total time are not within a normal deviation
        These results are probably not that reliable.

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      2
  75%      2
  80%      2
  90%      2
  95%      3
  98%      3
  99%      4
 100%     11 (longest request)
文章目录