nginx服务治理-安装篇

最近学习下关于使用nginx用作服务治理,在此做下记录供以后回顾使用。

一、关联软件和模块

  1. Nginx1.13.8,下载地址:http://nginx.org/
  2. LuaJIT-2.0.5,下载地址:http://luajit.org/download.html
  3. ngx_devel_kit,下载地址: https://github.com/simpl/ngx_devel_kit/releases
  4. pcre,下载地址:ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
  5. zlib-1.2.11,下载地址:http://zlib.net/
  6. lua-resty-redis-0.26,下载地址:https://github.com/openresty/lua-resty-redis/releases
  7. openssl-1.0.2n,下载地址:https://www.openssl.org/source/
  8. lua-nginx-module
    下载地址:https://github.com/openresty/lua-nginx-module/releases
  9. ngx_dynamic_upstream,
    下载地址:https://github.com/cubicdaiya/ngx_dynamic_upstream/releases
  10. lua-cjson ,下载地址:https://github.com/openresty/lua-cjson/releases

二、安装

  1. 使用tar命令解压所有下载后的tar包
  2. 安装LuaJIT(所有安装均修改安装路径,非root用户可进行操作)
    1)创建LuaJIT-2.0.5:mkdir LuaJIT-2.0.5
    2)修改安装路径:vi Makefile
    修改安装路径
    3)编译 make
    4)安装 make install
    这里写图片描述

  3. 安装lua-cjson
    1)修改安装路径(依赖于LuaJIT-2.0.5,故优先安装LuaJIT-2.0.5)
    这里写图片描述
    2)编译 make 会报错,见图
    这里写图片描述
    解决方式:修改Makefile,中的include路径(因为在LuaJIT-2.0.5的include中有下一层级luajit-2.0),重新编译(可与上图进行比较)
    这里写图片描述
    3)安装 make install,成功

  4. 安装Nginx
    1)配置lua环境 在用户跟目录下进行添加
vi .bash_profile
export LUAJIT_LIB=/weblogic/nginxtool/LuaJIT-2.0.5/lib
export LUAJIT_INC=/weblogic/nginxtool/LuaJIT-2.0.5/include/luajit-2.0

2)修改安装路径,并安装关联模块

./configure --prefix=/weblogic/nginxtool/nginx-1.13.8  --sbin-path=/weblogic/nginxtool/nginx-1.13.8/sbin/nginx --conf-path=/weblogic/nginxtool/nginx-1.13.8/conf/nginx.conf --pid-path=/weblogic/nginxtool/nginx-1.13.8/conf/nginx.pid  --http-proxy-temp-path=/weblogic/nginxtool/nginx-1.13.8/proxy_temp  --http-client-body-temp-path=/weblogic/nginxtool/nginx-1.13.8/client_temp --http-fastcgi-temp-path=/weblogic/nginxtool/nginx-1.13.8/fastcgi_temp --http-uwsgi-temp-path=/weblogic/nginxtool/nginx-1.13.8/uwsgi_temp --http-scgi-temp-path=/weblogic/nginxtool/nginx-1.13.8/scgi_temp --with-http_ssl_module --with-http_gzip_static_module --http-log-path=/weblogic/nginxtool/nginx-1.13.8/logs --with-http_stub_status_module --with-pcre=/weblogic/install_nginx/pcre-8.36 --with-zlib=/weblogic/install_nginx/zlib-1.2.11 --with-openssl=/weblogic/install_nginx/openssl-1.0.2n --with-ld-opt="-Wl,-rpath,/weblogic/nginxtool/LuaJIT-2.0.5/lib"  --add-module=/weblogic/install_nginx/ngx_devel_kit-0.3.0 --add-module=/weblogic/install_nginx/lua-nginx-module-0.10.11 --add-module=/weblogic/install_nginx/ngx_dynamic_upstream-0.1.6

3)编译 make
4)安装 make install,成功
这里写图片描述

三、Lua demo

  1. 在nginx.conf中编写代码
location /get {
            default_type 'text/plain';
            content_by_lua_block {
                ngx.say('Hello,world!')
            }   
        }

在浏览器中输入http://localhost:7000/get访问
返回结果:Hello,world!

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

墨香异境

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值