狠狠撸

狠狠撸Share a Scribd company logo
Docker+Mesos最佳实践
林志贤
lzx@kingdee.com
QQ:3908282
2016-10-28
大纲
? 概要
? Linux环境
? Docker
? Mesos+Marathon
? 网络问题及服务发现
? Jenkins on mesos
概要--What
? What is Docker?以下表述不一定准确
? 容器(Container)
? 比虚拟机更轻量的虚拟机
? 一个Linux,VM,进程
? What is Mesos?
? 分布式资源管理
? 插件式的运行框架: Spark,Docker,Jenkis
? What is Marathon
? 是Mesos的一种运行框架,运行Docker任务(实例)
? 网络问题
? 容器间通讯问题:---Flanneld
? 服务发现,服务docker的ip:port是动态的,消费方如何找到服务ip?--DNS
概要—Why
? Why Docker?
? 最大化利用资源
? 弹性计算,自动伸缩,二级扩容
? DevOpts
? Why Mesos? Docker集群编排工具三足鼎立
? Docker Swarm:官方,新生
? Mesos:成熟,生产环境
? Kubernetes: google出品,未成熟,安装麻烦(网络被墙)
? Why Marathon: 官方标配
? Why Flanneld:目前最成熟,安装容易
Linux环境
? Centos7.2
? Ubuntu16.04
Linux环境--IP设置
? 配置固定ip
? VMWare中配置nat网络,固定dhcp ip地址范围
? Centos7配置ip:http://blog.csdn.net/johnnycode/article/details/40624403
? Ubuntu配置ip:
http://www.cnblogs.com/linjiqin/archive/2013/06/21/3148346.html
? 如果不配置,虚拟机的ip地址可能会变化
Linux环境--软件源配置
? 配置国内mirrors:中科大最快,也可以用163
? Centos yum:https://lug.ustc.edu.cn/wiki/mirrors/help/centos
? Ubuntu apt: https://lug.ustc.edu.cn/wiki/mirrors/help/ubuntu
? Yum update
? Apt update
Docker
? 主机
? 镜像:Image
? 容器:Container
? 仓库:registry
客户端
Docker
Engine
Docker
Registry
运行过程
? Docker build
? Docker run
? Docker push
? Dokcer pull
? Image:创建镜像文件
? Container:运行Image生成Docker实例
(进程)
? push镜像到仓库
? 从仓库上拉Image
Jar JVM
run
类似:
常用命令
? Docker images: 查看images
? Docker ps: 查看运行的实例
? Docker run: 运行一个实例
? Docker pull:拉一个image
? Docker push:push image到registry
? Docker stop: 停止实例
? Docker inspect:查看实例信息
? Docker build, 从本地目录创建一个images
顿辞肠办别谤生态链
Docker安装
? Centos 7.2:配置源
? Centos 7.2: yum install docker
? 目前版本是1.10
? Centos 7.2: yum install docker-engine
? 目前版本是1.12
? 公司网络不好装, 请尽量安装docker-engine
? Ubuntu16.04: apt install docker.io
? 目前版本是1.12
tee /etc/yum.repos.d/docker.repo <<-'EOF'
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/
main/centos/7/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF
Docker练习
? Docker run hello-world
? Docker run nginx
? Docker images
? Docker ps –a
Docker仓库镜像
? 默认的镜像服务器是官方的,龟速
? 国内镜像配置:
? Ubuntu: 修改/etc/default/docker,添加:DOCKER_OPTS=“--registry-
mirror=https://pee6w651.mirror.aliyuncs.com”
? Centos: 修改/usr/lib/systemd/system/docker.service:
ExecStart=/usr/bin/dockerd --registry-
mirror=https://pee6w651.mirror.aliyuncs.com
创建私有仓库
? Docker pull registry
? sudo docker run -d -p 5000:5000 –v /本地目录: /var/lib/registry
registry,在本地启动一个仓库,仓库路径设置在本地目录
? Docker tag hello-world 172.20.222.81:5000/hello-world
? Docker push 172.20.222.81:5000/hello-world
? Docker pull 172.20.222.81:5000/hello-world
? Docker run --restart=always: 每次docker启动都会run该images
? 本地仓库是http,不是https,默认是不可以使用的,docker启动
参数加上: --insecure-registry 172.20.222.81:5000
私有仓库使用流程
build
Pull from
other registry
Local Image
In host
Tag image
to
(registry ip:port)/image
Push Image
Registry
dockerfile
? 编写Dockerfile文件,创建docker image
? 从本地目录创建image, Docker build –t tag .
Dockerfile文件:
from oraclejdk7
RUN mkdir /usr/local/service-demo-provider
ADD . /usr/local/service-demo-provider/
ENTRYPOINT /usr/local/service-demo-provider/bin/dockerstart.sh && tail -f /usr/local/service-demo-provider/logs/stdout.log
Dockerfile流程
? Dockerfile是编写docker的规格文件
? 可以继承
? 假设要运行service-demo-provider和service-web节点,编写
Dockerfile流程:
最小Linux
Ubuntu或
Centos
OracleJdk7
Dockerfile
Service-demo-provider
Dockerfile
Tomcat
Dockerfile
Service-Web
Dockerfile
nginx
基于顿辞肠办别谤的环境治理
Mesos
Mesos框架是一个在
Mesos上运行分布式
应用的应用程序,它
有两个组件:
调度器 : 与Mesos交互,
订阅资源,然后在
mesos从服务器中加
载任务。
执行器 : 从框架的环
境变量 配置中获得信
息,在mesos从服务
器中运行任务。
Mesos采用与Linux Kernel相同的机制,只是运行在不同的抽象层次上。Mesos Kernel
利用资源管理和调度的API在整个数据中心或云环境中运行和提供引用(例如,
Hadoop、Spark、Kafaka、ElasticSearch)。
Mesos架构
? Master
? Slave(Agent)
? Framework
? Scheduler
? Executor
两级调度
惭别蝉辞蝉流程
Marathon
? https://mesosphere.github.io/marathon/docs/
? Framework for Mesos
? 能直接运行cmd
? Docker
? Restfull api
Marathon
它是一个mesos框架,能够支持运行长服务,比如web应用等。是集群的分布式
Init.d,能够原样运行任何Linux二进制发布版本,如Tomcat Play等等,可以集群的
多进程管理。也是一种私有的PasS,实现服务的发现,为部署提供提供REST API
服务,有授权和SSL、配置约束,通过HAProxy实现服务发现和负载平衡。
Mesos and Docker
Marathon Application
? https://mesosphere.github.io/marathon/docs/application-basics.html
安装Mesos+Marathon
? Centos:
? 安装源:rpm -ivh
http://repos.mesosphere.com/el/7/noar
ch/RPMS/mesosphere-el-repo-7-
2.noarch.rpm
? yum install mesos marathon
? Ubuntu:
? 安装源: 右侧
? sudo apt-get -y install mesos marathon
? 默认安装了Zookeeper集群版本
sudo apt-key adv --keyserver
keyserver.ubuntu.com --recv E56151BF
DISTRO=$(lsb_release -is | tr '[:upper:]' '[:lower:]')
CODENAME=$(lsb_release -cs)
# Add the repository
echo "deb http://repos.mesosphere.io/${DISTRO}
${CODENAME} main" | 
sudo tee /etc/apt/sources.list.d/mesosphere.list
sudo apt-get -y update
单机启动
? Service zookeeper start: telnet 2181
? 设置zk
? Echo ‘zk://localhost:2181/mesos’ > /etc/mesos/zk
? 如果是zk集群,设置zk://ip1:2181,ip2:2181/mesos
? echo 'docker,mesos' > /etc/mesos-slave/containerizers
? Service mesos-master start: curl localhost:5050
? Service mesos-slave start
? Service mathon start: curl localhost 8080
? 如果zookeeper起不来,自己安装启动
? http://www.tuicool.com/articles/6nYJbmR
mesos集群配置
? master节点:
? $ echo 192.168.13.135 | sudo tee /etc/mesos-master/hostname
? $ echo 192.168.13.135 | sudo tee /etc/mesos-master/ip
? 安装marathon
? Slave节点:
? $ echo 192.168.13.136 | sudo tee /etc/mesos-slave/hostname
? $ echo 192.168.13.136 | sudo tee /etc/mesos-slave/ip
? echo 'docker,mesos' > /etc/mesos-slave/containerizers
? Both:
? Echo ‘zk://localhost:2181/mesos’ > /etc/mesos/zk
? 如果是zk集群,设置zk://ip1:2181,ip2:2181/mesos
? service启动
网络问题
? 容器间通讯问题:---Flanneld
? 服务发现,服务docker的ip:port是动态的,Mesos-DNS
Flanneld
? 是kubenetes配置网络的官方工具
? Coreos出品,etcd
? 依赖于etcd
? http://dockone.io/article/618
? go开发
Flanneld
安装
? 安装Etcd
? git clone https://github.com/coreos/etcd.git
? ./build
? 启动etcd:etcd --listen-client-urls http://0.0.0.0:4001 --advertise-
client-urls http://ip:4001
? 安装Flanneld,直接下载二进制文件,拷贝到/usr/bin/flanneld
? Curl –o /usr/bin/flanneld
https://github.com/coreos/flannel/releases/download/v0.6.2/flanneld-
amd64
flanneld子网划分
? 安装etcd的主机:
? etcdctl set /coreos.com/network/config ‘{ “Network”: “10.1.0.0/16” }’
? Both:
? flanneld -etcd-endpoints http://etcdip:4001
? source /run/flannel/subnet.env //生成子网
? Service stop docker
? sudo ifconfig docker0 ${FLANNEL_SUBNET} //修改docker0的子网
? 配置docker启动参数:--bip=${FLANNEL_SUBNET} --mtu=${FLANNEL_MTU}
Mesos-dns
? 解决容器IP发现问题
? http://mesosphere.github.io/mesos-dns/docs/
? Go语言开发
? 直接下载,rename to /usr/bin
? 配置config.json文件
? ./mesos-dns -config=config.json &
? 配置resolv.conf: nameserver 10.134.29.134
Mesos-dns
Jenkins on mesos
? http://www.chinacloud.cn/show.aspx?id=23735&cid=14
? http://www.open-open.com/lib/view/open1433315189744.html
Ad

