Openresty 学习笔记(四)lualocks包管理器安装使用
Luarocks是一个Lua包管理器,基于Lua语言开发,提供一个命令行的方式来管理Lua包依赖、安装第三方Lua包等,社区比较流行的包管理器之一,另还有一个LuaDist,Luarocks的包数量比LuaDist多,更细节的两者对比可参阅这里
在做一些openresty的项目的时候,经常会借助一些第三方包来协助开发,为了方便管理,我们可以使用openresy官方的opm,或者lua的包管理工具luarocks,只不过opm的包数量还不是太多,用的较多的还是luarocks,现在只能期待opm社区不断的发展壮大了。
编译安装
wget https://github.com/luarocks/luarocks/archive/v3.0.0.tar.gz tar zxvf v3.0.0.tar.gz cd luarocks-3.0.0/ ./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
# 安装需要root权限
sudo make install
安装参数说明
--prefix 设定 luarocks 的安装目录
--with-lua 则是系统中安装的 lua 的根目录
--lua-suffix 版本后缀,此处因为openresyt的lua解释器使用的是 luajit ,所以此处得写 jit
--with-lua-include 设置 lua 引入一些头文件头文件的目录
查看版本
luarocks --version
/usr/local/openresty/luajit/bin/luarocks 3.0.0
LuaRocks main command-line interface
提示错误
Configuring LuaRocks... Lua version detected: 5.1
Lua interpreter found: /usr/local/openresty/luajit/bin/luajit
lua.h found: /usr/local/openresty/luajit/include/luajit-2.1/lua.h
Could not find 'unzip'.
Make sure it is installed and available in your PATH. configure failed.
安装
sudo apt install unzip
执行 luarocks install package 就可以安装lua的包了luarocks install package --tree=path 还可以指定你安装的包的存放路径
下载 rapidjson包
$ luarocks install rapidjson --tree=/usr/local/openresty/lualib/resty
Installing https://luarocks.org/rapidjson-0.5.1-1.src.rock -- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- LUA_RAPIDJSON_VERSION: 0.5.1
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/luarocks_rapidjson-0.5.1-1-fd1Qr3/lua-rapidjson/build.luarocks
Scanning dependencies of target lua-rapidjson
[ 20%] Building CXX object CMakeFiles/lua-rapidjson.dir/src/Document.cpp.o
[ 40%] Building CXX object CMakeFiles/lua-rapidjson.dir/src/Schema.cpp.o
[ 60%] Building CXX object CMakeFiles/lua-rapidjson.dir/src/rapidjson.cpp.o
[ 80%] Building CXX object CMakeFiles/lua-rapidjson.dir/src/values.cpp.o
[100%] Linking CXX shared module rapidjson.so
[100%] Built target lua-rapidjson
[100%] Built target lua-rapidjson
Install the project...
-- Install configuration: "Release"
-- Installing: /usr/local/openresty/lualib/resty/lib/luarocks/rocks-5.1/rapidjson/0.5.1-1/lib/rapidjson.so
rapidjson 0.5.1-1 is now installed in /usr/local/openresty/lualib/resty (license: MIT)
安装路径
$/usr/local/openresty/lualib/resty/lib/luarocks/rocks-5.1
ls
30log luasocket manifest rapidjson
使用
local rapidjson = require('rapidjson')
rapidjson.encode()
rapidjson.decode()
rapidjson.load()
rapidjson.dump()
》》可能遇到的问题!!!
2018/12/24 10:34:06 [error] 11222#11222: init_by_lua error: init_by_lua:2: module 'resty.auto-ssl' not found: no field package.preload['resty.auto-ssl'] no file '/usr/local/openresty/lualib/resty/auto-ssl.lua' no file '/usr/local/openresty/site/lualib/resty/auto-ssl.ljbc' no file '/usr/local/openresty/site/lualib/resty/auto-ssl/init.ljbc' no file '/usr/local/openresty/lualib/resty/auto-ssl.ljbc' no file '/usr/local/openresty/lualib/resty/auto-ssl/init.ljbc' no file '/usr/local/openresty/site/lualib/resty/auto-ssl.lua' no file '/usr/local/openresty/site/lualib/resty/auto-ssl/init.lua' no file '/usr/local/openresty/lualib/resty/auto-ssl.lua' no file '/usr/local/openresty/lualib/resty/auto-ssl/init.lua' no file './resty/auto-ssl.lua' stack traceback: [C]: in function 'require' init_by_lua:2: in main chunk
》》解决方式一:切换成 root 账户安装,`luarocks install lua-resty-auto-ssl`。以上问题解决了
》》解决方式二:如果使用 sudo ,则使用绝对路径解决
$ sudo /usr/local/openresty/luajit/bin/luarocks install lua-resty-auto-ssl
Warning: The directory '/home/www/.cache/luarocks' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing /usr/local/openresty/luajit/bin/luarocks with sudo, you may want sudo's -H flag.
Installing https://luarocks.org/lua-resty-auto-ssl-0.12.0-1.src.rock mkdir -p /tmp/luarocks_lua-resty-auto-ssl-0.12.0-1-FdxVn9/lua-resty-auto-ssl/build
rm -f /tmp/luarocks_lua-resty-auto-ssl-0.12.0-1-FdxVn9/lua-resty-auto-ssl/build/stamp-dehydrated-*
mkdir -p /tmp/luarocks_lua-resty-auto-ssl-0.12.0-1-FdxVn9/lua-resty-auto-ssl/build/bin
curl -sSLo /tmp/luarocks_lua-resty-auto-ssl-0.12.0-1-FdxVn9/lua-resty-auto-ssl/build/bin/dehydrated "https://raw.githubusercontent.com/lukas2511/dehydrated/0bc0bd13d6abdc027c58bec12f7c2d3198d3a677/dehydrated"
chmod +x /tmp/luarocks_lua-resty-auto-ssl-0.12.0-1-FdxVn9/lua-resty-auto-ssl/build/bin/dehydrated
touch /tmp/luarocks_lua-resty-auto-ssl-0.12.0-1-FdxVn9/lua-resty-auto-ssl/build/stamp-dehydrated-2-0bc0bd13d6abdc027c58bec12f7c2d3198d3a677
rm -f /tmp/luarocks_lua-resty-auto-ssl-0.12.0-1-FdxVn9/lua-resty-auto-ssl/build/stamp-lua-resty-shell-*
curl -sSLo /tmp/luarocks_lua-resty-auto-ssl-0.12.0-1-FdxVn9/lua-resty-auto-ssl/lib/resty/auto-ssl/vendor/shell.lua "https://raw.githubusercontent.com/juce/lua-resty-shell/955243d70506c21e7cc29f61d745d1a8a718994f/lib/resty/shell.lua"
touch /tmp/luarocks_lua-resty-auto-ssl-0.12.0-1-FdxVn9/lua-resty-auto-ssl/build/stamp-lua-resty-shell-955243d70506c21e7cc29f61d745d1a8a718994f
rm -f /tmp/luarocks_lua-resty-auto-ssl-0.12.0-1-FdxVn9/lua-resty-auto-ssl/build/stamp-sockproc-*
mkdir -p /tmp/luarocks_lua-resty-auto-ssl-0.12.0-1-FdxVn9/lua-resty-auto-ssl/build/bin
cd /tmp/luarocks_lua-resty-auto-ssl-0.12.0-1-FdxVn9/lua-resty-auto-ssl/build && curl -sSLo sockproc-fc8ad3f15a7b2cf2eaf39663b90010efc55e207c.tar.gz "https://github.com/juce/sockproc/archive/fc8ad3f15a7b2cf2eaf39663b90010efc55e207c.tar.gz"
cd /tmp/luarocks_lua-resty-auto-ssl-0.12.0-1-FdxVn9/lua-resty-auto-ssl/build && tar -xf sockproc-fc8ad3f15a7b2cf2eaf39663b90010efc55e207c.tar.gz
cd /tmp/luarocks_lua-resty-auto-ssl-0.12.0-1-FdxVn9/lua-resty-auto-ssl/build/sockproc-fc8ad3f15a7b2cf2eaf39663b90010efc55e207c && make
make[1]: Entering directory '/tmp/luarocks_lua-resty-auto-ssl-0.12.0-1-FdxVn9/lua-resty-auto-ssl/build/sockproc-fc8ad3f15a7b2cf2eaf39663b90010efc55e207c'
gcc -Wall -Werror -o sockproc sockproc.c
make[1]: Leaving directory '/tmp/luarocks_lua-resty-auto-ssl-0.12.0-1-FdxVn9/lua-resty-auto-ssl/build/sockproc-fc8ad3f15a7b2cf2eaf39663b90010efc55e207c'
cp /tmp/luarocks_lua-resty-auto-ssl-0.12.0-1-FdxVn9/lua-resty-auto-ssl/build/sockproc-fc8ad3f15a7b2cf2eaf39663b90010efc55e207c/sockproc /tmp/luarocks_lua-resty-auto-ssl-0.12.0-1-FdxVn9/lua-resty-auto-ssl/build/bin/sockproc
chmod +x /tmp/luarocks_lua-resty-auto-ssl-0.12.0-1-FdxVn9/lua-resty-auto-ssl/build/bin/sockproc
touch /tmp/luarocks_lua-resty-auto-ssl-0.12.0-1-FdxVn9/lua-resty-auto-ssl/build/stamp-sockproc-2-fc8ad3f15a7b2cf2eaf39663b90010efc55e207c
install -d /usr/local/openresty/luajit/lib/luarocks/rocks-5.1/lua-resty-auto-ssl/0.12.0-1/lua/resty/auto-ssl
install -m 644 lib/resty/auto-ssl.lua /usr/local/openresty/luajit/lib/luarocks/rocks-5.1/lua-resty-auto-ssl/0.12.0-1/lua/resty/auto-ssl.lua
install -m 644 lib/resty/auto-ssl/init_master.lua /usr/local/openresty/luajit/lib/luarocks/rocks-5.1/lua-resty-auto-ssl/0.12.0-1/lua/resty/auto-ssl/init_master.lua
install -m 644 lib/resty/auto-ssl/init_worker.lua /usr/local/openresty/luajit/lib/luarocks/rocks-5.1/lua-resty-auto-ssl/0.12.0-1/lua/resty/auto-ssl/init_worker.lua
install -d /usr/local/openresty/luajit/lib/luarocks/rocks-5.1/lua-resty-auto-ssl/0.12.0-1/lua/resty/auto-ssl/jobs
install -d /usr/local/openresty/luajit/lib/luarocks/rocks-5.1/lua-resty-auto-ssl/0.12.0-1/lua/resty/auto-ssl/json_adapters
install -m 644 lib/resty/auto-ssl/json_adapters/cjson.lua /usr/local/openresty/luajit/lib/luarocks/rocks-5.1/lua-resty-auto-ssl/0.12.0-1/lua/resty/auto-ssl/json_adapters/cjson.lua
install -m 644 lib/resty/auto-ssl/json_adapters/dkjson.lua /usr/local/openresty/luajit/lib/luarocks/rocks-5.1/lua-resty-auto-ssl/0.12.0-1/lua/resty/auto-ssl/json_adapters/dkjson.lua
install -m 644 lib/resty/auto-ssl/jobs/renewal.lua /usr/local/openresty/luajit/lib/luarocks/rocks-5.1/lua-resty-auto-ssl/0.12.0-1/lua/resty/auto-ssl/jobs/renewal.lua
install -d /usr/local/openresty/luajit/lib/luarocks/rocks-5.1/lua-resty-auto-ssl/0.12.0-1/lua/resty/auto-ssl/servers
install -m 644 lib/resty/auto-ssl/servers/challenge.lua /usr/local/openresty/luajit/lib/luarocks/rocks-5.1/lua-resty-auto-ssl/0.12.0-1/lua/resty/auto-ssl/servers/challenge.lua
install -m 644 lib/resty/auto-ssl/servers/hook.lua /usr/local/openresty/luajit/lib/luarocks/rocks-5.1/lua-resty-auto-ssl/0.12.0-1/lua/resty/auto-ssl/servers/hook.lua
install -m 644 lib/resty/auto-ssl/ssl_certificate.lua /usr/local/openresty/luajit/lib/luarocks/rocks-5.1/lua-resty-auto-ssl/0.12.0-1/lua/resty/auto-ssl/ssl_certificate.lua
install -d /usr/local/openresty/luajit/lib/luarocks/rocks-5.1/lua-resty-auto-ssl/0.12.0-1/lua/resty/auto-ssl/ssl_providers
install -m 644 lib/resty/auto-ssl/ssl_providers/lets_encrypt.lua /usr/local/openresty/luajit/lib/luarocks/rocks-5.1/lua-resty-auto-ssl/0.12.0-1/lua/resty/auto-ssl/ssl_providers/lets_encrypt.lua
install -m 644 lib/resty/auto-ssl/storage.lua /usr/local/openresty/luajit/lib/luarocks/rocks-5.1/lua-resty-auto-ssl/0.12.0-1/lua/resty/auto-ssl/storage.lua
install -d /usr/local/openresty/luajit/lib/luarocks/rocks-5.1/lua-resty-auto-ssl/0.12.0-1/lua/resty/auto-ssl/storage_adapters
install -m 644 lib/resty/auto-ssl/storage_adapters/file.lua /usr/local/openresty/luajit/lib/luarocks/rocks-5.1/lua-resty-auto-ssl/0.12.0-1/lua/resty/auto-ssl/storage_adapters/file.lua
install -m 644 lib/resty/auto-ssl/storage_adapters/redis.lua /usr/local/openresty/luajit/lib/luarocks/rocks-5.1/lua-resty-auto-ssl/0.12.0-1/lua/resty/auto-ssl/storage_adapters/redis.lua
install -d /usr/local/openresty/luajit/lib/luarocks/rocks-5.1/lua-resty-auto-ssl/0.12.0-1/lua/resty/auto-ssl/utils
install -m 644 lib/resty/auto-ssl/utils/shell_execute.lua /usr/local/openresty/luajit/lib/luarocks/rocks-5.1/lua-resty-auto-ssl/0.12.0-1/lua/resty/auto-ssl/utils/shell_execute.lua
install -m 644 lib/resty/auto-ssl/utils/start_sockproc.lua /usr/local/openresty/luajit/lib/luarocks/rocks-5.1/lua-resty-auto-ssl/0.12.0-1/lua/resty/auto-ssl/utils/start_sockproc.lua
install -m 644 lib/resty/auto-ssl/utils/run_command.lua /usr/local/openresty/luajit/lib/luarocks/rocks-5.1/lua-resty-auto-ssl/0.12.0-1/lua/resty/auto-ssl/utils/run_command.lua
install -d /usr/local/openresty/luajit/lib/luarocks/rocks-5.1/lua-resty-auto-ssl/0.12.0-1/lua/resty/auto-ssl/vendor
install -m 644 lib/resty/auto-ssl/vendor/shell.lua /usr/local/openresty/luajit/lib/luarocks/rocks-5.1/lua-resty-auto-ssl/0.12.0-1/lua/resty/auto-ssl/vendor/shell.lua
install -d /usr/local/openresty/luajit/lib/luarocks/rocks-5.1/lua-resty-auto-ssl/0.12.0-1/bin/resty-auto-ssl
install -m 755 bin/letsencrypt_hooks /usr/local/openresty/luajit/lib/luarocks/rocks-5.1/lua-resty-auto-ssl/0.12.0-1/bin/resty-auto-ssl/letsencrypt_hooks
install -m 755 bin/start_sockproc /usr/local/openresty/luajit/lib/luarocks/rocks-5.1/lua-resty-auto-ssl/0.12.0-1/bin/resty-auto-ssl/start_sockproc
install -m 755 /tmp/luarocks_lua-resty-auto-ssl-0.12.0-1-FdxVn9/lua-resty-auto-ssl/build/bin/dehydrated /usr/local/openresty/luajit/lib/luarocks/rocks-5.1/lua-resty-auto-ssl/0.12.0-1/bin/resty-auto-ssl/dehydrated
install -m 755 /tmp/luarocks_lua-resty-auto-ssl-0.12.0-1-FdxVn9/lua-resty-auto-ssl/build/bin/sockproc /usr/local/openresty/luajit/lib/luarocks/rocks-5.1/lua-resty-auto-ssl/0.12.0-1/bin/resty-auto-ssl/sockproc
lua-resty-auto-ssl 0.12.0-1 is now installed in /usr/local/openresty/luajit (license: MIT)
》》解决方式三:修改/etc/sudoers这个文件,将要执行的命令所在的目录添加到后面
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/openresty/luajit/bin"
参考
1、https://segmentfault.com/a/1190000008658146
Openresty 学习笔记(四)lualocks包管理器安装使用的更多相关文章
- [转帖]Linux学习笔记之rpm包管理功能全解
		
