环境声明:
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
镜像制作开始
vim/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp
/etc/init.d/networkrestart
2.禁用zeroconf路由,实例访问元数据,必须要禁用默认的zeroconf路由
echo"NOZEROCONF=yes">>/etc/sysconfig/network
3.安装acpid,cloud-init包
acpid服务作用:重新引导或关闭实例
yum-yinstallepel-release&&yummakecache&&yum-yinstallacpidcloud-init chkconfigacpidon chkconfigcloud-initon chkconfigcloud-init-localon
4.配置控制台日志显示(nova console-log)
vim/boot/grub/menu.lst
default=0
timeout=5
serial--unit=0--speed=115200
terminal--timeout=10consoleserial
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
titleCentOS(2.6.32-431.el6.x86_64)
root(hd0,0)
kernel/vmlinuz-2.6.32-431.el6.x86_64roroot=/dev/mapper/VolGroup-lv_rootrd_NO_LUKSLANG=en_US.UTF-8rd_NO_MDrd_LVM_LV=VolGroup/lv_swapSYSFONT=latarcyrheb-sun16crashkernel=autord_LVM_LV=VolGroup/lv_rootKEYBOARDTYPE=pcKEYTABLE=usrd_NO_DMrhgbconsole=tty0console=ttyS0,115200n8quiet
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="curlhttp://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 echoroot:$mima|chpasswd fi
7.开机启动服务脚本
vim/etc/init.d/reset-root-pw
#!/bin/bash # #reset-root-pwStartupreset-root-pwtheserverdaemon # #chkconfig:50005525 #description:reset-root-pwisyindun-clouddaemon # 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 chkconfigreset-root-pw--add chkconfigreset-root-pwon chkconfigreset-root-pw--list
做到现在的话镜像就快要完成啦,还需要其他功能的,自行百度添加吧
不需要的话直接关机就ok
9.镜像配置好后,将其压缩就可以上传到openstack镜像列表中啦
下面是我做镜像收尾时用到的命令
显示kvm中所有虚拟机
virshlist--all
执行清理任务,如,之前的历史命令,mac地址,ip地址等
virt-sysprep-d@H_935_301@CentOS6
virshundefine@H_935_301@CentOS6
将镜像压缩
qemu-imgconvert-c-Oqcow2 压缩之前的路径+名字 压缩之后的路径+名字
原文链接:https://www.f2er.com/centos/378632.html