Recommended

PDF
Mesos intro
dennis zhuang
?
PDF
叠测辫补迟博客出品-服务器运维集群方法总结2
redhat9
?
PDF
叠测辫补迟博客出品-服务器运维集群方法总结
redhat9
?
PPTX
顿辞肠办别谤实务
國昭 張
?
PDF
02.飞濒蝉集群
Meng He
?
PPTX
Openstack neutron 原理详解
Yong Luo
?
PPTX
顿辞肠办别谤基础
國昭 張
?
PPTX
顿辞肠办别谤进阶探讨
國昭 張
?
PDF
叠测辫补迟博客出品-服务器运维集群方法总结3
redhat9
?
PPTX
公司应用架构:模块化、微服务与 Linux 容器技术
Lifan Yang
?
PDF
MySQL优化、新特性和新架构 彭立勋
Lixun Peng
?
PDF
微服务自己动手做
YenChen Liu 劉晏辰
?
DOC
Mysql Replication
liufabin 66688
?
PDF
对惭测厂蚕尝应用的一些总结
Lixun Peng
?
PDF
基于贵耻别濒的超融合一体机
EdwardBadBoy
?
PDF
豆瓣网技术架构变迁
reinhardx
?
PDF
构建基于尝补尘辫的网站架构
Cosey Lee
?
PDF
碍补蹿办补介绍
lurga
?
PDF
Openstack nova
Yong Luo
?
PDF
Docker
旭 張
?
PPTX
惭测厂蚕尝新技术探索与实践
Lixun Peng
?
PPTX
開發人員必須知道的 Kubernetes 核心技術 - Kubernetes Summit 2018
Will Huang
?
PPT
Database.Cache&Buffer&Lock
Lixun Peng
?
PPT
深入顿辞肠办别谤的资源管理
SpeedyCloud
?
PDF
顿辞肠办别谤初识
hubugui
?
PDF
MySQL多机房容灾设计(with Multi-Master)
Lixun Peng
?
PPTX
Tech.days Taiwan AZR305
Jeff Chu
?
PPTX
对惭测厂蚕尝的一些改进想法和实现
Lixun Peng
?
PDF
51 cto下载 51cto信息图:openshift vs cloudfoundry
Hong Cai
?
PPTX
DEV305 - ASP.NET 5 開發攻略
Will Huang
?

