vmware 扩展分区大小

add.png测试中遇到这样的情况,vmware虚拟机中增加的 sdb ,可用空间快要满了,需要增加空间,方法记录如下

  1. 在VMware上扩展磁盘
    在 vmware 虚拟机编辑页面,扩展磁盘的可用空间 (500GB -> 800GB)
    image

  2. 重启虚拟机
    重启后查看分区是否正确识别,可以看到已经正确识别新的分区大小

    # parted /dev/sdb
    GNU Parted 3.1
    Using /dev/sdb
    Welcome to GNU Parted! Type 'help' to view a list of commands.
    (parted) p
    Model: VMware Virtual disk (scsi)
    Disk /dev/sdb: 859GB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    Disk Flags: 
    
    Number  Start   End    Size   Type     File system  Flags
    1      1049kB  537GB  537GB  primary  xfs
    
    (parted) quit
  3. 重新分区
    删除原来分区,重新创建新的分区

    # fdisk /dev/sdb
    Welcome to fdisk (util-linux 2.23.2).
    
    Changes will remain in memory only, until you decide to write them.
    Be careful before using the write command.
    
    Command (m for help): p
    
    Disk /dev/sdb: 859.0 GB, 858993459200 bytes, 1677721600 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk label type: dos
    Disk identifier: 0x634e8675
    
    Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1            2048  1048575999   524286976   83  Linux
    
    Command (m for help): d                     # 删除分区
    Selected partition 1
    Partition 1 is deleted
    
    Command (m for help): n                     # 创建新的分区
    Partition type:
     p   primary (0 primary, 0 extended, 4 free)
     e   extended
    Select (default p): 
    Using default response p
    Partition number (1-4, default 1): 
    First sector (2048-1677721599, default 2048): 
    Using default value 2048
    Last sector, +sectors or +size{K,M,G} (2048-1677721599, default 1677721599): 
    Using default value 1677721599
    Partition 1 of type Linux and of size 800 GiB is set
    
    Command (m for help): w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    
    WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
    The kernel still uses the old table. The new table will be used at
    the next reboot or after you run partprobe(8) or kpartx(8)
    Syncing disks.
  4. 重启系统,确保分区表被重新读取

  5. 扩展分区
    首先 mount 新分区,然后使用 xfs_growfs 命令扩展分区

    # mount /dev/sdb1 /opt/yum/sample
    # xfs_growfs /dev/sdb1
    meta-data=/dev/sdb1              isize=512    agcount=4, agsize=32767936 blks
           =                       sectsz=512   attr=2, projid32bit=1
           =                       crc=1        finobt=0 spinodes=0
    data     =                       bsize=4096   blocks=131071744, imaxpct=25
           =                       sunit=0      swidth=0 blks
    naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
    log      =internal               bsize=4096   blocks=63999, version=2
           =                       sectsz=512   sunit=0 blks, lazy-count=1
    realtime =none                   extsz=4096   blocks=0, rtextents=0
    data blocks changed from 131071744 to 209714944
    
    #如果分区是 ext4 格式需要使用 resize2fs 命令
  6. 验证操作
    新分区的大小已经变为800G,原来的文件也没有丢失

    # df -h
    Filesystem               Size  Used Avail Use% Mounted on
    ……
    /dev/sdb1                800G  433G  368G  55% /opt/yum/sample

centos制作本地源

  1. 列出所有源

    # yum repolist
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    * base: mirrors.aliyun.com
    * extras: mirrors.aliyun.com
    * updates: mirrors.aliyun.com
    repo id repo name status
    base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 9,363
    epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 11,135
    extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 263
    openstack-mitaka/7/x86_64 OpenStack Newton Repository 1,675
    openstack-newton/7/x86_64 OpenStack Newton Repository 1,486
    updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 807
    repolist: 24,729
  2. 同步源(以openstack-newton为例)

    # yum install yum-utils -y #安装同步工具
    # mkdir -p /opt/yum #同步目录
    # reposync -d -r openstack-newton -p /opt/yum/ #开始同步,其他参数可以查看help
  3. 创建本地源(生成元数据文件)

    # yum install createrepo -y #安装工具
    # createrepo -v /opt/yum/openstack-newton/
  4. 安装http服务,配置本地源
  • 安装apache服务并设置开机自启

    # yum install httpd -y
    # systemctl enable httpd.service
  • 修改http默认目录

    # vim /etc/httpd/conf/httpd.conf
    
    DocumentRoot "/opt/yum"  #修改此处
    #
    # Relax access to content within /var/www.
    #
    <Directory "/opt"> #修改此处
    AllowOverride None
    # Allow open access:
    Require all granted
    
    # Further relax access to the default document root:
    <Directory "/opt/yum/"> #修改此处
  • 重启httpd

    # systemctl restart httpd.service

