官方倉庫:https://github.com/iresty/docker-apisix
官方倉庫
拉取
git clone git@github.com:iresty/docker-apisix.git
安裝 etcd 服務
1、拉去etcd鏡像
docker pull bitnami/etcd:3.3.13-r80
2、啟動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 環境執行命令:
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
3、測試是否安裝成功
進入etcd實例
docker exec -it etcd-server /bin/sh -c "[ -e /bin/bash ] && /bin/bash || /bin/sh"
I have no name!@1d05cea9f08c:/opt/bitnami/etcd$
測試
$ 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:/$
4、進入容器查看是否已經開啟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 協議。
4、啟動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)
1、拉去鏡像
docker pull registry.cn-beijing.aliyuncs.com/tinywan/apisix:alpine
2、修改配置文件
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
2、運行服務
> 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
3、查看服務是佛已經啟動
> 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/
即可使用, 不用填寫用戶名和密碼,直接登錄
直接點擊登錄
恭喜你安裝成功