More Related Content

What's hot (20)

PDF
叠测辫补迟博客出品-服务器运维集群方法总结3
redhat9
?
PPTX
公司应用架构:模块化、微服务与 Linux 容器技术
Lifan Yang
?
PDF
MySQL优化、新特性和新架构 彭立勋
Lixun Peng
?
PDF
微服务自己动手做
YenChen Liu 劉晏辰
?
DOC
Mysql Replication
liufabin 66688
?
PDF
对惭测厂蚕尝应用的一些总结
Lixun Peng
?
PDF
基于贵耻别濒的超融合一体机
EdwardBadBoy
?
PDF
豆瓣网技术架构变迁
reinhardx
?
PDF
构建基于尝补尘辫的网站架构
Cosey Lee
?
PDF
碍补蹿办补介绍
lurga
?
PDF
Openstack nova
Yong Luo
?
PDF
Docker
旭 張
?
PPTX
惭测厂蚕尝新技术探索与实践
Lixun Peng
?
PPTX
開發人員必須知道的 Kubernetes 核心技術 - Kubernetes Summit 2018
Will Huang
?
PPT
Database.Cache&Buffer&Lock
Lixun Peng
?
PPT
深入顿辞肠办别谤的资源管理
SpeedyCloud
?
PDF
顿辞肠办别谤初识
hubugui
?
PDF
MySQL多机房容灾设计(with Multi-Master)
Lixun Peng
?
PPTX
Tech.days Taiwan AZR305
Jeff Chu
?
PPTX
对惭测厂蚕尝的一些改进想法和实现
Lixun Peng
?
叠测辫补迟博客出品-服务器运维集群方法总结3
redhat9
?
公司应用架构:模块化、微服务与 Linux 容器技术
Lifan Yang
?
MySQL优化、新特性和新架构 彭立勋
Lixun Peng
?
微服务自己动手做
YenChen Liu 劉晏辰
?
Mysql Replication
liufabin 66688
?
对惭测厂蚕尝应用的一些总结
Lixun Peng
?
基于贵耻别濒的超融合一体机
EdwardBadBoy
?
豆瓣网技术架构变迁
reinhardx
?
构建基于尝补尘辫的网站架构
Cosey Lee
?
碍补蹿办补介绍
lurga
?
Openstack nova
Yong Luo
?
Docker
旭 張
?
惭测厂蚕尝新技术探索与实践
Lixun Peng
?
開發人員必須知道的 Kubernetes 核心技術 - Kubernetes Summit 2018
Will Huang
?
Database.Cache&Buffer&Lock
Lixun Peng
?
深入顿辞肠办别谤的资源管理
SpeedyCloud
?
顿辞肠办别谤初识
hubugui
?
MySQL多机房容灾设计(with Multi-Master)
Lixun Peng
?
Tech.days Taiwan AZR305
Jeff Chu
?
对惭测厂蚕尝的一些改进想法和实现
Lixun Peng
?

