CoreOS Architecture Learning

时间:2023-03-08 23:52:46
CoreOS Architecture Learning

目录

. CoreOS简介
. CoreOS部署、安装、使用
. CoreOS命令使用

1. CoreOS简介

0x1: CoreOS和Docker的关系

我们先来看一张Docker的架构图

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQwAAACyCAIAAAA4WWZ1AAAUCUlEQVR4nO2da1MbV5qA/WP4E/pi12pnJrNb21sDUcYkizPxkopj1/qWtTNDypchjmvKTJUpXHYmpjzEbjzYYwiObQIYX0qkpAGCuISLjTBgjcVdIEutltStlvTOh27duyWBhc7p9qt6PpijPi+H4/NwLo363cVFAUEQLQBgV5PdjmybjN688W/IG0JcCZQEJaEd4kqgJCgJ7bzRaGbNcPNX8fb3og+PRgYuhV7aOEFEScijKonL50S2RGkkufkOsOYMbv+3OHKNC/MoCUqie0q23JJiAf9qcNEhjl6PdR2QVYnfeTfoHkFJUBJ9s0N7En7tefThUWDNwP57aO4RSoKS6JgdkoSLAheNi6PXZU+Cr4ZREpREr+ykJMBFQfYk/vdKLsihJCiJLtlpSbhoPPrwM2DNkcEmlAQl0SU7LwnwngVgzdD6ywDnQUlQEv1RBkm4KEiPvwDWLIy1oiQoif4ojyShhX5gzbHvf4eSoCT6ozyScIIg33AMeJdQEpREZ5RJkihEe48Baw47e1ASlERnlE0S0fENsObIPy7SK0mHJwwAEufSRViUxHiShF7+CKw59uBjaiWZdYnAh8MA/ISD/rA6kGT2Sf1uxrLvtq1EAQdvHLOYmCTVv/6k7ppj3EiSBF6vAGuGm+9wUpxKSVycBGHn9Mo6gN8zmShf2wRpfYPjAQBACvtGp/OXFxn2bZDE0XbS8vvz9bv3XrSWTpIvB5JfTg331DNVp9uXjCMJF41D238Caw68XqFQEscEDxD2dMj/EL19KUkAYkHn7FjT2NxcOJZ4S6u8yLBvgSTPWvZV1XcvPWraW33qyVSivOdL5vjXPS2f7a02MdX7zrP2pfzleSRRat14YSRJINp9CFhz8NUgfZJMevwA6yuOJrv8uz+27EpJk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ayMTXgCA1bGBeYD5h8lnyF+ZSTw9vnDdoc/J//i0QFwJlCQP2snZaltGAsDNdJ2utZiOXO1fFWF16Bhjkb2CVdvp2hPHzp6ofLwIsNCpzDw3J0VYHjhTZF3SPztFEFcCJcmHZnK2ewsgOtnklXVDy0q6kqcugOX+xL6l9qkLwNl90MRYTNcTiRGLrIskIK4ESlKY3ORsjRM8ZL/EyXZLzgrtYJdbWXFdmRFhdegQU3xdRIG4EijJVkgkZ2uc4DOzwyXJHuiJFVenstaSJSmuLiJDXAmURBvt5GyVctJdlSyH6nt950QyCbVlC3URxmJCSagmT3K22s5JEYTVoQtHLKbaM40Da4K42FVnURvoB7vcAADgHT2thC2+LmIxoSS0o52crbLh4aRXTCuXN9wqA/1Q/xoAbDguJkuKr4uYUBIEKQhxJVAShHaIK4GSILRDXAmUBKEd4kqgJAjtEFcCJUFoh7gSKAlCO8SVQEkQ2iGuBEqC0A5xJVAShHaIK6Eqyb8AZHluThQEFv0AAAAASUVORK5CYII=" alt="" />

Docker是一种基于"Host OS"操作系统的虚拟化技术,部署Docker的前提是需要底层有一个运行Docker Container的操作系统,从理论上来说,RHEL、ubuntu、debain等系统,而CoreOS就是一款专门为了Docker虚拟化而设计的操作系统

0x2: CoreOS产生

CoreOS是一个基于Docker的轻量级容器化Linux发行版,专为大型数据中心而设计,旨在通过轻量的系统架构和灵活的应用程序部署能力简化数据中心的维护成本和复杂度

CoreOS Architecture Learning

0x3: CoreOS的特点

. CoreOS 没有提供包管理工具,而是通过容器化 (containerized) 的运算环境向应用程序提供运算资源。应用程序之间共享系统内核和资源,但是彼此之间又互不可见。这样就意味着应用程序将不会再被直接安装到操作系统中,而是通过 Docker 运行在容器中。这种方式使得操作系统、应用程序及运行环境之间的耦合度大大降低

. 相对于传统的部署方式而言,在 CoreOS 集群中部署应用程序更加灵活便捷,应用程序运行环境之间的干扰更少,而且操作系统自身的维护也更加容易。

