coreos tools intro section

pull/75/head
zhangbaitong 2015-09-28 11:43:40 +08:00
parent 6066e9cc5a
commit eb32546e3c
2 changed files with 105 additions and 0 deletions

View File

@ -100,6 +100,7 @@
* [实战 wordpress](fig/wordpress.md)
* [CoreOS 项目](coreos/README.md)
* [简介](coreos/intro.md)
* [工具](coreos/intro_tools.md)
* [Kubernetes 项目](kubernetes/README.md)
* [简介](kubernetes/intro.md)
* [快速上手](kubernetes/quickstart.md)

104
coreos/intro_tools.md Normal file
View File

@ -0,0 +1,104 @@
#CoreOS工具介绍
CoreOS提供了三大工具它们分别是服务发现容器管理和进程管理。
##使用etcd服务发现
CoreOS的第一个重要组件就是使用etcd来实现的服务发现。
如果你使用默认的样例cloud-config文件那么etcd会在启动时自动运行。
例如:
```
#cloud-config
hostname: coreos0
ssh_authorized_keys:
- ssh-rsa AAAA...
coreos:
units:
- name: etcd.service
command: start
- name: fleet.service
command: start
etcd:
name: coreos0
discovery: https://discovery.etcd.io/<token>
```
配置文件里有一个token获取它可以通过如下方式
访问地址
https://discovery.etcd.io/new
你将会获取一个包含你得teoken得URL。
##通过Docker进行容器管理
第二个组件就是docker它用来运行你的代码和应用。
每一个CoreOS的机器上都安装了它具体使用请参考本书其他章节。
##使用fleet进行进程管理
第三个CoreOS组件是fleet。
它是集群的分布式初始化系统。你应该使用fleet来管理你的docker容器的生命周期。
Fleet通过接受systemd单元文件来工作同时在你集群的机器上通过单元文件中编写的偏好来对它们进行调度。
首先让我们构建一个简单的可以运行docker容器的systemd单元。把这个文件保存在home目录并命名为hello.service
```
hello.service
[Unit]
Description=My Service
After=docker.service
[Service]
TimeoutStartSec=0
ExecStartPre=-/usr/bin/docker kill hello
ExecStartPre=-/usr/bin/docker rm hello
ExecStartPre=/usr/bin/docker pull busybox
ExecStart=/usr/bin/docker run --name hello busybox /bin/sh -c "while true; do echo Hello World; sleep 1; done"
ExecStop=/usr/bin/docker stop hello
```
然后,读取并启动这个单元:
```
$ fleetctl load hello.service
=> Unit hello.service loaded on 8145ebb7.../172.17.8.105
$ fleetctl start hello.service
=> Unit hello.service launched on 8145ebb7.../172.17.8.105
```
这样,你的容器将在集群里被启动。
下面我们查看下它的状态:
```
$ fleetctl status hello.service
● hello.service - My Service
Loaded: loaded (/run/fleet/units/hello.service; linked-runtime)
Active: active (running) since Wed 2014-06-04 19:04:13 UTC; 44s ago
Main PID: 27503 (bash)
CGroup: /system.slice/hello.service
├─27503 /bin/bash -c /usr/bin/docker start -a hello || /usr/bin/docker run --name hello busybox /bin/sh -c "while true; do echo Hello World; sleep 1; done"
└─27509 /usr/bin/docker run --name hello busybox /bin/sh -c while true; do echo Hello World; sleep 1; done
Jun 04 19:04:57 core-01 bash[27503]: Hello World
..snip...
Jun 04 19:05:06 core-01 bash[27503]: Hello World
```
我们可以停止容器:
```
fleetctl destroy hello.service
```
至此就是CoreOS提供的三大工具。