openstack镜像制作centos7

1,找一台宿主机安装kvm并检查是否支持虚拟化,这里我用的是vmware来做宿主机

egrep '(vmx|svm)' /proc/cpuinfo

然后安装kvm:

yum install epel-release net-tools vim unzip zip wget  qemu-kvm libvirt virt-install bridge-utils

验证是否安装成功:

[root@osa ~]# lsmod | grep kvm
kvm_intel
kvm kvm_intel
irqbypass kvm

启动kvm

[root@osa ~]# systemctl start libvirtd

加入开机自启动

[root@osa ~]# systemctl enable libvirtd

2 删除默认网桥并新建网桥

virsh net-destroy default
virsh net-undefine default

备份默认网卡配置文件

cp ifcfg-ens160 ifcfg-ens160.bak

新建br0:

vim /etc/sysconfig/network-scripts/ifcfg-br0

BOOTPROTO=static
DEVICE=br0
TYPE=Bridge
NM_CONTROLLED=no
IPADDR=172.100.60.80
NETMASK=255.255.255.0
GATEWAY=172.100.60.1
DNS1=172.100.60.31

修改原有的网卡配置文件ens160:

vim /etc/sysconfig/network-scripts/ifcfg-ens160

BOOTPROTO=none
DEVICE=ens160
NM_CONTROLLED=no
ONBOOT=yes
BRIDGE=br0

然后重启网卡:

service network restart

3 开始创建kvm虚拟机:

首先创建img文件:

qemu-img create -f qcow2 centos-7.1.qcow2 20g

然后创建虚拟机:

virt-install --name centos-7.1. --ram  --vcpu  --cdrom=/data/iso/CentOS--x86_64-DVD1511.iso --disk path=/data/images/centos-7.1..qcow2,bus=vi
rtio --os-variant=rhel6 --bridge=br0 --vnclisten=0.0.0.0 --vncport= --vnc

然后使用vnc连接

然后更新系统安装一些自己需要的软件

4,安装choud-init jq acpid

yum -y install acpid cloud-init  jq

chkconfig acpid on

chkconfig cloud-init on

echo "NOZEROCONF=yes" >> /etc/sysconfig/network

5,修改内核参数,并更新内核

编辑/etc/default/grub配置GRUB_CMDLINE_LINUX选项删除rhgb quiet 然后增加 console=tty0console=ttyS0,115200n8

GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap console=tty0 console=ttyS0,115200n8"
grub2-mkconfig -o /boot/grub2/grub.cfg

6,编辑配置cloud.cfg文件

红色部分为修改部分

users:
- default disable_root: 0
ssh_pwauth: 1 locale_configfile: /etc/sysconfig/i18n
mount_default_fields: [~, ~, 'auto', 'defaults,nofail', '', '']
resize_rootfs_tmp: /dev
ssh_deletekeys:
ssh_genkeytypes: ~
syslog_fix_perms: ~ cloud_init_modules:
- migrator
- bootcmd
- write-files
- growpart
- resizefs
- set_hostname
- update_hostname
- update_etc_hosts
- rsyslog
- users-groups
- ssh cloud_config_modules:
- mounts
- locale
- set-passwords
- yum-add-repo
- package-update-upgrade-install
- timezone
- puppet
- chef
- salt-minion
- mcollective
- disable-ec2-metadata
- runcmd cloud_final_modules:
- rightscale_userdata
- scripts-per-once
- scripts-per-boot
- scripts-per-instance
- scripts-user
- ssh-authkey-fingerprints
- keys-to-console
- phone-home
- final-message system_info:
default_user:
name: root
lock_passwd: true
gecos: Cloud User
groups: [wheel, adm, systemd-journal]
sudo: ["ALL=(ALL) NOPASSWD:ALL"]
shell: /bin/bash
distro: rhel
paths:
cloud_dir: /var/lib/cloud
templates_dir: /etc/cloud/templates
ssh_svcname: sshd # vim:syntax=yaml

7 关机

poweroff

8,执行清理任务在宿主机上

virt-sysprep -d CentOS7

9,拷贝镜像到glance节点上传镜像

上一篇:hdu3713 Double Maze


下一篇:iOS-MVVM--备用