對(duì)于安裝。我本人是比較偏向于,源碼或者二進(jìn)制手動(dòng)安裝。在安裝APISIX時(shí),其他都準(zhǔn)備就緒了,就在安裝APISIX時(shí),很多代碼拉不下來。導(dǎo)致我從源碼安裝到放棄。最終選擇Docker方式。
?最近,有幾個(gè)老項(xiàng)目需要做一些限流、安全、灰度發(fā)布等這些方面的升級(jí)。由于項(xiàng)目中也一直在用Nginx做請(qǐng)求轉(zhuǎn)發(fā)。所以在在OpenResty,Kong、APISIX三者之間初步對(duì)比了一下。從性能、功能和易用性的角度考慮,最終初步選擇APISIX這玩意。
對(duì)于安裝。我本人是比較偏向于,源碼或者二進(jìn)制手動(dòng)安裝。在安裝APISIX時(shí),其他都準(zhǔn)備就緒了,就在安裝APISIX時(shí),很多代碼拉不下來。導(dǎo)致我從源碼安裝到放棄。最終選擇Docker方式
安裝etcd
去Githubhttps://github.com/etcd-io/etcd/releases/下載編譯好的二進(jìn)制.
先創(chuàng)建好配置文件。
mkdir -p /etc/etcd/
cd /etc/etcd/
vim etcd.yaml
復(fù)制一下內(nèi)容
# This is the configuration file for the etcd server.
# Human-readable name for this member.
name: 'etcd1'
# Path to the data directory.
data-dir:
# Path to the dedicated wal directory.
wal-dir:
# Number of committed transactions to trigger a snapshot to disk.
snapshot-count: 10000
# Time (in milliseconds) of a heartbeat interval.
heartbeat-interval: 100
# Time (in milliseconds) for an election to timeout.
election-timeout: 1000
# Raise alarms when backend size exceeds the given quota. 0 means use the
# default quota.
quota-backend-bytes: 0
# List of comma separated URLs to listen on for peer traffic.
listen-peer-urls: http://172.31.79.250:2380
# List of comma separated URLs to listen on for client traffic.
listen-client-urls: http://172.31.79.250:2379
# Maximum number of snapshot files to retain (0 is unlimited).
max-snapshots: 5
# Maximum number of wal files to retain (0 is unlimited).
max-wals: 5
# Comma-separated white list of origins for CORS (cross-origin resource sharing).
cors:
# List of this member's peer URLs to advertise to the rest of the cluster.
# The URLs needed to be a comma-separated list.
initial-advertise-peer-urls: http://172.31.79.250:2380
# List of this member's client URLs to advertise to the public.
# The URLs needed to be a comma-separated list.
advertise-client-urls: http://172.31.79.250:2379
# Discovery URL used to bootstrap the cluster.
discovery:
# Valid values include 'exit', 'proxy'
discovery-fallback: 'proxy'
# HTTP proxy to use for traffic to discovery service.
discovery-proxy:
# DNS domain used to bootstrap initial cluster.
discovery-srv:
# Initial cluster configuration for bootstrapping.
initial-cluster:
# Initial cluster token for the etcd cluster during bootstrap.
initial-cluster-token: 'etcd-cluster'
# Initial cluster state ('new' or 'existing').
initial-cluster-state: 'new'
# Reject reconfiguration requests that would cause quorum loss.
strict-reconfig-check: false
# Enable runtime profiling data via HTTP server
enable-pprof: true
# Valid values include 'on', 'readonly', 'off'
proxy: 'off'
# Time (in milliseconds) an endpoint will be held in a failed state.
proxy-failure-wait: 5000
# Time (in milliseconds) of the endpoints refresh interval.
proxy-refresh-interval: 30000
# Time (in milliseconds) for a dial to timeout.
proxy-dial-timeout: 1000
# Time (in milliseconds) for a write to timeout.
proxy-write-timeout: 5000
# Time (in milliseconds) for a read to timeout.
proxy-read-timeout: 0
client-transport-security:
# Path to the client server TLS cert file.
cert-file:
# Path to the client server TLS key file.
key-file:
# Enable client cert authentication.
client-cert-auth: false
# Path to the client server TLS trusted CA cert file.
trusted-ca-file:
# Client TLS using generated certificates
auto-tls: false
peer-transport-security:
# Path to the peer server TLS cert file.
cert-file:
# Path to the peer server TLS key file.
key-file:
# Enable peer client cert authentication.
client-cert-auth: false
# Path to the peer server TLS trusted CA cert file.
trusted-ca-file:
# Peer TLS using generated certificates.
auto-tls: false
# The validity period of the self-signed certificate, the unit is year.
self-signed-cert-validity: 1
# Enable debug-level logging for etcd.
log-level: debug
logger: zap
# Specify 'stdout' or 'stderr' to skip journald logging even when running under systemd.
log-outputs: [stderr]
# Force to create a new one member cluster.
force-new-cluster: false
auto-compaction-mode: periodic
auto-compaction-retention: "1"
wget https://github.com/etcd-io/etcd/releases/download/v3.5.7/etcd-v3.5.7-linux-amd64.tar.gz
tar -xvf etcd-v3.5.7-linux-amd64.tar.gz
cd etcd-v3.5.7-linux-amd64
cp -a etcd etcdctl /usr/bin/
nohup etcd --config-file /etc/etcd/etcd.yaml >/tmp/etcd.log 2>&1 & #后臺(tái)啟動(dòng)etcd
安裝Docker
添加阿里鏡像源
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

