什么是Docker?
Docker 是一个开源项目,诞生于 2013 年初,最初是 dotCloud 公司内部的一个业余项目。它基于 Google 公司推出的 Go 语言实现。 项目后来加入了 Linux 基金会,遵从了 Apache 2.0 协议,项目代码在 GitHub 上进行维护。
Docker 自开源后受到广泛的关注和讨论,以至于 dotCloud 公司后来都改名为 Docker Inc。Redhat 已经在其 RHEL6.5 中集中支持 Docker;Google 也在其 PaaS 产品中广泛应用。
Docker 项目的目标是实现轻量级的操作系统虚拟化解决方案。 Docker 的基础是 Linux 容器(LXC)等技术。
在 LXC 的基础上 Docker 进行了进一步的封装,让用户不需要去关心容器的管理,使得操作更为简便。用户操作 Docker 的容器就像操作一个快速轻量级的虚拟机一样简单。
什么是Rancher?
Rancher是一个开源的容器管理平台,帮助构建企业私有容器服务,相当于KVM里的Openstack。官网地址是http://rancher.com/。以下图片摘自官方文档
Docker安装
-- 安装iptable防火墙支持NAT,关闭selinux,firewalld
[root@rancher-server]/#systemctl stop firewalld.service #停止firewall
[root@rancher-server]/#systemctl disable firewalld.service #禁止firewall开机启动
[root@rancher-server]/#yum install iptables -y
[root@rancher-server]/#systemctl start iptables.service
[root@rancher-server]/#systemctl enable iptables.service
[root@rancher-server]/#setenforce 0
[root@rancher-server]~# vim /etc/sysconfig/selinux
```
SELINUX=disabled
```
[root@rancher-server]echo "1" > /proc/sys/net/ipv4/ip_forward #打开包转发功能
[root@rancher-server]echo "net.ipv4.ip_forward = 1" >> /usr/lib/sysctl.d/00-system.conf #修改/usr/lib/sysctl.d/00-system.conf文件,让包转发功能在系统启动时自动生效:
[root@rancher-server]/#curl -sSL https://get.daocloud.io/docker | sh #执行docker安装脚本
[root@rancher-server]/#systemctl enable docker.service #Docker开机自启动
[root@rancher-server]/#systemctl start docker.service #启动Docker服务
Daocloud DockerHub 加速
由于国内众所周知的原因,官方的DockerHub访问太慢,所以这里使用Daocloud的国内镜像加速
[root@rancher-server]/#curl -sSL https://get.daocloud.io/daomonit/install.sh | sh -s 0315a03e1618eb785a2bf410997e2f6ab0490df7
后面的这一串字符串(0315a03e1618eb785a2bf410997e2f6ab0490df7 )每个账户都会有所不同,需要改一下,如果你直接复制粘贴那么你的容器就归我管理了·······。具体访问Daocloud官方网站即可https://dashboard.daocloud.io/nodes/new
Rancher Server 安装
[root@rancher-server]/#dao pull rancher/server
[root@rancher-server]/#docker run -d --restart=always -v /rancher/db:/var/lib/mysql --name rancher-server -p 8888:8080 rancher/server
49f3e6fd1588b21c3bcd40974a5eaf0da74d0a27e409e7759ddabbe213871308
--查看rancher/server 日志
[root@rancher-server]/#docker logs -f 49f3e6fd1588b21c3bcd40974a5eaf0da74d0a27e409e7759ddabbe213871308
···
···
2016-04-16 15:39:35,457 INFO [main] [ConsoleStatus] [1/32] [0ms] [0ms] Loading bootstrap
2016-04-16 15:39:35,536 INFO [main] [ConsoleStatus] [2/32] [79ms] [79ms] Loading config-defaults
2016-04-16 15:39:39,514 WARN [main] [liquibase] modifyDataType will lose primary key/autoincrement/not null settings for mysql. Use <sql> and re-specify all configuration if this is the case
2016-04-16 15:40:19,071 INFO [main] [ConsoleStatus] [3/32] [43614ms] [43535ms] Loading system
2016-04-16 15:40:19,110 INFO [main] [ConsoleStatus] [4/32] [43653ms] [39ms] Loading defaults
2016-04-16 15:40:19,266 INFO [main] [ConsoleStatus] [5/32] [43809ms] [155ms] Loading types
2016-04-16 15:40:22,146 INFO [main] [ConsoleStatus] [6/32] [46689ms] [2880ms] Loading system-services
2016-04-16 15:40:22,314 INFO [main] [ConsoleStatus] [7/32] [46857ms] [168ms] Loading agent-server
2016-04-16 15:40:22,480 INFO [main] [ConsoleStatus] [8/32] [47023ms] [166ms] Loading allocator-server
2016-04-16 15:40:23,467 INFO [main] [ConsoleStatus] [9/32] [48010ms] [987ms] Loading api-server
2016-04-16 15:40:24,846 INFO [main] [ConsoleStatus] [10/32] [49389ms] [1379ms] Loading iaas-api
2016-04-16 15:40:24,890 INFO [main] [ConsoleStatus] [11/32] [49433ms] [44ms] Loading archaius
2016-04-16 15:40:25,070 INFO [main] [ConsoleStatus] [12/32] [49613ms] [180ms] Loading core-model
2016-04-16 15:40:25,102 INFO [main] [ConsoleStatus] [13/32] [49645ms] [32ms] Loading core-object-defaults
2016-04-16 15:40:25,132 INFO [main] [ConsoleStatus] [14/32] [49675ms] [30ms] Loading encryption
2016-04-16 15:40:26,837 INFO [main] [ConsoleStatus] [15/32] [51380ms] [1705ms] Loading process
2016-04-16 15:40:26,869 INFO [main] [ConsoleStatus] [16/32] [51412ms] [32ms] Loading redis
2016-04-16 15:40:26,909 INFO [main] [ConsoleStatus] [17/32] [51452ms] [40ms] Starting bootstrap
2016-04-16 15:40:26,909 INFO [main] [ConsoleStatus] [18/32] [51452ms] [0ms] Starting config-defaults
2016-04-16 15:40:26,909 INFO [main] [ConsoleStatus] [19/32] [51452ms] [0ms] Starting system
2016-04-16 15:40:26,909 INFO [main] [ConsoleStatus] [20/32] [51452ms] [0ms] Starting defaults
2016-04-16 15:40:26,909 INFO [main] [ConsoleStatus] [21/32] [51452ms] [0ms] Starting types
2016-04-16 15:40:43,110 INFO [main] [ConsoleStatus] [22/32] [67653ms] [16201ms] Starting system-services
2016-04-16 15:40:43,110 INFO [main] [ConsoleStatus] [23/32] [67653ms] [0ms] Starting agent-server
2016-04-16 15:40:43,110 INFO [main] [ConsoleStatus] [24/32] [67653ms] [0ms] Starting allocator-server
2016-04-16 15:40:48,401 INFO [main] [ConsoleStatus] [25/32] [72944ms] [5291ms] Starting api-server
2016-04-16 15:40:49,451 INFO [main] [ConsoleStatus] [26/32] [73994ms] [1050ms] Starting iaas-api
2016-04-16 15:40:49,451 INFO [main] [ConsoleStatus] [27/32] [73994ms] [0ms] Starting archaius
2016-04-16 15:40:49,451 INFO [main] [ConsoleStatus] [28/32] [73994ms] [0ms] Starting core-model
2016-04-16 15:40:49,451 INFO [main] [ConsoleStatus] [29/32] [73994ms] [0ms] Starting core-object-defaults
2016-04-16 15:40:49,451 INFO [main] [ConsoleStatus] [30/32] [73994ms] [0ms] Starting encryption
2016-04-16 15:40:49,455 INFO [main] [ConsoleStatus] [31/32] [73998ms] [4ms] Starting process
2016-04-16 15:40:49,455 INFO [main] [ConsoleStatus] [32/32] [73998ms] [0ms] Starting redis
15:40:49.565 [main] INFO ConsoleStatus - [DONE ] [77190ms] Startup Succeeded, Listening on port 8081
time="2016-04-16T15:40:50Z" level=info msg="Starting websocket proxy. Listening on [:8080], Proxying to cattle API at [localhost:8081], Monitoring parent pid [10]."
time="2016-04-16T15:40:50Z" level=info msg="Downloading certificate from http://localhost:8081/v1/credentials/1c1/certificate"
time="2016-04-16T15:40:51Z" level=info msg="Starting Rancher Catalog service"
time="2016-04-16T15:40:51Z" level=info msg="Using catalog library=https://github.com/rancher/rancher-catalog.git"
time="2016-04-16T15:40:51Z" level=info msg="Using catalog community=https://github.com/rancher/community-catalog.git"
time="2016-04-16T15:40:51Z" level=info msg="Starting rancher-compose-executor" version=v0.7.4
time="2016-04-16T15:40:51Z" level=info msg="Setting log level" logLevel=info
time="2016-04-16T15:40:51Z" level=info msg="Starting go-machine-service..." gitcommit=dc97268
time="2016-04-16T15:40:51Z" level=info msg="Updating docker-machine-drivers from cattle."
time="2016-04-16T15:40:52Z" level=info msg="Initializing event router" workerCount=10
time="2016-04-16T15:40:52Z" level=info msg="Connection established"
Rancher Server 基本配置
防火墙开启允许8888端口的访问
[root@rancher-server]iptables -A INPUT -p tcp --dport 8888 -j ACCEPT
[root@rancher-server]service iptables save
浏览器访问Rancher UI
http://your-host:8888
设置本地用户验证
这里选择LOCAL即本地
添加HOST
[root@rancher-server]/# sudo docker run -d --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v1.0.1 http://192.168.2.22:8888/v1/scripts/F1D894A3C1468D289857:1460822400000:ohuf27vXvxwhVOEXHhW9Q5u5w04
1067bc91240a837fa2e6260458273f7f6897a50aaa812265bb7cd9df4ee41a79
稍等几分钟Host就会出现在HOSTS里面
来源:oschina
链接:https://my.oschina.net/u/1767904/blog/661271