解决lenove e450c安装centos7无线网卡(RTL8723BE)无法使用

1. 查询无线网卡型号

# /sbin/lspci | grep Network
04:00.0 Network controller: Realtek Semiconductor Co., Ltd. RTL8723BE PCIe Wireless Network Adapter

2. 查找驱动

github上有个项目提供Realtek的无线网卡驱动 https://github.com/lwfinger/rtlwifi_new 但是编译报错,查询得知需要3.12以上内核,而centos7 自带的内核是3.10

3. 安装 elrepo.org 中的驱动

升级内核时,发现 elrepo.org 中提供 RTL8723BE 的驱动,下载安装,重启成功识别无线网卡

# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
# yum install kmod-rtl8723be.x86_64
# reboot

使用kolla快速部署openstack all-in-one环境

kolla项目是为了容器化openstack,目标是做到100个节点的开箱即用,所有的组件的HA都具备。kolla是一个革命性的项目,我们以前积累的安装部署经验,全部都报废。使用kolla可以快速部署可扩展,可靠的生产就绪的openstack环境。

基本环境

操作系统:CentOS Linux release 7.2.1511 (Core)
内核版本:3.10.0-327.28.3.el7.x86_64
docker版本:Docker version 1.12.1, build 23cf638

部署kolla

  1. 安装依赖

    yum install epel-release python-pip
    yum install -y python-devel libffi-devel openssl-devel gcc
    pip install -U pip
  2. 修改docker启动文件

    # Create the drop-in unit directory for docker.service
    mkdir -p /etc/systemd/system/docker.service.d
    
    # Create the drop-in unit file
    tee /etc/systemd/system/docker.service.d/kolla.conf &lt;&lt;-'EOF'
    [Service]
    MountFlags=shared
    EOF
  3. 重启docker

    systemctl daemon-reload
    systemctl restart docker
  4. 安装docker的python库

    shellyum install python-docker-py
    or
    pip install -U docker-py
  5. 配置时间同步(此处略)
  6. 禁用libvirt

    systemctl stop libvirtd.service
    systemctl disable libvirtd.service
  7. 安装ansible
    这里需要注意的是如果安装stable版的kolla需要Ansible < 2.0,master版需要Ansible > 2.0。默认yum安装ansible版本>2.0,因为我要安装stable/mitaka版,所有指定安装版本。

    pip install -U ansible==1.9.4
  8. 安装stable版kolla
  • 下载源码

    git clone https://git.openstack.org/openstack/kolla -b stable/mitaka
  • 安装依赖

    pip install -r kolla/requirements.txt -r kolla/test-requirements.txt
  • 源码安装

    pip install kolla/
  1. 安装tox,生成配置文件

    pip install -U tox
    cd kolla/
    tox -e genconfig
    cp -rv etc/kolla /etc/
  2. 安装python client

    yum install python-openstackclient python-neutronclient
  3. 本地docker仓库
    all-in-one环境中本地仓库不是必须的这里没有配置

编译镜像

kolla-build

更多的编译选项可以参看:Building Container Images
如果个别镜像编译失败可以重新执行以上操作,因为docker的容器缓存,重新编译会很快
编译成功后生成的镜像如下所示:

