叫板OpenStack:八步用Docker实现私有云
【 资讯】看到各大厂商的云主机,会不会觉得高大上?目前大公司的主流方案是OpenStack,比如某个公司的私有云。 其实,我们可以通过Docker可以很容易实现自己的私有云。 下面进入正题。 假设你所在的公司拥有一台功能强悍的服务器,假设是centos,但开发人员,测试人员如果都在这一台主机上进行开发,测试,后果是灾难性的,但由于只有一 台服务器,你们老板甚至还想把这剩余的性能榨取出来搭建一些服务卖给大众...以往的话,开发,测试人员肯定要摔键盘了,这不是坑爹么?但如果你会 Docker,就能很容易实现这一目标,升职加薪,当上总经理,出任CEO,赢取白富美,迎来人生的巅峰呢! 是不是有点小激动了?来吧,哥教你怎么做。 一.升级Centos内核 官方推荐内核使用3.8以上,那我们升到长期稳定版的3.10.
二.安装docker [root@iZ2893wjzgyZ ~]# yum install http://mirrors.yun-idc.com/epel/6/x86_64/epel-release-6-8.noarch.rpm [root@iZ2893wjzgyZ ~]# yum install docker-io 三.启动docker [root@iZ2893wjzgyZ ~]# service docker start Starting cgconfig service: [ OK ] Starting docker: [ OK ] 四.获取镜像 由于镜像仓库在国内,国内慢的令人发指,推荐有import方式使用镜像(此例采用的此种镜像方案可以很容易安装ssh服务),在http://openvz.org/Download/templates/precreated中有很多压缩的镜像文件,可以将这些文件下载后采用import方式使用镜像 # wget http://download.openvz.org/template/precreated/ubuntu-14.04-x86_64-minimal.tar.gz # cat ubuntu-14.04-x86_64-minimal.tar.gz|docker import - ubuntu:14.04 # docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE ubuntu 14.0405ac7c0b938317 seconds ago 215.5 MB 这样我们就可以使用这个镜像作为自己的Base镜像 五.实现sshd,在Base镜像基础上生成一个新镜像 #docker run -t -i ubuntu:base /bin/bash root@050f6efc5ed6:/# vim /etc/apt/sources.list deb http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse root@050f6efc5ed6:/# apt-get update 安装supervisor服务 root@050f6efc5ed6:/# apt-get supervisor root@050f6efc5ed6:/# cp supervisord.conf conf.d/ root@050f6efc5ed6:/# cd conf.d/ root@050f6efc5ed6:/# vi supervisord.conf ; supervisor config file [unix_http_server] file=/var/run/supervisor.sock ; (the path to the socket file) chmod=0700 ; sockef file mode (default 0700) [supervisord] logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log) pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid) childlogdir=/var/log/supervisor ; ('AUTO' child log dir, default $TEMP) nodaemon=true ;(修改该软件的启动模式为非daemon,否则docker 在执行的时候会直接退出) [include] files = /etc/supervisor/conf.d/*.conf [program:sshd] command = /usr/sbin/sshd -D ; root@050f6efc5ed6:/# mkdir /var/run/sshd root@050f6efc5ed6:/# passwd root root@050f6efc5ed6:/# vi /etc/ssh/sshd_config root@050f6efc5ed6:/# exit 退出之后自动生成一个容器,接下来把容器commit生成封装了sshd的镜像 # docker commit f3c8 ubuntu 5c21b6cf7ab3f60693f9b6746a5ec0d173fd484462b2eb0b23ecd2692b1aff6b [root@iZ2893wjzgyZ tmp]# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE ubuntu sshd 02c4391d40a0 47 minutes ago 661.4 MB 六.开始分配容器 [root@iZ2893wjzgyZ tmp]# docker run -p 301:22 -d --name test ubuntu /usr/bin/supervisord [root@iZ2893wjzgyZ tmp]# docker run -p 302:22 -d --name dev ubuntu /usr/bin/supervisord [root@iZ2893wjzgyZ tmp]# docker run -p 303:22 -d --name client1 ubuntu /usr/bin/supervisord ....... [root@iZ2893wjzgyZ tmp]# docker run -p xxxxx:22 -d --name clientN ubuntu /usr/bin/supervisord (编辑:PHP编程网 - 黄冈站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |