CoreOS部署及应用
简介 CoreOS是基于Chrome OS修改的极简化Linux发行版本(CoreOS只需要114MB的内存就能运行,启动时占用的内存比普通的Linux服务器要少40%。),顶层提供分布式数据存储和系统管理工具,能够扩展并管理庞大的云计算服务器设施,用其官网概括理念为“A new way to think about servers”、“CoreOS is Linux for massive s
简介
CoreOS是基于Chrome OS修改的极简化Linux发行版本(CoreOS只需要114MB的内存就能运行,启动时占用的内存比普通的Linux服务器要少40%。),顶层提供分布式数据存储和系统管理工具,能够扩展并管理庞大的云计算服务器设施,用其官网概括理念为“A new way to think about servers”、“CoreOS is Linux for massive server deployments”,表示一个新思维方式思考未来服务器大规模部署的Linux服务器操作系统。CoreOS中的所有应用都完全在Docker容器中运行,操作系统本身会定期自动更新。
CoreOS具有以下几点特性:
1. Linux内核,Linux运行所需存在两个ROOT分区,一个被用作启动分区,一个被用作更新分区更新分区在更新完成后,自动重新启动系统,当前机器不需要从负载集群中移除,为了保证其它应用程序不被打断,会通过Linux cgroup限制更新过程中的磁盘、网络等IO使用。
2. systemd,作为默认系统和服务管理器
3. root分区被设计成只读,用以保证数据的一致性和更新可用
4. CoreOS很明智使用Docker作为容器管理器用以构建、发布应用,从这个层面来看,一个应用其实就是一个容器。
5. etcd组件负责服务发现和配置共享,采用Raft分布式一致性协议算法,承担起,组件之间服务通信使用。很自然的,容器(Container)之间应用、服务的伸缩,就显得很简单了。其基因层面支持集群特性,当然,你也可以解读为云环境的支持。
部署
测试主机环境为CentOS release 6.5 (Final),内核为2.6.32-431.el6.x86_64。我们
1.安装依赖软件
1. Virtualbox-5.0,为vagrant提供虚拟化支持
2. vagrant_1.8.1,ruby开发,使用Virtualbox等提供虚拟化支持,可跨平台部署
3. coreos-vagrant,为vagrant提供的coreos镜像
2.安装Virtualbox-5.0
cd /etc/yum.repos.d
wget http://download.virtualbox.org/virtualbox/rpm/el/virtualbox.repo
rpm -Uvh http://ftp.jaist.ac.jp/pub/Linux/Fedora/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
yum install gcc make patch dkms qt libgomp kernel-headers kernel-devel fontforge binutils glibc-headers glibc-devel -y
cd cd /usr/src/kernels/
#若不添加软连接,安装会报错
ln -s 3.10.0-327.10.1.el7.x86_64 3.10.0-327.el7.x86_64
export KERN_DIR=/usr/src/kernels/3.10.0-327.el7.x86_64
yum install VirtualBox-5.0
3.安装vagrant
wget https://releases.hashicorp.com/vagrant/1.8.1/vagrant_1.8.1_x86_64.rpm
rpm -ivh vagrant_1.8.1_x86_64.rpm
4.快速搭建CoreOS集群
git clone https://github.com/coreos/coreos-vagrant/
cd coreos-vagrant
cp user-data.sample user-data
#获取新token
curl https://discovery.etcd.io/new
#把获取的token放到user-data文件中
vim user-data
#cloud-config
---
coreos:
etcd2:
discovery: https://discovery.etcd.io/2fd5c65dea14ae8b9417bde39c794af4
$update_channel='stable'
#修改集群启动虚拟机个数,默认为1
cp config.rb.sample config.rb
vim config.rb
$num_instances=1
5.启动集群
[root@test]# vagrant up
Bringing machine 'core-01' up with 'virtualbox' provider...
==> core-01: Box 'coreos-stable' could not be found. Attempting to find and install...
core-01: Box Provider: virtualbox
core-01: Box Version: >= 0
==> core-01: Loading metadata for box 'https://storage.googleapis.com/stable.release.core-os.net/amd64-usr/current/coreos_production_vagrant.json'
core-01: URL: https://storage.googleapis.com/stable.release.core-os.net/amd64-usr/current/coreos_production_vagrant.json
==> core-01: Adding box 'coreos-stable' (v835.13.0) for provider: virtualbox
core-01: Downloading: http://stable.release.core-os.net/amd64-usr/835.13.0/coreos_production_vagrant.box
core-01: Calculating and comparing box checksum...
==> core-01: Successfully added box 'coreos-stable' (v835.13.0) for 'virtualbox'!
==> core-01: Importing base box 'coreos-stable'...
==> core-01: Matching MAC address for NAT networking...
==> core-01: Checking if box 'coreos-stable' is up to date...
==> core-01: Setting the name of the VM: coreos-vagrant_core-01_1456463236858_46275
==> core-01: Clearing any previously set network interfaces...
==> core-01: Preparing network interfaces based on configuration...
core-01: Adapter 1: nat
core-01: Adapter 2: hostonly
==> core-01: Forwarding ports...
core-01: 22 (guest) => 2222 (host) (adapter 1)
==> core-01: Running 'pre-boot' VM customizations...
==> core-01: Booting VM...
==> core-01: Waiting for machine to boot. This may take a few minutes...
core-01: SSH address: 127.0.0.1:2222
core-01: SSH username: core
core-01: SSH auth method: private key
==> core-01: Machine booted and ready!
==> core-01: Setting hostname...
==> core-01: Configuring and enabling network interfaces...
==> core-01: Running provisioner: file...
==> core-01: Running provisioner: shell...
core-01: Running: inline script
6.进入coreos
[root@test]# vagrant ssh
CoreOS stable (835.13.0)
注意:我曾在虚拟机为centos系统上搭建,启动vagrant后登陆vagrant ssh报错connecttimeout。后来使用物理机为centos系统且cpu支持虚拟化,vagrant ssh登陆成功。
应用
模拟在CoreOS中通过docker一个容器,容器的环境为centos,在centos上运行应用。
1.docker查找centos镜像
core@core-01 ~ $ docker search centos
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
centos The official build of CentOS. 1960 [OK]
jdeathe/centos-ssh CentOS-6 6.7 x86_64 / SCL/EPEL/IUS Repos /... 15 [OK]
jdeathe/centos-ssh-apache-php CentOS-6 6.7 x86_64 / Apache / PHP / PHP M... 13 [OK]
million12/centos-supervisor Base CentOS-7 with supervisord launcher, h... 9 [OK]
blalor/centos Bare-bones base CentOS 6.5 image 8 [OK]
nimmis/java-centos This is docker images of CentOS 7 with dif... 7 [OK]
torusware/speedus-centos Always updated official CentOS docker imag... 7 [OK]
centos/mariadb55-centos7 3 [OK]
nathonfowlie/centos-jre Latest CentOS image with the JRE pre-insta... 3 [OK]
nickistre/centos-lamp LAMP on centos setup 3 [OK]
consol/sakuli-centos-xfce Sakuli end-2-end testing and monitoring co... 2 [OK]
darksheer/centos Base Centos Image -- Updated hourly 1 [OK]
softvisio/centos Centos 1 [OK]
lighthopper/orientdb-centos A Dockerfile for creating an OrientDB imag... 1 [OK]
yajo/centos-epel CentOS with EPEL and fully updated 1 [OK]
layerworx/centos CentOS container with etcd, etcdctl, confd... 1 [OK]
feduxorg/centos-postgresql Centos Image with postgres 1 [OK]
timhughes/centos Centos with systemd installed and running 0 [OK]
lighthopper/openjdk-centos A Dockerfile for creating an OpenJDK image... 0 [OK]
blacklabelops/centos CentOS Base Image! Built and Updates Daily! 0 [OK]
grayzone/centos auto build for centos. 0 [OK]
jsmigel/centos-epel Docker base image of CentOS w/ EPEL installed 0 [OK]
ustclug/centos USTC centos 0 [OK]
januswel/centos yum update-ed CentOS image 0 [OK]
ericuni/centos centos dev 0 [OK]
2.docker拉取centos镜像
core@core-01 ~ $ docker pull centos
Using default tag: latest
latest: Pulling from library/centos
fa5be2806d4c: Pull complete
b4af4261cb15: Pull complete
5d358abc5d9c: Pull complete
2933d50b9f77: Pull complete
Digest: sha256:1272ae53bac7bf054dd209a0b4a8629bcc39526c2a767427c7639b630a224a9e
Status: Downloaded newer image for centos:latest
3.运行应用,如打印hello,CoreOS
core@core-01 ~ $ docker run -i -t centos echo "hello,CoreOS"
hello,CoreOS
core@core-01 ~ $ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
93de17ef4729 centos "echo hello,CoreOS" 5 seconds ago Exited (0) 5 seconds ago boring_lumiere
c2e5c93b92a2 centos "/bin/bash" 2 days ago Exited (0) 2 days ago high_sammet
总结
通过以上只是对CoreOS有了一个简单的了解,但是要管理CoreOS集群及docker容器,我们还需要详细了解Etcd、Fleet等其他工具。另外本文中讲到利用vagrant搭建虚拟化环境,也可以应用到日常工作中搭建测试环境及其他方面。
更多推荐
所有评论(0)