Similar to 顿辞肠办别谤+尘别蝉辞蝉安装最佳实践 (20)

PDF
51 cto下载 51cto信息图:openshift vs cloudfoundry
Hong Cai
?
PPTX
DEV305 - ASP.NET 5 開發攻略
Will Huang
?
PDF
Databases on AWS
Chien Chung Shen
?
PDF
从顿辞肠办别谤到容器服务
Li Yi
?
PPTX
Dev-Ops与Docker的最佳实践 QCon2016 北京站演讲
ChinaNetCloud
?
PDF
Docker introduce and vs kernel virtual machine
yangkun9
?
PDF
Linux Container Introduction
家弘 周
?
PDF
云端技术的新趋势
Ben Huang
?
PDF
OpenStack and Docke Integration V6
Guangya Liu
?
PDF
摆.狈别迟开发交流会闭摆2010.06.19闭大众点评网的技术变迁之路(王宏)
Shanda innovation institute
?
PDF
大众点评网的技术变迁之路
jeffz
?
PDF
公司导入容器经验分享与开源技能培养
Philip Zheng
?
PDF
一个 Mongodb command 的前世今生
dennis zhuang
?
PPTX
长荣大学/资料库系统初探
Lorex L. Yang
?
PPTX
20141128(刘胜)鲍罢颁2014分布式和云服务的思考与实践——支付清算行业分布式架构的探索
liu sheng
?
DOC
颁补蝉蝉补苍诲谤补的初步使用及一些简单的操作
zhubin885
?
PDF
阿里云技术实践
drewz lin
?
PPT
内存数据库摆1闭
小新 制造
?
PDF
Meteor
Tencent
?
PPTX
Couchbase introduction - Chinese
Vickie Zeng
?
51 cto下载 51cto信息图:openshift vs cloudfoundry
Hong Cai
?
DEV305 - ASP.NET 5 開發攻略
Will Huang
?
Databases on AWS
Chien Chung Shen
?
从顿辞肠办别谤到容器服务
Li Yi
?
Dev-Ops与Docker的最佳实践 QCon2016 北京站演讲
ChinaNetCloud
?
Docker introduce and vs kernel virtual machine
yangkun9
?
Linux Container Introduction
家弘 周
?
云端技术的新趋势
Ben Huang
?
OpenStack and Docke Integration V6
Guangya Liu
?
摆.狈别迟开发交流会闭摆2010.06.19闭大众点评网的技术变迁之路(王宏)
Shanda innovation institute
?
大众点评网的技术变迁之路
jeffz
?
公司导入容器经验分享与开源技能培养
Philip Zheng
?
一个 Mongodb command 的前世今生
dennis zhuang
?
长荣大学/资料库系统初探
Lorex L. Yang
?
20141128(刘胜)鲍罢颁2014分布式和云服务的思考与实践——支付清算行业分布式架构的探索
liu sheng
?
颁补蝉蝉补苍诲谤补的初步使用及一些简单的操作
zhubin885
?
阿里云技术实践
drewz lin
?
内存数据库摆1闭
小新 制造
?
Meteor
Tencent
?
Couchbase introduction - Chinese
Vickie Zeng
?
Ad

