您的位置:首页 > 博客中心 > 数据库 >

LAMP架构演进到LAMPGC,再演进到LNMLGC(linux+nginx+mysql+lua+gearman+C)

时间:2022-03-10 17:49

LAMP是一个大众的架构了,linux+apache+mysql+php

在我们系统的架构中,做了进一步的演进,linux+apahce+mysql+php+gearman+C

1、需要的源码文件 shell> ls drwxr-xr-x 6 1000 1000 4096 Feb 26 03:14 LuaJIT-2.0.3 drwxrwxr-x 10 root root 4096 Jun 1 2014 lua-nginx-module-0.9.8 drwxr-xr-x 9 1001 1001 4096 Feb 18 03:14 nginx-1.7.2 drwxrwxr-x 9 root root 4096 Sep 26 02:43 ngx_devel_kit-0.2.19 drwxr-xr-x 8 1169 1169 4096 Feb 26 03:17 pcre-8.21 2、安装luajit http://luajit.org/download/LuaJIT-2.0.3.tar.gz shell> cd LuaJIT-2.0.3 shell> make shell> make install 因为安装在缺省路径,所以LuaJIT对应的lib,include均在/usr/local目录里。 3、编译nginx https://codeload.github.com/openresty/lua-nginx-module/tar.gz/v0.9.8 https://codeload.github.com/simpl/ngx_devel_kit/tar.gz/v0.2.19 shell> ./configure --prefix=/usr/local/nginx --add-module=../ngx_devel_kit-0.2.19 --add-module=../lua-nginx-module-0.9.8 --with-pcre=../pcre-8.21 4、启动nginx shell> cd /usr/local/nginx/sbin shell> ./nginx ./nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory 提示找不到luajit库文件 shell> echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf shell> ldconfig shell> ./nginx 成功 5、nginx应用 将下列配置加入到/usr/local/nginx/conf/nginx.conf中: location /lua { set $test "hello, world."; content_by_lua ' ngx.header.content_type = "text/plain"; ngx.say(ngx.var.test); '; } shell> ./nginx -s reload 浏览顺访问: http://172.16.18.114/lua 显示:hello, world. 大功造成! 6、安装lua-resty-gearman模块 https://github.com/zhhchen/lua-resty-gearman/tree/master/lib/resty 7、nginx通过lua脚本调用gearman 在nginx.conf的http段增加: lua_package_path "/usr/local/lua-resty-gearman/lib/?.lua;;"; 在server下增加: location /test { content_by_lua ' local gearman = require "gearman" local gm = gearman:new() gm:set_timeout(1000) -- 1 sec ngx.header.content_type = "text/plain" local ok, err = gm:connect("172.16.18.162", 4730) if not ok then ngx.say("failed to connect: ", err) return end ok, err = gm:submit_job("reverse", "abcdef") -- submit_job,submit_job_bg,submit_job_high,submit_job_high_bg,submit_job_low,submit_job_low_bg are supported -- submit_job(function_name, workload[, unique]) if not ok then ngx.say("failed to submit job: ", err) return else ngx.say(ok) end -- put it into the connection pool of size 100, -- with 0 idle timeout local ok, err = gm:set_keepalive(0, 100) if not ok then ngx.say("failed to set keepalive: ", err) return end -- or just close the connection right away: -- local ok, err = gm:close() -- if not ok then -- ngx.say("failed to close: ", err) -- return -- end '; } 浏览顺访问: http://172.16.18.114/test 显示:fedcba

LAMP架构演进到LAMPGC,再演进到LNMLGC(linux+nginx+mysql+lua+gearman+C),布布扣,bubuko.com

热门排行

今日推荐

热门手游