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

今我何功德,曾不事农桑

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

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

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

openstack系列Minimal deployment for Rocky

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

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

image.png

image.png

#!/bin/bash
#This is a  script for editing nova-controller keystone
readonly create_user_passwd=1790600080
systemctl stop firewalld
echo "   这是一个一键配置Nova-Controller的keystone组件的脚本:"
echo " "
echo "   --------------------------------"
echo "   1、下面开始创建数据库并赋予相应权限……"
mysql -uroot -p1790600080 <<EOF
CREATE DATABASE keystone;
GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'localhost' IDENTIFIED BY '1790600080';
GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'%' IDENTIFIED BY '1790600080';
EOF

echo "   --------------------------------"
echo "   数据库已创建成功并赋予了相应权限"
echo "   --------------------------------"


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

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

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

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

    token_line=`cat -n /etc/keystone/keystone.conf | grep "\[token\]$" | awk '{print $1}'`
    sed -i $token_line'a\provider = fernet' /etc/keystone/keystone.conf

    echo "    4、/etc/keystone/keystone.conf文件已修改完毕"

   else
        echo "/etc/keystone/keystone.conf文件不存在!"
   fi

  echo " "
  echo "  /etc/keystone/keystone.conf配置文件以修改完毕!"

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

echo "   5、填充数据库并初始化"
su -s /bin/sh -c "keystone-manage db_sync" keystone
keystone-manage fernet_setup --keystone-user keystone --keystone-group keystone
keystone-manage credential_setup --keystone-user keystone --keystone-group keystone

echo "   6、引导身份服务:"
keystone-manage bootstrap --bootstrap-password 1790600080 --bootstrap-admin-url http://controller-ZJB:5000/v3/ --bootstrap-internal-url http://controller-ZJB:5000/v3/ --bootstrap-public-url http://controller-ZJB:5000/v3/ --bootstrap-region-id RegionOne


echo "   7、配置Apache HTTP server"
sed -i 's/#ServerName www.example.com:80/ServerName controller-ZJB/g' /etc/httpd/conf/httpd.conf
ln -s /usr/share/keystone/wsgi-keystone.conf /etc/httpd/conf.d/

echo "   8、配置httpd服务自启动"
systemctl enable httpd.service
systemctl start httpd.service

echo "   9、配置admin管理账户并创建域、项目、用户、角色:"
export OS_USERNAME=admin
export OS_PASSWORD=1790600080
export OS_PROJECT_NAME=admin
export OS_USER_DOMAIN_NAME=Default
export OS_PROJECT_DOMAIN_NAME=Default
export OS_AUTH_URL=http://controller-ZJB:5000/v3
export OS_IDENTITY_API_VERSION=3

openstack domain create --description "An Example Domain" example
openstack project create --domain default --description "Service Project" service
openstack project create --domain default --description "Demo Project" myproject
openstack user create --domain default --password $create_user_passwd myuser
openstack role create myrole
openstack role add --project myproject --user myuser myrole

echo "   10、验证keystone已成功安装运行:"
openstack --os-auth-url http://controller-ZJB:5000/v3 --os-project-domain-name Default --os-user-domain-name Default --os-project-name admin --os-username admin token issue



0

评论