Introduction

CoreOS is a powerful Linux distribution built to make large, scalable deployments on varied infrastructure simple to manage. Based on a build of Chrome OS, CoreOS maintains a lightweight host system and uses Docker containers for all applications. This system provides process isolation and also allows applications to be moved throughout a cluster easily.

To manage these clusters, CoreOS uses a globally distributed key-value store called etcd to pass configuration data between nodes. This component is also the platform for service discovery, allowing applications to be dynamically configured based on the information available through the shared resource.

In order to schedule and manage applications across the entirety of the cluster, a tool called fleet is used. Fleet serves as a cluster-wide init system that can be used to manage processes across the entire cluster. This makes it easy to configure highly available applications and manage the cluster from a single point. It does this by tying into each individual node’s systemd init system.

  • 更快的启动速度
  • 平滑版本升级
  • 应用容器化

Table of Contents

System Design

The general design of a CoreOS installation is geared towards clustering and containerization.

The main host system is relatively simple and foregoes many of the common “features” of traditional servers. In fact, CoreOS does not even have a package manager. Instead, all additional applications are expected to run as Docker containers, allowing for isolation, portability, and external management of the services.

At boot, CoreOS reads a user-supplied configuration file called “cloud-config” to do some initial configuration. This file allows CoreOS to connect with other members of a cluster, start up essential services, and reconfigure important parameters. This is how CoreOS is able to immediately join a cluster as a working unit upon creation.

Distributed Services

Cloud-init

在系统启动时,CoreOS 会读取一个平台定制的用户配置文件 (称为 cloud-config) 完成系统的初始化配置。通过配置中的信息,新启动 CoreOS 服务器将初始化必要的服务进程,并自动发现并指定集群的其他服务器交互信息,然后加入这个集群中。这种基于集群的“自发现”组织方式使得集群管理变得简单且高效。

通常来说,cloud-config 配置文件至少应当包括服务器所属的集群通信地址,以及启动 etcd 和 fleet 所需服务的参数。用户可以根据需要,在配置中添加更多定制化的服务,使得节点启动后立即成为功能完备的集群成员投入运行。

Etcd

在CoreOS 集群中处于骨架地位的是 etcd。 etcd 是一个分布式 key/value 存储服务,CoreOS 集群中的程序和服务可以通过 etcd 共享信息或做服务发现 。etcd 基于非常著名的 raft 一致性算法:通过选举形式在服务器之中选举 Lead 来同步数据,并以此确保集群之内信息始终一致和可用。etcd 以默认的形式安装于每个 CoreOS 系统之中。

在默认的配置下,etcd 使用系统中的两个端口:4001和7001,其中4001提供给外部应用程序以HTTP+Json的形式读写数据,而7001则用作在每个 etcd 之间进行数据同步。用户更可以通过配置 CA Cert让 etcd 以 HTTPS 的方式读写及同步数据,进一步确保数据信息的安全性。

Fleet

fleet 是一个通过 Systemd对CoreOS 集群中进行控制和管理的工具。

Install

Download

http://stable.release.core-os.net/amd64-usr/current/

  • http://stable.release.core-os.net/amd64-usr/current/coreos_production_iso_image.iso
  • coreos_production_image.bin.bz2
  • coreos_production_image.bin.bz2.sig
  • curl -LO https://stable.release.core-os.net/amd64-usr/current/coreos_production_vmware_ova.ova

Boot

coreos.autologin

config.yaml

#cloud-config

hostname: coreos
coreos:
    units:
        - name: etcd.service
          command: start
        - name: fleet.service
          command: start
        - name: docker.service
          command: start
        - name: static.network
          content: |
            [Match]
            Name=enp0s3
            [Network]
            Address=192.168.249.20/24
            Gateway=192.168.249.2
            DNS=192.168.249.2  
            DNS=192.168.249.1  
users:
    - name: toor
      ssh-authorized-keys:
        - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDV/3GzlkTQGt9KrihLzWXzFlcNhq1TBwRryXuk8ruYgzw2OUvzGN/vHtkZgDY/ZIpg7QR53HhZ8vpyTANOPPS4crEETniqlAZOHDGc8vPLEfIZwH8Dgu3DRZykHiqUthc/N+VRiDgEHT8DINaYMLsBbMpDZfUJlvhpIXij7z+dBSUSftEXpbdt6CpFsHNUNBPoVDyRiEjP0EK9JRppD8quBY2R9Bnk3B9m0/Mq1/LZuLopDmz+IsTxBnmgR1G+LSs//G8ZHZlUohwfbpDcfm81vjaQWxjOmn3Llti/j/3Fd4hN4wdrUdEvnBQ13ArkUgNzfqtIckw2xfoGGejvpxbP oxnz@rmbp
    - groups:
        - sudo
        - docker

VMWare Guestinfo

/usr/share/oem/bin/vmtoolsd --cmd "info-set guestinfo.coreos.config.data \
$(gzip -c cloud-config.yml|base64 -w0 && echo)"
/usr/share/oem/bin/vmtoolsd --cmd 'info-set \
guestinfo.coreos.config.data.encoding gzip+base64'
# verify
/usr/share/oem/bin/vmtoolsd --cmd 'info-get guestinfo.coreos.config.data'

Install

sudo su - root
cp /usr/bin/coreos-install ./
sed -ie 's/BASE_URL=/BASE_URL=http://192.168.249.172/1185.1.2/' coreos-install
./coreos-install -d /dev/sda -C stable -c ./config.yaml

References