此时我们还需要为openstack的镜像而打磨一下我们刚装好的系统,你可以使用virsh list来看当前已启动的虚拟机。
virsh start CentOSimgvirsh list
查看确定是我们刚才制作的虚拟机"CentOSimg"重新开启了.
之后再次用VNC连入到这个虚拟机中,端口不变,我们需要做下面的一些操作
4.1.删除网络配置
删除ifcfg-eth0的HWADDR一行,最后你的ifcfg-eth0的配置文件应该是这样的:
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0DEVICE="eth0"
BOOTPROTO="dhcp"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
删除已生成的网络设备规则
rm -rf /etc/udev/rules.d/70-persistent-net.rules4.2.关闭防火墙和selinux
sed -i s/^SELINUX=.*/SELINUX=disabled/g /etc/selinux/configservice iptables stop && chkconfig iptables off
service ip6tables stop && chkconfig ip6tables off
4.3(可选)设置系统能自动获取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 > /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 > /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