# docker images
REPOSITORY                                      TAG                 IMAGE ID            CREATED             SIZE
kolla/centos-binary-heat-engine                 2.0.3               28956cc878d3        20 hours ago        571.4 MB
kolla/centos-binary-heat-api-cfn                2.0.3               d69858fd13fa        20 hours ago        571.4 MB
kolla/centos-binary-heat-api                    2.0.3               90a92ca6b71a        20 hours ago        571.4 MB
kolla/centos-binary-heat-base                   2.0.3               8f1cf8a1f536        21 hours ago        551.6 MB
kolla/centos-binary-neutron-openvswitch-agent   2.0.3               e7d0233ca541        21 hours ago        822.3 MB
kolla/centos-binary-neutron-base                2.0.3               8767569ca9b3        21 hours ago        796.7 MB
kolla/centos-binary-openvswitch-vswitchd        2.0.3               6867586ae335        21 hours ago        330.6 MB
kolla/centos-binary-openvswitch-db-server       2.0.3               3c692f316662        21 hours ago        330.6 MB
kolla/centos-binary-openvswitch-base            2.0.3               c3a263463f8f        21 hours ago        330.6 MB
kolla/centos-binary-cron                        2.0.3               d16d53e85ed9        26 hours ago        317.5 MB
kolla/centos-binary-kolla-toolbox               2.0.3               1fd9634b88ee        26 hours ago        568.4 MB
kolla/centos-binary-heka                        2.0.3               627a3de5e91c        26 hours ago        371.1 MB
kolla/centos-binary-neutron-metadata-agent      2.0.3               aad43ed7a5a1        42 hours ago        796.7 MB
kolla/centos-binary-neutron-server              2.0.3               bc1a7c0ec402        42 hours ago        796.7 MB
kolla/centos-binary-nova-compute                2.0.3               619344ac721b        42 hours ago        1.055 GB
kolla/centos-binary-nova-libvirt                2.0.3               6144729fff5f        42 hours ago        1.106 GB
kolla/centos-binary-neutron-linuxbridge-agent   2.0.3               720c9c5fa63d        42 hours ago        822 MB
kolla/centos-binary-neutron-l3-agent            2.0.3               3a82df7cb9c2        42 hours ago        796.7 MB
kolla/centos-binary-glance-api                  2.0.3               fb67115357d5        42 hours ago        673.8 MB
kolla/centos-binary-neutron-dhcp-agent          2.0.3               8c6fa56497ca        42 hours ago        796.7 MB
kolla/centos-binary-nova-compute-ironic         2.0.3               6f235dc430e5        43 hours ago        1.019 GB
kolla/centos-binary-glance-registry             2.0.3               f4cf7bc1536f        43 hours ago        673.8 MB
kolla/centos-binary-cinder-volume               2.0.3               0197cc13468d        43 hours ago        788.4 MB
kolla/centos-binary-cinder-api                  2.0.3               ed7c623e7364        43 hours ago        800.4 MB
kolla/centos-binary-cinder-rpcbind              2.0.3               75466dc5a3ba        43 hours ago        790.2 MB
kolla/centos-binary-horizon                     2.0.3               92c7ea9fc493        43 hours ago        703.1 MB
kolla/centos-binary-cinder-backup               2.0.3               e3ee19440831        43 hours ago        761.3 MB
kolla/centos-binary-cinder-scheduler            2.0.3               e3ee19440831        43 hours ago        761.3 MB
kolla/centos-binary-nova-consoleauth            2.0.3               96a9638801cd        43 hours ago        609.6 MB
kolla/centos-binary-nova-api                    2.0.3               eff73f704a90        43 hours ago        609.4 MB
kolla/centos-binary-nova-conductor              2.0.3               6016ae01a60d        43 hours ago        609.4 MB
kolla/centos-binary-nova-scheduler              2.0.3               726f100a5533        43 hours ago        609.4 MB
kolla/centos-binary-nova-spicehtml5proxy        2.0.3               c6a1a49e4226        43 hours ago        609.9 MB
kolla/centos-binary-glance-base                 2.0.3               1e4efa0f6701        43 hours ago        673.8 MB
kolla/centos-binary-nova-network                2.0.3               87f6389dd11a        43 hours ago        610.4 MB
kolla/centos-binary-ironic-pxe                  2.0.3               82f25f73c28f        43 hours ago        574.2 MB
kolla/centos-binary-nova-novncproxy             2.0.3               4726875ed228        43 hours ago        610.1 MB
kolla/centos-binary-nova-ssh                    2.0.3               51c70b9e9c47        43 hours ago        610.4 MB
kolla/centos-binary-cinder-base                 2.0.3               7c2d031be713        43 hours ago        761.3 MB
kolla/centos-binary-keystone                    2.0.3               c51a93cc9e2e        43 hours ago        585.2 MB
kolla/centos-binary-ironic-api                  2.0.3               b1771f5cc27f        43 hours ago        570.6 MB
kolla/centos-binary-ironic-inspector            2.0.3               32f4e33e1037        43 hours ago        576.2 MB
kolla/centos-binary-ironic-conductor            2.0.3               d552c64f3a08        43 hours ago        599 MB
kolla/centos-binary-nova-base                   2.0.3               8f077fafc5d8        43 hours ago        588.7 MB
kolla/centos-binary-rabbitmq                    2.0.3               d9e543e4f179        43 hours ago        370.3 MB
kolla/centos-binary-ironic-base                 2.0.3               6c4c453ddbce        43 hours ago        550.8 MB
kolla/centos-binary-openstack-base              2.0.3               cf48d5b3f3ee        43 hours ago        518.2 MB
kolla/centos-binary-mariadb                     2.0.3               cd9b363fe034        43 hours ago        630.5 MB
kolla/centos-binary-memcached                   2.0.3               49c536466427        43 hours ago        354.6 MB
kolla/centos-binary-base                        2.0.3               d04ac1ecd01a        43 hours ago        300 MB
centos                                          latest              980e0e4c79ec        2 days ago          196.7 MB

