一、实验环境
操作系统: CentOS7.5 Minimal
IP:192.168.1.104
二、安装swarm
安装docker
# yum -y install yum-utils device-mapper-persistent-data lvm2
# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# yum list docker-ce --showduplicates | sort -r
# yum -y install docker-ce-18.06.0.ce
# systemctl start docker
# systemctl status docker
# systemctl enable docker
# docker version
启动docker服务并设为开机自启
# systemctl daemon-reload
# systemctl start docker
# systemctl status docker
# systemctl enable docker
# docker info
# docker version
设置镜像加速
# curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io
# systemctl restart docker
初始化swarm
# dokcer swarm init
# docker node ls
三、swarm部署kong
# mkdir /opt/project
# mkdir /opt/postgresql/data/
# vim /opt/project/postgres.yml
#########################################
version: "3"
services:
kong-postgres:
image: postgres:9.6
deploy:
replicas: 1
resources:
limits:
cpus: '1'
memory: 1G
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
environment:
- "POSTGRES_DB=kong"
- "POSTGRES_USER=kong"
- "POSTGRES_PASSWORD=Kong@123"
volumes:
- /opt/postgresql/data:/var/lib/postgresql/data
ports:
- "5432:5432"
kong-migrations:
image: kong:0.11.2
deploy:
replicas: 1
resources:
limits:
cpus: '2'
memory: 1G
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
environment:
- "KONG_DATABASE=postgres"
- "KONG_PG_HOST=kong-postgres"
- "KONG_PG_DATABASE=kong"
- "KONG_PG_USER=kong"
- "KONG_PG_PASSWORD=Kong@123"
command: "kong migrations up"
##NETWORK###
networks:
default:
driver: overlay
##########################################
# vim /opt/project/kong.yml
##############################################
version: "3"
services:
kong:
image: kong:0.11.2
deploy:
replicas: 1
resources:
limits:
cpus: '2'
memory: 1G
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
environment:
- "KONG_ADMIN_ACCESS_LOG=/dev/stdout"
- "KONG_ADMIN_ERROR_LOG=/dev/stderr"
- "KONG_PROXY_ACCESS_LOG=/dev/stdout"
- "KONG_PROXY_ERROR_LOG=/dev/stderr"
- "KONG_CASSANDRA_CONTACT_POINTS=db"
- "KONG_ADMIN_LISTEN=0.0.0.0:8001"
- "KONG_DATABASE=postgres"
- "KONG_PG_HOST=kong-postgres"
- "KONG_PG_DATABASE=kong"
- "KONG_PG_USER=kong"
- "KONG_PG_PASSWORD=Kong@123"
ports:
- "8000:8000"
- "8001:8001"
- "8443:8443"
- "8444:8444"
kong-dashboard:
image: "pgbi/kong-dashboard:v3.5.0"
deploy:
replicas: 1
resources:
limits:
cpus: '2'
memory: 1G
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
command: "start --kong-url http://kong:8001 --basic-auth admin=Admin@123"
ports:
- "8080:8080"
#########################################################
部署postgres,初始化kong数据库
# docker stack deploy kongApiGateway -c /opt/project/postgres.yml --with-registry-auth
IP:192.168.1.104
端口:5432
用户名:kong
密码:Kong@123
部署kong和kong-dabashboard
# docker stack deploy kongApiGateway -c /opt/project/kong.yml --with-registry-auth
查看服务装态
# docker service ls
# docker ps -a
四、测试访问
浏览器访问: http://192.168.1.104:8080
用户名密码:admin/Admin@123
五、参考
kong
https://docs.docker.com/samples/library/kong
使用kong作为docker swarm的集群网关
https://juejin.im/post/5d38497ef265da1bba594762
How to deploy Kong to docker swarm?
https://stackoverflow.com/questions/51038414/how-to-deploy-kong-to-docker-swarm
CentOS7.x上docker的安装方式
https://www.jianshu.com/p/d1a07a13a76f
Deploy Kong with Docker Compose
https://blog.toast38coza.me/up-and-running-with-kong-and-docker
使用docker-compose安装Kong及相关环境
http://topsee.online/2018/11/11/%E4%BD%BF%E7%94%A8docker-compose%E5%AE%89%E8%A3%85Kong%E5%8F%8A%E7%9B%B8%E5%85%B3%E7%8E%AF%E5%A2%83/
MySQL中Grant赋权时特殊字符的转义
http://topsee.online/2014/06/17/MySQL%E4%B8%ADGrant%E8%B5%8B%E6%9D%83%E6%97%B6%E7%89%B9%E6%AE%8A%E5%AD%97%E7%AC%A6%E7%9A%84%E8%BD%AC%E4%B9%89/
Compose file version 3 reference
https://docs.docker.com/compose/compose-file/#container_name
用docker swarm部署ELK日志系统
https://www.jianshu.com/p/ff4811c79985