Fork me on GitHub

Ubuntu20.04 源码安装APISIX-2.15.3

[TOC]

OpenResty源码安装

安装前准备

您必须将这些库 perl 5.6.1+, libpcre, libssl安装在您的电脑之中。 对于 Linux来说, 您需要确认使用 ldconfig 命令,让其在您的系统环境路径中能找到它们。

以下安装的内容就是取自https://raw.githubusercontent.com/apache/apisix/master/utils/linux-install-luarocks.sh(master可以替换为具体版本号)

1
2
sudo apt-get install make gcc g++ build-essential curl unzip
sudo apt-get install -y libssl-dev perl zlib1g-dev libpcre3 libpcre3-dev libldap2-dev libpq-dev

编译安装OpenResty

下载,解压openresty-$VERSION.tar.gz

1
2
3
4
mkdir -p /opt/src && cd /opt/src
curl -O https://openresty.org/download/openresty-1.21.4.1.tar.gz
tar xzvf openresty-1.21.4.1.tar.gz -C /opt/src
cd /opt/src/openresty-1.21.4.1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
./configure --prefix=/usr/local/openresty \
--with-poll_module \
--with-pcre-jit \
--without-http_rds_json_module \
--without-http_rds_csv_module \
--without-lua_rds_parser \
--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 \
-j`nproc`
1
make -j`nproc` && make install

安装OpenResty的相关组件

openresty-openssl111-dev openresty-pcre-dev openresty-zlib-dev

我们应该通过添加 GPG 公钥来安装一些需要的组件。这些可以在之后删除

1
sudo apt-get -y install --no-install-recommends wget gnupg ca-certificates

然后导入openresty的 GPG 密钥

1
wget -O - https://openresty.org/package/pubkey.gpg | sudo apt-key add -

接着添加 openresty 的官方 APT 库

1
2
echo "deb https://openresty.org/package/ubuntu $(lsb_release -sc) main" > openresty.list
sudo cp openresty.list /etc/apt/sources.list.d/

请注意,这是针对 x86_64 或 amd64 系统的

对于 Aarch64 或 ARM64 系统,你应该使用这个 URL 来代替

1
echo "deb https://openresty.org/package/arm64/ubuntu $(lsb_release -sc) main"

现在更新 APT 索引

1
sudo apt-get update

安装 Openrety 相关组件

1
sudo apt-get -y install openresty-openssl111-dev openresty-pcre-dev openresty-zlib-dev

安装完会生成/usr/local/openresty目录,且/usr/local/openresty/openssl111,/usr/local/openresty/pcre,/usr/local/openresty/zlib这子目录会在该目录下。

安装luarocks

1
2
3
4
5
6
7
8
9
10
wget https://luarocks.org/releases/luarocks-3.8.0.tar.gz
tar -xzvf luarocks-3.8.0.tar.gz
cd luarocks-3.8.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 && make install

结果如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
root@s91:/opt/src/apisix-3.2.0/utils/luarocks-3.8.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
--lua-suffix is no longer necessary.
The suffix is automatically detected.

Configuring LuaRocks version 3.8.0...

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
unzip found in PATH: /usr/bin

Done configuring.

LuaRocks will be installed at......: /usr/local/openresty/luajit
LuaRocks will install rocks at.....: /usr/local/openresty/luajit
LuaRocks configuration directory...: /usr/local/openresty/luajit/etc/luarocks
Using Lua from.....................: /usr/local/openresty/luajit
Lua include directory..............: /usr/local/openresty/luajit/include/luajit-2.1

* Type make and make install:
to install to /usr/local/openresty/luajit as usual.
* Type make bootstrap:
to install LuaRocks into /usr/local/openresty/luajit as a rock.

设置环境变量

1
vi /etc/profile

/etc/profile文件最后添加如下代码

1
2
export OPENRESTY_HOME=/usr/local/openresty
export PATH=$PATH:$OPENRESTY_HOME/bin:$OPENRESTY_HOME/luajit/bin