部署容器

  1. 生成密码
    openstack环境的密码等变量可以在 /etc/kolla/passwords.yml 中指定,为了方便可以使用kolla-genpwd工具自动生成复杂密码。

    kolla-genpwd

    为了方便,我们修改其中的管理员登陆密码

    vim /etc/kolla/passwords.yml
    keystone_admin_password: admin
  2. 修改部署配置文件
    修改/etc/kolla/globals.yml 文件,指定部署的一些信息

    vim /etc/kolla/globals.yml
    
    kolla_base_distro: "centos"
    kolla_install_type: "binary"
    enable_haproxy: "no"
    #kolla_internal_vip_address: "10.10.10.254"
    kolla_internal_address: "192.168.2.120"
    network_interface: "ens160"
    neutron_external_interface: "ens192"
    neutron_plugin_agent: "openvswitch"
    openstack_logging_debug: "True"
  3. 检查配置

    kolla-ansible prechecks
  4. 开始部署

    kolla-ansible deploy

    部署成功后查看容器

    # docker ps
    CONTAINER ID        IMAGE                                                 COMMAND                  CREATED             STATUS              PORTS               NAMES
    3938136934cf        kolla/centos-binary-horizon:2.0.3                     "kolla_start"            17 hours ago        Up 17 hours                             horizon
    cc68cb8d96e4        kolla/centos-binary-heat-engine:2.0.3                 "kolla_start"            17 hours ago        Up 17 hours                             heat_engine
    96c94995ef7c        kolla/centos-binary-heat-api-cfn:2.0.3                "kolla_start"            17 hours ago        Up 17 hours                             heat_api_cfn
    cb8ae3afb767        kolla/centos-binary-heat-api:2.0.3                    "kolla_start"            17 hours ago        Up 17 hours                             heat_api
    e8f98659e03f        kolla/centos-binary-neutron-metadata-agent:2.0.3      "kolla_start"            17 hours ago        Up 17 hours                             neutron_metadata_agent
    d326fa732c2b        kolla/centos-binary-neutron-l3-agent:2.0.3            "kolla_start"            17 hours ago        Up 17 hours                             neutron_l3_agent
    4b1bbbe4fe5b        kolla/centos-binary-neutron-dhcp-agent:2.0.3          "kolla_start"            17 hours ago        Up 17 hours                             neutron_dhcp_agent
    88b2afbba5d9        kolla/centos-binary-neutron-openvswitch-agent:2.0.3   "kolla_start"            17 hours ago        Up 17 hours                             neutron_openvswitch_agent
    b73d52de75b2        kolla/centos-binary-neutron-server:2.0.3              "kolla_start"            17 hours ago        Up 17 hours                             neutron_server
    1c716402d95f        kolla/centos-binary-openvswitch-vswitchd:2.0.3        "kolla_start"            17 hours ago        Up 17 hours                             openvswitch_vswitchd
    176e7ee659f1        kolla/centos-binary-openvswitch-db-server:2.0.3       "kolla_start"            17 hours ago        Up 17 hours                             openvswitch_db
    457e0921c61a        kolla/centos-binary-nova-ssh:2.0.3                    "kolla_start"            17 hours ago        Up 17 hours                             nova_ssh
    b02acebb3dc3        kolla/centos-binary-nova-compute:2.0.3                "kolla_start"            17 hours ago        Up 17 hours                             nova_compute
    59be78a597d8        kolla/centos-binary-nova-libvirt:2.0.3                "kolla_start"            17 hours ago        Up 17 hours                             nova_libvirt
    668ad8f91920        kolla/centos-binary-nova-conductor:2.0.3              "kolla_start"            17 hours ago        Up 17 hours                             nova_conductor
    34f81b4bc18b        kolla/centos-binary-nova-scheduler:2.0.3              "kolla_start"            17 hours ago        Up 17 hours                             nova_scheduler
    eb47844e6547        kolla/centos-binary-nova-novncproxy:2.0.3             "kolla_start"            17 hours ago        Up 17 hours                             nova_novncproxy
    93563016cf21        kolla/centos-binary-nova-consoleauth:2.0.3            "kolla_start"            17 hours ago        Up 17 hours                             nova_consoleauth
    cc8a1cca2e98        kolla/centos-binary-nova-api:2.0.3                    "kolla_start"            17 hours ago        Up 17 hours                             nova_api
    40db89e89758        kolla/centos-binary-glance-api:2.0.3                  "kolla_start"            17 hours ago        Up 17 hours                             glance_api
    4fa5f0f38f0d        kolla/centos-binary-glance-registry:2.0.3             "kolla_start"            17 hours ago        Up 17 hours                             glance_registry
    f05120c95a9f        kolla/centos-binary-keystone:2.0.3                    "kolla_start"            17 hours ago        Up 17 hours                             keystone
    149a49d57aa6        kolla/centos-binary-rabbitmq:2.0.3                    "kolla_start"            17 hours ago        Up 17 hours                             rabbitmq
    5f4298c3821e        kolla/centos-binary-mariadb:2.0.3                     "kolla_start"            17 hours ago        Up 17 hours                             mariadb
    64f6fbb19892        kolla/centos-binary-cron:2.0.3                        "kolla_start"            17 hours ago        Up 17 hours                             cron
    4cab0e756b61        kolla/centos-binary-kolla-toolbox:2.0.3               "/usr/local/bin/dumb-"   17 hours ago        Up 17 hours                             kolla_toolbox
    293a7ccaab52        kolla/centos-binary-heka:2.0.3                        "kolla_start"            17 hours ago        Up 17 hours                             heka
    6dcf3a2c12cc        kolla/centos-binary-memcached:2.0.3                   "kolla_start"            17 hours ago        Up 17 hours                             memcached
  5. 修改虚拟化类型
    因为是在虚拟机中安装,不支持kvm,需要修改虚拟类型为qemu

    vim /etc/kolla/nova-compute/nova.conf
    
    [libvirt]
    ...
    virt_type=qemu

