缘由

随着功能需求的深入, openresty领域的包已经不够用了, 需要lua领域本身累积的库, 也就是luarocks.

本文讲解了windows 10桌面和ubuntu server两套系统的方法

Ubuntu Server

比较简单, 无脑敲命令即可

$ wget https://luarocks.org/releases/luarocks-2.4.1.tar.gz
$ tar zxpf luarocks-2.4.1.tar.gz
$ cd luarocks-2.4.1
./configure --prefix=/usr/local/openresty/luajit \
--with-lua=/usr/local/openresty/luajit/ \
--lua-suffix=jit \
--with-lua-include=/usr/local/openresty/luajit/include/luajit-2.1
make build && make install

安装luasql-postgres

apt-get install libpq-dev
luarocks PGSQL_INCDIR=/usr/include/postgresql/ install luasql-postgres

mysql同理. 安装之后

luarocks install luasql-mysql MYSQL_INCDIR=/usr/include/mysql

禁用ssh密码方式登录

vim /etc/ssh/sshd_config

PasswordAuthentication no

Windows 10

这个就比较复杂了.

安装MinGW

其实这个是可选项, 如果你的系统路径能找到MSVC的编译器, 那么这一步可以忽略.

为了让以后windwos进行linux相关的作业简单点, 长痛不如短痛, 干脆就装了MinGW吧.

  1. 点击此处下载:https://sourceforge.net/projects/mingw/files/latest/download?source=files
  2. 双击mingw-get-setup.exe, 记得勾选图形界面(默认是勾选的), 这样会让你选择具体安装哪些东西时比较方便
  3. 在MinGW Installer图形界面勾选mingw32-base, 然后开始在线安装.

国内网速不是很好,断断续续的, 可能要等半天. 但最终我还是安装上了.

按默认路径安装你会发现C:\MinGW\bin\mingw32-gcc.exe这个玩意出现, 它就是luarocks要的东西.最后把C:\MinGW\bin加入windows环境变量

下载luarocks

以2.4.2为例, windows版的下载链接:http://luarocks.github.io/luarocks/releases/luarocks-2.4.2-win32.zip

下载完解压,这里注意下, 以管理员权限打开cmd窗口再cd进luarocks-2.4.2-win32文件夹

配置并安装luarocks

这里, 假设windows上openresty文件夹的路径为:%USERPROFILE%\Desktop\openresty

开始安装

在cmd依次敲下面两个命令

set PREFIX=%USERPROFILE%\Desktop\openresty
install /P %PREFIX%\luarocks /SELFCONTAINED /INC %PREFIX%\include\luajit-2.1 /LIB %PREFIX% /BIN %PREFIX% /MW

/P 表示把luarocks安装在openresty的luarocks文件夹

/SELFCONTAINED 表示/TREE和/CONFIG选项的值和/P一致. 这样就所有玩意都在luarocks这个文件里,方便查找.

/INC 表示luajit的include库所在的文件夹

/LIB 表示lua51.dll所在的文件夹

/BIN表示luajit.exe所在的文件夹

/MW表示用mingw32-gcc.exe编译器.

完成安装

正常情况下. 在命令行看到如下输出:

C:\Users\xn\Desktop\luarocks-2.4.2-win32>install /P %PREFIX%\luarocks /SELFCONTAINED /INC %PREFIX%\include\luajit-2.1 /LIB %PREFIX% /BIN %PREFIX% /MW

