Kong-网关快速初始化

操作步骤

  1. 执行 prepare.sh 文件,生成kong 和 konga 数据库,随后自动执行数据库迁移操作
  2. kong 容器挂载自定义插件,注意修改 constants.lua 文件中的 plugins 参数(可选操作,如果没有自定义插件可跳过)
  3. 执行 docker-compose up 启动 kong、konga、pg 三个容器

prepare.sh文件

#!/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 文件

version: "3.7"

networks:
  network:

volumes:
  pgdata:

services:
# Kong: The API Gateway
  kong:
    image: kong:3.1
    container_name: qidian-kong
    restart: always
    networks:
      - network
    env_file:
      - kong.env
    ports:
      - 48000:8000 # 接收处理 http 流量
      - 48443:8443 # 接收处理 https 流量
      #- 8001:8001 # http 管理 API
      #- 8444:8444 # https 管理 API
    depends_on:
      - postgresql

# Konga: Kong GUI
  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

# PostgeSQL Datebase
  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 文件

# kong
KONG_DATABASE=postgres
KONG_PG_HOST=postgresql
KONG_PG_USER=postgres
KONG_PG_PASSWORD=fOurED8pFJHhRxo0
KONG_PG_DATABASE=kong
KONG_CASSANDRA_CONTACT_POINTS=kong
KONG_PROXY_ACCESS_LOG=/dev/stdout
KONG_PROXY_ERROR_LOG=/dev/stderr
KONG_ADMIN_ACCESS_LOG=/dev/stdout
KONG_ADMIN_ERROR_LOG=/dev/stderr
KONG_ADMIN_LISTEN=0.0.0.0:8001, 0.0.0.0:8444 ssl

# konga
TOKEN_SECRET=6UM4DoVPmBQnzpZTtLE2a8RiKrHv9A0u
DB_ADAPTER=postgres
DB_HOST=postgresql
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=fOurED8pFJHhRxo0
DB_DATABASE=konga
NODE_ENV=production

# postgresql
shared_buffers=256MB
POSTGRES_PASSWORD=fOurED8pFJHhRxo0
PGTZ=Asia/Shanghai
TZ=Asia/Shanghai
posted @ 2023-02-08 16:59  名字到底要多长  阅读(29)  评论(0编辑  收藏  举报