Menu

  • Home
  • Work
    • Cloud
      • Virtualization
      • IaaS
      • PaaS
    • Java
    • Go
    • C
    • C++
    • JavaScript
    • PHP
    • Python
    • Architecture
    • Others
      • Assembly
      • Ruby
      • Perl
      • Lua
      • Rust
      • XML
      • Network
      • IoT
      • GIS
      • Algorithm
      • AI
      • Math
      • RE
      • Graphic
    • OS
      • Linux
      • Windows
      • Mac OS X
    • BigData
    • Database
      • MySQL
      • Oracle
    • Mobile
      • Android
      • IOS
    • Web
      • HTML
      • CSS
  • Life
    • Cooking
    • Travel
    • Gardening
  • Gallery
  • Video
  • Music
  • Essay
  • Home
  • Work
    • Cloud
      • Virtualization
      • IaaS
      • PaaS
    • Java
    • Go
    • C
    • C++
    • JavaScript
    • PHP
    • Python
    • Architecture
    • Others
      • Assembly
      • Ruby
      • Perl
      • Lua
      • Rust
      • XML
      • Network
      • IoT
      • GIS
      • Algorithm
      • AI
      • Math
      • RE
      • Graphic
    • OS
      • Linux
      • Windows
      • Mac OS X
    • BigData
    • Database
      • MySQL
      • Oracle
    • Mobile
      • Android
      • IOS
    • Web
      • HTML
      • CSS
  • Life
    • Cooking
    • Travel
    • Gardening
  • Gallery
  • Video
  • Music
  • Essay

CoreOS知识集锦

12
Oct
2016

CoreOS知识集锦

By Alex
/ in Linux,Virtualization
/ tags libvirt
0 Comments
简介

CoreOS是一个轻量级的Linux操作系统,CoreOS的自动化、安全性、可扩容性特征,让其非常适用于集群化的部署场景。

与其它的发行版不同,CoreOS没有包管理器,它倾向于在容器(例如Docker)中运行应用程序。CoreOS对流行的容器系统提供了开箱即用的支持。

CoreOS可以在云服务(例如EC2、GCE)、虚拟化平台(VMware、OpenStack、KVM)、裸金属值上运行。

Ignition

这是CoreOS提供的新的VM初始化机制,用于代替cloud-config。

Ignition能够执行磁盘分区、分区格式化、写入文件、配置用户、配置网络、创建RAID阵列等初始化操作。Ignition的运行时机非常的早,它在systemd启动之前、任何永久存储挂载之前即被调用。

在VM第一次(也仅仅是第一次)启动时,Ignition会从文件系统、URL、Hypervisor bridge读取JSON格式的配置文件,并将配置应用到VM。

运行CoreOS

即使是学习阶段,也最好创建3台CoreOS的集群,那样更容易认识CoreOS的特性。为了让CoreOS集群正常启动,你需要提供“点火配置”( Ignition config ),或者通过user_data提供一个cloud-config。

libvirt/cloud-config

本节记录基于libvirt创建CoreOS客户机的详细过程。

获取镜像

我们可以下载CoreOS官网提供的qcow2格式的镜像,此镜像适用于QEMU:

Shell
1
wget https://stable.release.core-os.net/amd64-usr/current/coreos_production_qemu_image.img.bz2

下载完毕后,解压镜像到 /home/alex/Vmware/KVM/coreos-20/vda.qcow2 备用,默认扩展名是img,手工改成qcow2。

Config drive

为了配置CoreOS实例,我们需要在宿主机上创建一个目录,此目录中包含一些配置信息。此目录最终映射将为客户机上的一个文件系统。执行以下命令:

Shell
1
2
mkdir -p /home/alex/Vmware/KVM/coreos-20/cloud-config/openstack/latest/
touch /home/alex/Vmware/KVM/coreos-20/cloud-config/openstack/latest/user_data

user_data是cloud config格式的配置文件,它提供了客户机运行时所需要的定制化信息。我们至少需要在其中配置SSH Key以便(初次)登录到CoreOS中:

user_data
1
2
3
4
#cloud-config
 