使得环境变量生效

1
source /etc/profile

重构Openresty

主要是为了加一些apisix所需的模块

To enable etcd client certificate you need to build APISIX-Base, see
https://apisix.apache.org/docs/apisix/FAQ#how-do-i-build-the-apisix-base-environment

apisix提供的openresty构建脚本
我将版本改为2.5.13,即version=${version:-0.0.0}改为了version=2.5.13。
由于git clone经常出问题(github不稳定,翻墙会好一些),我改了下脚本,可以先将需要的包都下载下来(所需的源码包百度网盘下载)[https://pan.baidu.com/s/1X8U4_pIL86QH3wJuhrv6LQ?pwd=k8sl]

可以提前将下载好的安装包放到构建脚本同目录下,构建脚本内容如下,我处理了下:1.有些解压出来不带v,但是文件名带v 2.解压出来是大写的。这两种情况

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/usr/bin/env bash
set -euo pipefail
set -x

version=${version:-2.15.3}

if ([ $# -gt 0 ] && [ "$1" == "latest" ]) || [ "$version" == "latest" ]; then
ngx_multi_upstream_module_ver="master"
mod_dubbo_ver="master"
apisix_nginx_module_ver="main"
wasm_nginx_module_ver="main"
lua_var_nginx_module_ver="master"
grpc_client_nginx_module_ver="main"
amesh_ver="main"
debug_args="--with-debug"
OR_PREFIX=${OR_PREFIX:="/usr/local/openresty-debug"}
else
ngx_multi_upstream_module_ver="1.1.1"
mod_dubbo_ver="1.0.2"
apisix_nginx_module_ver="1.12.0"
wasm_nginx_module_ver="0.6.4"
lua_var_nginx_module_ver="v0.5.3"
grpc_client_nginx_module_ver="v0.4.2"
amesh_ver="main"
debug_args=${debug_args:-}
OR_PREFIX=${OR_PREFIX:="/usr/local/openresty"}
fi

prev_workdir="$PWD"
repo=$(basename "$prev_workdir")
workdir=$(mktemp -d)
cd "$workdir" || exit 1

or_ver="1.21.4.1"
wget --no-check-certificate https://openresty.org/download/openresty-${or_ver}.tar.gz
tar -zxvpf openresty-${or_ver}.tar.gz > /dev/null

if [ "$repo" == ngx_multi_upstream_module ]; then
cp -r "$prev_workdir" ./ngx_multi_upstream_module-${ngx_multi_upstream_module_ver}
else
unzip ${prev_workdir}/ngx_multi_upstream_module-${ngx_multi_upstream_module_ver}.zip
fi

if [ "$repo" == mod_dubbo ]; then
cp -r "$prev_workdir" ./mod_dubbo-${mod_dubbo_ver}
else
unzip ${prev_workdir}/mod_dubbo-${mod_dubbo_ver}.zip
fi

if [ "$repo" == apisix-nginx-module ]; then
cp -r "$prev_workdir" ./apisix-nginx-module-${apisix_nginx_module_ver}
else
unzip ${prev_workdir}/apisix-nginx-module-${apisix_nginx_module_ver}.zip
fi

if [ "$repo" == wasm-nginx-module ]; then
cp -r "$prev_workdir" ./wasm-nginx-module-${wasm_nginx_module_ver}
else
unzip ${prev_workdir}/wasm-nginx-module-${wasm_nginx_module_ver}.zip
fi

if [ "$repo" == lua-var-nginx-module ]; then
cp -r "$prev_workdir" ./lua-var-nginx-module-${lua_var_nginx_module_ver}
else
unzip ${prev_workdir}/lua-var-nginx-module-${lua_var_nginx_module_ver#*v}.zip
fi

if [ "$repo" == grpc-client-nginx-module ]; then
cp -r "$prev_workdir" ./grpc-client-nginx-module-${grpc_client_nginx_module_ver}
else
unzip ${prev_workdir}/grpc-client-nginx-module-${grpc_client_nginx_module_ver#*v}.zip
fi

if [ "$repo" == amesh ]; then
cp -r "$prev_workdir" ./amesh-${amesh_ver}
else
unzip ${prev_workdir}/Amesh-${amesh_ver}.zip
fi

cd ngx_multi_upstream_module-${ngx_multi_upstream_module_ver} || exit 1
./patch.sh ../openresty-${or_ver}
cd ..

cd apisix-nginx-module-${apisix_nginx_module_ver}/patch || exit 1
./patch.sh ../../openresty-${or_ver}
cd ../..

cd wasm-nginx-module-${wasm_nginx_module_ver} || exit 1
./install-wasmtime.sh
cd ..

cc_opt=${cc_opt:-}
ld_opt=${ld_opt:-}
luajit_xcflags=${luajit_xcflags:="-DLUAJIT_NUMMODE=2 -DLUAJIT_ENABLE_LUA52COMPAT"}
no_pool_patch=${no_pool_patch:-}
# TODO: remove old NGX_HTTP_GRPC_CLI_ENGINE_PATH once we have released a new
# version of grpc-client-nginx-module
grpc_engine_path="-DNGX_GRPC_CLI_ENGINE_PATH=$OR_PREFIX/libgrpc_engine.so -DNGX_HTTP_GRPC_CLI_ENGINE_PATH=$OR_PREFIX/libgrpc_engine.so"

cd openresty-${or_ver} || exit 1
# FIXME: remove this once 1.21.4.2 is released
rm -rf bundle/LuaJIT-2.1-20220411
lj_ver=2.1-20230119
wget "https://github.com/openresty/luajit2/archive/v$lj_ver.tar.gz" -O "LuaJIT-$lj_ver.tar.gz"
tar -xzf LuaJIT-$lj_ver.tar.gz
mv luajit2-* bundle/LuaJIT-2.1-20220411

# ${lua_var_nginx_module_ver#*v}是为了去掉v

./configure --prefix="$OR_PREFIX" \
--with-cc-opt="-DAPISIX_BASE_VER=$version $grpc_engine_path $cc_opt" \
--with-ld-opt="-Wl,-rpath,$OR_PREFIX/wasmtime-c-api/lib $ld_opt" \
$debug_args \
--add-module=../mod_dubbo-${mod_dubbo_ver} \
--add-module=../ngx_multi_upstream_module-${ngx_multi_upstream_module_ver} \
--add-module=../apisix-nginx-module-${apisix_nginx_module_ver} \
--add-module=../apisix-nginx-module-${apisix_nginx_module_ver}/src/stream \
--add-module=../apisix-nginx-module-${apisix_nginx_module_ver}/src/meta \
--add-module=../wasm-nginx-module-${wasm_nginx_module_ver} \
--add-module=../lua-var-nginx-module-${lua_var_nginx_module_ver#*v} \
--add-module=../grpc-client-nginx-module-${grpc_client_nginx_module_ver#*v} \
--with-poll_module \
--with-pcre-jit \
--without-http_rds_json_module \
--without-http_rds_csv_module \
--without-lua_rds_parser \
--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-luajit-xcflags="$luajit_xcflags" \
$no_pool_patch \
-j`nproc`

make -j`nproc`
sudo make install
cd ..

cd apisix-nginx-module-${apisix_nginx_module_ver} || exit 1
sudo OPENRESTY_PREFIX="$OR_PREFIX" make install
cd ..

cd wasm-nginx-module-${wasm_nginx_module_ver} || exit 1
sudo OPENRESTY_PREFIX="$OR_PREFIX" make install
cd ..

cd grpc-client-nginx-module-${grpc_client_nginx_module_ver#*v} || exit 1
sudo sed -i s#https://go.dev/dl/#https://golang.google.cn/dl/#g install-util.sh
sudo /usr/local/go/bin/go env -w GO111MODULE=on
sudo /usr/local/go/bin/go env -w GOPROXY=https://goproxy.cn,direct
sudo OPENRESTY_PREFIX="$OR_PREFIX" make install
cd ..

cd Amesh-${amesh_ver} || exit 1
sudo OPENRESTY_PREFIX="$OR_PREFIX" sh -c 'PATH="${PATH}:/usr/local/go/bin" make install'
cd ..

# package etcdctl
ETCD_ARCH="amd64"
ETCD_VERSION=${ETCD_VERSION:-'3.5.4'}
ARCH=${ARCH:-$(uname -m | tr '[:upper:]' '[:lower:]')}

if [[ $ARCH == "arm64" ]] || [[ $ARCH == "aarch64" ]]; then
ETCD_ARCH="arm64"
fi

wget -q https://github.com/etcd-io/etcd/releases/download/v${ETCD_VERSION}/etcd-v${ETCD_VERSION}-linux-${ETCD_ARCH}.tar.gz
tar xf etcd-v${ETCD_VERSION}-linux-${ETCD_ARCH}.tar.gz
# ship etcdctl under the same bin dir of openresty so we can package it easily
sudo cp etcd-v${ETCD_VERSION}-linux-${ETCD_ARCH}/etcdctl "$OR_PREFIX"/bin/
rm -rf etcd-v${ETCD_VERSION}-linux-${ETCD_ARCH}

设置环境变量

1
vi /etc/profile

添加以下内容

1
2
3
4
cat >> /etc/profile << EOF
export $OPENRESTY_HOME=/usr/local/openresty
export PATH=$PATH:$OPENRESTY_HOME/bin
EOF

然后执行

1
souce /etc/profile

APISIX安装

进入APISIX源码目录

设置APISIX版本,并创建目录

1
2
APISIX_VERSION=2.15.3
mkdir apisix-${APISIX_VERSION}

下载源码包

1
curl -O https://downloads.apache.org/apisix/${APISIX_VERSION}/apache-apisix-${APISIX_VERSION}-src.tgz

解压源码包

1
mkdir -p /opt/src/apisix-${APISIX_VERSION} && tar xzvf apache-apisix-${APISIX_VERSION}-src.tgz -C /opt/src/apisix-${APISIX_VERSION}

修改luarocks源,添加以下配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
mkdir -p ~/.luarocks
cat >> ~/.luarocks/config-5.1.lua << EOF
rocks_servers = {
{
"https://luarocks.cn",
"https://luarocks.org",
"https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/",
"https://luafr.org/luarocks/",
"http://luarocks.logiceditor.com/rocks"
}
}
variables = {
OPENSSL_INCDIR = "/usr/local/openresty/openssl111/include",
OPENSSL_LIBDIR = "/usr/local/openresty/openssl111/lib"
}
EOF

构建

1
2
3
4
# Switch to the apisix-${APISIX_VERSION} directory
cd apisix-${APISIX_VERSION}
# Create dependencies
make deps

或指定源地址

1
make deps ENV_LUAROCKS_SERVER=https://luarocks.cn

构建的话由于网络问题,可能需要多试几次

最后安装

1
2
# Install apisix command
make install

1
2
3
4
5
6
7
sudo tee -a /etc/security/limits.conf << EOF
#
* soft nofile 65536
* hard nofile 65536
* soft nproc 65536
* hard nproc 65536
EOF

设置luarocks

1
2
3
OPENSSL_PREFIX=/usr/local/openresty/openssl111
luarocks config variables.OPENSSL_LIBDIR ${OPENSSL_PREFIX}/lib
luarocks config variables.OPENSSL_INCDIR ${OPENSSL_PREFIX}/include

拷贝源码构建目录下的apisix目录以及deps目录到 /usr/local/apisix

1
cp -r /opt/src/apisix-${APISIX_VERSION}/apisix/ /opt/src/apisix-${APISIX_VERSION}/deps/ /usr/local/apisix/

测试apisix

1
2
/usr/bin/apisix test
/usr/bin/apisix init

APISIX连接etcd

无证书方式

分别在三个节点上起etcd服务

1
2
3
4
5
6
7
8
9
10
11
12
13
/opt/etcd3/etcd \
--name s1 \
--data-dir /tmp/etcd-data \
--listen-client-urls http://0.0.0.0:2379 \
--advertise-client-urls http://0.0.0.0:2379 \
--listen-peer-urls http://0.0.0.0:2380 \
--initial-advertise-peer-urls http://0.0.0.0:2380 \
--initial-cluster s1=http://0.0.0.0:2380 \
--initial-cluster-token tkn \
--initial-cluster-state new \
--log-level info \
--logger zap \
--log-outputs stderr

1
2
3
4
5
6
7
8
9
10
11
12
13
/opt/etcd3/etcd \
--name s2 \
--data-dir /tmp/etcd-data \
--listen-client-urls http://0.0.0.0:2379 \
--advertise-client-urls http://0.0.0.0:2379 \
--listen-peer-urls http://0.0.0.0:2380 \
--initial-advertise-peer-urls http://0.0.0.0:2380 \
--initial-cluster s1=http://0.0.0.0:2380 \
--initial-cluster-token tkn \
--initial-cluster-state new \
--log-level info \
--logger zap \
--log-outputs stderr
1
2
3
4
5
6
7
8
9
10
11
12
13
/opt/etcd3/etcd \
--name s3 \
--data-dir /tmp/etcd-data \
--listen-client-urls http://0.0.0.0:2379 \
--advertise-client-urls http://0.0.0.0:2379 \
--listen-peer-urls http://0.0.0.0:2380 \
--initial-advertise-peer-urls http://0.0.0.0:2380 \
--initial-cluster s1=http://0.0.0.0:2380 \
--initial-cluster-token tkn \
--initial-cluster-state new \
--log-level info \
--logger zap \
--log-outputs stderr

如果是使用http的话,就配置下host就行了

1
2
3
4
5
6
7
8
9
# 其他配置省略...

etcd:
host:
- "http://10.1.80.91:2379"
- "http://10.1.80.92:2379"
- "http://10.1.80.93:2379"

# 其他配置省略...

有证书方式

如果是使用https的话,需要配置下etcd证书

创建放etcd证书的目录,并将证书拷贝过去,由于我是将etcd和apisix安装在一台上了,请根据具体情况来操作

1
2
3
sudo mkdir -p /usr/local/apisix/ssl
sudo cp /opt/etcd3/ssl/{etcd-ca.pem,etcd-server-key.pem,etcd-server.pem} /usr/local/apisix/ssl
sudo chmod a+r /usr/local/apisix/ssl/etcd-server-key.pem

chmod 666 /usr/local/apisix/ssl/etcd-server-key.pem 为什么加写权限,见常见问题

修改APISIX配置文件,可以先备份下,然后用config-default.yaml这个模板

1
2
3
cp /usr/local/apisix/conf/config.yaml /usr/local/apisix/conf/config.yaml.bak
cp /usr/local/apisix/conf/config-default.yaml /usr/local/apisix/conf/config.yaml
vi /usr/local/apisix/conf/config.yaml

修改内容如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 其余省略...
ssl:
enable: true
listen: # APISIX listening port in https.
- port: 9443
enable_http2: true
# - ip: 127.0.0.3 # Specific IP, If not set, the default value is `0.0.0.0`.
# port: 9445
# enable_http2: true
ssl_trusted_certificate: /usr/local/apisix/ssl/etcd-ca.pem # Specifies a file path with trusted CA certificates in the PEM format

# 其余省略...
etcd:
host: # it's possible to define multiple etcd hosts addresses of the same etcd cluster.
- "https://10.1.80.91:2379" # multiple etcd address, if your etcd cluster enables TLS, please use https scheme,
- "https://10.1.80.92:2379" # multiple etcd address, if your etcd cluster enables TLS, please use https scheme,
- "https://10.1.80.93:2379" # multiple etcd address, if your etcd cluster enables TLS, please use https scheme,
# e.g. https://127.0.0.1:2379.
prefix: /apisix # configuration prefix in etcd
use_grpc: false # enable the experimental configuration sync via gRPC
timeout: 30 # 30 seconds. Use a much higher timeout (like an hour) if the `use_grpc` is true.
#resync_delay: 5 # when sync failed and a rest is needed, resync after the configured seconds plus 50% random jitter
#health_check_timeout: 10 # etcd retry the unhealthy nodes after the configured seconds
startup_retry: 2 # the number of retry to etcd during the startup, default to 2
#user: root # root username for etcd
#password: 5tHkHhYkjr6cQY # root password for etcd
tls:
# To enable etcd client certificate you need to build APISIX-Base, see
# https://apisix.apache.org/docs/apisix/FAQ#how-do-i-build-the-apisix-base-environment
cert: /usr/local/apisix/ssl/etcd-server.pem # path of certificate used by the etcd client
key: /usr/local/apisix/ssl/etcd-server-key.pem # path of key used by the etcd client

verify: true # whether to verify the etcd endpoint certificate when setup a TLS connection to etcd,

初始化启动APISIX

启动apisix

1
2
3
/usr/bin/apisix test
/usr/bin/apisix init
/usr/bin/apisix start

如果以这种方式启动了,当使用systemd服务方式启动时,别忘了关掉之前的apisix进程

为APISIX添加systemd服务

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
sudo tee -a /usr/lib/systemd/system/apisix.service << EOF  
# apisix systemd service
# https://github.com/api7/apisix-build-tools/blob/master/usr/lib/systemd/system/apisix.service
[Unit]
Description=apisix
#Conflicts=apisix.service
After=network-online.target
Wants=network-online.target

[Service]
Type=forking
Restart=on-failure
WorkingDirectory=/usr/local/apisix
ExecStart=/usr/bin/apisix start
ExecStop=/usr/bin/apisix stop
ExecReload=/usr/bin/apisix reload
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target
EOF

启用apisix服务

1
2
systemctl daemon-reload
systemctl enable apisix

常见错误

Could not find header file for OPENSSL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Installing https://luarocks.org/luasec-0.9-1.src.rock

Error: Failed installing dependency: https://luarocks.org/luasec-0.9-1.src.rock - Could not find header file for OPENSSL
No file openssl/ssl.h in /usr/local/openresty/openssl/include
You may have to install OPENSSL in your system and/or pass OPENSSL_DIR or OPENSSL_INCDIR to the luarocks command.
Example: luarocks install luasec OPENSSL_DIR=/usr/local
make: *** [Makefile:152: deps] Error 1
root@exp:/tmp/src/apisix-2.15# ll /usr/local/openresty/op^C
root@exp:/tmp/src/apisix-2.15# apt install libssl-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
libssl-dev is already the newest version (1.1.1f-1ubuntu2.16).
0 upgraded, 0 newly installed, 0 to remove and 9 not upgraded.

需要安装openresty-openssl111-dev

1
sudo apt install -y openresty-openssl111-dev

gzip module requires the zlib library

在进行./configure编译Nginx提示gzip module requires the zlib library
执行sudo apt install zlib1g-dev可解决

1
sudo apt install zlib1g-dev

ngx_postgres addon was unable to detect version of the libpq library

在进行./configure编译Nginx提示ngx_postgres addon was unable to detect version of the libpq library
执行sudo apt-get install libpq-dev可解决

1
sudo apt-get install libpq-dev

安装apixsix make deps时报如下错误,说明没有安装libldap2-dev

1
2
3
4
Error: Failed installing dependency: https://luarocks.cn/lualdap-1.2.6-1.src.rock - Could not find header file for LDAP
No file ldap.h in /usr/local/include
No file ldap.h in /usr/include
No file ldap.h in /include

APISIX相关文件缺失

遇如下错误,只需将源码apisix-$VERSION/apisix目录拷贝到 /usr/local/apisix安装目录下 cp -r /opt/src/apisix-3.2.0/apisix/ /usr/local/apisix/

1
2
3
4
5
6
root@s91:/usr/local/apisix# apisix init
/usr/local/openresty//luajit/bin/luajit /usr/local/apisix/apisix/cli/apisix.lua init
/usr/local/openresty//luajit/bin/luajit: cannot open /usr/local/apisix/apisix/cli/apisix.lua: No such file or directory
root@s91:/usr/local/apisix# apisix test
/usr/local/openresty//luajit/bin/luajit /usr/local/apisix/apisix/cli/apisix.lua test
/usr/local/openresty//luajit/bin/luajit: cannot open /usr/local/apisix/apisix/cli/apisix.lua: No such file or directory

缺少主机名的解析

遇到如下错误,只需要在/etc/hosts里加一条记录 127.0.0.1 s92.idc3.meeleet.com 即可

1
sudo: unable to resolve host s92.idc3.meeleet.com: Temporary failure in name resolution

默认luarocks源下载慢,很容易下载失败的问题

APISIX make deps构建,如果出现以下错误,需要配置下luarcoks国内源优先,因为默认的源luarocks.org比较慢,使用https://luarocks.cn的源,成功率会高很多,但是可能还有偶尔失败,多试几次就可以了

1
2
3
4
5
6
7
8
9
10
11
12
Installing https://luarocks.org/lua-resty-radixtree-2.8.2-0.src.rock
Missing dependencies for lua-resty-radixtree 2.8.2-0:
lua-resty-expr 1.3.0 (not installed)

lua-resty-radixtree 2.8.2-0 depends on lua-resty-ipmatcher (0.6.1-0 installed)
lua-resty-radixtree 2.8.2-0 depends on lua-resty-expr 1.3.0 (not installed)
Installing https://luarocks.org/lua-resty-expr-1.3.0-0.rockspec
Cloning into 'lua-resty-expr'...
fatal: unable to access 'https://github.com/api7/lua-resty-expr/': GnuTLS recv error (-110): The TLS connection was non-properly terminated.

Error: Failed installing dependency: https://luarocks.org/lua-resty-radixtree-2.8.2-0.src.rock - Failed installing dependency: https://luarocks.org/lua-resty-expr-1.3.0-0.rockspec - Failed cloning git repository.
make: *** [Makefile:152: deps] Error 1

etcd-server-key.pem:Permission denied

1
2
3
2023/04/17 04:28:11 [warn] 110028#110028: *44161 [lua] v3.lua:716: request_chunk(): https://10.1.80.93:2379: /usr/local/apisix/ssl/etcd-server-key.pem: Permission denied. Retrying, context: ngx.timer
2023/04/17 04:28:11 [warn] 110028#110028: *44161 [lua] v3.lua:716: request_chunk(): https://10.1.80.91:2379: /usr/local/apisix/ssl/etcd-server-key.pem: Permission denied. Retrying, context: ngx.timer
2023/04/17 04:28:11 [warn] 110028#110028: *44161 [lua] v3.lua:716: request_chunk(): https://10.1.80.92:2379: /usr/local/apisix/ssl/etcd-server-key.pem: Permission denied. Retrying, context: ngx.timer

需要给证书文件所有用户以读权限

1
sudo chmod a+r /usr/local/apisix/ssl/etcd-server-key.pem

FAQ

需要安装Lua吗?

不需要,因为这里OpenResty用的LuaJIT来运行

怎么卸载APISIX

1
2
3
# To uninstall the APISIX runtime, run:
make uninstall
make undeps

参考

OpenResty® Linux 包

How to Use the OpenResty Web Framework for Nginx on Ubuntu 16.04

APISIX安装依赖

luarocks 简单使用&openresty 离线集成说明 原创

ubuntu 20.04安装 Apache APISIX

help request: please check the version of OpenResty and lua, OpenResty 1.19 + LuaJIT or OpenResty before 1.19 + Lua 5.1 is required for Apache APISIX

apisix配置需要证书的etcd集群