zoukankan      html  css  js  c++  java
  • openstack-Ubuntu-18.04镜像制作

    镜像制作

    https://docs.openstack.org/image-guide/ubuntu-image.html #制作ubuntu镜像参考

    https://docs.openstack.org/image-guide/obtain-images.html #官方提供的镜像(已安装完操作系统及环境)

    KVM服务器所需操作

    1、cd /usr/local/src  #上传ubuntu-18.04镜像
    
    2、qemu-img create -f qcow2 /var/lib/libvirt/images/ubuntu-1804.qcow2 10G
    #创建磁盘文件
    
    3、virt-install --virt-type kvm --name ubuntu-18.04 --ram 1024 --cdrom=/usr/local/src/ubuntu-18.04.3-server-amd64.iso --disk path=/var/lib/libvirt/images/ubuntu-1804.qcow2 --network bridge=br0 --graphics vnc,listen=0.0.0.0 --noautoconsole
    #创建虚拟机
    
    4、virt-manager   #xshell开启xll转发后,可以查看到虚拟机
    
    5、先按F6,再按ESC,输入修改网卡名称的内核参数,然后回车
    
    6、不需要通过代理
    
    7、不进行自动更新
    
    8、安装openssh服务,不安装openssh则无法通过ssh协议连接虚拟机
    

    进入KVM创建的ubuntu的虚拟机,进行相关初始化配置

    1、sudo su - root
    
    2、vim /etc/ssh/sshd_config
    PasswordAuthentication yes   #开启密码认证
    UseDNS no   #禁止反向解析
    PermitRootLogin yes   #允许root远程登录
    
    3、systemctl restart sshd
    
    4、将镜像源换成阿里云
    
    5、apt update
    
    6、apt install iproute2 ntpdate tcpdump telnet traceroute nfs-kernel-server nfs-common lrzsz tree openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev gcc iotop unzip zip -y   
    #安装基础命令
    
    7、apt install cloud-init -y   #centos还需要再安装一个包,ubuntu只安装这一个包即可
    #cloud init服务是安装在虚拟机中的,此服务会访问openstack API,通过API从而拿到公钥、实例类型、实例的元数据、当前虚拟机的磁盘空间等,然后对虚拟机进行相应调整,主要是对磁盘自动拉伸(只能增大,不会减小);不安装此服务的话,openstack创建完的虚拟机磁盘大小是固定的,即KVM创建虚拟机时磁盘是多大,openstack创建后就是多大,不会增大磁盘空间,所以需要安装此服务
    
    8、vim /etc/cloud/cloud.cfg
    users:
       - root    #使用root账号对磁盘进行拉伸
       
    disable_root: false  #允许使用root
    
    cloud_init_modules:
    # - migrator
    # - seed_random
    # - bootcmd
    # - write-files
     - growpart        #开启磁盘空间拉伸,拉伸后需要进行磁盘空间重置
     - resizefs        #开启磁盘空间重置
    # - disk_setup     #其余模块都关闭;如果模块都开,会影响虚拟机开机速度,开机时会加载很多模块
    # - mounts
    # - set_hostname   #此模块会把通过API获取到的实例名称设置为当前虚拟机的主机名
    # - update_hostname
    # - update_etc_hosts
    # - ca-certs
    # - rsyslog
    # - users-groups
    # - ssh            #关闭ssh模块,否则cloud-init会为了安全考虑,修改sshd的配置文件,禁止root用户远程ssh连接
    
    cloud_config_modules:
    # - emit_upstart
    # - snap
    # - ssh-import-id
    # - locale
    # - set-passwords
    # - grub-dpkg
    # - apt-pipelining
    # - apt-configure
    # - ubuntu-advantage
    # - ntp
    # - timezone
    # - disable-ec2-metadata
    # - runcmd
    # - byobu
    
    cloud_final_modules:
    # - package-update-upgrade-install
    # - fan
    # - landscape
    # - lxd
    # - ubuntu-drivers
    # - puppet
    # - chef
    # - mcollective
    # - salt-minion
    # - rightscale_userdata
    # - scripts-vendor
    # - scripts-per-once
    # - scripts-per-boot
    # - scripts-per-instance
    # - scripts-user
    # - ssh-authkey-fingerprints
    # - keys-to-console
    # - phone-home
    # - final-message
    # - power-state-change
    
    9、dpkg-reconfigure cloud-init       #配置cloud init使用EC2 API作为数据源读取元数据,其余的数据源都关闭
    
    10、把ansible的公钥拷贝到虚拟机中(镜像)
    
    11、systemctl disable cloud-init   
    #开机不启动cloud-init,否则openstack创建的虚拟机在开机时会向openstack API获取当前虚拟机的元数据,进行磁盘拉伸,这样会大大的影响虚拟机的开机速度
    
    12、poweroff   #关闭虚拟机
    

    KVM服务器把虚拟机磁盘文件拷贝到controller

    1、cd /var/lib/libvirt/images/
    
    2、scp ubuntu-1804.qcow2 172.31.7.102:/usr/local/src/
    #将虚拟机的磁盘文件拷贝到controller节点上
    

    controller及compute节点需要做的配置

    1、vim /etc/neutron/plugins/ml2/linuxbridge_agent.ini
    [securitygroup]
    enable_security_group = flase
    #controller及node节点都需要关闭安全组,否则会影响cloud-init访问openstack API
    
    2、重启neutron服务
    
    3、查看neutron日志是否有报错
    

    controller节点创建镜像

    1、cd /usr/local/src
    
    2、openstack image create "Ubuntu-18.04-template" --file ./ubuntu-1804.qcow2 --disk-format qcow2 --container-format bare --public
    #指定创建的镜像名称及磁盘文件路径,镜像可见性为公有
    

    dashboard创建虚拟机

    1、dashboard基于上传的ubuntu镜像创建虚拟机
    
    2、通过ansible等批量部署工具连接到创建的虚拟机
    
    3、systemctl start cloud-init
    #通过ansible连接到虚拟机批量开启cloud-init服务,进行磁盘拉伸(CPU、内存会自动拉伸,是不需要cloud-init服务的),cloud-init会把磁盘拉伸到创建虚拟机时,指定的实例类型所设置的磁盘大小
    
    4、df -TH                      #查看磁盘是否拉伸
    
    5、systemctl stop cloud-init   #磁盘拉伸后关闭cloud-init服务
    
  • 相关阅读:
    ssh-copy-id 的使用方法
    如何保证 docker daemon重启,但容器不重启
    vim设置golang语法高亮 (Centos)
    Error response from daemon: Error running DeviceCreate (createSnapDevice) dm_task_run failed
    Please supply the message using either -m or -F option.
    sudo: Sorry, you must have a tty to run sudo Error on a Linux and Unix
    vim plugins (vim 插件) 工具集
    OmniGraffle v6 注册码
    test
    Collections.addAll 为什么比collection.addall 快(转)
  • 原文地址:https://www.cnblogs.com/dongzhanyi123/p/13301029.html
Copyright © 2011-2022 走看看