ssh_authorized_keys:
- ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIBlsU4YrAi ... EIokU+jOd0MrsnOwQn9wJbov8Xhyw==
定义Domain

我们可以使用类似下面的命令来定义CoreOS的Domain:

Shell
1
2
3
virt-install --import --name coreos-20 --ram 1024 --vcpus 1
             --disk path=/home/alex/Vmware/KVM/coreos-20/vda.qcow2,format=qcow2,bus=virtio
             --filesystem /home/alex/Vmware/KVM/coreos-20/cloud-config/,config-2,type=mount,mode=squash

或者,在常规的Domain XML配置文件中,添加devices的子元素:

XML
1
2
3
4
<filesystem type='mount' accessmode='squash'>
    <source dir='/home/alex/Vmware/KVM/coreos-20/cloud-config/'/>
    <target dir='config-2'/>
</filesystem>
登录到CoreOS

默认情况下,CoreOS会尝试通过DHCP来获得自身的网络配置,我们可以在启动Domain后立即查看控制台,CoreOS的IP地址会打印在上面。执行下面的命令登录到CoreOS:

Shell
1
ssh -i path-to-key core@ip-of-coreos

登录成功后,你可以为core用户设置密码,或者执行其它操作。 

完整libvirt配置
coreos-20.xml
XML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
    <name>coreos-20</name>
    <memory unit='MiB'>1024</memory>
    <vcpu placement='static'>1</vcpu>
    <os>
        <type arch='x86_64' machine='pc'>hvm</type>
    </os>
    <features>
        <acpi/>
    </features>
    <cpu mode='custom' match='exact'>
        <model fallback='allow'>SandyBridge</model>
    </cpu>
    <clock offset='utc'/>
    <on_poweroff>destroy</on_poweroff>
    <on_reboot>restart</on_reboot>
    <on_crash>destroy</on_crash>
    <devices>
        <emulator>/usr/bin/qemu-system-x86_64</emulator>
        <disk type='volume' device='disk'>
            <driver name='qemu' type='qcow2'/>
            <source pool="default" volume="coreos-20.qcow2" />
            <target dev='vda' bus='virtio'/>
            <boot order='1'/>
        </disk>
        <filesystem type='mount' accessmode='squash'>
            <source dir='/home/alex/Vmware/libvirt/mount/coreos-base/cloud-config/'/>
            <target dir='config-2'/>
        </filesystem>
        <controller type='usb' index='0'/>
        <controller type='pci' index='0' model='pci-root'/>
        <interface type='network'>
            <mac address='DE:AD:BE:EF:00:20'/>
            <source network='default'/>
            <model type='virtio'/>
        </interface>
        <serial type='pty'>
            <target port='0'/>
        </serial>
        <console type='pty'>
            <target type='serial' port='0'/>
        </console>
        <input type='mouse' bus='ps2'/>
        <input type='keyboard' bus='ps2'/>
        <memballoon model='virtio'/>
    </devices>
</domain>
libvirt/Ignition-config

当前推荐的配置CoreOS的方式是Ignition,但是目前libvirt没有对Ignition的直接支持,需要引入QEMU特有的配置片断。

Ignition配置为JSON格式,示例:

/home/alex/Vmware/libvirt/mount/coreos-base/provision.ign
JavaScript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
{
  "ignition": {
    "config": {},
    "timeouts": {},
    "version": "2.1.0"
  },
  "networkd": {},
  "passwd": {
    "users": [
      {
        "name": "core",
        "sshAuthorizedKeys": [
          "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIBlsU4YrAif8Oh4Qdcq1SuF+CbPdr5T3DE3zzeYGG8nkcDMt/9dEjT8eHTMW+4BzCoIfYrIWIprJoykMnhZONBXnoXc/541tqU6MqF0ZRF0QlzSq6VLLLebG3zz+avdJSNLMAvolCLczP536EIokU+jOd0MrsnOwQn9wJbov8Xhyw=="
        ]
      }
    ]
  },
  "storage": {
    "files": [
      {
        "filesystem": "root",
        "group": {},
        "path": "/etc/hostname",
        "user": {},
        "contents": {
          "source": "data:,coreos-21",
          "verification": {}
        }
      }
    ]
  },
  "systemd": {}
}

