文件指南
檢視官方Docker安裝指南,發現只提供了映象地址,並未給出詳細操作步驟
With Docker
Tyk has three containers that are available to set up a Docker installation:
All three are required for a full deployment. We recommend that each container is installed on a separate machine for optimum performance.
實踐
Tyk Gateway container
參考映象指南,此處的目標是搭建帶Dashboard
的Tyk閘道器
Gateway - Pro installation with Dashboard
The gateway in a Pro installation is dependent on the dashboard service. We will assume that the dashboard service is installed, up and running. If not, we would recommend that you follow the dashboard installation guide here:
The gateway relies upon the dashboard service to load it's api definitions & proxy configurations. As such, there is no need to mount any app directory.
docker run -d \ --name tyk_gateway \ --network tyk \ -p 8080:8080 \ -v $(pwd)/tyk.with_dashboard.conf:/opt/tyk-gateway/tyk.conf \ tykio/tyk-gateway:latest 複製程式碼
文件中說明搭建閘道器需要先搭建Dashboard
Tyk Dashboard container
安裝指南,指南的第六步指向的連線已經失效,由此推斷之前存在一鍵安裝指令碼
Quickstart
Ensure you have set up the Redis, MongoDB and Tyk Gateway containers
Set up the docker instance IP as the Dashboard hostname (in your
/etc/hosts
file or as a DNS):127.0.0.1 dashboard.tyk.docker
Run the Dashboard
docker run -d --name tyk_dashboard -p 3000:3000 --link tyk_redis:redis --link tyk_mongo:mongo --link tyk_gateway:tyk_gateway tykio/tyk-dashboard
You should now be able to access your Dashboard at
http://dashboard.tyk.docker:3000/
(note for OSX users, replace 127.0.0.1 with whatever IP address your docker VM runs)Enter your Dashboard License. Go to
http://dashboard.tyk.docker:3000/
. You will see a screen asking for a license, enter it in the section marked “Already have a license?” and clickUse this license
.Grab the bootstrap script from our tyk-dashboard github repo and run:
./bootstrap.sh dashboard.tyk.docker
To use an external configuration files, use the
-v
option to mount it over/opt/tyk-dashboard/tyk_analytics.conf
經過查詢發現了舊版指南連結仍然可以訪問,但不建議使用,舊版指南
按照文件的說法需要申請許可證,官方提供開發許可證,提供郵箱即可獲取12個月的授權,申請地址
申請後根據文件提供的Docker啟動語句準備環境和Docker-compose檔案便於一鍵啟動
docker-compose.yml
檔案
version: "3.1"
services:
tyk_gateway:
image: tykio/tyk-gateway:latest
restart: always
networks:
- tyk-service-bridge
volumes:
- /www/wwwroot/tyk-free/apps:/opt/tyk-gateway/apps
depends_on:
- tyk_dashboard
tyk_dashboard:
image: tykio/tyk-dashboard
restart: always
networks:
- tyk-service-bridge
ports:
- 3000:3000
depends_on:
- mongo
- redis
mongo:
image: mongo
restart: always
networks:
- tyk-service-bridge
redis:
image: redis:4.0-alpine
restart: always
networks:
- tyk-service-bridge
networks:
tyk-service-bridge:
driver: bridge
複製程式碼
啟動
$ docker-compose up
複製程式碼
放行防火牆
$ firewall-cmd --zone=public --add-port=3000/tcp --permanent
$ firewall-cmd --reload
複製程式碼
訪問瀏覽器IP:3000
輸入祕鑰
許可證已經傳送到註冊郵件中,啟用後可登陸
但此時沒有預設的使用者名稱和密碼,並且暫時未找到配置的方式(差評),需要通過官方指令碼註冊使用者名稱和密碼
但官方指令碼依賴Python環境,若主機沒有python環境則無法執行
啟動指令碼:
#!/bin/bash
# Usage ./bootstrap.sh DASHBOARD_HOSTNAME
LOCALIP=$1
RANDOM_USER=$(env LC_CTYPE=C tr -dc "a-z0-9" < /dev/urandom | head -c 10)
PASS="test123"
echo "Creating Organisation"
ORGDATA=$(curl --silent --header "admin-auth: 12345" --header "Content-Type:application/json" --data '{"owner_name": "Default Org.","owner_slug": "default", "cname_enabled": true, "cname": ""}' http://$LOCALIP:3000/admin/organisations 2>&1)
#echo $ORGDATA
ORGID=$(echo $ORGDATA | python -c 'import json,sys;obj=json.load(sys.stdin);print(obj["Meta"])')
echo "ORGID: $ORGID"
echo "Adding new user"
USER_DATA=$(curl --silent --header "admin-auth: 12345" --header "Content-Type:application/json" --data '{"first_name": "John","last_name": "Smith","email_address": "'$RANDOM_USER'@example.com","password":"'$PASS'", "active": true,"org_id": "'$ORGID'"}' http://$LOCALIP:3000/admin/users 2>&1)
#echo $USER_DATA
USER_CODE=$(echo $USER_DATA | python -c 'import json,sys;obj=json.load(sys.stdin);print(obj["Message"])')
echo "USER AUTH: $USER_CODE"
USER_LIST=$(curl --silent --header "authorization: $USER_CODE" http://$LOCALIP:3000/api/users 2>&1)
#echo $USER_LIST
USER_ID=$(echo $USER_LIST | python -c 'import json,sys;obj=json.load(sys.stdin);print(obj["users"][0]["id"])')
echo "NEW ID: $USER_ID"
echo "Setting password"
OK=$(curl --silent --header "authorization: $USER_CODE" --header "Content-Type:application/json" http://$LOCALIP:3000/api/users/$USER_ID/actions/reset --data '{"new_password":"'$PASS'"}')
echo ""
echo "DONE"
echo "===="
echo "Login at http://$LOCALIP:3000/"
echo "User: $RANDOM_USER@example.com"
echo "Pass: $PASS"
echo ""
複製程式碼
為了方便使用,此處建立了包含啟動指令碼的Docker映象
使用方法:
$ docker run --rm -it --network tyk-free_tyk-service-bridge -e TARGET_IP=tyk_dashboard fjy8018/tyk-bootstrap:0.1
複製程式碼
隨即獲得登陸名和密碼
登陸成功