OpenResty入门,


操作系统:Centos 7

OpenResty是整合nginx模块,用作web开发工具之用,具体可以百度!

配置安装源

[root@localhost ~]# vim /etc/yum.repos.d/OpenResty.repo

内容如下:

[openresty]
name=Official OpenResty Repository
baseurl=https://openresty.org/yum/openresty/openresty/epel-$releasever-$basearch/
skip_if_unavailable=True
gpgcheck=1
gpgkey=https://copr-be.cloud.fedoraproject.org/results/openresty/openresty/pubkey.gpg
enabled=1
enabled_metadata=1

安装

[root@localhost ~]# yum install openresty

软件会安装到/usr/local/openresty/目录下

创建工作目录

[root@localhost ~]# mkdir ~/work
[root@localhost ~]# cd ~/work/
[root@localhost work]# mkdir logs/ conf

创建nginx配置

[root@localhost work]# vim conf/nginx.conf

内容如下

worker_processes  1;
error_log logs/error.log;
events {
    worker_connections 1024;
}
http {
    server {
        listen 8081;
        location / {
            default_type text/html;
            content_by_lua '
                ngx.say("<p>hello, world</p>")
            ';
        }
    }
}

配置环境变量

[root@localhost work]# export PATH=/usr/local/openresty/nginx/sbin:$PATH

启动

[root@localhost work]# nginx -p `pwd`/ -c conf/nginx.conf

正常情况的话,不会有什么输出到屏幕上。如果有问题,可以查看logs/error.log

看看效果

[root@localhost work]# curl http://localhost:8081/
<p>hello, world</p>

如果成功输出hello,world则就允许正常了。

压力测试

安装压力测试工具

[root@localhost work]# yum install httpd-tools

压测

[root@localhost work]# ab -c10 -n50000 http://localhost:8081/
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.11.2.2
Server Hostname:        localhost
Server Port:            8081

Document Path:          /
Document Length:        20 bytes

Concurrency Level:      10
Time taken for tests:   9.577 seconds
Complete requests:      50000
Failed requests:        0
Write errors:           0
Total transferred:      8400000 bytes
HTML transferred:       1000000 bytes
Requests per second:    5220.74 [#/sec] (mean)
Time per request:       1.915 [ms] (mean)
Time per request:       0.192 [ms] (mean, across all concurrent requests)
Transfer rate:          856.53 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.3      1       8
Processing:     1    1   0.4      1      10
Waiting:        1    1   0.2      1       9
Total:          1    2   0.4      2      10

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%      3
 100%     10 (longest request)

相关内容

    暂无相关文章