openstack 制作linux镜像+centos官方镜像使用教程

openstack 制作linux镜像+centos官方镜像使用教程

工具:VMware Workstation (虚拟机)、CentOS-7-x86_64-Minimal-1511.iso(Minimal是官方最小的centos镜像文件,也可以使用其他镜像正常大小的iso文件)。

1.创建一台VMware虚拟机(桌面版), 开启VT和CPU性能计数器。
在这里插入图片描述
2.安装kvm,并启动libvirtd并设置开机启动

# yum install epel* -y 
# yum -y install qemu-kvm libvirt virt-install bridge-utils virt-manager libguestfs-tools-c
# systemctl start libvirtd 
# systemctl enable libvirtd 

如果libvirtd 启动失败请执行:yum update librbd1  然后再次启动libvirtd 
如果字体乱码请执行: yum install dejavu-lgc-sans-fonts -y

3.创建qcow2文件

# qume-img creaet -f qcow2 /mnt/centos.qcow2 5G

4.启动KVM虚拟机(有两种启动方法)

方法1:

# virt-install --virt-type kvm --name centos --ram 1024\ 
--disk /mnt/centos.qcow2,format=qcow2\
--network network=default   --graphics vnc,listen=0.0.0.0 --noautoconsole\
 --os-type=linux --os-variant=centos7.0 \
 --location=/root/CentOS-7-x86_64-Minimal-1511.iso

执行完成后再执行:

# virt-manager

在这里插入图片描述
操作系统安装过程不提供。

方法2:

直接输入命令:
# virt-manager

在这里插入图片描述
首先点击文件,然后选择新建虚拟机。

在这里插入图片描述
后面的步骤根据提示进行操作即可,此处不再赘述。

5.操作系统安装完成后,再vmware虚拟机中使用命令 virsh dumpxml [虚拟机名] 来查询安装介质盘的名字,查询到介质后将介质弹出,否者重启后又将会进入系统安装界面。

#  virsh dumpxml centos 
......
在反馈信息中,找到如下内容。
    </disk>
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <target dev='hda' bus='ide'/>    ( 此处显示安装介质是”hda“)
      <readonly/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
......

弹出介质:
# virsh attach-disk --type cdrom --mode readonly centos "" hda
重启KVM虚拟机:
# virsh reboot centos

6.配置KVM虚拟机

给KVM虚拟机安装电源管理工具:
# yum install acpid
# systemctl enable acpid

#systemctl  stop firewalld
# systemctl disable firewalld
[root@test centos]# vi /etc/selinux/config 
SELINUX=disabled                  
安装cloud-init :
# yum install epel-release.noarch
# yum install cloud-init

编辑/etc/cloud/cloud.cfg文件,在末尾加入:   user: admin
安装cloud-utils-growpart以允许分区调整大小:
# yum install cloud-utils-growpart
要访问元数据服务的实例,必须禁用默认的zeroconf路由:

# echo "NOZEROCONF=yes" >> /etc/sysconfig/network
编辑/etc/default/grub文件并配置 GRUB_CMDLINE_LINUX选项:
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=cl/root rd.lvm.lv=cl/swap console=tty0 console=ttyS0,115200n8"

# grub2-mkconfig -o /boot/grub2/grub.cfg      //保存配置
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-229.14.1.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-229.14.1.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-229.4.2.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-229.4.2.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-229.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-229.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-605f01abef434fb98dd1309e774b72ba
Found initrd image: /boot/initramfs-0-rescue-605f01abef434fb98dd1309e774b72ba.img
done

关闭KVM实例
# poweroff         //这条命令不懂的可以百度下

6配置完成后,进行后期文件处理。

删除实例的MAC地址(在VMware中执行):
# virt-sysprep -d centos

取消定义libvirt域:
# virsh undefine centos

到这里qcow2 镜像制作完成。
我们上传到openstack中。

以下为centos官方镜像和制作的镜像使用教程

# openstack image create --disk-format qcow2 --file  centos.qcow2  --tag LVM --container-format bare  CentOS-7.2

创建openstack密匙对:

# ssh-keygen -q -N ""              //生成私匙
# openstack keypair create --public-key ~/.ssh/id_rsa.pub mykey                        //创建名为mykey的密匙对

查看密匙对:
#openstack keypair list
[root@controller ~]# openstack keypair list
+----------+-------------------------------------------------+
| Name     | Fingerprint                                     |
+----------+-------------------------------------------------+
| mykey    | 23:c8:0a:75:32:43:d9:ab:e4:46:61:d7:92:23:8d:03 |
+----------+-------------------------------------------------+

创建云主机:

# openstack server create --image 123456 --flavor 3 --key-name  mykey --nic net-id=456789  test

绑定浮动IP:
# nova floating-ip-associate 14556564  192.168.10.151    

连接测试(注意:连接必须使用centos用户):


[root@controller ~]# ssh centos@192.168.10.151 
Last login: Mon Feb 18 14:33:26 2019 from 30.0.0.20
[centos@test ~]$ 

   连接成功!!!!!!
# sudo su root               //切换到root用户
[centos@test ~]$ vi /etc/ssh/sshd_config
PasswordAuthentication yes                      //配置为yes代表允许ssh连接时使用密码登陆。
保存退出


#systemctl restart sshd

到此结束,谢谢观看。

  • 1
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值