libvrit Domain配置示例:

XML
1
2
3
4
5
6
7
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
    ...
    <qemu:commandline>
        <qemu:arg value="-fw_cfg"/>
        <qemu:arg value="name=opt/com.coreos/config,file=/home/alex/Vmware/libvirt/mount/coreos-base/provision.ign"/>
  </qemu:commandline>
</domain>

注意:QEMU 2.0版本不支持 -fw_cfg,手工构建最新版本可以支持。 

 

 

 

 

 

 

← 下午四点的树影斑驳
OpenTSDB学习笔记 →

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Related Posts

  • KVM和QEMU学习笔记
  • Ubuntu开发知识集锦
  • Linux信号、进程和会话
  • Ubuntu下安装Samba4
  • HAProxy知识集锦

Recent Posts

  • Investigating and Solving the Issue of Failed Certificate Request with ZeroSSL and Cert-Manager
  • A Comprehensive Study of Kotlin for Java Developers
  • 背诵营笔记
  • 利用LangChain和语言模型交互
  • 享学营笔记
ABOUT ME

汪震 | Alex Wong

江苏淮安人,现居北京。目前供职于腾讯云,专注容器方向。

GitHub:gmemcc

Git:git.gmem.cc

Email:gmemjunk@gmem.cc@me.com

ABOUT GMEM

绿色记忆是我的个人网站,域名gmem.cc中G是Green的简写,MEM是Memory的简写,CC则是我的小天使彩彩名字的简写。

我在这里记录自己的工作与生活,同时和大家分享一些编程方面的知识。

GMEM HISTORY
v2.00:微风
v1.03:单车旅行
v1.02:夏日版
v1.01:未完成
v0.10:彩虹天堂
v0.01:阳光海岸
MIRROR INFO
Meta
  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org
