安装docker环境

  • 登录root账户,查看内核版本

    1. [viktor@viktor ~]$ uname -a
    2. Linux viktor 3.10.0-957.27.2.el7.x86_64 #1 SMP Mon Jul 29 17:46:05 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
  • 把yum更新到最新

    1. [root@viktor viktor]# yum update
    2. Loaded plugins: fastestmirror
    3. Loading mirror speeds from cached hostfile
    4. * base: mirrors.usc.edu
    5. * epel: mirrors.sonic.net
    6. * extras: mirrors.oit.uci.edu
    7. * updates: repos.lax.quadranet.com
    8. No packages marked for update
  • 安装需要的软件包, yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的

    1. [root@viktor viktor]# yum install -y yum-utils device-mapper-persistent-data lvm2
    2. Loaded plugins: fastestmirror
    3. Loading mirror speeds from cached hostfile
    4. * base: mirror.scalabledns.com
    5. * epel: mirrors.sonic.net
    6. * extras: mirrors.oit.uci.edu
    7. * updates: mirror.scalabledns.com
    8. ....
  • 设置yum源

    1. [root@viktor viktor]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
    2. Loaded plugins: fastestmirror
    3. adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
    4. grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
    5. repo saved to /etc/yum.repos.d/docker-ce.repo
  • 可以查看所有仓库中所有docker版本,并选择特定版本安装

    1. [root@viktor viktor]# yum list docker-ce --showduplicates | sort -r
    2. * updates: mirror.scalabledns.com
    3. Loading mirror speeds from cached hostfile
    4. Loaded plugins: fastestmirror
    5. * extras: mirrors.oit.uci.edu
    6. * epel: mirrors.sonic.net
    7. docker-ce.x86_64 3:19.03.1-3.el7 docker-ce-stable
    8. docker-ce.x86_64 3:19.03.0-3.el7 docker-ce-stable
    9. docker-ce.x86_64 3:18.09.8-3.el7 docker-ce-stable
    10. docker-ce.x86_64 3:18.09.7-3.el7 docker-ce-stable
    11. docker-ce.x86_64 3:18.09.6-3.el7 docker-ce-stable
    12. docker-ce.x86_64 3:18.09.5-3.el7 docker-ce-stable
    13. docker-ce.x86_64 3:18.09.4-3.el7 docker-ce-stable
    14. docker-ce.x86_64 3:18.09.3-3.el7 docker-ce-stable
    15. docker-ce.x86_64 3:18.09.2-3.el7 docker-ce-stable
    16. docker-ce.x86_64 3:18.09.1-3.el7 docker-ce-stable
    17. docker-ce.x86_64 3:18.09.0-3.el7 docker-ce-stable
    18. docker-ce.x86_64 18.06.3.ce-3.el7 docker-ce-stable
    19. docker-ce.x86_64 18.06.2.ce-3.el7 docker-ce-stable
    20. docker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-stable
    21. docker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stable
    22. docker-ce.x86_64 18.03.1.ce-1.el7.centos docker-ce-stable
    23. docker-ce.x86_64 18.03.0.ce-1.el7.centos docker-ce-stable
    24. docker-ce.x86_64 17.12.1.ce-1.el7.centos docker-ce-stable
    25. docker-ce.x86_64 17.12.0.ce-1.el7.centos docker-ce-stable
    26. docker-ce.x86_64 17.09.1.ce-1.el7.centos docker-ce-stable
    27. docker-ce.x86_64 17.09.0.ce-1.el7.centos docker-ce-stable
    28. docker-ce.x86_64 17.06.2.ce-1.el7.centos docker-ce-stable
    29. docker-ce.x86_64 17.06.1.ce-1.el7.centos docker-ce-stable
    30. docker-ce.x86_64 17.06.0.ce-1.el7.centos docker-ce-stable
    31. docker-ce.x86_64 17.03.3.ce-1.el7 docker-ce-stable
    32. docker-ce.x86_64 17.03.2.ce-1.el7.centos docker-ce-stable
    33. docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable
    34. docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable
    35. * base: mirror.scalabledns.com
    36. Available Packages
  • 安装Docker,命令:yum install docker-ce-版本号,我选的是17.12.1.ce,如下

    1. [root@viktor viktor]# yum install docker-ce-17.12.1.ce
    2. Loaded plugins: fastestmirror
    3. Loading mirror speeds from cached hostfile
    4. * base: mirror.scalabledns.com
    5. * epel: mirrors.sonic.net
    6. * extras: mirrors.oit.uci.edu
    7. * updates: mirror.scalabledns.com
    8. ...
  • 启动Docker,命令:systemctl start docker,然后加入开机启动,如下

    1. [root@viktor viktor]# systemctl start docker
    2. [root@viktor viktor]# systemctl enable docker
    3. Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
  • 验证安装是否成功(有client和service两部分表示docker安装启动都成功了) ```shell [root@viktor viktor]# docker version Client: Version: 17.12.1-ce API version: 1.35 Go version: go1.9.4 Git commit: 7390fc6 Built: Tue Feb 27 22:15:20 2018 OS/Arch: linux/amd64

Server: Engine: Version: 17.12.1-ce API version: 1.35 (minimum version 1.12) Go version: go1.9.4 Git commit: 7390fc6 Built: Tue Feb 27 22:17:54 2018 OS/Arch: linux/amd64 Experimental: false

  1. - docker常用命令
  2. ```shell
  3. # 查看当前正在运行的容器
  4. docker ps
  5. # 查看所有容器的状态
  6. docker ps -a
  7. # 启动/停止某个容器
  8. docker start/stop id/name
  9. # 进入某个容器(使用exit退出后容器也跟着停止运行)
  10. docker attach id
  11. # 启动一个伪终端以交互式的方式进入某个容器(使用exit退出后容器不停止运行)
  12. docker exec -ti id
  13. # 查看本地镜像
  14. docker images
  15. # 删除某个容器
  16. docker rm id/name
  17. # 删除某个镜像
  18. docker rmi id/name
  19. # 复制ubuntu容器并且重命名为test且运行,然后以伪终端交互式方式进入容器,运行bash
  20. docker run --name test -ti ubuntu /bin/bash
  21. # 通过当前目录下的Dockerfile创建一个名为soar/centos:7.1的镜像
  22. docker build -t soar/centos:7.1 .
  23. # 以镜像soar/centos:7.1创建名为test的容器,并以后台模式运行,并做端口映射到宿主机2222端口,P参数重启容器宿主机端口会发生改变
  24. docker run -d -p 2222:22 --name test soar/centos:7.1

