APISIX 3.0安裝及配置使用【轉】

最近一直在研究微服務相關內容,通過對比各大API網關,發現新起之秀 APISIX無論從開源程度上來講還是功能上,都擁有很大的優勢。

經歷了幾天折磨一樣的學習,目前在本地環境中配置成功了一套,以供自己留存吧,實在是網上的很多文章要麼太老了,要麼就是亂寫一通。

 

APISIX官方網址:https://apisix.apache.org/

ETCD官方網址:https://etcd.io/

 

1、安裝ETCD(分佈式Key-Value存儲系統)

根據apisix提供的官方網檔,執行以下腳本就可以了:

1
2
3
4
wget https://github.com/etcd-io/etcd/releases/download/v3.5.8/etcd-v3.5.8-linux-amd64.tar.gz
tar -xvf etcd-v3.5.8-linux-amd64.tar.gz && \
  cd etcd-v3.5.8-linux-amd64 && \
sudo cp -a etcd etcdctl /usr/bin/

 這裏的安裝時間因爲國內的原因,可能需要執行很長時間,我們同樣也可以將文件提前下載好,丟到CentOS服務器上,再執行解壓縮就可以了。

2、配置ETCD

不知道是我找的資料不對,還是官方精簡了一些,本打算使用 systemctl 安裝ETCD,但是各種提示報錯,經過了大量的資料搜索和文章的研究與嘗試,這裏需要以下步驟進行安裝配置:

(1)創建 /etc/etcd/etcd.conf 服務配置文件,並編輯內容如下(本實例爲單機模式部署):

ETCD_NAME=etcd
ETCD_DATA_DIR=/etc/etcd/data

ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379
ETCD_LISTEN_PEER_URLS=http://0.0.0.0:2380

ETCD_ADVERTISE_CLIENT_URLS=http://0.0.0.0:2379
ETCD_INITIAL_ADVERTISE_PEER_URLS=http://0.0.0.0:2380
ETCD_INITIAL_CLUSTER_STATE=new
ETCD_INITIAL_CLUSTER_TOKEN=etcd-cluster

編寫完成後,保存即可。

