脚本本身并不难,主要脚本还是要熟悉对sed的使用
[root@controller ~]# cat sed.sh ##查看脚本内容
#!/bin/bash
##modify-openrc.sh
##email 2484576482@qq.com
##author czq
ext_dev=`ip a | grep "^3" | awk -F "[ :]+" '{print $2}'` ##获取外网网卡名并传给ext_dev
file=/etc/xiandian/openrc.sh ##定义openrc.sh的路径
[[ ! -f $file ]] && echo -e "\e[5;31mopenrc.sh不存在,请先安装iaas-xiandain\e[0m" && exit
sed -ri.bak 's/#(.*)PASS=/\1PASS=000000/' $file
con_ip=`ip a | sed -rn '9s#.*net (.+)/24.*#\1#p'` ##获取内网地址并传给con_ip
sed -ri /#HOST_IP=/cHOST_IP=$con_ip $file
sed -ri /#HOST_NAME=/cHOST_NAME=$HOSTNAME $file
echo -en "\e[1;31m请输入compute节点的ip地址和主机名: \e[0m" ##让用户交互的方式获取compute的ip和主机名
read com_ip com_name
sed -ri /#HOST_IP_NODE=/cHOST_IP_NODE=$com_ip $file
sed -ri "s/#(HOST_NAME_NODE=)/\1$com_name/" $file
sed -ri "s/#(RABBIT_USER=)/\1openstack/" $file
sed -ri 's/#(DOMAIN_NAME=)/\1demo/' $file
sed -ri 's/#(METADATA_SECRET=)/\1000000/' $file
sed -ri "s/#(INTERFACE_NAME=)/\1$ext_dev/" $file
sed -ri 's/#(minvlan=)/\1101/' $file
sed -ri 's/#(maxvlan=)/\1200/' $file
sed -ri 's/#(BLOCK_DISK=)/\1sdb1/' $file
sed -ri 's/#(OBJECT_DISK=)/\1sdc1/' $file
sed -ri "s/#(STORAGE_LOCAL_NET_IP=)/\1$com_ip/" $file
egrep -v "^$|^#" $file ##过滤空行和注释行并查看修改好的内容
执行脚本
[root@controller ~]# sh sed.sh ##在controller上执行
请输入compute节点的ip地址和主机名: 172.16.210.20 compute ##这里手动输入节点的ip地址和主机名
HOST_IP=172.16.210.10
HOST_NAME=controller
HOST_IP_NODE=172.16.210.20
HOST_NAME_NODE=compute
RABBIT_USER=openstack
RABBIT_PASS=000000
DB_PASS=000000
DOMAIN_NAME=demo
ADMIN_PASS=000000
DEMO_PASS=000000
KEYSTONE_DBPASS=000000
GLANCE_DBPASS=000000
GLANCE_PASS=000000
NOVA_DBPASS=000000
NOVA_PASS=000000
NEUTRON_DBPASS=000000
NEUTRON_PASS=000000
METADATA_SECRET=000000
INTERFACE_NAME=eno33559296
minvlan=101
maxvlan=200
CINDER_DBPASS=000000
CINDER_PASS=000000
BLOCK_DISK=sdb1
TROVE_DBPASS=000000
TROVE_PASS=000000
SWIFT_PASS=000000
OBJECT_DISK=sdc1
STORAGE_LOCAL_NET_IP=172.16.210.10
HEAT_DBPASS=000000
HEAT_PASS=000000
CEILOMETER_DBPASS=000000
CEILOMETER_PASS=000000
AODH_DBPASS=000000
AODH_PASS=000000
之后再使用scp命令把这个变量文件传给compute就好
[root@controller ~]# scp /etc/xiandian/openrc.sh 172.16.210.20:/etc/xiandian/
如果执行脚本的时候不小心没有输入好compute节点的ip和主机名可以把脚本事先备份好的那份恢复回来
[root@controller ~]# cp /etc/xiandian/openrc.sh.bak /etc/xiandian/openrc.sh
cp: overwrite ‘/etc/xiandian/openrc.sh’? y
[root@controller ~]#
网友评论