• 025_lua脚本语言


    一、
    --cat /opt/nginx/conf/conf.d
    lua_package_path '/opt/nginx/conf/lua/?.lua;;'; --lua模块路径,其中”;;”表示默认搜索路径
    lua_package_cpath '/opt/nginx/conf/lua/?.so;;'; --c模块

    init_by_lua_file '/opt/nginx/conf/lua/init_by_lua.lua'; --nginx Master进程加载配置时执行;通常用于初始化全局配置/预加载Lua模块
    init_worker_by_lua_file '/opt/nginx/conf/lua/init_worker_by_lua.lua'; -- 每个Nginx Worker进程启动时调用的计时器,如果Master进程不允许则只会在init_by_lua之后调用;通常用于定时拉取配置/数据,或者后端服务的健康检查
    log_by_lua_file '/opt/nginx/conf/lua/log_by_lua.lua'; --log阶段处理,比如记录访问量/统计平均响应时间
    access_by_lua_file '/opt/nginx/conf/lua/access_by_lua.lua'; --请求访问阶段处理,用于访问控制

    # 缓存配置
    # 所有可信IP, 包括:腾讯/阿里服务节点, 金色家园各个机房IP段及办公网IP段; 数据在Nginx初始化时倒入
    lua_shared_dict eleme_trusted_iplib 10M; #共享全局变量,在所有worker间共享
    lua_shared_dict eleme_whitelist_iplib 1M; # 仅金色家园各个机房IP段及办公网IP段

    # ngx_waf
    lua_shared_dict ngx_waf_locks 3M; # waf locks
    lua_shared_dict ngx_waf_counter 500M; # counter data
    lua_shared_dict ngx_waf_counter_exptime 500M; # counter exptime
    lua_shared_dict ngx_waf_defense_crawler_blacklist 10M; # blacklist

    # 配置相关
    lua_shared_dict ngx_admin_config 1M; # ngx_admin_config配置
    --[[#参考链接
    http://wiki.jikexueyuan.com/project/nginx-lua/lua.html #首页 Wiki 服务器 Nginx 跟我学 Nginx+Lua 开发
    http://jinnianshilongnian.iteye.com/blog/2186448
    http://jinnianshilongnian.iteye.com/category/333854 #第二章 OpenResty(Nginx+Lua)开发入门->跟我学Nginx+Lua开发(开涛)
    ]]
    二、
    (1)socket模块安装

    wget http://w3.impa.br/~diego/software/luasocket/old/luasocket-2.0.3-rc1.zip
    mv luasocket-2.0.3 /usr/local/include/
    cd /usr/local/include/
    cp luajit-2.0/l* luasocket-2.0.3/src/
    make
    make install
    lua
    > require("socket")
    >
    cp src/socket.lua /opt/nginx/conf/lua/
    (2)第二种方式,luarocks(类似yum)
    yum -y install luarocks.x86_64
    luajit -llyaml
    >local lyaml = require "lyaml"

    >print(package.searchpath('lyaml', package.path)) --I can get the path to the file like this:
    /usr/local/share/lua/5.1/lyaml/init.lua

    package.path='./?.lua;/usr/share/lua/5.1/?.lua;/usr/share/lua/5.1/?/init.lua;/usr/lib64/lua/5.1/?.lua;/usr/lib64/lua/5.1/?/init.lua;/opt/nginx/conf/lua/?.lua;;'

    print(package.path)

    <1>安装依赖
    yum install gcc gcc-c++ kernel-devel
    yum install readline-dev
    yum install ncurses-devel.i386
    <2>安装lua
    cd /usr/local/ && wget http://www.lua.org/ftp/lua-5.1.5.tar.gz
    tar zxvf lua-5.1.5.tar.gz
    cd lua-5.1.5
    vi Makefile
    INSTALL_TOP= /usr/local/lua-5.1.5
    make linux
    make install
    <3>安装luarocks
    cd /usr/local/include/ && wget https://luarocks.org/releases/luarocks-2.4.3.tar.gz
    tar zxpf luarocks-2.4.3.tar.gz
    cd luarocks-2.4.3
    ./configure --prefix=/usr/local/luarocks-2.4.3 --with-lua=/usr/local/lua-5.1.5
    make build
    make install
    <4>配置环境变量
    export PATH=$PATH:/usr/local/luarocks-2.4.3/bin:/usr/local/lua-5.1.5/bin:/usr/local/lua-5.1.5/bin
    export LUA_PATH="/usr/local/include/luarocks-2.4.3/share/lua/5.1/?.lua;/usr/local/include/luarocks-2.4.3/share/lua/5.1/lyaml/?.lua;/opt/nginx/conf/lua/?.lua;;" #等同于nginx配置中的lua_package_path
    export LUA_CPATH="/opt/nginx/modules/?.so;;/usr/local/include/luarocks-2.4.3/lib/luarocks/rocks;/usr/local/include/luarocks-2.4.3/lib/luarocks" #等同于nginx配置中的lua_package_cpath
    <5>luarocks常用命令
    # luarocks list
    luasocket
    3.0rc1-2 (installed) - /usr/local/include/luarocks-2.4.3/lib/luarocks/rocks
    lyaml
    6.1.3-1 (installed) - /usr/local/include/luarocks-2.4.3/lib/luarocks/rocks
    # luarocks path
    export LUA_PATH='/root/.luarocks/share/lua/5.1/?.lua;/root/.luarocks/share/lua/5.1/?/init.lua;/usr/local/luarocks-2.4.3/share/lua/5.1/?.lua;/usr/local/luarocks-2.4.3/share/lua/5.1/?/init.lua;./?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;/usr/local/lib/lua/5.1/?.lua;/usr/local/lib/lua/5.1/?/init.lua'
    export LUA_CPATH='/root/.luarocks/lib/lua/5.1/?.so;/usr/local/luarocks-2.4.3/lib/lua/5.1/?.so;./?.so;/usr/local/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so'


    参考:https://luarocks.org/#quick-start
    http://uncle-code.iteye.com/blog/2257970
    三、按照项目的salt安装

    /opt/luarocks/bin/luarocks install luasocket 2.0.2-6
    /usr/local/bin/luajit -e "require('socket')"
    /opt/luarocks/bin/luarocks install lyaml 6.1.1-4
    /usr/local/bin/luajit -e "require('lyaml')"
    /opt/luarocks/bin/luarocks install lua-resty-iputils
    /usr/local/bin/luajit -e "require('resty.iputils')"

    cd /opt && ln -s luarocks-2.4.1 luarocks
    四、生产部署只需要看这些就ok了。

    cd /tmp/waimai_lua

    eoc upload /tmp/waimai_lua/xg1-waimai-openapi-proxy-1-lua.tar.gz /opt/nginx/conf/lua -h wg-stargate-web-3
    eoc create -h wg-stargate-web-3 --script 'cd /opt/nginx/conf/lua/ && tar -xf xg1-waimai-openapi-proxy-1-lua.tar.gz' -y

    eoc upload /tmp/waimai_lua/xg1-waimai-openapi-proxy-1-luajit-2.1.tar.gz /usr/local/include/ -h wg-stargate-web-3
    eoc create -h wg-stargate-web-3 --script 'cd /usr/local/include/ && tar -xf xg1-waimai-openapi-proxy-1-luajit-2.1.tar.gz' -y

    eoc upload /tmp/waimai_lua/xg1-waimai-openapi-proxy-1-luarocks-2.4.1.tar.gz /opt -h wg-stargate-web-3
    eoc create -h wg-stargate-web-3 --script 'cd /opt && tar -xf xg1-waimai-openapi-proxy-1-luarocks-2.4.1.tar.gz' -y

    eoc upload /tmp/waimai_lua/ngx_func_lua.conf /opt/nginx/conf/conf.d -h wg-stargate-web-3


    eoc upload /tmp/waimai_lua/xg1-waimai-openapi-proxy-1-ngx_http_lua_upstream_module.so /opt/tengine-2.1.2/modules -h wg-stargate-web-3
    eoc upload /tmp/waimai_lua/xg1-waimai-openapi-proxy-1-yaml.so /usr/local/lib/lua/5.1/ -h wg-stargate-web-3
    cd /usr/local/lib/lua/5.1 && mv xg1-waimai-openapi-proxy-1-yaml.so yaml.so && chmod a+x yaml.so

  • 相关阅读:
    拉格朗日乘子基本概念
    "模式识别与机器学习"读书笔记——2.3(2)
    [raw]人工智能方向调查
    Android !No Launcher activity found!错误
    [raw]ubuntu在当前目录右键打开终端
    Android, 读取大型文件报错
    Blueman Ubuntu的蓝牙管理器
    VMware下Ubuntu8.04 方向键失效的解决方法
    无线中间人攻击初探
    【经验】短接 Flash 解决二次量产金士顿 DTI G2 4GB U盘(群联PS225139)问题
  • 原文地址:https://www.cnblogs.com/itcomputer/p/8867283.html
Copyright © 2020-2023  润新知