然后就可以通过 kolla_internal_address 访问openstack环境
image

一些有用的工具

  1. 部署完成后,运行以下命令可以生成一个openrc文件(运行openstack CLI所需的环境变量):

    kolla-ansible post-deploy
  2. openrc文件生成之后,使用以下命令可以帮你做一下openstack的初始化工作,包括上传一个glance镜像以及创建几个虚拟网络:

    source /etc/kolla/admin-openrc.sh
    kolla/tools/init-runonce
  3. 由于错误的出现,可能需要多次的部署,而有些错误重新部署是不会进行修正的,所以需要将整个环境进行清理:

    tools/cleanup-containers                #可用于从系统中移除部署的容器
    tools/cleanup-host                      #可用于移除由于残余网络变化引发的docker启动的neutron-agents主机
    tools/cleanup-images                    #可用于从本地缓存中移除所有的docker image

日志查看

kolla通过heka容器来收集所有容器的日志

docker exec -it heka bash

所有的容器都可以从这个目录中获取服务日志:/var/log/kolla/SERVICE_NAME。
如果需要输出日志,请运行:

docker logs

大多数容器不会stdout,上面的命令将不会提供信息。

出错处理

deploy时遇到以下错误:

TASK: [rabbitmq | fail msg="Hostname has to resolve to IP address of api_interface"] ***
failed: [localhost] =&gt; (item={'cmd': ['getent', 'ahostsv4', 'localhost'], 'end': '2016-06-24 04:51:39.738725', 'stderr': u'', 'stdout': '127.0.0.1       STREAM localhost\n127.0.0.1       DGRAM  \n127.0.0.1       RAW    \n127.0.0.1       STREAM \n127.0.0.1       DGRAM  \n127.0.0.1       RAW    ', 'changed': False, 'rc': 0, 'item': 'localhost', 'warnings': [], 'delta': '0:00:00.033351', 'invocation': {'module_name': u'command', 'module_complex_args': {}, 'module_args': u'getent ahostsv4 localhost'}, 'stdout_lines': ['127.0.0.1       STREAM localhost', '127.0.0.1       DGRAM  ', '127.0.0.1       RAW    ', '127.0.0.1       STREAM ', '127.0.0.1       DGRAM  ', '127.0.0.1       RAW    '], 'start': '2016-06-24 04:51:39.705374'}) =&gt; {"failed": true, "item": {"changed": false, "cmd": ["getent", "ahostsv4", "localhost"], "delta": "0:00:00.033351", "end": "2016-06-24 04:51:39.738725", "invocation": {"module_args": "getent ahostsv4 localhost", "module_complex_args": {}, "module_name": "command"}, "item": "localhost", "rc": 0, "start": "2016-06-24 04:51:39.705374", "stderr": "", "stdout": "127.0.0.1       STREAM localhost\n127.0.0.1       DGRAM  \n127.0.0.1       RAW    \n127.0.0.1       STREAM \n127.0.0.1       DGRAM  \n127.0.0.1       RAW    ", "stdout_lines": ["127.0.0.1       STREAM localhost", "127.0.0.1       DGRAM  ", "127.0.0.1       RAW    ", "127.0.0.1       STREAM ", "127.0.0.1       DGRAM  ", "127.0.0.1       RAW    "], "warnings": []}}
msg: Hostname has to resolve to IP address of api_interface

