OSX上摆脱vagrant搭建CoreOS集群

 2023-09-06 阅读 19 评论 0

摘要:一般我们在OSX下使用vagrant+virtualbox部署虚拟机集群做开发测试。现在我们还可以有更轻量的选择——xhyve。xhyve是FreeBSD 下的虚拟技术bhyve(The BSD Hypervisor) 的OSX移植,在OS X 10.10.3 Yosemite 之后的版本中可以使用。由于xhyve是基于FreeBSD原生的虚

 

一般我们在OSX下使用vagrant+virtualbox部署虚拟机集群做开发测试。现在我们还可以有更轻量的选择——xhyve。xhyve是FreeBSD 下的虚拟技术 bhyve (The BSD Hypervisor) 的OSX移植,在OS X 10.10.3 Yosemite 之后的版本中可以使用。由于xhyve是基于FreeBSD原生的虚拟方案,所以它性能好并且非常的轻量,只有 230 KB,不依赖其他软件或库。当xhyve发布时CoreOS快速的跟进,推出了基于xhyve的coreos-xhyve。这里我们使用corectl——一个coreos-xhyve的命令行工具来搭建CoreOS集群。

安装corectl

最快的方法使用brew

1
brew install corectl

从源码编译

1
2
3
git clone git@github.com:TheNewNormal/corectl.git
cd corectl
make

安装好后运行corectl -h可以看到所支持的命令

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
corectl -h
CoreOS over OSX made simple.
❯❯❯ http://github.com/TheNewNormal/corectlUsage:corectl [flags]corectl [command]Available Commands:rm          Removes one or more CoreOS images from local fskill        Halts one or more running CoreOS instancesls          Lists locally available CoreOS imagesload        Loads CoreOS instances defined in an instrumentation file.version     Shows corectl version informationps          Lists running CoreOS instancesquery       Display information about the running CoreOS instancespull        Pulls a CoreOS image from upstreamrun         Starts a new CoreOS instancessh         Attach to or run commands inside a running CoreOS instanceput         copy file to inside VMFlags:--debug   adds extra verbosity, and options, for debugging purposes and/or power usersUse "corectl [command] --help" for more information about a command.All flags can also be configured via upper-case environment variables prefixed with "COREOS_"
For example, "--debug" => "COREOS_DEBUG"

运行CoreOS VM

加载镜像

第一次输入sudo corectl run即会自动下载最新的 CoreOS Alpha 镜像并加载运行,镜像文件放置的位置是$HOME/.coreos/

run的参数还有

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
Usage:corectl run [flags]Aliases:run, startFlags:--cdrom string          append an CDROM (.iso) to VM--channel string        CoreOS channel (default "alpha")--cloud_config string   cloud-config file location (either a remote URL or a local path)--cpus int              VM's vCPUS (default 1)-d, --detached              starts the VM in detached (background) mode-h, --help                  help for run-l, --local latest          consumes whatever image is latest locally instead of looking online unless there's nothing available.--memory int            VM's RAM, in MB, per instance (1024 < memory < 8192) (default 1024)-n, --name string           names the VM. (if absent defaults to VM's UUID)--root string           append a (persistent) root volume to VM--sshkey string         VM's default ssh key--tap string            append tap interface to VM--uuid string           VM's UUID (default "random")--version string        CoreOS version (default "latest")--volume value          append disk volumes to VM (default [])Global Flags:--debug   adds extra verbosity, and options, for debugging purposes and/or power usersAll flags can also be configured via upper-case environment variables prefixed with "COREOS_"
For example, "--debug" => "COREOS_DEBUG"

想使用不同的镜像版本可以由--channel alpha/beta/stable指定

数据持久化

先新建一个5G的persistent.img盘

1
dd if=/dev/zero of= persistent.img  bs=1g count=5

格式化成ext4(需要e2fsprogs工具,安装brew install e2fsprogs)

1
/usr/local/Cellar/e2fsprogs/1.42.12/sbin/mke2fs  -t ext4 -m0 -F persistent.img

运行时加上

1
corectl run --name core --volume absolute_or_relative_path/to/persistent.img

启动后persistent.img被挂载在/dev/vda

ssh进入VM将/dev/vda 挂载 在 /data上

1
2
3
corectl ssh core
mkdir /data
sudo mount /dev/vda /data

后面数据就可以写入/data

启动集群

从https://discovery.etcd.io 获取token

1
curl -X GET 'https://discovery.etcd.io/new?size=3'

将token写入loud-config文件

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
#cloud-configcoreos:etcd2:# generate a new token for each unique cluster# from https://discovery.etcd.io/new?size=n where n = cluster size# discovery url to bootstrap the clusterdiscovery: hhttps://discovery.etcd.io/{$TOKEN}# multi-region and multi-cloud deployments need to use $public_ipv4# list of member’s client urls to advertise information to the rest of the clusteradvertise-client-urls: http://$public_ipv4:2379# this address is used to communicate etcd data around the clusterinitial-advertise-peer-urls: http://$private_ipv4:2380# listen on both the official ports and the legacy ports# legacy ports can be omitted if your application doesn't depend on them# url to listen for client trafficlisten-client-urls: http://0.0.0.0:2379,http://0.0.0.0:4001# url to listen for peer trafficlisten-peer-urls: http://$private_ipv4:2380,http://$private_ipv4:7001fleet:public-ip: $public_ipv4flannel:interface: $public_ipv4units:- name: etcd2.servicecommand: start- name: fleet.servicecommand: start

启动三个CoreVM

1
2
3
sudo corectl run --cloud_config ./cloud-config-file --name core-1
sudo corectl run --cloud_config ./cloud-config-file --name core-2
sudo corectl run --cloud_config ./cloud-config-file --name core-3

随便ssh进一个VM使用etcdctl member list看到集群已经建立

1
2
3
4
etcdctl  member list
28fede81eb6ee920: name=78c956f8b901497fbd909c0a4fa4a9f7 peerURLs=http://192.168.64.30:2380 clientURLs=http://192.168.64.30:2379 isLeader=false
a4661fcb2e28c76a: name=1a7f48cd84c540528b0a61483f071307 peerURLs=http://192.168.64.31:2380 clientURLs=http://192.168.64.31:2379 isLeader=false
eebd0c9e16e3e5be: name=fd92329bf3004bf98f3a6553606a00b0 peerURLs=http://192.168.64.32:2380 clientURLs=http://192.168.64.32:2379 isLeader=true

更多信息可以参考这个项目coreos-osx

Share

 

转载来源:http://sineyuan.github.io/2016/05/29/coreos-osx-without-vagrant/

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/5/4209.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息