docker-compose安装Kong网关Konga教程

docker-compose安装Kong网关Konga教程,第1张

docker-compose安装Kong网关Konga教程

Kong网关Konga安装教程
    • 安装docker-compose
    • 修改 docker-compose.yml
    • 快捷脚本 start.sh
            • 授权
          • 使用快捷命令
      • 参考文章

安装docker-compose

链接: Git.

curl -L https://github.com/docker/compose/releases/download/1.25.1-rc1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
修改 docker-compose.yml
version: '3'
services: 
  kong-database:
    image: postgres:9.6
    restart: always  #每次总是启动
    networks: 
      - kong-net
    environment:
      POSTGRES_USER: kong
      POSTGRES_DB: kong
      POSTGRES_PASSWORD: kong
    ports:
      - "5432:5432"
#######################
# 执行数据库迁移
######################
  kong-migration:
    image: kong:latest
    command: "kong migrations bootstrap"
    networks: 
      - kong-net
    restart: on-failure
    environment:
      - KONG_DATAbase=postgres
      - KONG_PG_DATAbase=kong
      - KONG_PG_PASSWORD=kong
      - KONG_PG_HOST=kong-database
    links: 
      - kong-database #连接的是kong-database服务的
    depends_on:
      - kong-database #依赖于kong-database服务

#####################
# kong gateway
#####################
  kong:
    image: kong:latest
    restart: always
    networks:
      - kong-net
    environment:
      KONG_DATAbase: postgres
      KONG_PG_HOST: kong-database
      KONG_PG_PASSWORD: kong
      KONG_PROXY_LISTEN: 0.0.0.0:8000
      KONG_PROXY_LISTEN_SSL: 0.0.0.0:8443
      KONG_ADMIN_LISTEN: 0.0.0.0:8001
    depends_on:
      - kong-migration
    links: 
      - kong-database
    healthcheck:
      test: ["CMD", "curl", "-f", "http://kong:8001"]
      interval: 5s
      timeout: 2s
      retries: 15
    ports:
      - "8001:8001"
      - "8000:8000"
      - "8443:8443"
#######################
#以下两个是konga  GUI
#######################
  konga-prepare:
    image: pantsel/konga:latest
    command: "-c prepare -a postgres -u postgresql://kong:kong@kong-database:5432/konga"  #注意是用户名:密码@数据库服务名称:端口
    networks:
      - kong-net
    restart: on-failure
    links:
      - kong-database
    depends_on:
      - kong        #依赖kong服务
      - kong-database #依赖kong-database服务

  konga:
    image: pantsel/konga:latest
    restart: always
    networks:
      - kong-net
    environment:
      DB_ADAPTER: postgres
      DB_HOST: kong-database
      DB_USER: kong
      DB_DATAbase: konga
      DB_PASSWORD: kong #必须加上密码,不然会失败
    depends_on:
      - kong
      - kong-database
    ports:
      - "1337:1337"
networks:
  kong-net:
    driver: bridge

快捷脚本 start.sh
#使用说明,用来提示输入参数
usage() {
	echo "Usage: sh 执行脚本.sh [init|start|stop|rm]"
	exit 1
}

init(){
	docker-compose up -d 
}

start(){
	docker-compose up -d kong-database kong konga
}

#关闭所有模块
stop(){
	docker-compose stop
}

#删除所有模块
rm(){
	docker-compose rm
}

#根据输入参数,选择执行对应方法,不输入则执行使用说明
case "" in
"init")
	init
;;
"start")
	start
;;
"stop")
	stop
;;
"rm")
	rm
;;
*)
	usage
;;
esac

授权
chmod +x start.sh
使用快捷命令
#初始化
./start.sh init
#停止
./start.sh stop
#删除
./start.sh rm
#启动
./start.sh start

参考文章

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5691825.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存