首页 > 代码库 > openstack镜像之centos
openstack镜像之centos
环境声明:
os centos6
openstack mitaka
本文修改主机密码的方式为 metadata 注入方式,在云主机内部再配合一个修改密码的脚本,达到重置云主机密码的作用
原文链接:http://readshlinux.blog.51cto.com/9322509/1900532
参考文档:
https://docs.openstack.org/image-guide/centos-image.html
http://www.cnblogs.com/CLTANG/p/4332612.html
本文就不说安装虚拟机那一部分啦,不会的亲,请自行百度,google
镜像制作开始
1.修改主机的网卡配置文件,将网卡改为开机启动
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp
/etc/init.d/network restart
2.禁用zeroconf路由,实例访问元数据,必须要禁用默认的zeroconf路由
echo "NOZEROCONF=yes" >> /etc/sysconfig/network
3.安装acpid,cloud-init包
acpid服务作用:重新引导或关闭实例
yum -y install epel-release && yum makecache && yum -y install acpid cloud-init chkconfig acpid on chkconfig cloud-init on chkconfig cloud-init-local on
4.配置控制台日志显示(nova console-log)
添加本文红色字体内容即可
vim /boot/grub/menu.lst
default=0
timeout=5
serial --unit=0 --speed=115200
terminal --timeout=10 console serial
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.32-431.el6.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swap SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=VolGroup/lv_root KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb console=tty0 console=ttyS0,115200n8 quiet
initrd /initramfs-2.6.32-431.el6.x86_64.img
5.配置cloud-init
vim /etc/cloud/cloud.cfg
users:
- default
disable_root: 0
ssh_pwauth: 1
... ...
system_info:
default_user:
name: root
lock_passwd: true
... ...
6.修改、重置密码脚本(同一个)
#!/bin/bash # curl="curl http://169.254.169.254/openstack/latest/meta_data.json" changepw=`$curl | sed ‘s/{"random_seed.*{"admin_pass": "//‘ | sed ‘s/}, "project_id.*//‘ | awk -F‘"‘ ‘{print $5}‘` mima=`$curl | sed ‘s/{"random_seed.*{"admin_pass": "//‘ | sed ‘s/}, "project_id.*//‘ | awk -F‘"‘ ‘{print $1}‘` if [ $changepw == True ] then echo root:$mima | chpasswd fi
7.开机启动服务脚本
vim /etc/init.d/reset-root-pw
#!/bin/bash # # reset-root-pw Start up reset-root-pw the server daemon # # chkconfig: 5000 55 25 # description: reset-root-pw is yindun-cloud daemon # RESET_PW_root=/sbin/reset-root-pw $RESET_PW_root &> /dev/null
8.为上面两个脚本添加相应的权限,并加入到开机自启
chmod +x /etc/init.d/reset-root-pw chmod +x /sbin/reset-root-pw chkconfig reset-root-pw --add chkconfig reset-root-pw on chkconfig reset-root-pw --list
做到现在的话镜像就快要完成啦,还需要其他功能的,自行百度添加吧
不需要的话直接关机就ok
9.镜像配置好后,将其压缩就可以上传到openstack镜像列表中啦
下面是我做镜像收尾时用到的命令
显示kvm中所有虚拟机
virsh list --all
执行清理任务,如,之前的历史命令,mac地址,ip地址等
virt-sysprep -d CentOS6
在kvm中删除虚拟机,仅仅删除xml文件,不会删除镜像文件
virsh undefine CentOS6
将镜像压缩
qemu-img convert -c -O qcow2 压缩之前的路径+名字 压缩之后的路径+名字
本文出自 “RSLinux” 博客,请务必保留此出处http://readshlinux.blog.51cto.com/9322509/1900532
openstack镜像之centos