侧边栏壁纸
博主头像
枕头下放双臭袜子博主等级

今我何功德,曾不事农桑

  • 累计撰写 166 篇文章
  • 累计创建 32 个标签
  • 累计收到 0 条评论

Openstack-glance组件一键部署安装脚本(v1版,命令组合)

枕头下放双臭袜子
2020-01-15 / 0 评论 / 0 点赞 / 774 阅读 / 0 字 / 正在检测是否收录...

openstack系列Minimal deployment for Rocky

脚本已测试,如需使用,修改脚本所有controller-ZJB为你的主机名,修改所有1790600080为你的密码

win的编码与unix的编码有区别,如果你直接粘贴使用,最好安装dos2unix将脚本文件转码!

image.png

image.png

#!/bin/bash
#This is a script for editing glance
# 如果你需要使用此脚本,将主机名controller-ZJB修改为你的主机名
# 所有1790600080处修改为自己的密码

readonly create_domain_pass=1790600080

echo "   这是一个修改glance配置文件的脚本:"
echo "   -------------------------------"
echo "   1、下面开始创建数据库并赋予相应权限"
mysql -u root -p1790600080 <<EOF
    CREATE DATABASE glance;
    GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost'  IDENTIFIED BY '1790600080';
    GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY '1790600080';
EOF

echo "   --------------------------------"
echo "   数据库已创建成功并赋予了相应权限"
echo "   --------------------------------"
echo "   2、创建服务凭证:"


export OS_PROJECT_DOMAIN_NAME=Default
export OS_USER_DOMAIN_NAME=Default
export OS_PROJECT_NAME=admin
export OS_USERNAME=admin
export OS_PASSWORD=1790600080
export OS_AUTH_URL=http://controller-ZJB:5000/v3
export OS_IDENTITY_API_VERSION=3
export OS_IMAGE_API_VERSION=2

openstack user create --domain default --password $create_domain_pass glance
openstack role add --project service --user glance admin
openstack service create --name glance --description "OpenStack Image" image
openstack endpoint create --region RegionOne image public http://controller-ZJB:9292
openstack endpoint create --region RegionOne image internal http://controller-ZJB:9292
openstack endpoint create --region RegionOne image admin http://controller-ZJB:9292

echo "   --------------------------------"
echo "   Compute服务凭证已创建完成!"

echo "   3、安装软件包……"
yum -y install openstack-glance
echo "   --------------------------------"
if [ $? == 0 ];then
echo "    软件已成功安装!"
else
   echo "   软件安装出错,请手动查看问题!"
fi


echo "   --------------------------------"
echo "   4、修改Nova配置文件:"
echo " "
read -p  "     选择是否一键修改glance配置文件(y/n)" answer

#判断/etc/glance/glance-api.conf文件是否存在,不存在直接输出错误
if [ $answer == "y" ];then
  ls /etc/glance/glance-api.conf &> /dev/null
  if [ $? == 0 ];then

  echo "   --------------------------------"
  echo "   下面开始修改/etc/glance/glance-api.conf配置文件"

  database_line=`cat -n /etc/glance/glance-api.conf | grep "\[database\]$" | awk '{print $1}'`
  sed -i $database_line'a\connection = mysql+pymysql://glance:1790600080@controller-ZJB/glance' /etc/glance/glance-api.conf

  keystone_authtoken_line=`cat -n /etc/glance/glance-api.conf | grep "\[keystone_authtoken\]$" | awk '{print $1}'`
  sed -i $keystone_authtoken_line'a\www_authenticate_uri  = http://controller-ZJB:5000' /etc/glance/glance-api.conf
  sed -i `expr $keystone_authtoken_line + 1`'a\auth_url = http://controller-ZJB:5000' /etc/glance/glance-api.conf
  sed -i `expr $keystone_authtoken_line + 2`'a\memcached_servers = controller-ZJB:11211' /etc/glance/glance-api.conf
  sed -i `expr $keystone_authtoken_line + 3`'a\auth_type = password' /etc/glance/glance-api.conf
  sed -i `expr $keystone_authtoken_line + 4`'a\project_domain_name = Default' /etc/glance/glance-api.conf
  sed -i `expr $keystone_authtoken_line + 5`'a\user_domain_name = Default' /etc/glance/glance-api.conf
  sed -i `expr $keystone_authtoken_line + 6`'a\project_name = service' /etc/glance/glance-api.conf
  sed -i `expr $keystone_authtoken_line + 7`'a\username = glance' /etc/glance/glance-api.conf
  sed -i `expr $keystone_authtoken_line + 8`'a\password = 1790600080' /etc/glance/glance-api.conf


  paste_deploy_line=`cat -n /etc/glance/glance-api.conf | grep "\[paste_deploy\]$" | awk '{print $1}'`
  sed -i $paste_deploy_line'a\flavor = keystone' /etc/glance/glance-api.conf


  glance_store_line=`cat -n /etc/glance/glance-api.conf | grep "\[glance_store\]$" | awk '{print $1}'`
  sed -i $glance_store_line'a\stores = file,http' /etc/glance/glance-api.conf
  sed -i $glance_store_line'a\default_store = file' /etc/glance/glance-api.conf
  sed -i $glance_store_line'a\filesystem_store_datadir = /var/lib/glance/images/' /etc/glance/glance-api.conf
  echo "    /etc/glance/glance-api.conf文件已修改完毕"
  else
     echo "/etc/glance/glance-api.conf文件不存在!"
  fi

