centos7安裝openresty

介紹: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以上的超高鏈接併發。nginx

一、安裝openrestyredis

   1)、經過在CentOS 系統中添加 openresty 倉庫,便於將來安裝或更新咱們的軟件包(經過 yum update 命令)vim

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

  2)、安裝openrestycentos

sudo yum install openresty

  3)、安裝命令行工具 resty緩存

sudo yum install openresty-resty

  命令行工具 opm 在 openresty-opm 包裏,而 restydoc 工具在 openresty-doc 包裏頭。服務器

   4)、查看openresty 倉庫裏頭的軟件包併發

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

  

  至此安裝成功,默認安裝在  /usr/local/openrestyapp

二、測試工具

  1)、啓動

--此命令運行在/usr/local/openresty目錄下
sudo /sbin/service openresty start 
--中止
sudo /sbin/service openresty stop

  

三、hello word

   1)、建立example文件夾

cd usr/

mkdir example

  2)、建立lua.conf及lua腳本

cd example/

vim lua.conf

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;  
    }  
} 

--此文件夾用於存放lua腳本

mkdir luafile

vim test.lua

ngx.say("hello world");

  3)、配置nginx.conf

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    include /usr/example/lua.conf;#引入lua腳本配置文件
    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介紹參考自:http://www.javashuo.com/article/p-gsorlxtu-w.html 以及本身的理解

相關文章
相關標籤/搜索