docker安装kong - Go语言中文社区

docker安装kong


linux centos下安装docker

     主要推荐yum安装,并且自认为yum安装docker是最简洁的办法,yum安装请自行百度.

 1.yum瞎扯篇

     首先我们先需要保证yum好使,然后简单的配置下yum镜像源地址,进入yum源配置文件所在的文件夹。

      cd /etc/yum.repos.d/

  我们看下当前的文件如下:

  请自行备份CentOS-Base.repo , 这是当前用到的镜像源,如出现问题可恢复镜像源

 

下载163的yum源配置文件到上面那个文件夹内

CentOS7

1

[root@localhost yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo

 
CentOS6

1

[root@localhost yum.repos.d]# wget http://mirrors.163.com/.help/CentOS6-Base-163.repo

运行yum makecache生成缓存

1

[root@localhost yum.repos.d]# yum makecache

 

这时候再更新系统就会看到以下mirrors.163.com信息

1

2

3

4

5

6

[root@localhost yum.repos.d]# yum -y update

已加载插件:fastestmirror, refresh-packagekit, security

设置更新进程Loading mirror speeds from cached hostfile

* base: mirrors.163.com

* extras: mirrors.163.com

如果yum makecache 时候一直尝试其他镜像  可以打开CentOS-Base.repo  文件内容如下

 

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-7 - Extras - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=http://mirrors.163.com/centos/7/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

 

  把所有的$releasever 替换为7 如果CentOS6 就替换为6 ,笔者是在yum makecache 时候 extras 一直不动 

  所以换了extras 的$releasever 替换了为7。

  ========================言归正传======================

  运行docker需要内核版本为3.8或者更高的版本,uname -r 可以查看内核版本.

  首先确保yum安装包最新   执行  yum update    , 如果出现下载速度慢,请上翻一步步来 ,配置下yum镜像源

 

2.安装docker

       安装docker

  yum -y install docker-io

  启动docker

  sudo   service docker start

       查看状态是否启动成功

        sudo  service docker status

        如果docker启动出错请查看具体原因:

        查看状态:

        $ systemctl status docker.service -l 

        我遇到的报错信息

        Error starting daemon: SELinux is not supported with the overlay2 graph driver on this kernel. Either boot into a newer

        kernel or disable selinux in docker (--selinux-enabled=false)

        意思是说, 此linux的内核中的SELinux不支持 overlay2 graph driver ,解决方法有两个,要么启动一个新内核,

        要么就在docker里禁用selinux,--selinux-enabled=false

        重新编辑docker配置文件:

        vi /etc/sysconfig/docker  

        找到 --selinux-enabled  改为 --selinux-enabled=false  

        重启docker

3.docker安装Kong

       Create a Docker network  (创建一个容器网络)

$ docker network create kong-net

       启动数据库

          目前来说Kong启动支持俩种数据库,这里我们分别介绍安装 (只能选择一种哦!!!重点用红色给你标记上)

           Cassandra (Cassandra 是一套开源分布式 Key-Value 存储系统,开源分布式NoSQL数据库系统)

   

 $ docker run -d --name kong-database 
               --network=kong-net 
               -p 9042:9042 
               cassandra:3

         PostgreSQL(没啥说的开源对象关系数据库管理系统)

 

 $ docker run -d --name kong-database 
               --network=kong-net 
               -p 5432:5432 
               -e "POSTGRES_USER=kong" 
               -e "POSTGRES_DB=kong" 
               postgres:9.6

      初始数据库

          注意  KONG_DATABASE应该选择你刚才选择的数据库   ,如果cassandra  就写KONG_DATABASE=cassandra 

          第一个  --e "KONG_DATABASE="  

 $ docker run --rm 
     --network=kong-net 
     -e "KONG_DATABASE=postgres" 
     -e "KONG_PG_HOST=kong-database" 
     -e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" 
     kong:latest kong migrations up

     启动Kong

 $ docker run -d --name kong 
     --network=kong-net 
     -e "KONG_DATABASE=postgres" 
     -e "KONG_PG_HOST=kong-database" 
     -e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" 
     -e "KONG_PROXY_ACCESS_LOG=/dev/stdout" 
     -e "KONG_ADMIN_ACCESS_LOG=/dev/stdout" 
     -e "KONG_PROXY_ERROR_LOG=/dev/stderr" 
     -e "KONG_ADMIN_ERROR_LOG=/dev/stderr" 
     -e "KONG_ADMIN_LISTEN=0.0.0.0:8001, 0.0.0.0:8444 ssl" 
     -p 8000:8000 
     -p 8443:8443 
     -p 8001:8001 
     -p 8444:8444 
     kong:latest

   接下来我们就可以访问Kong了   访问http://localhost:8001/    Kong启动成功! 

 

3.docker安装Kong-dashboard

sudo docker run --name kong-dashboard1 -d -p 8084:8080 pgbi/kong-dashboard:latest start --kong-url http://127.0.0.1:8001

  注意参数 pgbi/kong-dashboard:latest   可以写为 pgbi/kong-dashboard:v2

  v2 是老版本的dashboard   是存在bug的 ,建议用最新版本即latest

 

  全部安装完事我们用docker ps 看一下   应该是启动了3个,我们的端口是8084

  访问http://localhost:8084/   就可看到doshboard管理界面。

 

 

 

 下一篇我们会介绍Kong  api  基础使用。

版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/StayHungry2016/article/details/84974739
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2020-03-01 19:59:44
  • 阅读 ( 1131 )
  • 分类:docker

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