FATAL: all hosts have already failed -- aborting

PLAY RECAP ********************************************************************
to retry, use: --limit @/root/site.retry

localhost                  : ok=87   changed=24   unreachable=0    failed=1

解决办法:

vim /etc/hosts
127.0.0.1     localhost
192.168.2.120 localhost

openstack 使用 nova docker driver

一、安装docker并修改使用阿里云的镜像加速

以下操作在controller节点和compute节点进行(controller节点安装docker是为了方便下载docker镜像直接导入glance)
1. 创建yum repo文件(这里使用阿里云的源)

# tee /etc/yum.repos.d/docker.repo <<-'EOF'
[dockerrepo]
name=Docker Repository
baseurl=http://mirrors.aliyun.com/docker-engine/yum/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/docker-engine/yum/gpg
EOF

2.安装docker

# yum install docker-engine

3.修改docker使用阿里云镜像加速

# cp -n /lib/systemd/system/docker.service /etc/systemd/system/docker.service
# sed -i "s|ExecStart=/usr/bin/dockerd|ExecStart=/usr/bin/dockerd --registry-mirror=https://dhxb****.mirror.aliyuncs.com|g" /etc/systemd/system/docker.service
# systemctl daemon-reload

上文https://dhxb****.mirror.aliyuncs.com是我的加速器地址,获取自己加速地址请参考阿里云:https://cr.console.aliyun.com/#/accelerator
4.启动docker并设置开机自启

# systemctl enable docker
# systemctl start docker

二、在compute节点安装并配置novadocker

1.安装novadocker

# usermod -aG docker nova
# yum -y install git python-pip
# pip install -e git+https://github.com/openstack/nova-docker#egg=novadocker
# cd src/novadocker/
# python setup.py install

2.配置 /etc/nova/nova.conf 使用docker driver

