apisix 环境搭建过程记录

1. 前言

由于windows10 自带 linux内核,所以在本机先后安装了 Ubuntu 子系统。又在 Ubuntu子系统中安装了etcd和 apisix网关,并测试环境搭建成功。

注意,ubuntu 修改成国内镜像 安装会稍微快一点。
安装 Ubuntu系统的方法 请参考 之前写的文章
windows10 安装 linux 子系统 到指定位置

1.1 安装 apisix 依赖

# 添加 OpenResty 源
wget -qO - https://openresty.org/package/pubkey.gpg | sudo apt-key add -
sudo apt-get update
sudo apt-get -y install software-properties-common
sudo add-apt-repository -y "deb http://openresty.org/package/ubuntu $(lsb_release -sc) main"
sudo apt-get update

# 安装 etcd
wget https://github.com/etcd-io/etcd/releases/download/v3.4.13/etcd-v3.4.13-linux-amd64.tar.gz
tar -xvf etcd-v3.4.13-linux-amd64.tar.gz && \
    cd etcd-v3.4.13-linux-amd64 && \
    sudo cp -a etcd etcdctl /usr/bin/

# 安装 OpenResty 和 编译工具
sudo apt-get install -y git openresty curl openresty-openssl111-dev make gcc libpcre3 libpcre3-dev

# 安装 LuaRocks
curl https://raw.githubusercontent.com/apache/apisix/master/utils/linux-install-luarocks.sh -sL | bash -

# 开启 etcd server
nohup etcd &

在运行 安装 LuaRocks 时,程序没反应,通过访问 网址 https://raw.githubusercontent.com/apache/apisix/master/utils/linux-install-luarocks.sh
在本地创建 linux-install-luarocks.sh 运行安装。
注意安装时 用到 unzip 命令,如果运行 本地 .sh 报错,则还需安装 unzip 。

linux-install-luarocks.sh 文件内容。

#!/usr/bin/env bash
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
set -ex

# you might need sudo to run this script
if [ -z ${OPENRESTY_PREFIX} ]; then
    OPENRESTY_PREFIX="/usr/local/openresty"
fi

wget https://github.com/luarocks/luarocks/archive/v3.4.0.tar.gz
tar -xf v3.4.0.tar.gz
cd luarocks-3.4.0 || exit

OR_BIN="$OPENRESTY_PREFIX/bin/openresty"
OR_VER=$($OR_BIN -v 2>&1 | awk -F '/' '{print $2}' | awk -F '.' '{print $1"."$2}')
if [[ -e $OR_BIN && "$OR_VER" == 1.19 ]]; then
    WITH_LUA_OPT="--with-lua=${OPENRESTY_PREFIX}/luajit"
else
    # For old version OpenResty, we still need to install LuaRocks with Lua
    WITH_LUA_OPT=
fi

./configure $WITH_LUA_OPT \
    > build.log 2>&1 || (cat build.log && exit 1)

make build > build.log 2>&1 || (cat build.log && exit 1)
sudo make install > build.log 2>&1 || (cat build.log && exit 1)
cd .. || exit
rm -rf luarocks-3.4.0

mkdir ~/.luarocks || true

# OpenResty 1.17.8 or higher version uses openssl111 as the openssl dirname.
OPENSSL_PREFIX=${OPENRESTY_PREFIX}/openssl
if [ -d ${OPENRESTY_PREFIX}/openssl111 ]; then
    OPENSSL_PREFIX=${OPENRESTY_PREFIX}/openssl111
fi

luarocks config variables.OPENSSL_LIBDIR ${OPENSSL_PREFIX}/lib
luarocks config variables.OPENSSL_INCDIR ${OPENSSL_PREFIX}/include

1.2 安装 apisix

github上拉取源码并上传到宿主机上文件夹名:apisix

安装运行时依赖的 Lua 库:

# 切换到 apisix 目录
cd apisix
# 创建依赖
make deps

1.3 管理 Apache APISIX 服务

我们可以在 Apache APISIX 的目录下使用命令初始化依赖、启动服务和停止服务,也可以通过 make help 命令查看所有命令和对应的功能。

初始化依赖
运行以下命令初始化 NGINX 配置文件和 etcd。

初始化依赖

make init
启动 Apache APISIX
运行以下命令启动 Apache APISIX。

启动 Apache APISIX

make run
停止运行 Apache APISIX
优雅停机 make quit 和强制停机 make stop都可以停止运行 Apache APISIX。建议您优先选择优雅停机的方式停止 Apache APISIX,因为这种停止方式能够保证 Apache APISIX 完成了已经接受到的请求之后再停止;而强制停机则是立即停止 Apache APISIX,在这种情况下,Apache APISIX 接收到但未完成的请求会随着强制停机一并停止。

执行优雅停机的命令如下所示:

停止 Apache APISIX

make quit
执行强制停机的命令如下所示:

停止运行 Apache APISIX

make stop
查看其他操作
运行 make help 命令,查看返回结果,获取其他操作的命令和描述。

查看其他操作

make help

2. 过程问题处理

问题一: Can’t locate t/APISIX.pm in @INC (you may need to install the t::APISIX module) 。。。。。
在这里插入图片描述
问题处理:
// 查看是否有当前目录路径
perl -V

添加当前 apisix 目录到 perl 模块目录:
// 添加当前目录路径 到 perl 的@INC
export PERL5LIB=.:$PERL5LIB:/home/apisix_projects/apisix

测试单个 模块 :
prove -Itest-nginx/lib -r t/plugin/example.t
在这里插入图片描述

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值