Tag - Docker

Docker swarm 容器    2017-03-26 21:24:06    757

早就知道docker1.12有很大的改变,仰慕也是很久了,十一期间,抽了点时间(其他时间都在玩)根据官方文档试了下,还是挺好玩的,很多功能也很实用(服务发现、自动伸缩等),下面就是我的操作步奏,大家一起来看看

首先,开放如下端口:

TCP 2377 集群管理节点通信的端口

TCP & UDP 7946 集群节点通信的端口

TCP & UDP 4789 overlay 网络通信端口

  1. firewall-cmd --permanent --add-port={2377/tcp,2377/udp,7946/tcp,7946/udp,4789/tcp,4789/udp}
  2. firewall-cmd --reload
  3. firewall-cmd --list-all

启动集群

  1. # 主节点
  2. docker swarm init --advertise-addr 192.168.11.33
  3. # 子节点
  4. docker swarm join \
  5. --token SWMTKN-1-51w1r44gg7n392k4eti1i52zrbhwjwkmmqoe2zugtur483rdyb-9yb9ucnj23xc0k49sh7cddge3 \
  6. 192.168.11.33:2377

在swarm中部署一个服务

  1. # 创建服务
  2. docker service create --replicas 1 --name helloworld alpine ping docker.com
  3. # 查看服务
  4. docker service ls
  5. # 使用inspect查看服务
  6. docker service inspect --pretty helloworld
  7. # 使用inspect查看服务的详细信息
  8. docker service inspect helloworld
  9. # 查看服务在各个节点上运行的信息
  10. docker service ps helloworld

在swarm中均衡服务

  1. # 将helloworld节点拓展到5个
  2. docker service scale helloworld=5
  3. # 查看服务在节点上的运行信息
  4. docker servi
Docker k8s kubernetes mongo 容器    2017-03-26 21:20:51    1070

某些特殊情况下,需要将某些服务固定在一台宿主机上,K8S也适应这种方式,下面以mongo为例,来看看如何实现的:

  1. kubectl label nodes kube-node node=kube-node
  2. kubectl get node -a -l "node=kube-node"

pod或者rc的配置项中添加如下配置:

  1. nodeSelector:
  2. node: kube-node4

如mongo启动的rc文件

  1. apiVersion: v1
  2. kind: ReplicationController
  3. metadata:
  4. name: mongo
  5. spec:
  6. replicas: 1
  7. template:
  8. metadata:
  9. labels:
  10. run: mongo
  11. spec:
  12. containers:
  13. - name: mongo
  14. image: daocloud.io/library/mongo:3.2.4
  15. ports:
  16. - containerPort: 27017
  17. volumeMounts:
  18. - mountPath: /data/db
  19. name: mongo
  20. volumes: [{"name":"mongo","hostPath":{"path":"/root/volumes/mongo"}}]
  21. nodeSelector:
  22. node: kube-node4

by 刘迎光@萤火虫工作室
OpenBI交流群:495266201
MicroService 微服务交流群:217722918
mail: liuyg#liuyingguang.cn
博主首页(==防止爬虫==):http://blog.liuyingguang.cn

Docker jetty jersey 微服务 MicroService 容器    2017-03-26 11:06:08    905

本项目是将restful项目打包成可执行的war包,在docker中执行

环境介绍:

  1. docker 1.10.3
  2. jetty 8
  3. jersey 1.19

关键配置:

1. pom.xml配置

  1. <build>
  2. <finalName>${project.artifactId}</finalName>
  3. <plugins>
  4. <plugin>
  5. <groupId>org.mortbay.jetty</groupId>
  6. <artifactId>jetty-maven-plugin</artifactId>
  7. <version>${jetty.version}</version>
  8. <configuration>
  9. <systemProperties>
  10. </systemProperties>
  11. <webApp>
  12. <contextPath>/</contextPath>
  13. </webApp>
  14. </configuration>
  15. </plugin>
  16. <plugin>
  17. <groupId>org.apache.maven.plugins</groupId>
  18. <artifactId>maven-compiler-plugin</artifactId>
  19. <version>2.5.1</version>
  20. <configuration>
  21. <source>1.7</source>
  22. <target>1.7</target>
  23. </configuration>
  24. </plugin>
  25. <plugin>
  26. <groupId>org.apache.maven.plugins</groupId>
  27. <artifactId>maven-source-plugin</artifactId>
  28. <version>2.2</version>
  29. <executions>
  30. <execution>
  31. <id>attach-sources</id>
  32. <goals>
  33. <goal>jar</goal>
  34. </goals>
  35. </execution>
  36. </executions>
  37. </plugin>
  38. <plugin>
  39. <groupId>org.
Docker consul swarm overlay 容器    2017-03-26 11:04:44    1147

Docker的使用中,尤为重要的是服务发现和docker的宿主机集群及跨主机overlay网络的搭建,这里来介绍下常用来配合使用的swarm+consul集群的搭建(此处全基于docker容器)

集群介绍:

192.168.11.30 为consul服务的leader,swarm的集群server和client节点,并为primary

192.168.11.32 为consul服务的节点,swarm的集群server和client节点,并为备份节点

服务分布:

192.168.11.30:

consul、swarm、nginx

192.168.11.32:

consul、swarm、nexus、jenkins、registry

基础环境

修改docker基础配置

cluster-store 是consul的leader的地址

cluster-advertise 是swarm client的地址,即当前主机

11.30

  1. vi /usr/lib/systemd/system/docker.service
  2. ExecStart=/usr/bin/docker daemon --tls=false -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375 --cluster-store=consul://192.168.11.30:8500 --cluster-advertise=192.168.11.30:2375
  3. systemctl daemon-reload
  4. systemctl restart docker

11.32

  1. vi /usr/lib/systemd/system/docker.service
  2. ExecStart=/usr/bin/docker daemon --tls=false -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375 --cluster-store=consul://192.168.11.30:8500 --cluster-
2/2