[DEFAULT]
compute_driver = novadocker.virt.docker.DockerDriver

[docker]
# Commented out. Uncomment these if you'd like to customize:
## vif_driver=novadocker.virt.docker.vifs.DockerGenericVIFDriver
## snapshots_directory=/var/tmp/my-snapshot-tempdir

将/src/novadocker/etc/nova/rootwrap.d/docker.filters文件拷贝到/etc/nova/rootwrap.d/docker.filters,并修改rootwrap.d的访问权限,然后启动nova-compute服务

# cp -R /src/novadocker/etc/nova/rootwrap.d /etc/nova/
# chown -R root:nova /etc/nova/rootwrap.d # systemctl restart openstack-nova-compute

三、上传镜像到glacne

1.在glance的配置文件中启用driver

# vim /etc/glance/glance-api.conf
[image_format]
container_formats = ami,ari,aki,bare,ovf,docker

2.重启glance-api服务

# openstack-sevice restart glance

3.获取docker镜像,并上传到glance中

# docker pull cirros
# docker save cirros | glance image-create --container-format=docker --disk-format=raw --name cirros

四、创建docker instance

创建实例

# nova boot --image cirros --flavor m1.tiny --nic net-id=59cc6a1d-0cc1-44c7-8b0a-9dc071fde397 cirros-docker

使用docker命令查看容器

# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dc6e1c21887d cirros "/sbin/init" 47 minutes ago Up 47 minutes nova-bfeeb788-7fdf-476f-904a-8cc8ee3eb81c

注:dashboard上控制台无法使用

遇到的一些问题

修改使用docker driver后nova-compute的日志可以在 /var/log/message查看
1.重启nova-conpute服务失败

……
Aug 08 12:14:51 compute2 nova-compute[21233]: 2016-08-08 12:14:51.388 21233 ERROR nova.virt.driver File "/usr/lib/python2.7/site-packages/oslo_config
Aug 08 12:14:51 compute2 nova-compute[21233]: 2016-08-08 12:14:51.388 21233 ERROR nova.virt.driver __import__(module_str)
Aug 08 12:14:51 compute2 nova-compute[21233]: 2016-08-08 12:14:51.388 21233 ERROR nova.virt.driver ImportError: No module named conf.netconf

解决方法:

# cd src/novadocker/
# git checkout -b stable/liberty origin/stable/liberty
# python setup.py install

然后即可正常启动nova-compute服务

2.创建虚拟机的时候提示报错

404 Client Error: Not Found ("No such image: cirros-docker")]

解决方法:上传image的时候image name必须和docker image的名字一致,否则在创建instance的时候就是有上述错误

3.启动虚拟机的时候报命名空间权限错误

Aug 8 14:12:59 compute2 nova-compute: 2016-08-08 14:12:59.200 12444 ERROR nova.compute.manager [instance: 3608b187-fe0c-4554-aa96-d5ed630042bc] Command: sudo nova-rootwrap /etc/nova/rootwrap.conf ip netns exec ee27f11ab9dc265ad864dbcb8b9a800693fd9517f0bcfa166e3ccae66c300843 ip link set lo up
Aug 8 14:12:59 compute2 nova-compute: 2016-08-08 14:12:59.200 12444 ERROR nova.compute.manager [instance: 3608b187-fe0c-4554-aa96-d5ed630042bc] Exit code: 1
Aug 8 14:12:59 compute2 nova-compute: 2016-08-08 14:12:59.200 12444 ERROR nova.compute.manager [instance: 3608b187-fe0c-4554-aa96-d5ed630042bc] Stdout: u''
Aug 8 14:12:59 compute2 nova-compute: 2016-08-08 14:12:59.200 12444 ERROR nova.compute.manager [instance: 3608b187-fe0c-4554-aa96-d5ed630042bc] Stderr: u'Cannot open network namespace "ee27f11ab9dc265ad864dbcb8b9a800693fd9517f0bcfa166e3ccae66c300843": Permission denied\n'

解决方法:关闭selinux

# sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
# reboot

参考文章:
http://blog.csdn.net/zhangli_perdue/article/details/50155705
https://github.com/openstack/nova-docker
http://heavenkong.blogspot.com/2016/07/resolved-mitaka-novadocker-error.html