Kong 网关快速初始化
操作步骤
执行 prepare.sh 文件,生成kong 和 konga 数据库,随后自动执行数据库迁移操作
kong 容器挂载自定义插件,注意修改 constants.lua 文件中的 plugins 参数(可选操作,如果没有自定义插件可跳过)
执行 docker-compose up 启动 kong、konga、pg 三个容器
prepare.sh文件 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 # !/bin/bash set -e echo "Creating Database Container..." sudo docker-compose up -d postgresql sleep 5 echo "Create Database Container Completed" echo "##################################################################" echo "Creating Database KONG..." sudo docker-compose exec --user postgres postgresql psql -c "CREATE DATABASE KONG OWNER POSTGRES" echo "Create Database KONG Completed" echo "##################################################################" echo "Creating Database KONGA..." sudo docker-compose exec --user postgres postgresql psql -c "CREATE DATABASE KONGA OWNER POSTGRES" echo "Create Database KONGA Completed" echo "##################################################################" DB_HOST=$(cat kong.env | grep DB_HOST | awk -F "=" '{print $2}') DB_USER=$(cat kong.env | grep DB_USER | awk -F "=" '{print $2}') DB_PASSWORD=$(cat kong.env | grep DB_PASSWORD | awk -F "=" '{print $2}') DB_DATABASE=$(cat kong.env | grep DB_DATABASE | awk -F "=" '{print $2}') DB_PORT=$(cat kong.env | grep DB_PORT | awk -F "=" '{print $2}')# Kong Migration echo "Kong Migrating..."# Konga Migration sudo docker-compose run kong kong migrations bootstrap echo "Kong Migrate Completed" echo "##################################################################"# Konga Migration echo "Konga Initializing..." sudo docker-compose run konga -c prepare -a postgres -u postgresql://$DB_USER:$DB_PASSWORD@$DB_HOST:$DB_PORT/$DB_DATABASE echo "Konga Init Completed"# Down all containers sudo docker-compose down echo "##################################################################" echo "##################################################################" echo "All Steps Completed, Please Run 'docker-compose up -d' to Start the Service!"
docker-compose.yml 文件 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 version: "3.7" networks: network: volumes: pgdata: services: kong: image: kong:3.1 container_name: qidian-kong restart: always networks: - network env_file: - kong.env ports: - 48000 :8000 - 48443 :8443 depends_on: - postgresql konga: image: pantsel/konga:0.14.9 container_name: qidian-konga restart: always networks: - network env_file: - kong.env ports: - 41337 :1337 depends_on: - postgresql postgresql: image: postgres:11.1-alpine container_name: qidian-postgresql restart: always networks: - network ports: - 54324 :5432 env_file: - kong.env volumes: - pgdata:/var/lib/postgresql/data
Kong.env 文件 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 KONG_DATABASE =postgresKONG_PG_HOST =postgresqlKONG_PG_USER =postgresKONG_PG_PASSWORD =fOurED8pFJHhRxo0KONG_PG_DATABASE =kongKONG_CASSANDRA_CONTACT_POINTS =kongKONG_PROXY_ACCESS_LOG =/dev/stdoutKONG_PROXY_ERROR_LOG =/dev/stderrKONG_ADMIN_ACCESS_LOG =/dev/stdoutKONG_ADMIN_ERROR_LOG =/dev/stderrKONG_ADMIN_LISTEN =0.0 .0.0 :8001 , 0.0 .0.0 :8444 sslTOKEN_SECRET =6 UM4DoVPmBQnzpZTtLE2a8RiKrHv9A0uDB_ADAPTER =postgresDB_HOST =postgresqlDB_PORT =5432 DB_USER =postgresDB_PASSWORD =fOurED8pFJHhRxo0DB_DATABASE =kongaNODE_ENV =productionshared_buffers =256 MBPOSTGRES_PASSWORD =fOurED8pFJHhRxo0PGTZ =Asia/ShanghaiTZ =Asia/Shanghai