来自 谷歌云平台官方博客 的消息:CoreOS 的 CTO —— Brandon Philips 宣布 Google 的 Compute Engine 平台已经提供了 CoreOS 系统的支持。CoreOS 可轻松的与 Google 的负载均衡和 replica pools 集成,实现应用程序跨区域的伸缩。
CoreOS 使用 cloud-config 来配置机器启动后的自动集群:
$ curl https://discovery.etcd.io/new
https://discovery.etcd.io/b97f446100a293c8107500e11c34864b
在你的 cloud-config 文档中设置发现 token
$ cat cloud-config.yaml
#cloud-config
coreos:
etcd:
# generate a new token for each unique cluster from
https://discovery.etcd.io/new
discovery: https://discovery.etcd.io/b97f446100a293c8107500e11c34864b
# multi-region and multi-cloud deployments need to use $public_ipv4
addr: $private_ipv4:4001
peer-addr: $private_ipv4:7001
units:
- name: etcd.service
command: start
- name: fleet.service
command: start
在生成 cloud-config 后便可通过一个命令启动3台机器的集群,记住要替换你的项目 id:
gcutil --project=<project-id> addinstance
--image=projects/coreos-cloud/global/images/coreos-beta-310-1-0-v20140508
--persistent_boot_disk --zone=us-central1-a --machine_type=n1-standard-1
--metadata_from_file=user-data:cloud-config.yaml core1 core2 core3
为了展示快速的调度能力,我们提交并启动一个很简单的 Docker 容器并显示一条消息,首先 SSH 登录其中一台机器,记住替换你的项目 id
$ gcutil --project=coreos ssh --ssh_user=core core1
创建一个单元文件并在容器中运行
$ cat example.service
[Unit]
Description=MyApp
After=docker.service
Requires=docker.service
[Service]
RemainAfterExit=yes
ExecStart=/usr/bin/docker run busybox /bin/echo 'I was scheduled with fleet!'
为了在新的集群上运行单元文件,可通过 fleetctl 来提交:
$ fleetctl start example.service
$ fleetctl list-units
UNIT STATE LOAD ACTIVE SUB DESC MACHINE
example.service launched loaded active exited MyApp b603fc4d.../10.240.246.57
可通过 feetctl 轻松获取注册表容器的状态:
$ fleetctl status example.service
● example.service - MyApp
Loaded: loaded (/run/fleet/units/example.service; linked-runtime)
Active: active (exited) since Thu 2014-05-22 20:27:54 UTC; 4s ago
Process: 15789 ExecStart=/usr/bin/docker run busybox /bin/echo
I was scheduled with fleet! (code=exited, status=0/SUCCESS)
Main PID: 15789 (code=exited, status=0/SUCCESS)
May 22 20:27:54 core-01 systemd[1]: Started MyApp.
May 22 20:27:57 core-01 docker[15789]: I was scheduled with fleet!
使用这些基础的工具你可以轻松创建基于 CoreOS 的完全分布式应用,可通过 CoreOS blog 获取更多关于使用 fleet、负载均衡等方面的示例。完整的在 Compute Engine 运行 CoreOS 的文档请参考 head over to the docs.
CoreOS 的详细介绍:请点这里
CoreOS 的下载地址:请点这里
本文永久更新链接地址:http://www.linuxidc.com/Linux/2014-05/102173.htm
