zoukankan      html  css  js  c++  java
  • OpenStack--创建一个Centos7的镜像

    在管理节点创建一个虚拟机镜像

    1. 安装virt-install,qemu-kvm, libvirt,并启动libvrit
    [root@Marvin-Node1 ~]# yum install -y qemu-kvm libvirt
    [root@Marvin-Node1 ~]# yum install -y virt-install
    [root@Marvin-Node1 ~]# systemctl start libvirtd && systemctl enable libvirtd
    [root@Marvin-Node1 ~]# ifconfig  
    eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 10.0.0.56 netmask 255.255.255.0  broadcast 10.0.0.255
            inet6 fe80::250:56ff:fe91:df22  prefixlen 64  scopeid 0x20<link>
            ether 00:50:56:91:df:22  txqueuelen 1000  (Ethernet)
            RX packets 6449007  bytes 8443638629 (7.8 GiB)
            RX errors 0  dropped 508  overruns 0  frame 0
            TX packets 3246349  bytes 274871849 (262.1 MiB)
            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 0  (Local Loopback)
            RX packets 4957466  bytes 1360755790 (1.2 GiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 4957466  bytes 1360755790 (1.2 GiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
            inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
            ether 52:54:00:cc:71:8c  txqueuelen 0  (Ethernet)
            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

    这里如果没有问题,使用ifconfig命令,可以看到多出一个virbr0的网卡

    2. 创建一个目录,用于存放镜像,并上传CentOS7的镜像到该目录下

    创建目录/opt/image

    [root@Marvin-Node1 ~]# mkdir -p /opt/image

    可以通过xftp等软件来上传镜像,上传完成后开始创建虚拟机

    3.创建虚拟机

    3.1 创建一个10G的虚拟机硬盘

    [root@Marvin-Node1 ~]# qemu-img create -f qcow2 /tmp/centos.qcow2 10G

    3.2 创建虚拟机

    [root@Marvin-Node1 ~]# virt-install --virt-type kvm --name centos --ram 1024 
    >   --disk /tmp/centos.qcow2,format=qcow2 
    >   --network network=default 
    >   --graphics vnc,listen=0.0.0.0 --noautoconsole 
    >   --os-type=linux --os-variant=centos7.0 
    >   --location=/opt/image/CentOS-7-x86_64-Everything-1511.iso
    Starting install...
    Retrieving file .treeinfo...                                                            | 1.1 kB  00:00:00     
    Retrieving file vmlinuz...                                                              | 4.9 MB  00:00:00     
    Retrieving file initrd.img...                                                           |  37 MB  00:00:00     
    Creating domain...                                                                      |    0 B  00:00:00     
    Domain installation still in progress. You can reconnect to 
    the console to complete the installation process.

    通过VNC工具连接到管理界面进行系统安装

     

    时区选择上海

     

     选择支持中文

    分区,将所有容量都给根分区,且只分一个根分区

    完成安装,设置root密码

     安装完成后点击reboot,系统会关机,并不会重启,这时候在宿主机上可以通过命令查看刚才已经建立的虚拟机

    [root@Marvin-Node1 ~]# virsh list --all
     Id    Name                           State
    ----------------------------------------------------
     -     centos                         shut off
     启动虚拟机
     [root@Marvin-Node1 ~]# virsh start centos
    Domain centos started

    启动后再次通过VNC工具连接上去,进行IP配置,系统优化,安装常用软件,配置yum源等工作,ip的如果不需要IPv6,只要留下以下4行就行

     

     4. 在OpenStack的管理节点创建虚拟机镜像

    [root@Marvin-Node1 ~]# source admin-openstack.sh
    [root@Marvin-Node1 ~]# openstack image create "centos7-x86_64"    --file /tmp/centos.qcow2    --disk-format qcow2 --container-format bare    --public
    +------------------+------------------------------------------------------+
    | Field            | Value                                                |
    +------------------+------------------------------------------------------+
    | checksum         | ec4343723602ab6df95ffeecee3d96ac                     |
    | container_format | bare                                                 |
    | created_at       | 2017-09-11T17:19:01Z                                 |
    | disk_format      | qcow2                                                |
    | file             | /v2/images/66d34783-d85c-479f-ad89-9fbdc3da38f7/file |
    | id               | 66d34783-d85c-479f-ad89-9fbdc3da38f7                 |
    | min_disk         | 0                                                    |
    | min_ram          | 0                                                    |
    | name             | centos7-x86_64                                       |
    | owner            | 22cd7c4eb794462a94ef4907971effb9                     |
    | protected        | False                                                |
    | schema           | /v2/schemas/image                                    |
    | size             | 1243676672                                           |
    | status           | active                                               |
    | tags             |                                                      |
    | updated_at       | 2017-09-11T17:19:08Z                                 |
    | virtual_size     | None                                                 |
    | visibility       | public                                               |
    +------------------+------------------------------------------------------+
    [root@Marvin-Node1 ~]# cd /var/lib/glance/images/
    [root@Marvin-Node1 images]# ll -h
    total 1.2G
    -rw-r----- 1 glance glance 1.2G Sep 12 01:19 66d34783-d85c-479f-ad89-9fbdc3da38f7   ## 这个1.2G的就是创建的镜像
    -rw-r----- 1 glance glance  13M Sep  9 01:31 91355df9-dd45-45d6-9b95-67b61aedafbd
    [root@Marvin-Node1 images]# 
    5. 在web界面创建一台centos7的虚拟机

    5.1 使用admin登录到web界面,安装虚拟机

    看到控制台后就可以使用前面root帐号的密码登录了

     

     转载:https://www.jianshu.com/p/137e6f3f0369

     
  • 相关阅读:
    Mysql如何修改unique key
    centos 编译 安装 protobuf
    EasyNetQ简单使用
    微信发送模板消息
    Python删除开头空格
    代码积累-Common
    sql With(NoLock),With(ReadPast)
    webform 使用log4net配置
    log4net.dll添加报错
    js-小数计算问题
  • 原文地址:https://www.cnblogs.com/royfans/p/15157001.html
Copyright © 2011-2022 走看看