ApiSix的docker 容器化部署及使用

⼀.etcd安装
Docekr安装Etcd
环境准备
此处安装,是利⽤下载的 etcd 源⽂件,利⽤ docker build 构建完整镜像,具体操作如下:
1.环境准备
1.1. 新建⽂件夹
在磁盘某个路径下新建⼀个⽂件夹,⽤处操作 Dockerfile 和 源⽂件。
演⽰中的路径在 /data/docker-compose/etcd ,如特殊说明,否则都在此路径,以下简称
ETCD_HOME
1.2. 下载

在 ETCD_HOME 中下载最新版本,官⽅下载地址如下: wget https://github.com/etcd-io/etcd/

1.3. ⽂件解压
解压⽂件 tar.gz 得到 etcd-v3.4.20-linux-amd64 ⽂件夹。

tar -zxvf etcd-v3.4.20-linux-amd64.tar.gz

1.4. ⽂件拷⻉
在 etcd-v3.4.20-linux-amd64 ⽂件夹下,有 etcd 和 etcdctl 两个⽂件,拷⻉⾄与 etcd-v3.4.20-linuxamd64 同⼀级。

cp etcd-v3.4.20-linux-amd64/etcd etcd-v3.4.20-linux-amd64/etcdctl .

在这里插入图片描述
2.安装
2.1Dockerfile编写

FROM alpine:latest
ADD etcd /usr/local/bin/
ADD etcdctl /usr/local/bin/
RUN mkdir -p /var/etcd/
RUN mkdir -p /var/lib/etcd/
RUN echo 'hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4' >> /etc/nsswitch.conf
EXPOSE 2379 2380
CMD ["/usr/local/bin/etcd"]

2.2构建镜像并推送

//打包为docker镜像
docker build -t 阿里云镜像仓库地址/xxxx/etcd:5.1.Z .
//将docker镜像推送到阿里云上
docker push  阿里云镜像仓库地址/xxxxx/etcd:5.1.Z

2.3启动镜像

docker run -d -v /usr/share/ca-certificates/:/etc/ssl/certs -p 4001:4001 -p 2380:2380 -p 2379:2379 \--name etcd 阿里云镜像仓库地址/xxxx/etcd:5.1.Z /usr/local/bin/etcd \-name etcd0 \-advertise-client-urls http://182.182.33.103:2379 \-listen-client-urls http://0.0.0.0:2379 \-initial-advertise-peer-urls http://0.0.0.0:2380 \-listen-peer-urls http://0.0.0.0:2380 \-initial-cluster-token etcd-cluster-1 \-initial-cluster etcd0=http://0.0.0.0:2380 \-initial-cluster-state new
name: 节点名称
advertise-client-urls: 知客户端url, 也就是服务的url 就是etcd部署在那台机器上就写那台的ip
initial-advertise-peer-urls: 告知集群其他节点url
listen-peer-urls: 监听URL,用于与其他节点通讯
initial-cluster-token: 集群的ID
initial-cluster: 集群中所有节点

3.下载并安装etcd-manager(etcd的可视化客户端)

https://etcdmanager.io/

二.安装apisix
1.首先在创建如下文件夹和文件:
文件地址:
/opt/apisix/apisix-conf/
上传config.yaml到上面的文件夹下
内容:主要修改的是etcd:host部分

#
# 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.
#apisix:node_listen: 9080              # APISIX listening portenable_ipv6: falseenable_control: truecontrol:ip: "0.0.0.0"port: 9092deployment:admin:allow_admin:               # https://nginx.org/en/docs/http/ngx_http_access_module.html#allow- 0.0.0.0/0              # We need to restrict ip access rules for security. 0.0.0.0/0 is for test.admin_key:- name: "admin"key: edd1c9f034335f136f87ad84b625c8f1role: admin                 # admin: manage all configuration data- name: "viewer"key: 4054f7cf07e344346cd3f287985e76a2role: vieweretcd:host:                           # it's possible to define multiple etcd hosts addresses of the same etcd cluster.- "http://182.182.33.103:2379"          # multiple etcd addressprefix: "/apisix"               # apisix configurations prefixtimeout: 30                     # 30 secondsplugin_attr:prometheus:export_addr:ip: "0.0.0.0"port: 9091

