APISIX系列 | 使用 docker-apisix 安裝APISIX服務

官方倉庫:https://github.com/iresty/docker-apisixgit

官方倉庫github

拉取docker

git clone git@github.com:iresty/docker-apisix.git

安裝 etcd 服務windows

一、拉去etcd鏡像api

docker pull bitnami/etcd:3.3.13-r80

二、啓動etcd服務器實例瀏覽器

docker run -it --name etcd-server \
-v /e/github/docker-apisix/example/etcd_conf/etcd.conf.yml:/opt/bitnami/etcd/conf/etcd.conf.yml \
-p 2379:2379 \
-p 2380:2380  \
--env ALLOW_NONE_AUTHENTICATION=yes \
-d bitnami/etcd:3.3.13-r80

 Windows 環境執行命令:bash

docker run -it --name etcd-server -v /e/github/docker-apisix/example/etcd_conf/etcd.conf.yml:/opt/bitnami/etcd/conf/etcd.conf.yml -p 2379:2379 -p 2380:2380  --env ALLOW_NONE_AUTHENTICATION=yes -d bitnami/etcd:3.3.13-r80

三、測試是否安裝成功服務器

進入etcd實例app

docker exec -it etcd-server /bin/sh -c "[ -e /bin/bash ] && /bin/bash || /bin/sh"
I have no name!@1d05cea9f08c:/opt/bitnami/etcd$

測試less

$  etcdctl put key-test "Hi Tinywan!" // 設置
OK
I have no name!@1d05cea9f08c:/$  etcdctl get key-test // 獲取
key-test
Hi Tinywan!
I have no name!@1d05cea9f08c:/$  etcdctl del key-test // 刪除
1
I have no name!@1d05cea9f08c:/$  etcdctl get key-test // 刪除
I have no name!@1d05cea9f08c:/$

四、進入容器查看是否已經開啓v2協議

> docker exec -it etcd-server bash
$ etcd --help |grep enable-v2
usage: etcd [flags]
       start an etcd server

       etcd --version
       show the version of etcd

       etcd -h | --help
       show the help information about etcd

       etcd --config-file
       path to the server configuration file

       etcd gateway
       run the stateless pass-through etcd TCP connection forwarding proxy

       etcd grpc-proxy
       run the stateless etcd v3 gRPC L7 reverse proxy

        --enable-v2 'true'
        --experimental-enable-v2v3 ''

--enable-v2 'true' 表示已經開啓v2協議。

緣由:APISIX 目前僅支持 etcd 的 v2 協議存儲,但最新版的 etcd (3.4 開始)已經默認關閉 v2 協議。 須要在啓動參數中添加 --enable-v2=true,才能啓用 v2 協議。  

四、啓動etcd客戶端實例

$ docker run -it --rm \
    --network app-tier \
    --env ALLOW_NONE_AUTHENTICATION=yes \
    bitnami/etcd:latest etcdctl --endpoints http://etcd-server:2379 set /message Hello

Windows 環境

docker run -it --rm --network app-tier --env ALLOW_NONE_AUTHENTICATION=yes bitnami/etcd:3.3.13-r80 etcdctl --endpoints http://etcd-server:2379 set /message Hello

安裝 apisix 服務

使用官方鏡像可能會超時,提示錯誤:request canceled (Client.Timeout exceeded while awaiting headers)

一、拉去鏡像

docker pull registry.cn-beijing.aliyuncs.com/tinywan/apisix:alpine

二、修改配置文件

config.yaml

etcd:
  host: "http://127.0.0.1:2379"   # etcd address

修改成本機電腦的內網IP,windows 查看本地內網IP。打開命令行,輸入 ipconfig

 修改後

etcd:
  host: "http://192.168.1.3:2379"   # etcd address  

二、運行服務

> docker run  --name tinywan-api-gateway  \
-v /e/GitHub/docker-apisix/example/apisix_conf/config.yaml:/usr/local/apisix/conf/config.yaml \
-v /e/GitHub/docker-apisix/example/apisix_log:/usr/local/apisix/logs  \
-p 8080:9080 \
-p 8083:9443 registry.cn-beijing.aliyuncs.com/tinywan/apisix:alpine

這裏掛在配置文件和日誌目錄都是使用的絕對路徑

windows 文件目錄爲

E:\GitHub\docker-apisix

 則掛在目錄地址爲

/e/GitHub/docker-apisix

三、查看服務是佛已經啓動

> docker ps
CONTAINER ID        IMAGE                                                    COMMAND                  CREATED             STATUS                          PORTS                                            NAMES   
7747e9a4bcd6        registry.cn-beijing.aliyuncs.com/tinywan/apisix:alpine   "sh -c '/usr/bin/api…"   14 seconds ago      Up 13 seconds                   0.0.0.0:8080->9080/tcp, 0.0.0.0:8083->9443/tcp   tinywan-api-gateway
1d05cea9f08c        bitnami/etcd:3.3.13-r80                                  "/entrypoint.sh etcd"    29 minutes ago      Up 29 minutes                   0.0.0.0:2379-2380->2379-2380/tcp                 etcd-server

控制檯

APISIX 內置了 dashboard,使用瀏覽器打開 http://127.0.0.1:8080/apisix/dashboard/ 便可使用, 不用填寫用戶名和密碼,直接登陸  

 直接點擊登陸

 恭喜你安裝成功

相關文章
相關標籤/搜索