安装

官网http://www.lua.org/start.html 参考  https://blog.csdn.net/qq_23954569/article/details/70879672

cd ~
sudo apt-get install -y libreadline7 libreadline-dev
wget http://www.lua.org/ftp/lua-5.3.5.tar.gz
tar zxf lua-5.3.5.tar.gz
cd lua-5.3.5
sudo make linux test
sudo make install

因为放在了home,所以重装之后,只需要执行最后1句就OK了

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

包管理luarocks

才1M

cd ~
wget https://luarocks.org/releases/luarocks-3.0.4.tar.gz
tar zxpf luarocks-3.0.4.tar.gz
cd luarocks-3.0.4
./configure; sudo make bootstrap
sudo luarocks install luasocket

 安装luasql-postgres

安装时要求本地有postgres源码 

Error: Could not find header file for PGSQL
No file libpq-fe.h in /usr/local/include
No file libpq-fe.h in /usr/include
No file libpq-fe.h in /include
You may have to install PGSQL in your system and/or pass PGSQL_DIR or PGSQL_INCDIR to the luarocks command.
Example: luarocks install luasql-postgres PGSQL_DIR=/usr/local

但是我的pg是在docker镜像里的, 所以怎么办呢?要么在host上装pg,但完全没必要.超极本上资源已经很紧了,只写代码,不做数据库.

那么下载pg源码 唯一要注意的,就是必须和docker里的版本保持一致.

源码所在位置

https://www.postgresql.org/ftp/source/

cd ~
wget https://ftp.postgresql.org/pub/source/v11.2/postgresql-11.2.tar.gz
tar zxf postgresql-11.2.tar.gz

在安装时指定PG路径, 注意不是PGSQL_DIR

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

连接db简单使用

 

luasql = require "luasql.postgres"
env = assert(luasql.postgres())
-- database user pwd host port
conn = assert(env:connect("postgres","postgres","example",'127.0.0.1'))

-- version
cur = conn:execute("SELECT version();")
print(cur:fetch())

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