/opt/apisix/dashboard_conf/
上传conf.yaml文件到上面的文件夹下
内容:主要修改etcd cluster

#
# 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.
#conf:listen:host: 0.0.0.0     # `manager api` listening ip or host nameport: 9000          # `manager api` listening portallow_list:           # If we don't set any IP list, then any IP access is allowed by default.- 0.0.0.0/0etcd:endpoints:          # supports defining multiple etcd host addresses for an etcd cluster- "http://182.182.33.103:2379"# yamllint disable rule:comments-indentation# etcd basic auth info# username: "root"    # ignore etcd username if not enable etcd auth# password: "123456"  # ignore etcd password if not enable etcd authmtls:key_file: ""          # Path of your self-signed client side keycert_file: ""         # Path of your self-signed client side certca_file: ""           # Path of your self-signed ca cert, the CA is used to sign callers' certificates# prefix: /apisix     # apisix config's prefix in etcd, /apisix by defaultlog:error_log:level: warn       # supports levels, lower to higher: debug, info, warn, error, panic, fatalfile_path:logs/error.log  # supports relative path, absolute path, standard output# such as: logs/error.log, /tmp/logs/error.log, /dev/stdout, /dev/stderraccess_log:file_path:logs/access.log  # supports relative path, absolute path, standard output# such as: logs/access.log, /tmp/logs/access.log, /dev/stdout, /dev/stderr# log example: 2020-12-09T16:38:09.039+0800        INFO        filter/logging.go:46        /apisix/admin/routes/r1        {"status": 401, "host": "127.0.0.1:9000", "query": "asdfsafd=adf&a=a", "requestId": "3d50ecb8-758c-46d1-af5b-cd9d1c820156", "latency": 0, "remoteIP": "127.0.0.1", "method": "PUT", "errs": []}security:# access_control_allow_origin: "http://httpbin.org"# access_control_allow_credentials: true          # support using custom cors configration# access_control_allow_headers: "Authorization"# access_control-allow_methods: "*"# x_frame_options: "deny"content_security_policy: "default-src 'self'; script-src 'self' 'unsafe-eval' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; frame-src *"  # You can set frame-src to provide content for your grafana panel.authentication:secret:secret              # secret for jwt token generation.# NOTE: Highly recommended to modify this value to protect `manager api`.# if it's default value, when `manager api` start, it will generate a random string to replace it.expire_time: 3600     # jwt token expire time, in secondusers:                # yamllint enable rule:comments-indentation- username: admin   # username and password for login `manager api`password: admin- username: userpassword: userplugins:                          # plugin list (sorted in alphabetical order)- api-breaker- authz-keycloak- basic-auth- batch-requests- consumer-restriction- cors# - dubbo-proxy- echo# - error-log-logger# - example-plugin- fault-injection- grpc-transcode- hmac-auth- http-logger- ip-restriction- jwt-auth- kafka-logger- key-auth- limit-conn- limit-count- limit-req# - log-rotate# - node-status- openid-connect- prometheus- proxy-cache- proxy-mirror- proxy-rewrite- redirect- referer-restriction- request-id- request-validation- response-rewrite- serverless-post-function- serverless-pre-function# - skywalking- sls-logger- syslog- tcp-logger- udp-logger- uri-blocker- wolf-rbac- zipkin- server-info- traffic-split

2.执行下载和启动docker的命令

docker run -d --name apisix -p 9080:9080 -p 9443:9443  -p 9180:9180 -v /opt/apisix/apisix-conf/config.yaml:/usr/local/apisix/conf/config.yaml:ro apache/apisix:latest

下面这是web端命令:

docker run -d --name apisix-dashboard -p 9000:9000 -v /opt/apisix/dashboard_conf/conf.yaml:/usr/local/apisix-dashboard/conf/conf.yaml apache/apisix-dashboard:3.0.0-alpine

容器启动成功后访问ApiSix仪表台,如下图成功访问
在这里插入图片描述

3.apisix代理地址的使用
配置上游:
在这里插入图片描述

在这里插入图片描述
填写名称、可选择上游类型。这里选择的是节点,当然可以选择服务发现,但是需要配置。

创建完上游后可以创建路由

在这里插入图片描述

在这里插入图片描述

