码迷,mamicode.com
首页 > 其他好文 > 详细

openStack 王者归来之 trivial matters

时间:2015-01-19 10:48:36      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:

<一,openStack img 制作>

 tips:制作大部分cloud platforms img准备工作.

<1,>

  一台linux系统(最好centOS6 根据当前cloud platform and linux OS compatibility)的机器,作为制作镜像的机器.

1,安装底层支持软件包

yum groupinstall Virtualization libvirt virt-install qemu-kvm;

2,某种类型 的iso文件准备

3,启动libvirtd

<2,>开始制作镜像

qemu-img create -f qcow2 ruiyCentOS-openStack.qcow2 30G

chown qemu:qemu  *.qcow2 -R

virt-install -n RuiyCnetOSimg -r 4096 --cpu host -c /images/Centos-*iso --disk path=*.qcow2,device=disk,bus=virtio,size=30,format=qcow2 --vnc --vncport=5978 --vnclisten=0.0.0.0 -v

为openStack的镜像而打磨一下我们刚装好的系统

virsh start/destroy/undefine VMInames;

1,delete /etc/udev/rules.d/70-persistent-net.rules (删除以生成的网络设备规则!)

2,删除ifcfg-eth0的HWADDR一行

/etc/sysconfig/network-scripts/ifcfg-eth0内容如下:

DEVICE="eth0"

BOOTPROTO="dhcp"

NM_CONTROLLED="yes"

ONBOOT="yes"

TYPE="Ethernet"

3,关闭firewall和selinux/config

sed -i s/^SELINUX=.*/SELINUX=disabled/g /etc/selinux/config

service iptables stop && chkconfig iptables off;

设置系统能自动获取openstack指定的hostname和ssh-key
使用vim编辑/etc/rc.local文件
然后将以下内容输入进去,放在”touch /var/lock/subsys/local”之前

if [ ! -d /root/.ssh ]; then
mkdir -p /root/.ssh
chmod 700 /root/.ssh
fi
# Fetch public key using HTTP
ATTEMPTS=30
FAILED=0

while [ ! -f /root/.ssh/authorized_keys ]; do
curl -f http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key > /tmp/metadata-key 2>/dev/null
if [ $? -eq 0 ]; then
cat /tmp/metadata-key >> /root/.ssh/authorized_keys
chmod 0600 /root/.ssh/authorized_keys
restorecon /root/.ssh/authorized_keys
rm -f /tmp/metadata-key
echo “Successfully retrieved public key from instance metadata”
echo “*****************”
echo “AUTHORIZED KEYS”
echo “*****************”
cat /root/.ssh/authorized_keys
echo “*****************”

curl -f http://169.254.169.254/latest/meta-data/hostname > /tmp/metadata-hostname 2>/dev/null
if [ $? -eq 0 ]; then
TEMP_HOST=`cat /tmp/metadata-hostname`
sed -i “s/^HOSTNAME=.*$/HOSTNAME=$TEMP_HOST/g” /etc/sysconfig/network
/bin/hostname $TEMP_HOST
echo “Successfully retrieved hostname from instance metadata”
echo “*****************”
echo “HOSTNAME CONFIG”
echo “*****************”
cat /etc/sysconfig/network
echo “*****************”

else
echo “Failed to retrieve hostname from instance metadata. This is a soft error so we’ll continue”
fi
rm -f /tmp/metadata-hostname
else
FAILED=$(($FAILED + 1))
if [ $FAILED -ge $ATTEMPTS ]; then
echo “Failed to retrieve public key from instance metadata after $FAILED attempts, quitting”
break
fi
echo “Could not retrieve public key from instance metadata (attempt #$FAILED/$ATTEMPTS), retrying in 5 seconds…”
sleep 5
fi
done

1,quick guide to creating a OpenStack bootable image;

  1.1 wget os iso

  wget http://releases.ubuntu.com/14.04/ubuntu-14.04-server-adm64.iso

  1.2 create disk image:

  qemu-img create -f qcow2 ubuntu-14.04-server.qcow2 30G

  1.3 using KVM,launch an instance using iso and disk image (4096Mb ram and 2 processors)

  kvm -hda ubuntu-14.04-server.qcow2 -cdrom ubuntu-14.04-server-adm64.iso -m 4096 -smp 2  

  1.4 upload the image to glance:

  glance image-create --name ubuntu-14.04-server --disk-format=qcow2 --container-format=bare --is-public=True < ubuntu-14.04-server.qcow2

  1.5 boot

  nova boot --image ubuntu-14.04-server --flavor 3 VMI001

(Tips:delete /etc/udev/rules.d/70-persistent-net.rules (beforce uploading the image to glance))

in order for the nic interface ordering to start at eth0,otherwise it will start eth1.... which might not automatically start a dhcp-client on the interface.

 

openStack 王者归来之 trivial matters

标签:

原文地址:http://www.cnblogs.com/ruiy/p/4233104.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!