在Ubuntu上以源码方式部署Apache APISIX网关(使用腾讯云服务)

0x001 简介

  本介绍Ubuntu2022.04 LTS基础上通过源码安装部署APISIX 2.3.2 LTS网关操作方案APISIX基于Openresty开发一款性能网关深圳支流科技201910捐赠Apache基金会2020715Apache基金会毕业成为顶级项目国内大厂都有使用APISIX[1]

0x002  前置条件和环境要求

笔者假定读者已掌握基础的Linux使用知识,并且拥有良好的网络。以下操作步骤均在以下环境操作并得到验证。

软件

版本

备注

Ubuntu Server

22.04 LTS 64

使用apt-get 更新重启

APISIX

3.2.2 LTS

\

Docker

25.0.4

控制面板

Etcd

3.5.4

APISIX存储配置文件

0x003 安装部署Openresty

参考以下步骤安装Openresty测试安装Nginx以及其他Web服务器软件

先安装以下工具软件使用镜像安装

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

导入Openresty软件GPG公钥命令执行需要确保当前所在目录对应权限写入

wget -- https://openresty.org/package/pubkey.gpg | sudo gpg --dearmor -o /usr/share/keyrings/openresty.gpg

添加APT软件命令不会回显没有任何报错成功

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/openresty.gpg] http://openresty.org/package/ubuntu $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/openresty.list > /dev/null

更新apt软件源

sudo apt-get update

安装软件,注意openresty-zlib-devopenresty-pcre-devopenresty-openssl111-dev软件开发后续APISXI安装需要依赖

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

此时访问服务器公网IP:80端口看界面代表openresty以及安装成功

0x004 安装Etcd

输入以下命令锁定etcd版本

ETCD_VERSION='3.5.4'

下载软件包耐心等待下载完成如果失败可以删除下载文件重试确实无法下载本地下载上传服务器(https://github.com/etcd-io/etcd/releases/download/v3.5.4/etcd-v3.5.4-linux-amd64.tar.gz)。

wget https://github.com/etcd-io/etcd/releases/download/v${ETCD_VERSION}/etcd-v${ETCD_VERSION}-linux-amd64.tar.gz

下载完成后解压进入解压目录

tar -xvf etcd-v${ETCD_VERSION}-linux-amd64.tar.gz && cd etcd-v${ETCD_VERSION}-linux-amd64

运行以下命令启动etcd注意这里10.0.20.4是服务器的内网IP需要根据自己实际情况进行修改配置IP方便docker控制板访问其他服务器的apisix连接etcd

nohup ./etcd --listen-client-urls http://172.16.48.10:2379 --advertise-client-urls http://172.16.48.10:2379 >/tmp/etcd.log 2>&1 &

查看/tmp/etcd.log是否启动成功

cat /tmp/etcd.log

没有报错启动成功

0x005 安装APISXI

安装依赖等待完成

sudo apt-get install -y curl make gcc g++ cpanminus libpcre3 libpcre3-dev libldap2-dev unzip openresty-zlib-dev openresty-pcre-dev openresty-openssl111-dev

没有报错安装成功

安装依赖luarocks无法下载到执行的话,轻下载到本地上传到服务器执行。

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

以下即执行完成

下载APISIX源码

APISIX_VERSION='3.2.2'
mkdir apisix-${APISIX_VERSION}
git clone --depth 1 --branch ${APISIX_VERSION} https://github.com/apache/apisix.git apisix-${APISIX_VERSION}

以上即是完成切换apisix-3.2.2目录

构建安装make help看到支持选项

make help

运行安装运行依赖如有超时可以运行命令

make deps

以下安装完毕

修改配置文件etcd地址

vim conf/config-default.yaml

找到626

此处修改0x0044内网地址

运行以下命令初始etcd数据

make init

运行ulimit -n 66535 再运行以下命令有告警

make run

注意:

此时APISIX运行90809443端口测试以下地址即可确认是否正确启动

0x006 安装Docker并拉取控制面板

以下极速安装docker(腾讯云内网镜像)

sudo install -0755 -/etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+/etc/apt/keyrings/docker.asc

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] http://mirrors.tencentyun.com/docker-ce/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin  

创建以下配置conf.yaml

conf:
  listen:
    host: 0.0.0.0
    port: 9000
  etcd:
    endpoints: 
      - 172.16.48.10:2379
authentication:
  secret:
    r9h052aasasasax
  expire_time: 3600
  users:
    - username: admin
      password: admin
plugins:
  - api-breaker
  - authz-casbin
  - authz-casdoor
  - authz-keycloak
  - aws-lambda
  - azure-functions
  - basic-auth
  # - batch-requests
  - clickhouse-logger
  - client-control
  - consumer-restriction
  - cors
  - csrf
  - datadog
  # - dubbo-proxy
  - echo
  - error-log-logger
  # - example-plugin
  - ext-plugin-post-req
  - ext-plugin-post-resp
  - ext-plugin-pre-req
  - fault-injection
  - file-logger
  - forward-auth
  - google-cloud-logging
  - grpc-transcode
  - grpc-web
  - gzip
  - hmac-auth
  - http-logger
  - ip-restriction
  - jwt-auth
  - kafka-logger
  - kafka-proxy
  - key-auth
  - ldap-auth
  - limit-conn
  - limit-count
  - limit-req
  - loggly
  # - log-rotate
  - mocking
  # - node-status
  - opa
  - openid-connect
  - opentelemetry
  - openwhisk
  - prometheus
  - proxy-cache
  - proxy-control
  - proxy-mirror
  - proxy-rewrite
  - public-api
  - real-ip
  - redirect
  - referer-restriction
  - request-id
  - request-validation
  - response-rewrite
  - rocketmq-logger
  - server-info
  - serverless-post-function
  - serverless-pre-function
  - skywalking
  - skywalking-logger
  - sls-logger
  - splunk-hec-logging
  - syslog
  - tcp-logger
  - traffic-split
  - ua-restriction
  - udp-logger
  - uri-blocker
  - wolf-rbac
  - zipkin
  - elasticsearch-logge
  - openfunction
  - tencent-cloud-cls
  - ai
  - cas-auth

运行docker命令创建容器

sudo docker pull apache/apisix-dashboard
sudo docker run ---name dashboard \
           -9000:9000        \
           -`pwd`/conf.yaml:/usr/local/apisix-dashboard/conf/conf.yaml \
           apache/apisix-dashboard

0x007 通过控制面板配置路由

访问9000端口输入admin\admin登录

创建路由配置某个域名80端口

访问地址:9080即可再次看到运行80openresty内容

0x008 总结

更多详细配置参考资料部分,[5]APISIX详细配置文件[6]控制面板配置

0x009 参考资料

[1] GitHub - apache/apisix: The Cloud-Native API Gateway

[2] OpenResty - OpenResty® Linux Packages

[3] Installation | Apache APISIX® -- Cloud-Native API Gateway

[4] https://github.com/apache/apisix/blob/master/utils/linux-install-luarocks.sh

[5] https://github.com/apache/apisix/blob/master/conf/config-default.yaml

[6] https://github.com/apache/apisix-dashboard/blob/master/api/conf/conf.yaml

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值