安裝Docker
yum install docker-ce docker-ce-cli containerd.io
啟動(dòng)Docker服務(wù)
設(shè)置Docker開機(jī)自動(dòng)啟動(dòng)
Docker compose安裝
下載并安裝
curl -SL https://github.com/docker/compose/releases/download/v2
上面這個(gè)地址非常慢,有時(shí)候直接連不通,具體原因,大家肯定都知道。所以下載用國(guó)內(nèi)的鏡像地址吧
sudo curl -L https://get.daocloud.io/docker/compose/releases/download/v2.16.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
去下載源碼https://github.com/apache/apisix-docker.git。cd apisix-docker/example進(jìn)入到example目錄
由于etcd我是以二進(jìn)制方式安裝,那么apisix_conf和dashboard_conf里面的etcd配置信息改為實(shí)際地址和端口。
etcd:
host: # it's possible to define multiple etcd hosts addresses of the same etcd cluster.
- "http://172.31.79.250:2379" # multiple etcd address
prefix: "/apisix" # apisix configurations prefix
timeout: 30 # 30 seconds
另外docker-compose-arm64.yml里面的ETCD去掉,再去掉depends_on,刪除下面這段
接下來執(zhí)行啟動(dòng)命令docker-compose -f docker-compose-arm64.yml -p docker-apisix up -d

這樣,APISIX便搭建好了

我們使用dashboard_conf文件夾中conf.yaml文件里的users屬性來登錄APISIX.

創(chuàng)建APISIX服務(wù)


上游類型可以是,固定維護(hù)的節(jié)點(diǎn)或者是服務(wù)注冊(cè)

服務(wù)注冊(cè)中心支持目前比較主流的注冊(cè)中心

這里我們選擇的是節(jié)點(diǎn)方式


這時(shí)候,我們就可以去訪問9080端口的/web1/路徑

刷新一下頁(yè)面。請(qǐng)求會(huì)轉(zhuǎn)發(fā)到另外一個(gè)服務(wù)上

APISIX初步安裝完成,基本功能我們可以基于web UI界面配置完成,還可以借助插件來保護(hù)我們的服務(wù),讓服務(wù)更加穩(wěn)定、安全。接下來就是進(jìn)一步的探究APISIX提供的插件。