centos7安装openresty

 

介绍:

   Nginx 采用一个 master 进程管理多个 worker 进程(master-worker)模式,基本的事件处理都在 woker 中,master 负责一些全局初始化,以及对 worker 的管理。在OpenResty中,每个 woker 使用一个 LuaVM,当请求被分配到 woker 时,将在这个 LuaVM 里创建一个 coroutine(协程)。协程之间数据隔离,每个协程具有独立的全局变量_G。OpenResty致力于将服务器应用完全运行与nginx中,充分利用nginx事件模型进行非阻塞I/O通信。其对MySQL、redis、Memcached的I\O通信操作也是非阻塞的,可以轻松应对10K以上的超高连接并发。

1、安装openresty

   1)、通过在CentOS 系统中添加 openresty 仓库,便于未来安装或更新我们的软件包(通过 yum update 命令)

sudo yum install yum-utils
sudo yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo

  2)、安装openresty

?
1
sudo yum install openresty

  3)、安装命令行工具 resty

?
1
sudo yum install openresty-resty

  命令行工具 opm 在 openresty-opm 包里,而 restydoc 工具在 openresty-doc 包里头。

   4)、查看openresty 仓库里头的软件包

?
1
sudo yum --disablerepo="*" --enablerepo="openresty" list available

  

  至此安装成功,默认安装在  /usr/local/openresty

2、测试

  1)、启动

?
1
2
3
4
--此命令运行在/usr/local/openresty目录下
sudo /sbin/service openresty start
--停止
sudo /sbin/service openresty stop

  

3、hello word

   1)、创建example文件夹

?
1
2
3
cd usr/
 
mkdir example

  2)、创建lua.conf及lua脚本

?
1
2
3
cd example/
 
vim lua.conf< br >< br >
?
1
2
3
4
5
6
7
8
9
server { 
     listen       80; 
     server_name  _; 
     lua_code_cache off;  #关闭lua缓存
     location /lua { 
         default_type 'text/html';  
         content_by_lua_file /usr/example/lua/test.lua; 
    
}
?
1
< br >--此文件夹用于存放lua脚本< br >< br >mkdir luafile< br >< br >vim test.lua< br >< br >ngx.say("hello world");

  3)、配置nginx.conf

?
1
2
3
4
5
6
7
8
worker_processes  1;
events {
     worker_connections  1024;
}
http {
     include       mime.types;
     default_type  application/octet-stream;
     include /usr/example/lua.conf;#引入lua脚本配置文件
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
     server {
         listen       80;
         server_name  localhost;
         location / {
             root   html;
             index  index.html index.htm;
         }
         error_page   500 502 503 504  /50x.html;
         location = /50x.html {
             root   html;
         }
     }
}
 
         
            

  4)、重启openrsty

 openresty介绍参考自:https://www.cnblogs.com/zampo/p/4269147.html 

 

介绍:

   Nginx 采用一个 master 进程管理多个 worker 进程(master-worker)模式,基本的事件处理都在 woker 中,master 负责一些全局初始化,以及对 worker 的管理。在OpenResty中,每个 woker 使用一个 LuaVM,当请求被分配到 woker 时,将在这个 LuaVM 里创建一个 coroutine(协程)。协程之间数据隔离,每个协程具有独立的全局变量_G。OpenResty致力于将服务器应用完全运行与nginx中,充分利用nginx事件模型进行非阻塞I/O通信。其对MySQL、redis、Memcached的I\O通信操作也是非阻塞的,可以轻松应对10K以上的超高连接并发。

1、安装openresty

   1)、通过在CentOS 系统中添加 openresty 仓库,便于未来安装或更新我们的软件包(通过 yum update 命令)

sudo yum install yum-utils
sudo yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo

  2)、安装openresty

?
1
sudo yum install openresty

  3)、安装命令行工具 resty

?
1
sudo yum install openresty-resty

  命令行工具 opm 在 openresty-opm 包里,而 restydoc 工具在 openresty-doc 包里头。

   4)、查看openresty 仓库里头的软件包

?
1
sudo yum --disablerepo="*" --enablerepo="openresty" list available

  

  至此安装成功,默认安装在  /usr/local/openresty

2、测试

  1)、启动

?
1
2
3
4
--此命令运行在/usr/local/openresty目录下
sudo /sbin/service openresty start
--停止
sudo /sbin/service openresty stop

  

3、hello word

   1)、创建example文件夹

?
1
2
3
cd usr/
 
mkdir example

  2)、创建lua.conf及lua脚本

?
1
2
3
cd example/
 
vim lua.conf< br >< br >
?
1
2
3
4
5
6
7
8
9
server { 
     listen       80; 
     server_name  _; 
     lua_code_cache off;  #关闭lua缓存
     location /lua { 
         default_type 'text/html';  
         content_by_lua_file /usr/example/lua/test.lua; 
    
}
?
1
< br >--此文件夹用于存放lua脚本< br >< br >mkdir luafile< br >< br >vim test.lua< br >< br >ngx.say("hello world");

  3)、配置nginx.conf

?
1
2
3
4
5
6
7
8
worker_processes  1;
events {
     worker_connections  1024;
}
http {
     include       mime.types;
     default_type  application/octet-stream;
     include /usr/example/lua.conf;#引入lua脚本配置文件
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
     server {
         listen       80;
         server_name  localhost;
         location / {
             root   html;
             index  index.html index.htm;
         }
         error_page   500 502 503 504  /50x.html;
         location = /50x.html {
             root   html;
         }
     }
}
 
         
            

  4)、重启openrsty

 openresty介绍参考自:https://www.cnblogs.com/zampo/p/4269147.html 

 

猜你喜欢

转载自www.cnblogs.com/xiao-xue-di/p/12888773.html
今日推荐