环境
[15:51:58 root@lin3 ~ $]cat /etc/centos-release
CentOS Linux release 7.6.1810 (Core)
简介
OpenResty(又称:ngx_openresty) 是一个基于 NGINX 的可伸缩的 Web 平台,由中国人章亦春发起,提供了很多高质量的第三方模块。
OpenResty 是一个强大的 Web 应用服务器,Web 开发人员可以使用 Lua 脚本语言调动 Nginx 支持的各种 C 以及 Lua 模块,更主要的是在性能方面,OpenResty可以 快速构造出足以胜任 10K 以上并发连接响应的超高性能 Web 应用系统。
360,UPYUN,阿里云,新浪,腾讯网,去哪儿网,酷狗音乐等都是 OpenResty 的深度用户。
第一步:安装
中文官网:https://openresty.org/cn/
安装说明:https://openresty.org/cn/linux-packages.html
1.安装
## 添加 openresty 仓库
yum install yum-utils
yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo
## 安装 OpenResty
yum install -y openresty
## 安装命令行工具 resty
## 命令行工具 opm 在 openresty-opm 包里,而 restydoc 工具在 openresty-doc 包里头。
yum install -y openresty-resty
## 列出所有 openresty 仓库里头的软件包:
yum --disablerepo="*" --enablerepo="openresty" list available
2.启动
## 默认安装路径
/usr/local/openresty
## 启动
/usr/local/openresty/nginx/sbin/nginx
## 验证配置
/usr/local/openresty/nginx/sbin/nginx -t
## 重新加载
/usr/local/openresty/nginx/sbin/nginx -s reload
第二步:压力测试
1.安装 ab 测试工具
yum -y install httpd-tools
2.开始测试
ab -c 10 -n 500000 http://192.168.30.122:80/
## 测试结果
## 基本1.5万/秒
[16:25:31 root@lin3 ~ $]ab -c 10 -n 500000 http://192.168.30.122: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 192.168.30.122 (be patient)
Completed 50000 requests
Completed 100000 requests
Completed 150000 requests
Completed 200000 requests
Completed 250000 requests
Completed 300000 requests
Completed 350000 requests
Completed 400000 requests
Completed 450000 requests
Completed 500000 requests
Finished 500000 requests
Server Software: Tengine/2.2.2
Server Hostname: 192.168.30.122
Server Port: 80
Document Path: /
Document Length: 555 bytes
Concurrency Level: 10
Time taken for tests: 31.531 seconds
Complete requests: 500000
Failed requests: 0
Write errors: 0
Total transferred: 394500000 bytes
HTML transferred: 277500000 bytes
Requests per second: 15857.53 [#/sec] (mean)
Time per request: 0.631 [ms] (mean)
Time per request: 0.063 [ms] (mean, across all concurrent requests)
Transfer rate: 12218.35 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 8
Processing: 0 0 0.1 0 9
Waiting: 0 0 0.1 0 9
Total: 0 1 0.1 1 10
Percentage of the requests served within a certain time (ms)
50% 1
66% 1
75% 1
80% 1
90% 1
95% 1
98% 1
99% 1
100% 10 (longest request)
第三步:使用
1.LUA 的简单示例
## lua 简单示例
location /lua {
default_type text/html;
content_by_lua_block {
ngx.say("<p>hello, world</p>")
}
}
## 访问结果
[16:15:34 root@lin3 ~ $]curl http://192.168.30.122/lua
<p>hello, world</p>
网友评论