安装Docker-Compose

  • 下载Docker-Compose:

    1. sudo curl -L https://github.com/docker/compose/releases/download/1.23.0-rc3/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
  • 安装Docker-Compose:

    1. sudo chmod +x /usr/local/bin/docker-compose
  • 查看版本 :

    1. docker-compose version

flink环境准备

本文教程是基于 Docker 进行的,因此你只需要安装了 Docker 即可。不需要依赖 Java、Scala 环境、或是IDE。

注意:Docker 默认配置的资源可能不太够,会导致运行 Flink Job 时卡死。因此推荐配置 Docker 资源到 3-4 GB,3-4 CPUs。
image.png
本次教程的环境使用 Docker Compose 来安装,包含了所需的各种服务的容器,包括:

  • Flink SQL Client:用来提交query,以及可视化结果
  • Flink JobManager 和 TaskManager:用来运行 Flink SQL 任务。
  • Apache Kafka:用来生成输入流和写入结果流。
  • Apache Zookeeper:Kafka 的依赖项
  • ElasticSearch:用来写入结果

以下是Docker Compose 配置文件:

  1. version: '2'
  2. services:
  3. sql-client:
  4. image: fhueske/flink-sql-client-training-1.7.2:latest
  5. depends_on:
  6. - kafka
  7. - jobmanager
  8. - elasticsearch
  9. environment:
  10. FLINK_JOBMANAGER_HOST: jobmanager
  11. ZOOKEEPER_CONNECT: zookeeper
  12. KAFKA_BOOTSTRAP: kafka
  13. ES_HOST: elasticsearch
  14. jobmanager:
  15. image: flink:1.7.2-scala_2.12
  16. hostname: "jobmanager"
  17. expose:
  18. - "6123"
  19. ports:
  20. - "8081:8081"
  21. command: jobmanager
  22. environment:
  23. - JOB_MANAGER_RPC_ADDRESS=jobmanager
  24. taskmanager:
  25. image: flink:1.7.2-scala_2.12
  26. expose:
  27. - "6121"
  28. - "6122"
  29. depends_on:
  30. - jobmanager
  31. command: taskmanager
  32. links:
  33. - jobmanager:jobmanager
  34. environment:
  35. - JOB_MANAGER_RPC_ADDRESS=jobmanager
  36. zookeeper:
  37. image: wurstmeister/zookeeper
  38. ports:
  39. - "2181:2181"
  40. kafka:
  41. image: wurstmeister/kafka:0.11.0.1
  42. ports:
  43. - "9092"
  44. depends_on:
  45. - zookeeper
  46. environment:
  47. HOSTNAME_COMMAND: "route -n | awk '/UG[ \t]/{print $$2}'"
  48. KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
  49. volumes:
  50. - /var/run/docker.sock:/var/run/docker.sock
  51. elasticsearch:
  52. image: docker.elastic.co/elasticsearch/elasticsearch-oss:6.3.1
  53. environment:
  54. - cluster.name=docker-cluster
  55. - bootstrap.memory_lock=true
  56. - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
  57. - discovery.type=single-node
  58. ports:
  59. - "9200:9200"
  60. - "9300:9300"
  61. ulimits:
  62. memlock:
  63. soft: -1
  64. hard: -1
  65. nofile:
  66. soft: 65536
  67. hard: 65536

然后打开命令行窗口,进入存放 docker-compose.yml 文件的目录,然后运行以下命令:

  1. [root@viktor docker]# docker-compose up -d
  2. Creating network "docker_default" with the default driver
  3. Pulling jobmanager (flink:1.7.2-scala_2.12)...
  4. 1.7.2-scala_2.12: Pulling from library/flink
  5. 9cc2ad81d40d: Pull complete
  6. e6cb98e32a52: Pull complete
  7. ae1b8d879bad: Pull complete
  8. 2383fa4462e7: Pull complete
  9. 7ac3ce9f2067: Pull complete
  10. ce9a16d8ddcb: Pull complete
  11. d0078391b205: Pull complete
  12. cb7d61aa945e: Pull complete
  13. 5dcb8e0f7236: Pull complete
  14. f3f880699fcf: Pull complete
  15. ffa37d915f80: Pull complete
  16. 0b51594f6132: Pull complete
  17. Pulling taskmanager (flink:1.7.2-scala_2.12)...
  18. 1.7.2-scala_2.12: Pulling from library/flink
  19. ...

运行flink SQL Client

运行下面命令进入 Flink SQL CLI 。
docker-compose exec sql-client ./sql-client.sh

该命令会在容器中启动 Flink SQL CLI 客户端。然后你会看到如下的欢迎界面。
image.png

您可以通过键入quit或离开SQL CLI客户端exit
关闭训练环境。
docker-compose down

注意:如果训练环境无响应,请重新启动Docker引擎,并为Docker提供更多资源。
我们在使用3-4 GB内存和3-4个CPU内核运行Docker方面取得了很好的经验。