前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Openresty

Openresty

作者头像
yaohong
发布2019-09-11 15:35:50
9160
发布2019-09-11 15:35:50
举报
文章被收录于专栏:姚红专栏姚红专栏

一:简介

OpenResty(又称:ngx_openresty) 是一个基于 NGINX 的可伸缩的 Web 平台,由中国人章亦春发起,提供了很多高质量的第三方模块。

OpenResty 是一个强大的 Web 应用服务器,Web 开发人员可以使用 Lua 脚本语言调动 Nginx 支持的各种 C 以及 Lua 模块,更主要的是在性能方面,OpenResty可以 快速构造出足以胜任 10K 以上并发连接响应的超高性能 Web 应用系统。

360,UPYUN,阿里云,新浪,腾讯网,去哪儿网,酷狗音乐等都是 OpenResty 的深度用户。

二:安装依赖包

代码语言:javascript
复制
#yum install readline-devel pcre-devel openssl-devel gcc

三:安装openresty

3.1下载openresty源码

代码语言:javascript
复制
#wget https://openresty.org/download/openresty-1.9.7.4.tar.gz

3.2解压安装包

代码语言:javascript
复制
#tar xzvf openresty-1.9.7.4.tar.gz

3.3配置编译选项,可以根据你的实际情况增加、减少相应的模块

代码语言:javascript
复制
#cd openresty-1.9.7.4/
#./configure --prefix=/opt/openresty --with-luajit --without-http_redis2_module --with-http_iconv_module

3.4编译安装

代码语言:javascript
复制
# make
#make install 

四:使用

代码语言:yaml
复制
4.1修改配置文件如下
代码语言:javascript
复制
# cat /opt/openresty/nginx/conf/nginx.conf
worker_processes  1;
error_log logs/error.log info;

events {
    worker_connections 1024;
}

http {
    server {
        listen 8003;

        location / {
            content_by_lua 'ngx.say("hello world.")';
        }
    }
}

4.2启动nginx

代码语言:javascript
复制
#/opt/openresty/nginx/sbin/nginx

4.3使用nginx

代码语言:javascript
复制
# curl http://127.0.0.1:8003/
hello world.

五:性能测试

5.1安装压力测试工具

代码语言:javascript
复制
#yum install httpd-tools

5.2测试

代码语言:javascript
复制
# ab -c10 -n50000 http://localhost:8003/
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 localhost (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/1.9.7.4
Server Hostname:        localhost
Server Port:            8003

Document Path:          /
Document Length:        13 bytes

Concurrency Level:      10
Time taken for tests:   7.857 seconds
Complete requests:      50000
Failed requests:        0
Write errors:           0
Total transferred:      8050000 bytes
HTML transferred:       650000 bytes
Requests per second:    6363.75 [#/sec] (mean)
Time per request:       1.571 [ms] (mean)
Time per request:       0.157 [ms] (mean, across all concurrent requests)
Transfer rate:          1000.55 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.2      0       1
Processing:     1    1   0.2      1       4
Waiting:        1    1   0.1      1       3
Total:          1    2   0.1      2       4

Percentage of the requests served within a certain time (ms)
  50%      2
  66%      2
  75%      2
  80%      2
  90%      2
  95%      2
  98%      2
  99%      2
 100%      4 (longest request)

六:nginx服务相关命令

6.1启动

代码语言:javascript
复制
#/opt/openresty/nginx/sbin/nginx

6.2停止

代码语言:javascript
复制
#/opt/openresty/nginx/sbin/nginx -s stop

6.3重启

代码语言:javascript
复制
#/opt/openresty/nginx/sbin/nginx -s reload

6.4检验nginx配置是否正确

代码语言:javascript
复制
# /opt/openresty/nginx/sbin/nginx -t
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-03-18 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一:简介
  • 二:安装依赖包
  • 三:安装openresty
  • 四:使用
  • 五:性能测试
  • 六:nginx服务相关命令
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档