点击下一步选择上游服务
在这里插入图片描述
然后一直下一步到提交。
之后就可以打开postman进行测试了。
默认访问的端口是9080
在这里插入图片描述
apisix相关文档:

https://apisix.apache.org/zh/docs/apisix/getting-started/README/https://apisix.apache.org/zh/docs/

三.代理轮询的使用
1.上游类型为节点
配置上游。
在这里插入图片描述
上述目标节点的配置其实是同一个后端服务的,只不过我在一台机器上无法使用相同的端口所以修改了一下端口,这个的含义就是我的一个后端服务做了集群部署,这样配置就可以轮询去访问多台服务器上的同一个后端服务。
上游配置完可以配置服务也可以直接配置路由,当配置服务后再配置路由绑定服务选择自己创建的服务。

2.服务发现的形式(这里以nacos注册中心为例)
服务发现的文章可以看看这篇:https://www.aneasystone.com/archives/2023/03/apisix-service-discovery.html
在/opt/apisix/apisix-conf/
的config.yaml文件中添加nacos配置
整体配置:

 nacos:host:- "http://nacos:nacos@193.193.173.721:8848"prefix: "/nacos/v1/"fetch_interval: 30    # default 30 secweight: 100           # default 100timeout:connect: 2000       # default 2000 mssend: 2000          # default 2000 msread: 5000          # default 5000 ms

简洁配置:

discovery:nacos:host:- "http://193.193.173.721:8848"

官网文档地址:https://apisix.apache.org/zh/docs/apisix/discovery/nacos/
配置完成后重启apisix服务
配置上游
在这里插入图片描述
上游配置完可以配置服务也可以直接配置路由。
nacos截图
在这里插入图片描述
分别访问不同服务器上的同一个服务,发现可以做到轮询访问。
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/183703.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

LeetCode 设计前中后队列

题目 1670. 设计前中后队列 请你设计一个队列,支持在前,中,后三个位置的 push 和 pop 操作。 请你完成 FrontMiddleBack 类: FrontMiddleBack() 初始化队列。void pushFront(int val) 将 val 添加到队列的 最前面 。void pushMidd…

Linux系统平均负载

我们经常会使用 top 命令来查看系统的性能情况,在 top 命令的第一行可以看到 load average 这个数据,如下图所示: load average 包含 3 列,分别表示 1 分钟、5 分钟和 15 分钟的 系统平均负载 系统平均负载: 如果将 …

如何扩展服务器存储容量_Maizyun

如何扩展服务器存储容量 随着互联网和数据的快速发展,服务器存储容量往往成为限制业务发展的重要因素。 如何有效扩展服务器的存储容量以满足业务需求是很多公司和个人需要面对的问题。 本文将探讨如何扩展服务器的存储容量来解决存储空间不足的问题。 1.了解存储…

golang—kafka架构原理快速入门以及自测环境搭建(docker单节点部署)

kafka Apache Kafka 是一个分布式的流处理平台。它具有以下特点: 支持消息的发布和订阅,类似于 RabbtMQ、ActiveMQ 等消息队列支持数据实时处理能保证消息的可靠性投递支持消息的持久化存储,并通过多副本分布式的存储方案来保证消息的容错高…

【华为交换】交换机MSTP+VRRP配置

功能简介 企业用户访问外网的流量,可能会同时包含二层流量和三层流量(例如,企业内二层VPN用户和三层VPN用户访问MPLS公网)。企业用户希望接入网络既能包含多条接入链路(不同链路之间互为备份)以保障接入的…

【brpc学习实践十一】session-local与thread-local应用与brpc抽象工厂模式实践

什么是session-local与thread-local 百度内的检索程序大量地使用了thread-local storage (缩写TLS),有些是为了缓存频繁访问的对象以避免反复创建,有些则是为了在全局函数间隐式地传递状态。你应当尽量避免后者,这样的函数难以测试,不设置thread-local变量甚至无法运行。s…

哪些因素会影响香港服务器的下载速度_Maizyun

哪些因素会影响香港服务器的下载速度? 随着互联网的普及和快速发展,越来越多的企业和个人选择使用香港服务器来托管其网站、应用程序和其他在线服务。 然而,很多因素可能会影响香港服务器的下载速度。 本文将探讨影响香港服务器下载速度的几…

Java中xml映射文件是干什么的

