在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):mtourne/nginx_log_by_lua开源软件地址(OpenSource Url):https://github.com/mtourne/nginx_log_by_lua开源编程语言(OpenSource Language):Lua 51.7%开源软件介绍(OpenSource Introduction):This is an example for embedding Lua into the logging phase of Nginx and building a simple log aggregation service. InstallationOne of the only dependencies not directly included in OpenResty is libpcre. You can either install it from source, or use your distribution. A modern version (>8.21) is recommended to leverage PCRE_JIT (faster regex), but it will still work with an older version. In my case on Mac OS using Homebrew :
Then download the latest OpenResty from this page and compile it. More up do date installation intruction can be found on the Openresty install page
Now let's finally compile it.
I found a slight issue that only happens on Mac OS while using hombrew, and I had to the configure line where to find my pcre library (
This will create a /usr/local/openresty/ directory that contains everything you need
Launching the demo serverLet's check that the Nginx we just compiled has all the necessary to run this example
This will display all the module that Nginx has been built with, including ngx_lua-0.7.5 here (the dev version of ngx_lua can be found here)
Now let's run Nginx with the configuration example. (You don't need to run it as root, as the example doesn't listen on port 80)
The server will run until you send you hit Control+C
Testing it
If everything went right, you should see the sever response :
Now, let's query our log aggregation port :
And here is the result :
As a final test you can try hammering your web application and see the log aggregation in action :
Beyond the exampleFor the purpose of the example the code is very simple, but with very simple additions a json printer could be added to make the output easier to consume by other services (OpenResty does include the package lua-cjson) We could also push the example further and aggregate logs to calculate timings similarly to Happy Hacking! |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论