- # nova-manage vm list | grep compute_one | awk '{print $1}'
- vm_1
复制代码
只有一个vm_1
在mysql中修改instances表,把vm_1所在的host改成compute_two
- # mysql -uroot -pmysql
- mysql> use nova;
- mysql> update instances set host='compute_two' where hostname='vm_1';
- OK!
复制代码
查看vm_1它的实例名字是什么
- # nova show vm_1 | grep instance_name | awk '{print $4}'
- instance-00000004
复制代码
去compute_two上查看vm_1的xml防火墙规则名字
- # instance_name='instance-00000004'
- cd /var/lib/nova/instances/$instance_name
- # filter_name=`cat libvirt.xml | grep filter= | awk -F'"' '{print $2}'`
- # echo $filter_name
- nova-instance-instance-00000004-fa163e0cb87b
复制代码
在compute_two上新建vm_1防火墙规则文件
- # filter_uuid=`uuidgen $filter_name`
- # cat > /etc/libvirt/nwfilter/$filter_name.xml << _LongGeek_
- <filter name='$filter_name' chain='root'>
- <uuid>$filter_uuid</uuid>
- <filterref filter='nova-base'/>
- </filter>
- _LongGeek_
复制代码
提取vm_1的mac地址和ip地址
- # instance_mac=`cat /var/lib/nova/instances/$instance_name/libvirt.xml | grep mac | awk -F "'" '{print $2}'`
- # instance_ip=`cat /var/lib/nova/instances/$instance_name/libvirt.xml | grep IP | awk -F '"' '{print $4}'`
复制代码
把vm_1的ip地址写入到配置文件
- # echo -e "n$instance_mac,vm_1.novalocal,$instance_ip" >> /var/lib/nova/networks/nova-br100.conf
复制代码
重启libvirtd,让防火墙规则生效
- # /etc/init.d/libvirtd restart
复制代码
定义xml文件,并启动
- # cd /var/lib/nova/instances/$instance_name/
- # virsh define libvirt.xml
- # virsh start instance-00000004
复制代码
OK.数据在,fixed网络也没有问题.
恢复floating ip,首先需要在mysql中找出vm_1以前使用的floating ip是多少
先找出vm_1的fixed ip的id号
- # fixed_id=`mysql -uroot -pmysql -e "select * from nova.fixed_ips where address=$instance_ip;" | awk '{print $7}' | tail -n 1`
复制代码
通过vm_1的fixed ip的id号找出float ip地址
- # float_ip=`mysql -uroot -pmysql -e "select * from nova.floating_ips where id=$fixed_id;" | awk '{print $7}' | tail -n1`
复制代码
修改float ip地址所在的host
- # mysql -uroot -pmysql -e "update nova.floating_ips set host='compute_two' where address=$float_ip;"
复制代码
手工添加$float_ip到compute_two上
- # ip addr add $float_ip/32 dev eth1
复制代码
添加iptables规则
- # iptables -t nat -A nova-network-OUTPUT -d $float_ip/32 -j DNAT --to-destination $instance_ip
- # iptables -t nat -A nova-network-PREROUTING -d $float_ip/32 -j DNAT --to-destination $instance_ip
- # iptables -t nat -A nova-network-float-snat -s $instance_ip/32 -j SNAT --to-source $float_ip
- # /etc/init.d/iptables save
复制代码
开启路由转发
- # vim /etc/sysctl.conf
- net.ipv4.ip_forward = 1
- # sysctl -p
复制代码
OK,floating_ip也恢复了,都可以在dashboard上操作。