Recent Posts
  • Investigating and Solving the Issue of Failed Certificate Request with ZeroSSL and Cert-Manager
    In this blog post, I will walk ...
  • A Comprehensive Study of Kotlin for Java Developers
    Introduction Purpose of the Study Understanding the Mo ...
  • 背诵营笔记
    Day 1 Find Your Greatness 原文 Greatness. It’s just ...
  • 利用LangChain和语言模型交互
    LangChain是什么 从名字上可以看出来,LangChain可以用来构建自然语言处理能力的链条。它是一个库 ...
  • 享学营笔记
    Unit 1 At home Lesson 1 In the ...
  • K8S集群跨云迁移
    要将K8S集群从一个云服务商迁移到另外一个,需要解决以下问题: 各种K8S资源的迁移 工作负载所挂载的数 ...
  • Terraform快速参考
    简介 Terraform用于实现基础设施即代码(infrastructure as code)—— 通过代码( ...
  • 草缸2021
    经过四个多月的努力,我的小小荷兰景到达极致了状态。

  • 编写Kubernetes风格的APIServer
    背景 前段时间接到一个需求做一个工具,工具将在K8S中运行。需求很适合用控制器模式实现,很自然的就基于kube ...
  • 记录一次KeyDB缓慢的定位过程
    环境说明 运行环境 这个问题出现在一套搭建在虚拟机上的Kubernetes 1.18集群上。集群有三个节点: ...
  • eBPF学习笔记
    简介 BPF,即Berkeley Packet Filter,是一个古老的网络封包过滤机制。它允许从用户空间注 ...
  • IPVS模式下ClusterIP泄露宿主机端口的问题
    问题 在一个启用了IPVS模式kube-proxy的K8S集群中,运行着一个Docker Registry服务 ...
  • 念爷爷
      今天是爷爷的头七,十二月七日、阴历十月廿三中午,老人家与世长辞。   九月初,回家看望刚动完手术的爸爸,发

  • 6 杨梅坑

  • liuhuashan
    深圳人才公园的网红景点 —— 流花山

  • 1 2020年10月拈花湾

  • 内核缺陷触发的NodePort服务63秒延迟问题
    现象 我们有一个新创建的TKE 1.3.0集群,使用基于Galaxy + Flannel(VXLAN模式)的容 ...
  • Galaxy学习笔记
    简介 Galaxy是TKEStack的一个网络组件,支持为TKE集群提供Overlay/Underlay容器网 ...
TOPLINKS
  • Zitahli's blue 91 people like this
  • 梦中的婚礼 64 people like this
  • 汪静好 61 people like this
  • 那年我一岁 36 people like this
  • 为了爱 28 people like this
  • 小绿彩 26 people like this
  • 彩虹姐姐的笑脸 24 people like this
  • 杨梅坑 6 people like this
  • 亚龙湾之旅 1 people like this
  • 汪昌博 people like this
  • 2013年11月香山 10 people like this
  • 2013年7月秦皇岛 6 people like this
  • 2013年6月蓟县盘山 5 people like this
  • 2013年2月梅花山 2 people like this
  • 2013年淮阴自贡迎春灯会 3 people like this
  • 2012年镇江金山游 1 people like this
  • 2012年徽杭古道 9 people like this
  • 2011年清明节后扬州行 1 people like this
  • 2008年十一云龙公园 5 people like this
  • 2008年之秋忆 7 people like this
  • 老照片 13 people like this
  • 火一样的六月 16 people like this
  • 发黄的相片 3 people like this
  • Cesium学习笔记 90 people like this
  • IntelliJ IDEA知识集锦 59 people like this
  • Bazel学习笔记 38 people like this
  • 基于Kurento搭建WebRTC服务器 38 people like this
  • PhoneGap学习笔记 32 people like this
  • NaCl学习笔记 32 people like this
  • 使用Oracle Java Mission Control监控JVM运行状态 29 people like this
  • Ceph学习笔记 27 people like this
  • 基于Calico的CNI 27 people like this
Tag Cloud
ActiveMQ AspectJ CDT Ceph Chrome CNI Command Cordova Coroutine CXF Cygwin DNS Docker eBPF Eclipse ExtJS F7 FAQ Groovy Hibernate HTTP IntelliJ IO编程 IPVS JacksonJSON JMS JSON JVM K8S kernel LB libvirt Linux知识 Linux编程 LOG Maven MinGW Mock Monitoring Multimedia MVC MySQL netfs Netty Nginx NIO Node.js NoSQL Oracle PDT PHP Redis RPC Scheduler ServiceMesh SNMP Spring SSL svn Tomcat TSDB Ubuntu WebGL WebRTC WebService WebSocket wxWidgets XDebug XML XPath XRM ZooKeeper 亚龙湾 单元测试 学习笔记 实时处理 并发编程 彩姐 性能剖析 性能调优 文本处理 新特性 架构模式 系统编程 网络编程 视频监控 设计模式 远程调试 配置文件 齐塔莉
Recent Comments
  • qg on Istio中的透明代理问题
  • heao on 基于本地gRPC的Go插件系统
  • 黄豆豆 on Ginkgo学习笔记
  • cloud on OpenStack学习笔记
  • 5dragoncon on Cilium学习笔记
  • Archeb on 重温iptables
  • C/C++编程:WebSocketpp(Linux + Clion + boostAsio) – 源码巴士 on 基于C/C++的WebSocket库
  • jerbin on eBPF学习笔记
  • point on Istio中的透明代理问题
  • G on Istio中的透明代理问题
  • 绿色记忆:Go语言单元测试和仿冒 on Ginkgo学习笔记
  • point on Istio中的透明代理问题
  • 【Maven】maven插件开发实战 – IT汇 on Maven插件开发
  • chenlx on eBPF学习笔记
  • Alex on eBPF学习笔记
  • CFC4N on eBPF学习笔记
  • 李运田 on 念爷爷
  • yongman on 记录一次KeyDB缓慢的定位过程
  • Alex on Istio中的透明代理问题
  • will on Istio中的透明代理问题
  • will on Istio中的透明代理问题
  • haolipeng on 基于本地gRPC的Go插件系统
  • 吴杰 on 基于C/C++的WebSocket库
©2005-2025 Gmem.cc | Powered by WordPress | 京ICP备18007345号-2