顿辞肠办别谤+尘别蝉辞蝉安装最佳实践

Editor's Notes

  • #15: ExecStart=/usr/bin/docker daemon --registry-mirror=https://pee6w651.mirror.aliyuncs.com
  • #21: 上图修改自Apache Mesos网站上的图片,如图所示,Mesos实现了两级调度架构,它可以管理多种类型的应用程序。 第一级调度是Master的守护进程,管理Mesos集群中所有节点上运行的Slave守护进程。集群由物理服务器或虚拟服务器组成,用于运行应用程序的任务,比如Hadoop和MPI作业。 第二级调度由被称作Framework的“组件”组成。Framework包括调度器(Scheduler)和执行器(Executor)进程,其中每个节点上都会运行执行器。Mesos能和不同类型的Framework通信,每种Framework由相应的应用集群管理。上图中只展示了Hadoop和MPI两种类型,其它类型的应用程序也有相应的Framework。 http://www.kancloud.cn/infoq/mesos/47815
  • #22: Agent 1 reports to the master that it has 4 CPUs and 4 GB of memory free. The master then invokes the allocation policy module, which tells it that framework 1 should be offered all available resources. The master sends a resource offer describing what is available on agent 1 to framework 1. The framework’s scheduler replies to the master with information about two tasks to run on the agent, using <2 CPUs, 1 GB RAM> for the first task, and <1 CPUs, 2 GB RAM> for the second task. Finally, the master sends the tasks to the agent, which allocates appropriate resources to the framework’s executor, which in turn launches the two tasks (depicted with dotted-line borders in the figure). Because 1 CPU and 1 GB of RAM are still unallocated, the allocation module may now offer them to framework 2.
  • #23: 我们来研究下上图的事件流程。上一篇谈到,Slave是运行在物理或虚拟服务器上的Mesos守护进程,是Mesos集群的一部分。 Framework由调度器(Scheduler)应用程序和任务执行器(Executor)组成,被注册到Mesos以使用Mesos集群中的资源。 Slave 1向Master汇报其空闲资源:4个CPU、4GB内存。 然后,Master触发分配策略模块,得到的反馈是Framework 1要请求全部可用资源。 Master向Framework 1发送资源邀约,描述了Slave 1上的可用资源。 Framework的调度器(Scheduler)响应Master,需要在Slave上运行两个任务,第一个任务分配资源,第二个任务分配资源。 最后,Master向Slave下发任务,分配适当的资源给Framework的任务执行器(Executor),接下来由执行器启动这两个任务(如图中虚线框所示)。 此时,还有1个CPU和1GB的RAM尚未分配,因此分配模块可以将这些资源供给Framework 2。
  • #25: 这样,我们可以如同一台Linux主机一样管理数千台服务器,它们的对应原理如下图,使用Marathon类似Linux主机内的init Systemd等外壳管理,而Mesos则不只包含一个Linux核,可以调度数千台服务器的Linux核,实际是一个数据中心的内核:
  • #26: A Mesos cluster comprises a few masters and many slaves. As work is farmed out to them, Mesos slaves delegate to?executors?for the setup and teardown of individual tasks. It is the executor that manages communication between the slave and the Docker daemon. The Docker daemon manages caching and launch of Docker images, which can be pulled from the global Docker index or a local registry. When a Docker container is started as a Mesos task, it runs beneath the Docker daemon on a slave server. Although the Docker container does not run as a true child process of the executor, as it would have under the old Docker standalone mode, the executor is able to manage translation of resource limits, signals and Mesos process control messages to appropriate calls of the?docker?tool. Fine-grained resource monitoring, forthcoming in mainline Mesos and part of some service management tools, is hard to do right if the container does not run directly under the executor — so this architecture may be revised in the future.
  • #35: Ubuntu: DOCKER_OPTS="--insecure-registry 172.20.222.81:5000 --registry-mirror=https://pee6w651.mirror.aliyuncs.com --bip=10.1.0.0/24 --mtu=1472” Centos: 修改/usr/lib/systemd/system/docker.service: ExecStart=/usr/bin/dockerd --bip=10.1.0.0/24 --mtu=1472”
  • #36: { ? "zk": "zk://172.16.7.11:2181,172.16.7.12:2181,172.16.7.13:2181/mesos", ? "masters": ["172.16.7.11:5050","172.16.7.12:5050","172.16.7.13:5050"], ? "refreshSeconds": 60, ? "ttl": 60, ? "domain": "mesos", ? "port": 53, ? "resolvers": ["219.150.32.132"], ? "timeout": 5,? ? "httpon": true, ? "dnson": true, ? "httpport": 8123, ? "externalon": true, ? "listener": "172.16.7.12", ? "SOAMname": "ns1.mesos", ? "SOARname": "root.ns1.mesos", ? "SOARefresh": 60, ? "SOARetry": ? 600, ? "SOAExpire": ?86400, ? "SOAMinttl": 60, ? "IPSources": ["netinfo", "mesos", "host"] }