Linux系统下如何搭建luarocks环境

 更新时间:2024年06月19日 11:25:06   作者:longxiaobai_WJ  

这篇文章主要介绍了Linux系统下如何搭建luarocks环境问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教

目录
  • 1. notes
  • 2. luarocks
  • 3. lua – luarocks
  • 4. luajit – luarocks
  • 5. openresty
  • 6. git
  • 7. node
  • 8. openresty conf
  • 总结

1. notes

  • 本文中 openrestygitnode 为随手记录;
  • 主要搭建 luarocks 环境,测试实现openresty部分功能

2. luarocks

  • lua或luajit安装一个即可
wget https://luarocks.org/releases/luarocks-3.3.1.tar.gz

tar -zxpf luarocks-3.3.1.tar.gz

luarocks -h

luarocks list

luarocks install luafilesystem
# 还可以指定你安装的包的存放路径
luarocks install package --tree=path 

3. lua – luarocks

yum install -y readline-devel

# 系统原有lua,通过以下命令查看版本
lua -v

# 安装同版本或稳定版本
wget http://www.lua.org/ftp/lua-5.1.4.tar.gz
tar -zxvf lua-5.1.4.tar.gz

# make linux test
cd lua-5.1.4
echo "INSTALL_TOP= /usr/local/lua_5.1.4" >> Makefile
make linux && make install

cd luarocks-3.3.1
# lua - configure
./configure --prefix=/usr/local/luarocks_3.3.1 --with-lua=/usr/local/lua_5.1.4 --with-lua-include=/usr/local/lua_5.1.4/include/

make && make install

# lua require('cjson')
luarocks install lua-cjson

# Maybe Globals Env Note Settings
export LUALOCKS_HOME=/usr/local/luarocks_3.3.1
export LUA_HOME=/usr/local/lua_5.1.4
export LUA_PATH="$LUALOCKS_HOME/share/lua/5.1/?.lua;?.lua;;"
export LUA_CPATH="$LUALOCKS_HOME/lib/lua/5.1/?.so;?.so;;"

export PATH = $PATH:$HOME/bin:$LUALOCKS_HOME/bin:$LUA_HOME/bin

4. luajit – luarocks

cd luarocks-3.3.1
# luajit - configure
./configure --prefix=/usr/local/luajit/ \
--with-lua=/usr/local/luajit/ \
--lua-suffix=jit \
--with-lua-include=/usr/local/luajit/include/luajit-2.0 \
--rocks-tree=/usr/local/

# --prefix 设定 luarocks 的安装目录
# --with-lua 则是系统中安装的 lua 的根目录
# --lua-suffix 版本后缀,此处因为openresyt的lua解释器使用的是 luajit, 所以此处得写 jit
# --with-lua-include 设置 lua 引入一些头文件头文件的目录

make && make install

vim ~/.bashrc 
export LUAJIT_LIB=/usr/local/luajit/lib
export LUAJIT_INC=$LUAJIT_LIB/include/luajit-2.0

ln -s /usr/local/bin/luarocks /usr/bin/luarocks
# 删除软连接 
# rm /usr/bin/luarocks

# luajit require('cjson')
luarocks install lua-cjson

5. openresty

# Yum Install
yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo

yum install -y openresty

# Or 编译安装
wget https://openresty.org/download/openresty-1.19.3.1.tar.gz
tar -zxvf openresty-1.19.3.1.tar.gz

# 下载所需插件,如下示例
wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz 
tar -zxvf ngx_cache_purge-2.3.tar.gz # 解压缓存插件, /usr/local/src/ngx_cache_purge-2.3

# 编译 OpenResty
./configure --prefix=/usr/local/openresty --with-luajit --without- 
http_redis2_module --with-http_stub_status_module --with-http_v2_module --with- 
http_gzip_static_module --with-http_sub_module \
--add-module=/usr/local/src/ngx_cache_purge-2.3 # 配置缓存插件的源码路径

# 安装 OpenResty
gmake && gmake install

cd luarocks-3.3.1
# luajit - configure, --prefix 为 OpenResty --prefix - luajit
./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
sudo make install

6. git

yum -y install git

7. node

wget https://nodejs.org/dist/v16.19.1/node-v16.19.1-linux-x64.tar.xz
tar -C /usr/local --strip-components 1 -xJf node-v16.19.1-linux-x64.tar.xz

8. openresty conf

./configure --prefix=/usr/local/openresty/nginx \
--with-cc-opt='-O2 -DNGX_LUA_ABORT_AT_PANIC -I/usr/local/openresty/zlib/include -I/usr/local/openresty/pcre/include -I/usr/local/openresty/openssl111/include' \
--with-ld-opt='-Wl,-rpath,/usr/local/openresty/luajit/lib -L/usr/local/openresty/zlib/lib -L/usr/local/openresty/pcre/lib -L/usr/local/openresty/openssl111/lib -Wl,-rpath,/usr/local/openresty/zlib/lib:/usr/local/openresty/pcre/lib:/usr/local/openresty/openssl111/lib' \
--with-cc='ccache gcc -fdiagnostics-color=always' \
--with-pcre-jit \
--with-stream \
--with-stream_ssl_module -\
-with-stream_ssl_preread_module \
--with-http_v2_module \
--without-mail_pop3_module \
--without-mail_imap_module \
--without-mail_smtp_module \
--with-http_stub_status_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_secure_link_module \
--with-http_random_index_module \
--with-http_gzip_static_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-threads \
--with-compat \
--with-stream \
--with-http_ssl_module \
--add-module=../ngx_devel_kit-0.3.1 \
--add-module=../echo-nginx-module-0.62 \
--add-module=../xss-nginx-module-0.06 \
--add-module=../ngx_coolkit-0.2 \
--add-module=../set-misc-nginx-module-0.33 \
--add-module=../form-input-nginx-module-0.12 \
--add-module=../encrypted-session-nginx-module-0.09 \
--add-module=../srcache-nginx-module-0.32 \
--add-module=../ngx_lua-0.10.21 \
--add-module=../ngx_lua_upstream-0.07 \
--add-module=../headers-more-nginx-module-0.33 \
--add-module=../array-var-nginx-module-0.05 \
--add-module=../memc-nginx-module-0.19 \
--add-module=../redis2-nginx-module-0.15 \
--add-module=../redis-nginx-module-0.3.9 \
--add-module=../ngx_stream_lua-0.0.11 \

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持小闻网。

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。