Java中的XML映射文件主要用于将Java对象与XML文档之间进行转换。它通常用于处理数据交换和存储,例如将Java对象转换为XML格式以便在网络上传输或保存到文件中,或者将XML文档解析为Java对象以进行处理。这种转换可以通过Java的JAXB(Java Archi…

springMVC实验(二)—调式工具APIFOX的使用

【知识要点】 后端开发调试工具 前后端分离已经成为互联网类软件开发主流模式,没有前端操作的支持,如何调试后端程序的就是开发人员必须解决的问题。如:get类请求可以直接使用浏览器就能模拟测试,但是post、put等类型的请求&…

layui 日期选择框弹出后消失

原因是窗口太小,日期窗碰撞边缘后会消失,解决方法是增加 trigger: click 属性。 laydate.render({ elem: #kp_date , type: date , trigger: click });

thinkphp5.1 验证器

thinkPHP5——验证器的使用总结-CSDN博客

YoloV8改进策略:AKConv即插即用,轻松涨点

文章目录 摘要1、引言2、相关工作3、方法3.1、定义初始采样位置3.2、可变卷积操作3.3、扩展AKConv4、实验4.1、在COCO2017上的目标检测实验4.2、在VOC 7+12上的目标检测实验4.3、在VisDrone-DET2021上的目标检测实验4.4、比较实验4.5、探索初始采样形状5、分析讨论6、结论Yolov…

数据结构与算法-D1数据结构引入

1、结构体 2、内存(malloc) 意义: 1、提高编程能力 2、可复用性、可维护性、可读性、效率更高 数据结构:研究数据之间关系,包括逻辑结构、存储结构、数据操作 逻辑结构: 按每个元素可能具有的直接前趋数和直接后趋数将逻辑结构…

Ubuntu 环境下 NFS 服务安装及配置使用

需求:公司内部有多台物理服务器,需要A服务器上的文件让B服务器访问,也就是两台服务器共享文件,当然也可以对A服务器上的文件做权限管理,让B服务器只读或者可读可写 1、NFS 介绍 NFS 是 Network FileSystem 的缩写&…

前端纯js导入导出json配置文件

在做后台系统需求的时候,有个需求是需要把当前表单配置导出,在另一个配置项下,导入这些配置,相当于做了一下配置拷贝。通常我们导出下载一个文件,是先向后端发起请求,由后端处理数据后,再返回文…

交调与互调

交调与互调 概念参考: 《高频电子线路》张肃文 《射频技术》于宝明、丁宁 交调(Cross-modulation) 如果接收机的前端电路选择性不够好,是有用信号与干扰信号同时加到接收机的输入端,而且这两种信号都是受音频调制…

jvm 调优参数

-XX:AlwaysPreTouch 指定JVM启动时即刻分配整个堆内存空间;应用启动会变慢,但是运行时变快。 -XX:MaxRAMPercentage60.0 指定JVM最大堆内存使用比例为60%;适用于容器部署 -XX:MinRAMPercentage60.0 指定JVM最小堆内存使用比例为60%&#xff1…

可以在电脑桌面展示工作计划表的软件

很多上班族都表示自己在工作时,会面临大量且复杂的工作任务,这时候就会拖延工作,或者感觉时间不够用,所以需要有明确的工作计划来指导自己如何分类时间和精力,确保每项工作任务都能够按时完成。如果需要制定每天的工作…

力扣labuladong一刷day22天二分搜索共2题

力扣labuladong一刷day22天二分搜索共2题 一、704. 二分查找 题目链接&#xff1a;https://leetcode.cn/problems/binary-search/ 思路&#xff1a;典型的二分查找&#xff0c;如果是左闭右闭那么说明left < right 。如果左闭右开那么说明 left < right class Solutio…

C++学习之路(十二)C++ 用Qt5实现一个工具箱(增加一个XML文本格式化功能)- 示例代码拆分讲解

上篇文章&#xff0c;我们用 Qt5 实现了在小工具箱中添加了《进制转换器功能》功能。为了继续丰富我们的工具箱&#xff0c;今天我们就再增加一个平时经常用到的功能吧&#xff0c;就是「 XML文本格式化 」功能。下面我们就来看看如何来规划开发一个这样的小功能并且添加到我们…