设为首页 收藏本站
查看: 583|回复: 0

[经验分享] Docker与OpenStack集成实战

[复制链接]

尚未签到

发表于 2018-5-29 07:42:58 | 显示全部楼层 |阅读模式
  1、计算节点安装Docker
  root@compute2: ~# apt install docker.io -y
  或
  root@compute2:~# sh -c "echo deb https://get.docker.io/ubuntu docker main >> /etc/apt/sources.list.d/docker.list"
  root@compute2:~# apt-get update
  root@compute2:~# apt-get install lxc-docker
  root@compute2: ~# apt install docker.io -y
  查看当前版本
  root@compute2:/var/lib/docker# docker --version
  Docker version 1.12.0, build 8eab29e
  root@compute2:~# docker -v
  Docker version 1.12.0, build 8eab29e
  root@compute2:~# dpkg -l | grep docker
  rc  docker.io                                  1.11.2-0ubuntu5~16.04                                       amd64        Linux container runtime
  ii  lxc-docker                                 1.9.1                                                       amd64        Linux container runtime
  ii  lxc-docker-1.9.1                           1.9.1                                                       amd64        Linux container runtime
  查找镜像
  root@compute2:~# docker search ubuntu
  dorapro/ubuntu                    ubuntu image                                    0                    [OK]
  konstruktoid/ubuntu               Ubuntu base image                               0                    [OK]
  uvatbc/ubuntu                     Ubuntu images with unprivileged user            0                    [OK]
  2、下载Ubuntu镜像
  root@compute2: ~#  docker pull ubuntu
  Using default tag: latest
  latest: Pulling from library/ubuntu
  2f0243478e1f: Pull complete
  d8909ae88469: Pull complete
  820f09abed29: Pull complete
  01193a8f3d88: Pull complete
  Digest: sha256:8e2324f2288c26e1393b63e680ee7844202391414dbd48497e9a4fd997cd3cbf
  Status: Downloaded newer image for ubuntu:latest
  root@compute2:~# docker images -a
  REPOSITORY                 TAG                 IMAGE ID            CREATED             SIZE
  ubuntu                     latest              bd3d4369aebc        12 days ago         126.6 MB
  ubuntu-1604-sleepy_kilby   latest              94c88d9d0023        3 weeks ago         126.4 MB
  ubuntu                     <none>              f8d79ba03c00        3 weeks ago         126.4 MB
  cmer81/centos7-openstack   latest              3317e0f4e0fb        7 months ago        322.2 MB
  3、启动并登录Docker容器
  root@compute2:~# docker run -i -t ubuntu
  root@c0a0294d98d2:/# cat /etc/issue
  Ubuntu 16.04.1 LTS \n \l
  给容器设置root密码
  [root@dfbc7c3db16b /]# passwd root
  Changing password for user root.
  New password:
  Retype new password:
  passwd: all authentication tokens updated successfully.
  设置允许root密码登录
  [root@dfbc7c3db16b /]# vi /etc/ssh/sshd_config
  PermitRootLogin yes
  PasswordAuthentication yes
  SSH到容器中
  root@compute2:~# ssh 172.17.0.3
  root@172.17.0.3's password:
  [root@dfbc7c3db16b ~]#
  [root@dfbc7c3db16b ~]#
  [root@dfbc7c3db16b ~]#
  [root@dfbc7c3db16b ~]# ifconfig
  eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
          inet 172.17.0.3  netmask 255.255.0.0  broadcast 0.0.0.0
          inet6 fe80::42:acff:fe11:3  prefixlen 64  scopeid 0x20<link>
          ether 02:42:ac:11:00:03  txqueuelen 0  (Ethernet)
          RX packets 434  bytes 52434 (51.2 KiB)
          RX errors 0  dropped 0  overruns 0  frame 0
          TX packets 419  bytes 42782 (41.7 KiB)
          TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
          inet 127.0.0.1  netmask 255.0.0.0
          inet6 ::1  prefixlen 128  scopeid 0x10<host>
          loop  txqueuelen 1  (Local Loopback)
          RX packets 0  bytes 0 (0.0 B)
          RX errors 0  dropped 0  overruns 0  frame 0
          TX packets 0  bytes 0 (0.0 B)
          TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  [root@dfbc7c3db16b ~]#
  退出Docker容器
  root@76da79f898c3:/# exit
  exit
  4、在另一个docker主机查看目前运行的docker进程的ID
  root@compute2:~# docker ps -a
  CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                        PORTS               NAMES
  a8ffa3d75d46        ubuntu              "/bin/bash"         51 seconds ago      Exited (127) 42 seconds ago                       sleepy_kilby
  aee77e7dec7b        ubuntu              "/bin/bash"         2 minutes ago       Exited (0) 53 seconds ago                         compassionate_hodgkin
  c0a0294d98d2        ubuntu              "/bin/bash"         47 minutes ago      Exited (127) 38 minutes ago                       ecstatic_ritchie
  5、将镜像保存为
  root@compute2:~# docker commit a8ffa3d75d46 ubuntu-1604-sleepy_kilby
  sha256:94c88d9d002364ed5b405357f6910fbc6fdddda917a07f99933a65e66e74fe99
  6、将此镜像打包成一个文件
  root@compute2:~# docker save ubuntu-1604-sleepy_kilby > /root/ubuntu-1604.tar
  7、从终端直接启动容器
  root@compute2:~# docker run -i -t -p 50001:22 ubuntu-1604-sleepy_kilby /bin/bash
  nova-docker方案实践
  安装novadocker
  python-pip 有一个BUG,如果已安装python-pip,先删除,
  root@compute2:~# apt-get remove python-pip
  root@compute2:~#apt-get autoremove
  root@compute2:~# easy_install -U pip
  root@compute2:~# pip install -e git+https://github.com/stackforge/nova-docker#egg=novadocker
  root@compute2:~# cd src/novadocker/
  root@compute2:~/src/novadocker# python setup.py install
  配置NOVA
  root@compute2:~# vim /etc/nova/nova.conf
  [DEFAULT]
  compute_driver = novadocker.virt.docker.DockerDriver
  创建/etc/nova/rootwrap.d/dockers.filters
  # nova-rootwrap command filters for setting up network in the docker driver
  # This file should be owned by (and only-writeable by) the root user
  [Filters]
  # nova/virt/docker/driver.py: 'ln', '-sf', '/var/run/netns/.*'
  ln: CommandFilter, /bin/ln, root
  配置Glance
  root@controller:/etc/glance# vim glance-api.conf
  [DEFAULT]
  container_formats = ami,ari,aki,bare,ovf,docker
  下载Docker镜像
  查找适用于OpenStack的镜像
  root@compute2:~# docker search openstack
  NAME                                 DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
  krystism/openstack-keystone          An easy way to try openstack keystone service   7                    [OK]
  continuse/openstack-controller       OpenStack Controller Service for CoreOS         5                    [OK]
  centurylink/openstack-cli-wetty      This image provides a Wetty terminal with ...   4                    [OK]
  cmer81/centos7-openstack             Centos7 image for openstack-cloudinit           2                    [OK]
  continuse/openstack-nova-docker      OpenStack Nova-Docker Service for CoreOS        2                    [OK]
  cosmicq/openstack-nova               (project not complete) The Nova (compute) ...   1                    [OK]
  cosmicq/openstack-rabbitmq           (project not complete) RabbitMQ (AMQP) ser...   1                    [OK]
  ennweb/openstack-controller          OpenStack Controller                            1                    [OK]
  cosmicq/openstack-keystone           (project not complete) The Keystone (authe...   1                    [OK]
  cosmicq/openstack-mariadb            (project not complete) MariaDB and PHPMyAd...   1                    [OK]
  continuse/openstack-network          OpenStack Network (Neutron) Service for Co...   1                    [OK]
  continuse/openstack-compute          OpenStack Compute Service for CoreOS            1                    [OK]
  krystism/openstack-glance            An easy way to try openstack glance service     1                    [OK]
  factual/docker-openstack-database    OpenStack Database (MariaDB)                    1                    [OK]
  pataquets/openstack-dashboard                                                        0                    [OK]
  colstrom/openstack-cli               OpenStack CLI                                   0                    [OK]
  continuse/openstack-cinder           OpenStack Block Storage Service for CoreOS      0                    [OK]
  alvaroaleman/openstack-horizon       A simple Docker image for the Openstack Ho...   0                    [OK]
  pataquets/openstack-keystone                                                         0                    [OK]
  pierrezemb/exherbo-openstack         Exherbo image generator for OpenStack           0                    [OK]
  factual/docker-openstack-messaging   OpenStack Messaging service (RabbitMQ)          0                    [OK]
  ennweb/openstack-compute             OpenStack Compute on Docker                     0                    [OK]
  anguslees/openstack-tox                                                              0                    [OK]
  gbraad/openstack-client              Container with the OpenStack client and 's...   0                    [OK]
  jmcvea/openstack-client              OpenStack command line tools                    0                    [OK]
  root@compute2:~#
  root@compute2:~# docker pull cmer81/centos7-openstack
  Using default tag: latest
  latest: Pulling from cmer81/centos7-openstack
  a3ed95caeb02: Pull complete
  3286cdf780ef: Pull complete
  889e0983d8b8: Pull complete
  48ed448d00d6: Pull complete
  0ebb5fe0f8ad: Pull complete
  c93dc6f68ef1: Pull complete
  cf8e344e8663: Pull complete
  9827381c9ae3: Pull complete
  8f1f6b35ea96: Pull complete
  Digest: sha256:84b374fe2a8bf40a8716d79e5ea179b2fb28352e8a18fa49ddda2ab295bebe6e
  Status: Downloaded newer image for cmer81/centos7-openstack:latest
  root@compute2:~# docker save cmer81/centos7-openstack | glance --os-image-api-version 1 image-create --is-public=True --container-format=docker --disk-format=raw --name cmer81/centos7-openstack
  +------------------+--------------------------------------+
  | Property         | Value                                |
  +------------------+--------------------------------------+
  | checksum         | 114c19e55638a317b837ae73f6c8314c     |
  | container_format | docker                               |
  | created_at       | 2016-08-17T03:03:22.000000           |
  | deleted          | False                                |
  | deleted_at       | None                                 |
  | disk_format      | raw                                  |
  | id               | 521f5a87-22cc-4851-a812-dee1b17b5e46 |
  | is_public        | True                                 |
  | min_disk         | 0                                    |
  | min_ram          | 0                                    |
  | name             | cmer81/centos7-openstack             |
  | owner            | f9027cccf7da4f2399c7fdf32e8776f0     |
  | protected        | False                                |
  | size             | 334179328                            |
  | status           | active                               |
  | updated_at       | 2016-08-17T03:03:28.000000           |
  | virtual_size     | None                                 |
  +------------------+--------------------------------------+
  查找ubuntu镜像
  root@compute2:~# docker search ubuntu
  NAME                              DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
  ubuntu                            Ubuntu is a Debian-based Linux operating s...   4468      [OK]      
  ubuntu-upstart                    Upstart is an event-based replacement for ...   65        [OK]      
  rastasheep/ubuntu-sshd            Dockerized SSH service, built on top of of...   31                   [OK]
  torusware/speedus-ubuntu          Always updated official Ubuntu docker imag...   27                   [OK]
  ubuntu-debootstrap                debootstrap --variant=minbase --components...   25        [OK]      
  nickistre/ubuntu-lamp             LAMP server on Ubuntu                           8                    [OK]
  nuagebec/ubuntu                   Simple always updated Ubuntu docker images...   7                    [OK]
  nickistre/ubuntu-lamp-wordpress   LAMP on Ubuntu with wp-cli installed            6                    [OK]
  nimmis/ubuntu                     This is a docker images different LTS vers...   5                    [OK]
  jordi/ubuntu                      Ubuntu Base Image                               1                    [OK]
  admiringworm/ubuntu               Base ubuntu images based on the official u...   1                    [OK]
  seetheprogress/ubuntu             Ubuntu image provided by seetheprogress us...   1                    [OK]
  darksheer/ubuntu                  Base Ubuntu Image -- Updated hourly             1                    [OK]
  life360/ubuntu                    Ubuntu is a Debian-based Linux operating s...   0                    [OK]
  datenbetrieb/ubuntu               custom flavor of the official ubuntu base ...   0                    [OK]
  konstruktoid/ubuntu               Ubuntu base image                               0                    [OK]
  lynxtp/ubuntu                     https://github.com/lynxtp/docker-ubuntu         0                    [OK]
  esycat/ubuntu                     Ubuntu LTS                                      0                    [OK]
  widerplan/ubuntu                  Our basic Ubuntu images.                        0                    [OK]
  croscon/ubuntu                    Crosconized Ubuntu                              0                    [OK]
  teamrock/ubuntu                   TeamRock's Ubuntu image configured with AW...   0                    [OK]
  smartentry/ubuntu                 ubuntu with smartentry                          0                    [OK]
  ustclug/ubuntu                    ubuntu image for docker with USTC mirror        0                    [OK]
  dorapro/ubuntu                    ubuntu image                                    0                    [OK]
  webhippie/ubuntu                  Docker images for ubuntu                        0                    [OK]
  下载镜像
  root@compute2:~# docker pull ubuntu
  Using default tag: latest
  latest: Pulling from library/ubuntu
  Digest: sha256:8e2324f2288c26e1393b63e680ee7844202391414dbd48497e9a4fd997cd3cbf
  Status: Image is up to date for ubuntu:latest
  把镜像上传到Glance中
  root@compute2:~# docker save ubuntu | glance image-create --container-format=docker --disk-format=raw --name ubuntu-docer
  +------------------+--------------------------------------+
  | Property         | Value                                |
  +------------------+--------------------------------------+
  | checksum         | 364a6b81f4a3f5fb5c4a0e1d62395322     |
  | container_format | docker                               |
  | created_at       | 2016-08-17T02:46:58Z                 |
  | disk_format      | raw                                  |
  | id               | e2616723-b55d-48a6-9548-606f0da7dddb |
  | min_disk         | 0                                    |
  | min_ram          | 0                                    |
  | name             | ubuntu-docer                         |
  | owner            | f9027cccf7da4f2399c7fdf32e8776f0     |
  | protected        | False                                |
  | size             | 132096512                            |
  | status           | active                               |
  | tags             | []                                   |
  | updated_at       | 2016-08-17T02:46:59Z                 |
  | virtual_size     | None                                 |
  | visibility       | private                              |
  +------------------+--------------------------------------+
  、
  root@compute2:~# nova image-list
  +--------------------------------------+-----------------------------------------+--------+--------+
  | ID                                   | Name                                    | Status | Server |
  +--------------------------------------+-----------------------------------------+--------+--------+
  | 96872d33-73a1-4e1d-bc9e-5b4206a258af | CentOS-7-x86_64-GenericCloud            | ACTIVE |        |
  | c8d224af-b3ed-42be-a29b-ea7295abf932 | Ubuntu16.04-server-clouding-powerpc64el | ACTIVE |        |
  | e9b86672-f9d2-48f3-b57f-0320fc4a048f | Ubuntu16.04-xenial-server-cloud-amd64   | ACTIVE |        |
  | 521f5a87-22cc-4851-a812-dee1b17b5e46 | cmer81/centos7-openstack                | ACTIVE |        |
  | e2616723-b55d-48a6-9548-606f0da7dddb | ubuntu-docer                            | ACTIVE |        |
  | ba5c1506-4389-42b5-acfb-849855b019b5 | ubuntu-server-clouding-amd64            | ACTIVE |        |
  | b2170c9b-41da-4b55-a4ec-88b8b3fc528e | ubuntu1604-server-cloud-ppc64el         | ACTIVE |        |
  | c94a41f5-10b2-43f8-ae5d-1c91886f6f94 | windows2012server-clouding              | ACTIVE |        |
  +--------------------------------------+-----------------------------------------+--------+--------+
  root@compute2:~# nova boot centos7-openstack --image 521f5a87-22cc-4851-a812-dee1b17b5e46 --nic net-id=a969f82e-b4cc-48cf-a04a-64923dc73b4a --flavor 22 --security-groups default --key key
  +--------------------------------------+-----------------------------------------------------------------+
  | Property                             | Value                                                           |
  +--------------------------------------+-----------------------------------------------------------------+
  | OS-DCF:diskConfig                    | MANUAL                                                          |
  | OS-EXT-AZ:availability_zone          |                                                                 |
  | OS-EXT-SRV-ATTR:host                 | -                                                               |
  | OS-EXT-SRV-ATTR:hostname             | centos7-openstack                                               |
  | OS-EXT-SRV-ATTR:hypervisor_hostname  | -                                                               |
  | OS-EXT-SRV-ATTR:instance_name        | instance-0000070f                                               |
  | OS-EXT-SRV-ATTR:kernel_id            |                                                                 |
  | OS-EXT-SRV-ATTR:launch_index         | 0                                                               |
  | OS-EXT-SRV-ATTR:ramdisk_id           |                                                                 |
  | OS-EXT-SRV-ATTR:reservation_id       | r-3euaomoc                                                      |
  | OS-EXT-SRV-ATTR:root_device_name     | -                                                               |
  | OS-EXT-SRV-ATTR:user_data            | -                                                               |
  | OS-EXT-STS:power_state               | 0                                                               |
  | OS-EXT-STS:task_state                | scheduling                                                      |
  | OS-EXT-STS:vm_state                  | building                                                        |
  | OS-SRV-USG:launched_at               | -                                                               |
  | OS-SRV-USG:terminated_at             | -                                                               |
  | accessIPv4                           |                                                                 |
  | accessIPv6                           |                                                                 |
  | adminPass                            | KjbkCzV8VVn2                                                    |
  | config_drive                         |                                                                 |
  | created                              | 2016-08-17T03:23:21Z                                            |
  | description                          | -                                                               |
  | flavor                               | zoom.medium (22)                                                |
  | hostId                               |                                                                 |
  | host_status                          |                                                                 |
  | id                                   | 41dad309-eb1a-4445-b1eb-81b87cd34d97                            |
  | image                                | cmer81/centos7-openstack (521f5a87-22cc-4851-a812-dee1b17b5e46) |
  | key_name                             | key                                                             |
  | locked                               | False                                                           |
  | metadata                             | {}                                                              |
  | name                                 | centos7-openstack                                               |
  | os-extended-volumes:volumes_attached | []                                                              |
  | progress                             | 0                                                               |
  | security_groups                      | default                                                         |
  | status                               | BUILD                                                           |
  | tenant_id                            | f9027cccf7da4f2399c7fdf32e8776f0                                |
  | updated                              | 2016-08-17T03:23:21Z                                            |
  | user_id                              | 957ba591d7824e0ab6e54d5c40e6be85                                |
  +--------------------------------------+-----------------------------------------------------------------+
  root@compute2:~# nova list
  +--------------------------------------+-------------------+--------+------------+-------------+-----------------------------------+
  | ID                                   | Name              | Status | Task State | Power State | Networks                          |
  +--------------------------------------+-------------------+--------+------------+-------------+-----------------------------------+
  | 41dad309-eb1a-4445-b1eb-81b87cd34d97 | centos7-openstack | ACTIVE | -          | Running     | private=10.1.1.80, 10.1.1.78      |
  | 4f6c62b0-3917-4a4c-a017-bc57ff1a7e4d | ubuntu            | ACTIVE | -          | Running     | private=10.1.1.46
  
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-482340-1-1.html 上篇帖子: docker 配置Btrfs和Device mapper存储驱动设置 下篇帖子: Docker之cgroup篇
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表