C:\Users\xn\Desktop\luarocks-2.4.2-win32>rem=rem --[[
LuaRocks 2.4.x installer. ========================
== Checking system... ==
======================== Admin privileges available for installing
Looking for Lua interpreter
Found luajit.exe, testing it...
checking for C:\Users\xn\Desktop\openresty\lua5.1.lib
checking for C:\Users\xn\Desktop\openresty\lua51.lib
checking for C:\Users\xn\Desktop\openresty\lua5.1.dll
checking for C:\Users\xn\Desktop\openresty\lua51.dll
Found lua51.dll
checking for C:\Users\xn\Desktop\openresty\include\luajit-2.1\lua.h
Found lua.h
C:\Users\xn\Desktop\openresty\luajit.exe uses MSVCRT.DLL as runtime
Runtime check completed. ==========================
== System check results ==
========================== Will configure LuaRocks with the following paths:
LuaRocks : C:\Users\xn\Desktop\openresty\luarocks
Config file : C:\Users\xn\Desktop\openresty\luarocks\config-5.1.lua
Rocktree : C:\Users\xn\Desktop\openresty\luarocks\systree Lua interpreter : C:\Users\xn\Desktop\openresty\luajit.exe
binaries : C:\Users\xn\Desktop\openresty
libraries : C:\Users\xn\Desktop\openresty
includes : C:\Users\xn\Desktop\openresty\include\luajit-2.1
architecture: x86
binary link : lua51.dll with runtime MSVCRT.dll Compiler : MinGW (make sure it is in your path before using LuaRocks) Press <ENTER> to start installing, or press <CTRL>+<C> to abort. Use install /? for installation options. ============================
== Installing LuaRocks... ==
============================ Installing LuaRocks in C:\Users\xn\Desktop\openresty\luarocks...
Created LuaRocks command: C:\Users\xn\Desktop\openresty\luarocks\luarocks.bat
Created LuaRocks command: C:\Users\xn\Desktop\openresty\luarocks\luarocks-admin.bat Configuring LuaRocks...
Created LuaRocks site-config file: C:\Users\xn\Desktop\openresty\luarocks\lua\luarocks\site_config_5_1.lua
Created LuaRocks config file: C:\Users\xn\Desktop\openresty\luarocks\config-5.1.lua Creating rocktrees...
Created system rocktree : "C:\Users\xn\Desktop\openresty\luarocks\systree"
Local user rocktree exists : "C:\Users\xn\AppData\Roaming\LuaRocks" ============================
== LuaRocks is installed! ==
============================ You may want to add the following elements to your paths;
Lua interpreter;
PATH : C:\Users\xn\Desktop\openresty
PATHEXT : .LUA
LuaRocks;
PATH : C:\Users\xn\Desktop\openresty\luarocks
LUA_PATH : C:\Users\xn\Desktop\openresty\luarocks\lua\?.lua;C:\Users\xn\Desktop\openresty\luarocks\lua\?\init.lua
Local user rocktree (Note: %APPDATA% is user dependent);
PATH : %APPDATA%\LuaRocks\bin
LUA_PATH : %APPDATA%\LuaRocks\share\lua\5.1\?.lua;%APPDATA%\LuaRocks\share\lua\5.1\?\init.lua
LUA_CPATH: %APPDATA%\LuaRocks\lib\lua\5.1\?.dll
System rocktree
PATH : C:\Users\xn\Desktop\openresty\luarocks\systree\bin
LUA_PATH : C:\Users\xn\Desktop\openresty\luarocks\systree\share\lua\5.1\?.lua;C:\Users\xn\Desktop\openresty\luarocks\systree\share\lua\5.1\?\init.lua
LUA_CPATH: C:\Users\xn\Desktop\openresty\luarocks\systree\lib\lua\5.1\?.dll Note that the %APPDATA% element in the paths above is user specific and it MUST be replaced by its actual value.
For the current user that value is: C:\Users\xn\AppData\Roaming.

提示得很贴心了.把%USERPROFILE%\Desktop\openresty\luarocks加入系统路径, 再试试luarocks install luafilesystem

如果一切顺利,你会发现%USERPROFILE%\Desktop\openresty\luarocks\systree\lib\lua\5.1下出现了lfs.dll, 这就说明安装成功了.

配置nginx路径

包是成功安装好了, 那么怎么让nginx能找到它呢, 在配置文件里这样搞:

http {
lua_package_path "C:\Users\xn\Desktop\openresty\luarocks\systree\share\lua\5.1\?.lua;C:\Users\xn\Desktop\openresty\luarocks\systree\share\lua\5.1\?\init.lua;;";
lua_package_cpath "C:\Users\xn\Desktop\openresty\luarocks\systree\lib\lua\5.1\?.dll;;";
}

Hello world

最后lua里面require('lfs'), 大功告成

参考

https://github.com/luarocks/luarocks/wiki/Installation-instructions-for-Windows

http://www.tuicool.com/articles/fQZVJjQ

https://luarocks.org/

https://stackoverflow.com/questions/43189975/how-to-install-luasql-on-linux-ubuntu-16

将luarocks整合进openresty的更多相关文章

  1. JavaScript怎么把对象里的数据整合进另外一个数组里

    https://blog.csdn.net/qq_26222859/article/details/70331833 var json1 = [ {"guoshui":[ 3000 ...

  2. hibernate整合进spring后的事务处理

    单独使用hibernate处理事务 本来只用hibernate开发,从而可以省了DAO层实现数据库访问和跨数据库,也可以对代码进行更好的封装,当我们web中单独使用hibernate时,我们需要单独的 ...

  3. solr入门之pinyin4j源代码改写动态加入扩展词及整合进war项目中

    1.初始化时载入用户定义的字典 package net.sourceforge.pinyin4j; import net.sourceforge.pinyin4j.multipinyin.Trie; ...

  4. LUA整合进MFC代码

    这几天研究了一下lua,主要关注的是lua和vc之间的整合,把代码都写好放在VC宿主程序里,然后在lua里调用宿主程序的这些代码(或者叫接口.组件,随便你怎么叫),希望能用脚本来控制主程序的行为.这实 ...

  5. 如果你的shiro没学明白,那么应该看看这篇文章,将shiro整合进springboot

    最近在做项目的时候需要用到shiro做认证和授权来管理资源 在网上看了很多文章,发现大多数都是把官方文档的简介摘抄一段,然后就开始贴代码,告诉你怎么怎么做,怎么怎么做 相信很多小伙伴即使是跟着那些示例 ...

  6. 整理代码,将一些曾经用过的功能整合进一个spring-boot

    一 由于本人的码云太多太乱了,于是决定一个一个的整合到一个springboot项目里面. 附上自己的项目地址https://github.com/247292980/spring-boot 功能 1. ...

  7. Unity3d:UI面板管理整合进ToLua

    本文基于 https://github.com/chiuan/TTUIFramework https://github.com/jarjin/LuaFramework_UGUI 进行的二次开发,Tha ...

  8. 一晚上将一个模板整合进了DJANGO

    哈哈,说不定,下个图表项目就可以用上呢???:)

  9. 使用Openresty构建认证网关

    [入门]使用Openresty构建认证网关 lwhile关注 0.5092017.10.07 16:00:03字数 1,330阅读 4,112 在单体应用中, 我们可以通过 cookie + sess ...

随机推荐

  1. 关于tr069网管开发系列教程

    原创作品,转载请注明出处,严禁非法转载.如有错误,请留言! email:40879506@qq.com 声明:本系列涉及的开源程序代码学习和研究,严禁用于商业目的. 如有任何问题,欢迎和我交流.(企鹅 ...

  2. POJ-2923 Relocation---01背包+状态压缩

    题目链接: https://vjudge.net/problem/POJ-2923 题目大意: 有n个货物,给出每个货物的重量,每次用容量为c1,c2的火车运输,问最少需要运送多少次可以将货物运完 思 ...

  3. html标记语言 --文本标记

    html标记语言 --文本标记 二.文本标记 1.h1-h6 标题标记,h1最大 2.font 字体设置标记 2.1 size字体大小.<font size="> 取值范围1-7 ...

  4. hue集成hive访问报database is locked

    这个问题这应该是hue默认的SQLite数据库出现错误,你可以使用mysql postgresql等来替换 hue默认使用sqlite作为元数据库,不推荐在生产环境中使用.会经常出现database ...

  5. 以技术面试官的经验分享毕业生和初级程序员通过面试的技巧(Java后端方向)

    本来想分享毕业生和初级程序员如何进大公司的经验,但后来一想,人各有志,有程序员或许想进成长型或创业型公司或其它类型的公司,所以就干脆来分享些提升技能和通过面试的技巧,技巧我讲,公司你选,两厢便利. 毕 ...

  6. [HNOI 2001]求正整数

    Description 对于任意输入的正整数n,请编程求出具有n个不同因子的最小正整数m.例如:n=4,则m=6,因为6有4个不同整数因子1,2,3,6:而且是最小的有4个因子的整数. Input n ...

  7. C++Primer学习——函数

    编译器能以任意顺序对形参进行求值 函数的返回类型不能是数组类型和函数类型. 函数开始时为形参分配内存,一旦函数结束,形参也就被销毁了. 如果弄成静态局部变量,那么回到程序终止结束时才被销毁. void ...

  8. 【LA3938】"Ray, Pass me the dishes!"

    原题链接 Description After doing Ray a great favor to collect sticks for Ray, Poor Neal becomes very hun ...

  9. HDU 5726 GCD 区间GCD=k的个数

    GCD Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submis ...

  10. bzoj 1085: [SCOI2005]骑士精神

    Description 在一个5×5的棋盘上有12个白色的骑士和12个黑色的骑士,且有一个空位.在任何时候一个骑士都能按照骑士的走法(它可以走到和它横坐标相差为1,纵坐标相差为2或者横坐标相差为2,纵 ...