APISIX安装记录

依赖:

  1. etcd : 版本必须为v3.4以上,不支持3.4以下的版本

  1. openresty

  1. luarocks

etcd安装

https://github.com/etcd-io/etcd/releases/

访问以上页面,根据自己的系统选择相应的安装包进行下载。解压安装包,进入安装目录,

执行 nohup ./etcd --name infra1 --listen-client-urls http://172.16.254.131:2379 --advertise-client-urls http://172.16.254.131:2379 &根据自己的服务器地址和端口启动etcd。

后台运行 'nohup ./etcd --name infra1 --listen-client-urls http://172.16.254.129:2379 --advertise-client-urls http://172.16.254.129:2379 &'根据自己的服务器地址和端口启动etcd。

报错解决

在arm架构的服务器中会出现etcd on unsupported platform without ETCD_UNSUPPORTED_ARCH=arm64 set报错。输入export ETCD_UNSUPPORTED_ARCH=arm64 命令之后再次执行启动命令方可解决

openresty 安装

openresty依赖openssl,需要提前安装openssl

openssl 安装

下载源码包

openssl-1.1.1k.tar.gz

tar -zxvf openssl-version.tar.gz
cd openssl-version/
./config --prefix=/usr/local/openssl
make
make install

报错

报错1
     wget https://www.cpan.org/src/5.0/perl-5.30.1.tar.gz
     tar -xzf perl-5.30.1.tar.gz
     cd perl-5.30.1
     ./Configure -des -Dprefix=$HOME/localperl
     make
     make install
报错2

安装时一直报Go find a public domain implementation or fix your PATH setting!是因为安装系统的时候使用的是最小化mini安装,系统没有安装make。直接yum安装下即可:yum -y install gcc automake autoconf libtool make


openresty 安装

https://openresty.org/cn/download.html

下载源码包

openresty-1.19.3.2.tar.gz

tar -zxvf openresty-version.tar.gz
cd openresty-version

## --with 是启用一些插件 
## --without 是禁用一些插件
./configure --with-luajit \
            --without-http_redis2_module \
            --with-http_iconv_module \
            --with-http_stub_status_module \
            --with-http_realip_module \
            --with-http_v2_module \
            --with-openssl=/usr/local/openssl  
make
make install 

报错

报错1

报错 ‘/bin/sh: line 2: ./config: No such file or directory’

解决该问题,修改配置文件/bundle/nginx-1.11.2/auto/lib/openssl/conf中

/.openssl删除掉,也就是避免了找路径的时候找.openssl这个路径

解决问题后重新执行上一步的./configure
报错2

需要安装pcre的devel包,pcre-devel。使用yum安装即可:(以下命令还带有ssl、zlib等依赖的安装)

yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel
报错3

是CentOS 8没有安装epel源的问题。安装epel源后问题解决。

yum install epel-release
报错3

需要指定源码路径。因为openresty(确切的说,是nginx)依赖pcre做正则引擎,还有要用openssl做安全引擎。所以,先要安装pcre和openssl。千万注意,要用源码,在安装openresty的时候,通过--with-<module>指定源码路径。

./configure --prefix=/usr/local/openresty --with-pcre=/opt/pcre2-10.23 --with-openssl=/opt/openssl-1.1.0e

仍然报错,就直接去nginx下执行 ./configure。手动把nginx给解析了

配置openresty环境变量

vim /etc/profile

#文件末尾添加
export PATH=$PATH:/user/local/openresty/bin:/usr/local/openresty/nginx/sbin

source /etc/profile

luarocks 安装

Source code(tar.gz)

下载源码包

tar -zxvf luarocks-3.4.0.tar.gz

cd luarocks

./configure --with-lua=/usr/local/openresty/luajit

make build

make install

apisix安装

wget https://downloads.apache.org/apisix/2.12.0/apache-apisix-2.12.0-src.tgz
tar zxvf apache-apisix-2.12.0-src.tgz -C apisix-2.12.0
LUAROCKS_SERVER=https://luarocks.cn make deps
### APISIX 入门指南 APISIX 是一个高性能的开源 API 网关,支持动态路由、插件扩展、负载均衡等功能。以下是对 APISIX 入门和使用的详细介绍。 #### 1. APISIX 的基本功能与特性 APISIX 提供了简单易用的搭建流程和丰富的功能模块,能够满足日常网关需求,并支持二次开发以适应个性化需求[^1]。其核心组件包括路由(Route)、服务(Service)、上游(Upstream)和插件(Plugin)。这些组件之间的关系可以通过配置实现灵活的请求转发和服务抽象[^2]。 #### 2. 安装 APISIX 安装 APISIX 可以通过源码编译或使用预构建的二进制包完成。以下是基于源码的安装步骤: ```bash # 定义版本号 APISIX_VERSION='3.10.0' # 创建工作目录并克隆代码仓库 mkdir apisix-${APISIX_VERSION} git clone --depth 1 --branch ${APISIX_VERSION} https://github.com/apache/apisix.git apisix-${APISIX_VERSION} # 进入项目目录 cd apisix-${APISIX_VERSION} # 安装依赖项 make deps # 初始化环境 make init # 启动服务 make run ``` 如果需要卸载或清理环境,可以执行以下命令: ```bash make uninstall && make undeps ``` 此外,还可以通过 `apisix start` 和 `apisix stop` 分别启动和停止服务[^4]。 #### 3. 配置 APISIX APISIX 的配置文件位于 `conf/config-default.yaml`,用户可以根据实际需求修改 etcd 地址、日志级别等参数。例如,修改 etcd 配置: ```yaml etcd: host: - "http://127.0.0.1:2379" prefix: "/apisix/" ``` #### 4. 创建路由与服务 在 APISIX 中,路由用于匹配客户端请求并将请求转发到后端服务。以下是一个简单的路由创建示例: ```bash curl http://127.0.0.1:9080/apisix/admin/routes/1 \ -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \ -X PUT \ -d ' { "uri": "/hello", "upstream": { "type": "roundrobin", "nodes": { "127.0.0.1:1980": 1 } } }' ``` 上述命令定义了一个 URI 为 `/hello` 的路由,并将其请求转发到本地的 `127.0.0.1:1980` 服务[^3]。 #### 5. 使用插件 APISIX 支持多种插件,如限流、认证、日志记录等。启用插件时,需在路由或全局配置中添加插件名称及参数。例如,启用 `key-auth` 插件进行身份验证: ```bash curl http://127.0.0.1:9080/apisix/admin/routes/1 \ -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \ -X PUT \ -d ' { "uri": "/hello", "plugins": { "key-auth": {} }, "upstream": { "type": "roundrobin", "nodes": { "127.0.0.1:1980": 1 } } }' ``` #### 6. 监控与管理 APISIX 提供了一个内置的管理界面,可通过以下命令启动: ```bash apisix dashboard ``` 此界面可用于查看实时流量、路由配置和插件状态。 --- ###
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值