Linux学习笔记之rpm包管理功能全解 https://www.cnblogs.com/JetpropelledSnake/p/11177277.html rpm 的管理命令 之前学习过 yum 的 ...
 - openresty 学习笔记四:连接mysql和进行相关操作
		
openresty 学习笔记四:连接mysql和进行相关操作 毕竟redis是作为缓存,供程序的快速读写,虽然reidis也可以做持久化保存,但还是需要一个做数据存储的数据库.比如首次查询数据在red ...
 - Linux学习笔记之rpm包管理功能全解
		
0x00 软件包管理器 所有的软件都是由文件格式的程序代码(即源代码),经过编译成为一个可执行二进制文件:对于一个软件来说,其包含二进制程序.库文件.配置文件以及帮助文件.在应用中,每次要安装程序时通 ...
 - mac版sublime text2包管理器安装步骤
		
第一步: control+-打开命令执行窗口. 第二步: 将包管理器的代码复制到命令执行窗口: import urllib2,os,hashlib; h = '2915d1851351e5ee549c ...
 - 在linux中使用包管理器安装node.js
		
网上文章中,在linux下安装node.js都是使用源码编译,其实node的github上已经提供了各个系统下使用各自的包管理器(package manager)安装node.js的方法. 1. 在U ...
 - ubuntu利用包管理器安装Node.JS
		