. CoreOS 采用双系统分区 (dual root partition) 设计。两个分区分别被设置成主动模式和被动模式并在系统运行期间各司其职
) 主动分区负责系统运行
) 被动分区负责系统升级
一旦新版本的操作系统被发布,一个完整的系统文件将被下载至被动分区,并在系统下一次重启时从新版本分区启动,原来的被动分区将切换为主动分区,而之前的主动分区则被切换为被动分区,两个分区扮演的角色将相互对调。同时在系统运行期间系统分区被设置成只读状态,这样也确保了 CoreOS 的安全性。CoreOS 的升级过程在默认条件下将自动完成,并且通过 cgroup 对升级过程中使用到的网络和磁盘资源进行限制,将系统升级所带来的影响降至最低 . CoreOS 使用 Systemd 取代 SysV 作为系统和服务的管理工具。与 SysV 相比
) Systemd 不但可以更好的追踪系统进程,而且也具备优秀的并行化处理能力,加之按需启动等特点,并结合 Docker 的快速启动能力,在 CoreOS 集群中大规模部署 Docker Containers 与使用其他操作系统相比在性能上的优势将更加明显
) Systemd 的另一个特点是引入了 "target" 的概念,每个 target 应用于一个特定的服务,并且可以通过继承一个已有的 target 扩展额外的功能,这样使得操作系统对系统上运行的服务拥有更好的控制力 . 通过对系统结构的重新设计,CoreOS 剔除了任何不必要的软件和服务。在一定程度上减轻了维护一个服务器集群的复杂度,帮助用户从繁琐的系统及软件维护工作中解脱出来。虽然CoreOS 最初源自于Google ChromeOS,但是从一开始就决定了 CoreOS 更加适合应用于一个集群环境而不是一个传统的服务器操作系统

Relevant Link:

http://www.infoq.com/cn/articles/what-is-coreos
http://baike.baidu.com/view/10876826.htm?fr=aladdin
http://www.oschina.net/p/coreos
http://www.oschina.net/translate/coreos_and_docker_first_steps?cmp
http://www.infoq.com/cn/news/2014/07/etcd-cluster-discovery

0x4: CoreOS为大规模云计算、数据中心集群而做的改造

. CoreOS针对Linux内核所做的改造
) 存在两个ROOT分区,一个被用作启动分区,一个被用作更新分区
) 更新分区在更新完成后,自动重新启动系统,当前机器不需要从负载集群中移除,为了保证其它应用程序不被打断,会通过Linux cgroup限制更新过程中的磁盘、网络等IO使用。 . 采用systemd取代传统的SysV
) 支持并行化任务
) 同时采用 socket 式与 D-Bus 总线式激活服务
) 按需启动守护进程(daemon)
) 利用 Linux 的 cgroups 监视进程
) 支持快照和系统恢复
) 维护挂载点和自动挂载点
) 各服务间基于依赖关系进行精密控制 . root分区被设计成只读,用以保证数据的一致性和更新可用 . CPU、IO等资源隔离
基于容器(Container)的架构实现资源隔离,CoreOS很明智使用Docker作为容器管理器用以构建、发布应用,从这个层面来看,一个应用其实就是一个容器 . etcd组件负责服务发现和配置共享,采用Raft分布式一致性协议算法,承担起,组件之间服务通信使用。很自然的,容器(Container)之间应用、服务的伸缩,就显得很简单了

Relevant Link:

https://coreos.com/

2. CoreOS部署、安装、使用

A new way to think about servers
CoreOS is Linux for massive server deployments

CoreOS is a new Linux distribution that has been rearchitected to provide features needed to run modern infrastructure stacks. The strategies and architectures that influence CoreOS allow companies like Google, Facebook and Twitter to run their services at scale with high resilience.

0x1: CoreOS Installation Based On VirtualBox

CoreOS是一种操作系统架构的产品,CoreOS的安装需要基于一定的硬件/虚拟机环境上实现

http://www.blogjava.net/yongboy/archive/2013/08/26/403325.html

0x2: CoreOS Installation Based On VMware

. Choosing a Channel
//This is a rough sketch that should work on OSX and Linux:
curl -LO http://alpha.release.core-os.net/amd64-usr/current/coreos_production_vmware_insecure.zip
unzip coreos_production_vmware_insecure.zip -d coreos_production_vmware_insecure
cd coreos_production_vmware_insecure
open coreos_production_vmware_insecure.vmx . To deploy on an ESXi/vSphere host, convert the VM to OVF
cd coreos_developer_vmware_insecure
mkdir coreos
ovftool coreos_production_vmware_insecure.vmx coreos/coreos.insecure.ovf . creates the following files in ../coreos/:
//解压后的结果
coreos.insecure-disk1.vmdk
coreos.insecure.ovf
coreos.insecure.mf . use the vSphere Client to deploy the VM as follows:
) menu "File"..."Deploy OVF Template..."
) in the wizard, specify the location of the /coresos/ coreos.insecure.ovf created earlier
) name your VM
) choose "thin provision" for the disk format
) choose your network settings
) confirm the settings then click "Finish" . Cloud-Config . Logging in
cd coreos_developer_vmware_insecure
ssh -i insecure_ssh_key core@10.0.1.81 . Replacing the key
cat ~/.ssh/id_rsa.pub | ssh core@10.0.1.81 -i insecure_ssh_key update-ssh-keys -a user
ssh core@10.0.1.81 update-ssh-keys -D oem . Using CoreOS

Relevant Link:

https://coreos.com/docs/running-coreos/platforms/vmware/
https://coreos.com/docs/

3. CoreOS命令使用

https://coreos.com/docs/quickstart/

Copyright (c) 2014 LittleHann All rights reserved