用法: nova meta 云主机id 或者 主机名称 set changePasswd=True admin_pass=密码 实例: nova meta 17d96745-63a7-4401-87de-f34ca418a5e6 set changePasswd=True admin_pass=Admin@ |
NAME=eth0 DEVICE=eth0 BOOTPROTO=dhcp TYPE=Ethernet ONBOOT=yes |
阐述: 这里写eth1 是为了云主机对应两个网卡做的,如果能确保以后只用一个网卡的,可以不用写eth1; 但是现在的趋势都是设置的两个网络,一个作为内网,一个作为外网 |
NAME=eth1 DEVICE=eth1 BOOTPROTO=dhcp TYPE=Ethernet ONBOOT=yes |
yum -y install acpid cloud-init jq chkconfig acpid on chkconfig cloud-init on 禁用zeroconf路由,实例访问元数据,必须要禁用默认的zeroconf路由 echo "NOZEROCONF=yes" >> /etc/sysconfig/network |
sed -i 's/disable_root: 1/disable_root: 0/g' /etc/cloud/cloud.cfg sed -i 's/ssh_pwauth: 0/ssh_pwauth: 1/g' /etc/cloud/cloud.cfg sed -i 's/name: centos/name: root/g' /etc/cloud/cloud.cfg |
#!/bin/bash cat > /etc/init.d/meta_data_service << END #!/bin/bash # # meta_data_service Start up meta_data_service the server daemon # # chkconfig: 2345 98 98 # description: meta_data_service sspaas-cloud daemon # BASE_DIR=/sbin ARGV="\$@" start() { echo "START meta_data SERVERS" \$BASE_DIR/meta_data > /dev/null 2>&1 & } stop() { #meta_data.pid echo "STOP meta_data SERVERS" meta_datapid=\`ps -ef|grep meta_data|grep -v grep|awk '{ print\$2 }'\` for i in \$meta_datapid do kill -9 \$meta_datapid done } case \$ARGV in start) start ERROR=\$? ;; stop) stop ERROR=\$? ;; restart) stop start ERROR=\$? ;; *) echo "meta_data [start|restart|stop]" esac exit \$ERROR END cat > /etc/init.d/meta_network_service << END #!/bin/bash # # meta_network_service Start up meta_network_service the server daemon # # chkconfig: 2345 99 99 # description: meta_network_service sspaas-cloud daemon # BASE_DIR=/sbin ARGV="\$@" start() { echo "START meta_data SERVERS" \$BASE_DIR/meta_network > /dev/null 2>&1 & } stop() { #meta_data.pid echo "STOP meta_data SERVERS" meta_networkpid=\`ps -ef|grep meta_network|grep -v grep|awk '{ print\$2 }'\` for i in \$meta_networkpid do kill -9 \$meta_networkpid done } case \$ARGV in start) start ERROR=\$? ;; stop) stop ERROR=\$? ;; restart) stop start ERROR=\$? ;; *) echo "meta_network [start|restart|stop]" esac exit \$ERROR END cat > /sbin/meta_data << END #!/bin/bash m=\`curl http://169.254.169.254/openstack/latest/meta_data.json | jq '.meta'\` status=\`echo \$m | jq '.changePasswd' | sed 's/"//g'\` password=\`echo \$m | jq '.admin_pass' | sed 's/"//g'\` if [ \$status == True ];then echo root:\$password | chpasswd fi while true do m1=\`curl http://169.254.169.254/openstack/latest/meta_data.json | jq '.meta' | jq '.changePasswd' | sed 's/"//g'\` sleep 3 m2=\`curl http://169.254.169.254/openstack/latest/meta_data.json | jq '.meta'\` changepw=\`echo \$m2 | jq '.changePasswd' | sed 's/"//g'\` pass=\`echo \$m2 | jq '.admin_pass' | sed 's/"//g'\` if [ \$m1 == False ] && [ \$changepw == True ];then echo root:\$pass | chpasswd else echo "noting to do" >/dev/null fi done END cat > /sbin/meta_network << END #!/bin/bash while true do temp=\`ifconfig eth0 | grep broadcast | awk '{ print \$2 }' | awk -F "." 'BEGIN{ OFS="." }{ print \$1,\$2,\$3 }'\` ip0=\`ip a | grep eth0: | wc -l\` ip1=\`ip a | grep eth1: | wc -l\` route0=\`route -n | grep "^0.0.0.0" | grep \$temp.254 |wc -l\` if [ \$ip0 -eq 1 ] && [ \$ip1 -eq 1 ] && [ \$route0 -eq 1 ];then route del default gw \$temp.254 elif [ \$ip0 -eq 1 ] && [ \$ip1 -eq 0 ] && [ \$route0 -eq 0 ];then route add default gw \$temp.254 fi sleep 3 done END chmod +x /sbin/meta_data chmod +x /sbin/meta_network chmod +x /etc/init.d/meta_data_service chmod +x /etc/init.d/meta_network_service # gzexe /sbin/meta_data rm -f /sbin/meta_data~ gzexe /sbin/meta_network rm -f /sbin/meta_network~ # chkconfig --add meta_data_service chkconfig --add meta_network_service |
chkconfig --del meta_data_service chkconfig --del meta_network_service rm -f /sbin/meta_data rm -f /sbin/meta_network rm -f /etc/init.d/meta_data_service rm -f /etc/init.d/meta_network_service |
rm -f anaconda-ks.cfg rm -f meta_centos69.sh |