(2)編寫systemctl服務文件(/usr/lib/systemd/system/etcd.service

[Unit]
Description=etcd key-value store
Documentation=https://github.com/etcd-io/etcd
After=network.target

[Service]
EnvironmentFile=/etc/etcd/etcd.conf
ExecStart=/usr/bin/etcd
Restart=always

[Install]
WantedBy=multi-user.target

 

(3)以服務方式啓用及啓用加載自啓

1
2
systemctl start etcd
systemctl enable etcd

到這裏,整個ETCD服務就安裝完成了

3、安裝APISIX

這一步操作很簡單,直接根據官方文檔來操作就可以了,安裝說明:https://apisix.apache.org/docs/apisix/installation-guide/

(1)安裝OpenRestry並且安裝APISIX包

sudo yum install -y https://repos.apiseven.com/packages/centos/apache-apisix-repo-1.0-1.noarch.rpm

(2)添加APISIX YUM包源

sudo yum-config-manager --add-repo https://repos.apiseven.com/packages/centos/apache-apisix.repo

(3)執行APISIX安裝

# 默認安裝
sudo yum install apisix

# 指定版本安裝
sudo yum install apisix-3.3.0

安裝完APISIX我們先不要啓動,先去 /usr/local/apisix/conf/config.yaml中修改對應的文件配置,我這例子的配置如下:

#
# 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.
#
# If you want to set the specified configuration value, you can set the new
# in this file. For example if you want to specify the etcd address:
#
# deployment:
#   role: traditional
#   role_traditional:
#     config_provider: etcd
#   etcd:
#     host:
#       - http://127.0.0.1:2379
#
# To configure via environment variables, you can use `${{VAR}}` syntax. For instance:
#
# deployment:
#   role: traditional
#   role_traditional:
#     config_provider: etcd
#   etcd:
#     host:
#       - http://${{ETCD_HOST}}:2379
#
# And then run `export ETCD_HOST=$your_host` before `make init`.
#
# If the configured environment variable can't be found, an error will be thrown.
#
# Also, If you want to use default value when the environment variable not set,
# Use `${{VAR:=default_value}}` instead. For instance:
#
# deployment:
#   role: traditional
#   role_traditional:
#     config_provider: etcd
#   etcd:
#     host:
#       - http://${{ETCD_HOST:=localhost}}:2379
#
# This will find environment variable `ETCD_HOST` first, and if it's not exist it will use `localhost` as default value.
#

apisix:
  node_listen: 8000

deployment:
  role: traditional
  role_traditional:
    config_provider: etcd
  etcd:
    host:
      - http://127.0.0.1:2379
  admin:
    admin_key:
      - name: admin
        key: edd1c9f034335f136f87ad84b625c8f1  # using fixed API token has security risk, please update it when you deploy to production environment
        role: admin

這裏要注意的是,apisix: node_listen 是不存在的,你要自己添加上並指定一下需要綁定的端口,並且在etcd 下的host 指定你ETCD服務器安裝的位置(推薦使用內網,不要對外開放端口哈)

這裏配置完成後,我們就可以使用systemctl啓動APISIX咯

# 使用systemctl 將APISIX安裝爲服務
systemctl start apisix

# 添加服務開機自啓動
systemctl enable apsix

啓動成功後,通過訪問網址 http://127.0.0.1:8000 會提示404 Route Not Found的字樣,這時,我們的APISIX服務就安裝完成咯!

4、安裝APISIX-DASHBOARD(管理控制面板)

同樣的,我們根據官方給的文檔進行安裝,文檔地址:https://apisix.apache.org/docs/dashboard/install/

因爲我們使用的CENTOS直接安裝,那麼我們執行如下的BASH腳本即可:

sudo yum install -y https://github.com/apache/apisix-dashboard/releases/download/v3.0.1/apisix-dashboard-3.0.1-0.el7.x86_64.rpm

安裝需要一定的時間,安裝完成後記得去 /usr/local/apisix/dashboard/conf/conf.yaml 文件中修改對應的配置ETCD地址及管理員、用戶的賬號及密碼!

以上操作完成後,同樣的執行以下命令,apisix-dashboard也就啓動完成,我這裏默認開的是9000端口,那麼完成後通過瀏覽器訪問 http://127.0.0.1:9000 就可以使用咯

# 使用systemctl 將APISIX-DASHBOARD安裝爲服務
systemctl start apisix-dashboard

# 添加服務開機自啓動
systemctl enable apsix-dashboard

 

 

以上所有便是APISIX在centos 7.6的安裝過程,如果安裝中大家有什麼問題,可以一起留言討論一下

 

 

5、限流,流控、身份驗證使用

參考如下

API網關】APISIX介紹和安裝使用_apisix使用-CSDN博客

https://blog.csdn.net/u011397981/article/details/128826364

轉自

基於CentOS 7.6安裝及配置APISIX 3.0環境 - star丶清影 - 博客園
https://www.cnblogs.com/briny/p/17387663.html

 

使用參考

Apache Apisix配置路由轉發_apisix 路由-CSDN博客

https://blog.csdn.net/rothchil/article/details/126449467

 

APISIX網關-路由-路由轉發-路徑改寫_apisix 正則改寫-CSDN博客

https://blog.csdn.net/fylysyn12291211/article/details/132428784

 

 

參考

Apache APISIX 快速入門之二 —— APISIX 單機安裝部署 - 簡書

https://www.jianshu.com/p/42142b507cc6

 

API網關】APISIX介紹和安裝使用_apisix使用-CSDN博客

https://blog.csdn.net/u011397981/article/details/128826364

 

Linux DockerAPISIX集羣部署【珍藏版】_docker安裝apisix-CSDN博客

https://blog.csdn.net/weixin_44917045/article/details/129861931

 

APISIX 入門(國產微服務網關) - 簡書

https://www.jianshu.com/p/19607e0c7005?utm_campaign=haruki&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

 

APISIX網關-路由-路由轉發-路徑改寫_apisix 正則改寫-CSDN博客

https://blog.csdn.net/fylysyn12291211/article/details/132428784

 

Apache Apisix配置路由轉發_apisix 路由-CSDN博客

https://blog.csdn.net/rothchil/article/details/126449467

 

雲原生技術平臺CNP雲原生網關APISIX-雲原生技術平臺CNP操作指南-移動雲產品幫助中心

https://ecloud.10086.cn/op-help-center/doc/article/69222

 

【雲原生網關】apisix使用詳解

http://www.bryh.cn/a/329198.html

 

apisix安裝過程和坑 - 簡書

https://www.jianshu.com/p/06cf7efa13b9?ivk_sa=1024320u

 

apisix安裝詳解(版本2.7-CSDN博客

https://blog.csdn.net/yuangan1529/article/details/120209171

基於CentOS 7.6安裝及配置APISIX 3.0環境 - star丶清影 - 博客園

https://www.cnblogs.com/briny/p/17387663.html

博客 | 支流科技

https://www.apiseven.com/blog

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章