题记
前面一篇博客已经向各位介绍了SuperMap iCloudManager 8C SP2已经支持Docker平台了,并介绍了如何部署,当然我们可以看到,当时的部署方式通过一个已经安装好的VMWare 的OVF包(内置了iCM\Zabbix-server\mariaDB),然后与另外一个Docker环境进行联动。
SuperMapiCloudManager 8C SP2正式发布:拥抱Docker
http://blog.csdn.net/chinagissoft/article/details/51545904
这种方式的好处就是,好多信息同时帮用户做了,用户可以非常方便的使用这个OVF包,那如果是物理环境呢?可能用户还需要自己来部署类似OVF实现的步骤,而且更重要的是,这与我们现在Docker所提倡的微服务相矛盾,所谓微服务简单来说就是将原来在同一个服务器的多个服务器拆分为独立的容器运行,这与相互之间并不影响,而且隔离安全,在我们分析问题也能够清楚的划分界限。
所以,我们更希望的部署方式应该是这样的。
所有的组成部分都已容器的形式存在,那么我们就需要创建并启动相关的容器即可,非常高兴的是,目前我们常用的容器对象,在容器仓库中都可以找到,包括SuperMap GIS 8C 的相关产品,如果我们涉及的服务越多,所参与的容器就越多,那么问题来了,如果非常好的去编排、管理这些大量的容器?如果靠人工来做,岂不是非常郁闷。
还好,Docker 提供了Docker-Compose工具来解决这个问题。
Docker Compose是一个部署多个容器的简单但是非常必要的工具,Docker Compose在实际工作中非常有价值,相信随着Docker Compose的完善,其必将取代docker run成为开发者启动docker容器的首选。
1、默认安装好的Docker环境是没有docker-compose的,需要额外安装
安装方式1:下载包安装
curl -L https://github.com/docker/compose/releases/download/1.1.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose安装之后需要设置权限
chmod +x /usr/local/bin/docker-compose
安装方式2:直接apt-get install即可
sudo pip install -U docker-compose
安装完毕之后,就可以直接运行docker-compose命令了。
2、编排docker-compose.yml
由于SuperMap iCloudManager需要借助于Zabbix-Server进行监控,相关监控信息默认存储在MariaDB(MySQL),所以,只需要这三种镜像即可。
zabbix-db: image: zabbix/zabbix-db-mariadb ports: - "3306:3306" environment: - MARIADB_USER=zabbix - MARIADB_PASS=zabbix zabbix-server: image: zabbix/zabbix-3.0:3.0.0 ports: - "80:80" - "10051:10051" links: - zabbix-db:zabbix_db environment: - ZS_DBHost=zabbix_db - ZS_DBUser=zabbix - ZS_DBPassword=zabbix icloudmanager: image: supermap/icloudmanager:c802 environment: - ZABBIX_URI=http://zabbix-server:80/api_jsonrpc.php - ZABBIX_USERNAME=Admin - ZABBIX_PASSWORD=zabbix - PLATFORMTYPE=DOCKER - DOCKER_SERVERIP=192.168.21.178 #修改你自己的Docker服务器IP - DOCKER_SERVERPORT=2375 #修改你自己的Docker端口 - DOCKER_PROTOCOL=tcp - DOCKER_API_VERSION=1.22 ports: - "8080:8080" links: - zabbix-server:zabbix-server
我们在使用Docker Compose就可以通过我们编排好的docker-compose.yml文件来自动化的完成逻辑部署。
注意:
docker-compose的docker-compose.yml与dockerfile都需要编排脚本,两种区别也比较明显。docker-compose.yml主要编排容器与容器直接的关系,dockerfile主要编排一个容器内部的关系。当然两者的命令类似,(这是我个人的简单理解)
在上面的yaml文件中,我们可以看到compose文件的基本结构。首先是定义一个服务名,下面是yaml服务中的一些选项条目:
注意:在linux执行注意格式问题。
关于docker端口修改,参考上一篇安装iCM链接介绍。
3、Docker-Compose执行
默认直接运行docker-compose up即可(up命令及创建和启动容器实例),也可以添加参数-f 输入docker-compose.yml的路径,如果不输入,只要在运行命令当前路径存放yml文件即可。
root@docker2:~# docker-compose up -d Pulling zabbix-db (zabbix/zabbix-db-mariadb:latest)... latest: Pulling from zabbix/zabbix-db-mariadb 1544084fad81: Pull complete df0fc3863fbc: Pull complete a3d54b467fad: Pull complete 86f54d6b4779: Pull complete cfba9b6f790a: Pull complete 1db3f9e7d065: Pull complete bf38cfadf2fd: Pull complete ef32faf6169c: Pull complete b030f283076d: Pull complete 263abf799cfb: Pull complete af166cd8baec: Pull complete 8a2ea714f6e1: Pull complete Digest: sha256:4e306267f5e9b37efc48ae7cefcbd0befc366943b125596f2d46c8511160f02b Status: Downloaded newer image for zabbix/zabbix-db-mariadb:latest Pulling zabbix-server (zabbix/zabbix-3.0:3.0.0)... 3.0.0: Pulling from zabbix/zabbix-3.0 77494712c17c: Pull complete 9deb9659ce4e: Pull complete 0e737cb310ea: Pull complete 16d24c04e4af: Pull complete 1f9078a7675f: Pull complete a93c62422c98: Pull complete 7b63781750d3: Pull complete 7250a285fc56: Pull complete cc056fd00c94: Pull complete 6ba115307d0f: Pull complete 2d8e0b63fc5e: Pull complete Digest: sha256:6dad46ad179209961208e9b0002932231fae1395c4c2d33776b7d4cb8796404f Status: Downloaded newer image for zabbix/zabbix-3.0:3.0.0 Pulling icloudmanager (supermap/icloudmanager:c802)... c802: Pulling from supermap/icloudmanager 5c710afc4104: Downloading [==> ] 3.243 MB/65.7 MB 0c1b7a0002c7: Download complete 257fb77d6206: Download complete 1348637f7ed1: Download complete 4d6732aef6e2: Download complete 4d5a6dcd3514: Download complete 984abbe5b293: Download complete 7620e89572f3: Downloading [====> ] 1.837 MB/22.59 MB 6f29d129414f: Downloading [=========> ] 416.8 kB/2.202 MB c4274a2d3f19: Downloading [=================> ] 1.605 MB/4.489 MB d41f9a16045f: Download complete d27c03ab4b59: Downloading [> ] 2.697 MB/192.9 MB 7e28ec434867: Download complete 352eba0511ce: Downloading [================================> ] 5.684 MB/8.621 MB d66f66e4bcef: Download complete 5f822d80f039: Download complete 7e8cea3fb905: Download complete b624c51cbbab: Pull complete 3b200fe90bd8: Pull complete Digest: sha256:22754e49ff94feeaadf8a32fbfebf1153a3c5d4499d1db9ead127e2d71d16c10 Status: Downloaded newer image for supermap/icloudmanager:c802 Creating root_zabbix-db_1 Creating root_zabbix-server_1 Creating root_icloudmanager_1 root@docker2:~#
我们可以看到已经下载好的镜像
root@docker2:~# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE zabbix/zabbix-3.0 3.0.0 2d8e0b63fc5e 30 hours ago 719.8 MB supermap/icloudmanager c802 3b200fe90bd8 4 days ago 533.6 MB zabbix/zabbix-db-mariadb latest 8a2ea714f6e1 13 days ago 554.6 MB ubuntu/mysql latest 62b80c65d15b 6 months ago 373.3 MB ubuntu/os latest 39eea0e53d4e 6 months ago 653.2 MB ubuntu 14.04 1d073211c498 7 months ago 187.9 MB ubuntu 14.04.3 1d073211c498 7 months ago 187.9 MB ubuntu 12.04 0ac5b09d8536 7 months ago 136.1 MB tutum/ubuntu latest 151c4704c045 11 months ago 251.5 MB training/sinatra latest f0f4ab557f95 2 years ago 447 MB
也可以查看已经配置好的运行实例
root@docker2:~# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6c444ce91ca4 supermap/icloudmanager:c802 "/bin/sh -c /etc/iclo" 8 minutes ago Up 8 minutes 0.0.0.0:8080->8080/tcp root_icloudmanager_1 ee4b8e6cff5c zabbix/zabbix-3.0:3.0.0 "/config/bootstrap.sh" 8 minutes ago Up 8 minutes 0.0.0.0:80->80/tcp, 0.0.0.0:10051->10051/tcp, 162/udp, 10052/tcp root_zabbix-server_1 d3f65bdcb149 zabbix/zabbix-db-mariadb "/run.sh" 8 minutes ago Up 8 minutes 0.0.0.0:3306->3306/tcp root_zabbix-db_1 46ddb7c1d0d7 ubuntu:14.04 "/bin/bash" 8 weeks ago Exited (137) 4 hours ago sharp_raman 1cf6125b550f ubuntu:12.04 "/bin/bash" 8 weeks ago Exited (130) 8 weeks ago big_mirzakhani c1ba487df40a 62b80c65d15b "/bin/sh -c mysqld" 6 months ago Exited (1) 6 months ago naughty_lovelace 5743c82b6cba 62b80c65d15b "/bin/sh -c mysqld /b" 6 months ago Exited (1) 6 months ago awesome_leakey
4、启动iCM管理界面
问题来了,如果我们的宿主机重启之后,所有的容器实例就关闭了,如何还能保证编排的容器能够按照逻辑启动呢?
1、关闭docker服务测试
root@docker2:~# service docker restart docker stop/waiting docker start/running, process 15141 root@docker2:~# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6c444ce91ca4 supermap/icloudmanager:c802 "/bin/sh -c /etc/iclo" 38 minutes ago Exited (137) 10 seconds ago root_icloudmanager_1 ee4b8e6cff5c zabbix/zabbix-3.0:3.0.0 "/config/bootstrap.sh" 38 minutes ago Exited (137) 10 seconds ago root_zabbix-server_1 d3f65bdcb149 zabbix/zabbix-db-mariadb "/run.sh" 38 minutes ago Exited (143) 18 seconds ago root_zabbix-db_1 46ddb7c1d0d7 ubuntu:14.04 "/bin/bash" 8 weeks ago Exited (137) 5 hours ago sharp_raman 1cf6125b550f ubuntu:12.04 "/bin/bash" 8 weeks ago Exited (130) 8 weeks ago big_mirzakhani c1ba487df40a 62b80c65d15b "/bin/sh -c mysqld" 6 months ago Exited (1) 6 months ago naughty_lovelace 5743c82b6cba 62b80c65d15b "/bin/sh -c mysqld /b" 6 months ago Exited (1) 6 months ago awesome_leakey
2、使用docker-compose restart命令
root@docker2:~# docker-compose restart Restarting root_icloudmanager_1 ... done Restarting root_zabbix-server_1 ... done Restarting root_zabbix-db_1 ... done
3、查看docker运行实例
root@docker2:~# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6c444ce91ca4 supermap/icloudmanager:c802 "/bin/sh -c /etc/iclo" 48 minutes ago Up 15 seconds 0.0.0.0:8080->8080/tcp root_icloudmanager_1 ee4b8e6cff5c zabbix/zabbix-3.0:3.0.0 "/config/bootstrap.sh" 48 minutes ago Up 15 seconds 0.0.0.0:80->80/tcp, 0.0.0.0:10051->10051/tcp, 162/udp, 10052/tcp root_zabbix-server_1 d3f65bdcb149 zabbix/zabbix-db-mariadb "/run.sh" 48 minutes ago Up 15 seconds 0.0.0.0:3306->3306/tcp root_zabbix-db_1 46ddb7c1d0d7 ubuntu:14.04 "/bin/bash" 8 weeks ago Exited (137) 5 hours ago sharp_raman 1cf6125b550f ubuntu:12.04 "/bin/bash" 8 weeks ago Exited (130) 8 weeks ago big_mirzakhani c1ba487df40a 62b80c65d15b "/bin/sh -c mysqld" 6 months ago Exited (1) 6 months ago naughty_lovelace 5743c82b6cba 62b80c65d15b "/bin/sh -c mysqld /b" 6 months ago Exited (1) 6 months ago awesome_leakey