步骤1:用curl获取源代码在我们用卷曲获取源代码之前,我们必须先升级操作系统,然后用卷发命令获取NodeSource添加到本地仓库. root@ubuntu-:~#apt-get update 安装 ...
 - 利用包管理器安装Node.JS
		
步骤1:用curl获取源代码在我们用卷曲获取源代码之前,我们必须先升级操作系统,然后用卷发命令获取NodeSource添加到本地仓库. root@ubuntu-15:~#apt-get update安 ...
 - SurvivalShooter学习笔记(八.敌人管理器)
		
敌人管理器:管理敌人的随机出生点创建 在场景中建立几个空物体,作为敌人的出生点 public class EnemyManager : MonoBehaviour { public PlayerHea ...
 - Struts2学习笔记四:深入拦截器
		
一:拦截器的工作原理 拦截器的执行过程可以类比filter过滤器,ActionInvocation实例执行过程中,先执行action实例上引用的拦截器们,然后才执行action实例处理请求,返回res ...
 
随机推荐
- 动态逆序对[CDQ分治]
			
题面 luogu cdq分治入门 注意删的是值不是位置! #include <cstdio> #include <algorithm> #include <cmath&g ...
 - nagios 监控内存使用情况
			
监控本机内存cd /usr/lib64/nagios/pluginstouch check_mem.sh #!/bin/bash " ]; then memTotal_b=`free -b ...
 - 解决win10“cmd自动弹出一闪而过”问题的方法
			
1.禁用CMD win+Q gpedit 打开组策略 用户配置--管理模板--系统--阻止访问命令提示符--已启用. 2.启用PowerShell PS:需要使用CMD时可用powershell代替: ...
 - [NOI2010]海拔(最小割)
			
题目描述 YT市是一个规划良好的城市,城市被东西向和南北向的主干道划分为n×n个区域.简单起见,可以将YT市看作一个 正方形,每一个区域也可看作一个正方形.从而,YT城市中包括(n+1)×(n+1)个 ...
 - 单片机的基本构成、工作原理 LET′S TRY“嵌入式编程”: 1 of 6
			
单片机的基本构成.工作原理 LET′S TRY“嵌入式编程”: 1 of 6 本连载讲解作为嵌入式系统开发技术人员所必需具备的基础知识.这些基础知识是硬件和软件技术人员都应该掌握的共通技术知识.有了电 ...
 - linux(fedora) 第三课
			
树形打印所有进程名:pstree pstree | grep pstree -A2 -B2(查看pstree前后两行) NI的值[-20,20) nice(改变NI的值):改变程序优先级 nice - ...
 - 编码标准:ASCII、GBK、Unicode(UTF8、UTF16、UTF32)
			
英文编码(单字节字符集,码值范围0~127):字节最高位是0 ASCII编码,用于英文字符.中文编码(双字节字符集):首字节(8位)的最高位是1.可依据首字节最高位来判断中英文. GB2312, 旧版 ...
 - maomao的现在与未来
			
今晚开始,maomao决定要成为一个和以前不一样的人了. 自从高一开始竞赛生涯以来,我的竞赛就一直处于不是很好,也不是很差的水平,就像我初中一年级到二年级一直处于的状态一样.一直以来,我从来没有对自己 ...
 - (map string)Crazy Search  hdu1381
			
Crazy Search Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
 - Collection中的迭代器
			
迭代器:boolean hasNext() 判断集合中是否还有没有被取出数据nexe() 取出集合中下一个元素package cn.lijun.demo4; import java.util.Arra ...