#修改/etc/glance/glance-registry.conf配置文件
  ls /etc/glance/glance-registry.conf &>/dev/null
  if [ $? == 0 ]; then

  echo "   --------------------------------"
  echo "   下面开始修改/etc/glance/glance-registry.conf配置文件"

  database_line1=`cat -n /etc/glance/glance-registry.conf | grep "\[database\]$" | awk '{print $1}'`
  sed -i $database_line1'a\connection = mysql+pymysql://glance:1790600080@controller-ZJB/glance' /etc/glance/glance-registry.conf

  keystone_authtoken_line1=`cat -n /etc/glance/glance-registry.conf | grep "\[keystone_authtoken\]$" | awk '{print $1}'`
  sed -i $keystone_authtoken_line1'a\www_authenticate_uri = http://controller-ZJB:5000' /etc/glance/glance-registry.conf
  sed -i `expr $keystone_authtoken_line1 + 1`'a\auth_url = http://controller-ZJB:5000' /etc/glance/glance-registry.conf
  sed -i `expr $keystone_authtoken_line1 + 2`'a\memcached_servers = controller-ZJB:11211' /etc/glance/glance-registry.conf
  sed -i `expr $keystone_authtoken_line1 + 3`'a\auth_type = password' /etc/glance/glance-registry.conf
  sed -i `expr $keystone_authtoken_line1 + 4`'a\project_domain_name = Default' /etc/glance/glance-registry.conf
  sed -i `expr $keystone_authtoken_line1 + 5`'a\user_domain_name = Default' /etc/glance/glance-registry.conf
  sed -i `expr $keystone_authtoken_line1 + 6`'a\project_name = service' /etc/glance/glance-registry.conf
  sed -i `expr $keystone_authtoken_line1 + 7`'a\username = glance' /etc/glance/glance-registry.conf
  sed -i `expr $keystone_authtoken_line1 + 8`'a\password = 1790600080' /etc/glance/glance-registry.conf

  paste_deploy_line1=`cat -n /etc/glance/glance-registry.conf | grep "\[keystone_authtoken\]$" | awk '{print $1}'`
  sed -i $paste_deploy_line1'a\flavor = keystone' /etc/glance/glance-registry.conf
    echo "    /etc/glance/glance-registry.conf文件已修改完毕"
  else
    echo "/etc/glance/glance-registry.conf配置文件不存在"
  fi
# 	sed -i '/\[database\]/a\connection = mysql+pymysql://glance:1790600080@controller-ZJB/glance' /etc/glance/glance-api.conf
# 	sed -i '/\[keystone_authtoken\]/a\www_authenticate_uri  = http://controller-ZJB:5000\nauth_url = http://controller-ZJB:5000\nmemcached_servers = controller-ZJB:11211\nauth_type = password\nproject_domain_name = Default\nuser_domain_name = Default\nproject_name = service\nusername = glance\npassword =1790600080' /etc/glance/glance-api.conf
# 	sed -i '/\[paste_deploy\]/a\flavor = keystone' /etc/glance/glance-api.conf
# 	sed -i '/\[glance_store\]/a\stores = file,http\ndefault_store = file\nfilesystem_store_datadir = /var/lib/glance/images/' /etc/glance/glance-api.conf

# 	echo "    1、/etc/glance/glance-api.conf文件已修改完毕"
#    else
#         echo "/etc/glance/glance-api.conf文件不存在!"
#    fi

# #判断/etc/glance/glance-registry.conf文件是否存在,不存在直接输出错误
#    ls /etc/glance/glance-registry.conf &>/dev/null
#    if [ $? == 0 ]; then
#    	sed -i '/\[database\]/a\connection = mysql+pymysql://glance:1790600080@controller-ZJB/glance' /etc/glance/glance-registry.conf
# 	sed -i '/\[keystone_authtoken\]/a\www_authenticate_uri = http://controller-ZJB:5000\nauth_url = http://controller-ZJB:5000\nmemcached_servers = controller-ZJB:11211\nauth_type = password\nproject_domain_name = Default\nuser_domain_name = Default\nproject_name = service\nusername = glance\npassword = 1790600080' /etc/glance/glance-registry.conf
#    	sed -i '/\[paste_deploy\]/a\flavor = keystone' /etc/glance/glance-registry.conf

	# echo "    2、/etc/glance/glance-registry.conf文件已修改完毕"
 #   else
	# echo "/etc/glance/glance-registry.conf配置文件不存在"
 #   fi

#填充数据库
echo "   --------------------------------"
echo "   5、填充数据库:"
echo " "
su -s /bin/sh -c "glance-manage db_sync" glance

#启动服务并设置开机自启动
echo "   --------------------------------"
echo "   6、启动服务并设置开机自启动:"
echo " "
systemctl enable openstack-glance-api.service openstack-glance-registry.service
systemctl start openstack-glance-api.service openstack-glance-registry.service

echo "  --------------------------------"
echo "   7、下载一个简单镜像"
echo " "
wget http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img

echo "  --------------------------------"
echo "   8、使用qcow2格式上传镜像到镜像服务"
echo " "
openstack image create "cirros" --file /root/cirros-0.4.0-x86_64-disk.img --disk-format qcow2 --container-format bare --public

echo "  --------------------------------"
echo "   9、测试是否上传成功"
echo " "
openstack image list

elif [ $answer == "n" ]; then
   echo " "
   echo "    已退出此脚本"
fi

0

评论