prev.sh(预执行脚本):
#! /bin/bash
HOSTS_IP=`ifconfig |grep inet| sed -n '1p'|awk '{print $2}'|awk -F ':' '{print $2}'`
echo "HOSTS_IP is:"$HOSTS_IP
MYSQL_PW=1111
echo "MYSQL_PW is :"$MYSQL_PW
#一、准备工作
#1. 配置ubuntu源仓库
cp /etc/apt/sources.list /etc/apt/sources.list.tmp
cat :> /etc/apt/sources.list
echo deb http://mirrors.163.com/ubuntu/ precise main universe restricted multiverse >> /etc/apt/sources.list
echo deb-src http://mirrors.163.com/ubuntu/ precise main universe restricted multiverse >> /etc/apt/sources.list
echo deb http://mirrors.163.com/ubuntu/ precise-security universe main multiverse restricted >> /etc/apt/sources.list
echo deb-src http://mirrors.163.com/ubuntu/ precise-security universe main multiverse restricted >> /etc/apt/sources.list
echo deb http://mirrors.163.com/ubuntu/ precise-updates universe main multiverse restricted >> /etc/apt/sources.list
echo deb http://mirrors.163.com/ubuntu/ precise-proposed universe main multiverse restricted >> /etc/apt/sources.list
echo deb-src http://mirrors.163.com/ubuntu/ precise-proposed universe main multiverse restricted >> /etc/apt/sources.list
echo deb http://mirrors.163.com/ubuntu/ precise-backports universe main multiverse restricted >> /etc/apt/sources.list
echo deb-src http://mirrors.163.com/ubuntu/ precise-backports universe main multiverse restricted >> /etc/apt/sources.list
echo deb-src http://mirrors.163.com/ubuntu/ precise-updates universe main multiverse restricted >> /etc/apt/sources.list
echo deb http://ubuntu-cloud.archive.canonical.com/ubuntu precise-updates/folsom main >> /etc/apt/sources.list
echo deb http://ubuntu-cloud.archive.canonical.com/ubuntu precise-proposed/folsom main >> /etc/apt/sources.list
apt-get install ubuntu-cloud-keyring
apt-get update
#2. 安装ntp等服务(ntp非常重要,第一次安装失败与没有安装ntp服务有很大的关系,当时的想法是在一台机器上进行安装没必要进行时间同步。)
apt-get install vlan bridge-utils ntp mysql-server python-mysqldb
sed -i.orig 's/127.0.0.1/0.0.0.0/g' /etc/mysql/my.cnf
sed -i '/\[client\]/a\default-character-set = utf8' /etc/mysql/my.cnf
#sed -i '/\[mysqld\]/a\init_connect = "SET NAMES utf8"' /etc/mysql/my.cnf
sed -i '/\[mysqld\]/a\skip-name-resolve' /etc/mysql/my.cnf
service mysql restart
sed -i 's/server ntp.ubuntu.com/server ntp.ubuntu.com server 127.127.1.0 fudge 127.127.1.0 stratum 10/g' /etc/ntp.conf
service ntp restart
#chang hosts file
sed -i.orig 's/127.0.1.1/'$HOSTS_IP'/g' /etc/hosts
#add hostname to /etc/hostname
#echo `hostname` >>/etc/hostname
#3.创建数据库
mysql -u root -p$MYSQL_PW -e "create database nova;"
mysql -u root -p$MYSQL_PW -e "create database glance;"
mysql -u root -p$MYSQL_PW -e "create database cinder;"
mysql -u root -p$MYSQL_PW -e "create database keystone;"
#4. 配置数据库访问权限
mysql -u root -p$MYSQL_PW -e "grant all privileges on *.* to root@'%' identified by '$MYSQL_PW';"
mysql -u root -p$MYSQL_PW -e "grant all privileges on nova.* to nova@'%' identified by '$MYSQL_PW';"
mysql -u root -p$MYSQL_PW -e "grant all privileges on glance.* to glance@'%' identified by '$MYSQL_PW';"
mysql -u root -p$MYSQL_PW -e "grant all privileges on keystone.* to keystone@'%' identified by '$MYSQL_PW';"
mysql -u root -p$MYSQL_PW -e "grant all privileges on cinder.* to cinder@'%' identified by '$MYSQL_PW';"
mysql -u root -p$MYSQL_PW -e "flush privileges;"
#二、安装和配置keystone
#1. 安装keystone相关软件包
apt-get install -y keystone python-keystone python-keystoneclient
#2. 配置相关文件
sed -i 's/sqlite:\/\/\/\/var\/lib\/keystone\/keystone.db/mysql:\/\/keystone:'$MYSQL_PW'@'$HOSTS_IP':3306\/keystone/g' /etc/keystone/keystone.conf
#3. 同步数据库
keystone-manage db_sync
#(very important!!)
#4. 设置环境变量
echo export SERVICE_TOKEN=ADMIN >> /etc/profile
echo export OS_TENANT_NAME=admin >> /etc/profile
echo export OS_USERNAME=admin >> /etc/profile
echo export OS_PASSWORD=$MYSQL_PW >> /etc/profile
echo export OS_AUTH_URL=http://$HOSTS_IP:5000/v2.0/ >> /etc/profile
echo export SERVICE_ENDPOINT=http://$HOSTS_IP:35357/v2.0/ >> /etc/profile
echo export OS_NO_CACHE=1 >> /etc/profile
source /etc/profile
#5. 重启机子
#init 6
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
conf.sh(配置脚本)
#! /bin/bash
HOSTS_IP=`ifconfig |grep inet| sed -n '1p'|awk '{print $2}'|awk -F ':' '{print $2}'`
echo "HOSTS_IP is:"$HOSTS_IP
MYSQL_PW=1111
echo "MYSQL_PW is :"$MYSQL_PW
service mysql restart
service ntp restart
#3.创建数据库
mysql -u root -p$MYSQL_PW -e "create database nova;"
mysql -u root -p$MYSQL_PW -e "create database glance;"
mysql -u root -p$MYSQL_PW -e "create database cinder;"
mysql -u root -p$MYSQL_PW -e "create database keystone;"
#4. 配置数据库访问权限
mysql -u root -p$MYSQL_PW -e "grant all privileges on *.* to root@'%' identified by '$MYSQL_PW';"
mysql -u root -p$MYSQL_PW -e "grant all privileges on nova.* to nova@'%' identified by '$MYSQL_PW';"
mysql -u root -p$MYSQL_PW -e "grant all privileges on glance.* to glance@'%' identified by '$MYSQL_PW';"
mysql -u root -p$MYSQL_PW -e "grant all privileges on keystone.* to keystone@'%' identified by '$MYSQL_PW';"
mysql -u root -p$MYSQL_PW -e "grant all privileges on cinder.* to cinder@'%' identified by '$MYSQL_PW';"
mysql -u root -p$MYSQL_PW -e "flush privileges;"
#select * from user_tenant_membership;
#6. 创建keystone中各种用户
keystone user-create --name admin --pass $MYSQL_PW --email admin@foobar.com
keystone user-create --name nova --pass $MYSQL_PW --email nova@foobar.com
keystone user-create --name glance --pass $MYSQL_PW --email glance@foobar.com
keystone user-create --name cinder --pass $MYSQL_PW --email cinder@foobar.com
#7. 创建keystone中的role(admin和Member)
keystone role-create --name admin
keystone role-create --name Member
#8. 创建两个tenant(admin和service)
keystone tenant-create --name=service
keystone tenant-create --name=admin
#9. 创建各种service(每个service对应OpenStack中的相应组件的相关服务)
keystone service-create --name nova --type compute --description "OpenStack Compute Service"
keystone service-create --name glance --type image --description "OpenStack Image Service"
keystone service-create --name keystone --type identity --description "OpenStack Identity Service"
keystone service-create --name ec2 --type ec2 --description "EC2 Service"
keystone service-create --name cinder --type volume --description "Cinder Service"
#10.创建与service相对应的endpoint glance 9292 ;nova 8774 ;volume 8778 ;keystone 5000
keystone service-list
#(查询出所有的service)
#+----------------------------------+----------+----------+----------------------------+
#| id | name | type | description |
#+----------------------------------+-----------+----------------------------+
#| edd09273443a4b1985aa75dee06389b5 | cinder | volume | Cinder Service |
#| d84599a956e24b0a92a895ea1c3ff661 | ec2 | ec2 | EC2 Service |
#| dcde085d9c254ea883191cf5c2f7581a | glance | image | OpenStack Image Service |
#| ae648160579e440db20bca8fd2f34bdf | keystone | identity | OpenStack Identity Service |
#| bdee479544884cdea243d56ffdd050d3 | nova | compute | OpenStack Compute Service |
#+----------------------------------+-
keystone user-list
keystone role-list
keystone tenant-list
echo "--------------------------keyston service-list------------------------------------------------"
cinder_id=`keystone service-list |grep cinder|awk -F "|" '{ print $2}'`
echo "cinder_id:" $cinder_id
ec2_id=`keystone service-list |grep ec2|awk -F "|" '{ print $2}'`
echo "ec2_id:" $ec2_id
glance_id=`keystone service-list |grep glance|awk -F "|" '{ print $2}'`
echo "glance_id:" $glance_id
keystone_id=`keystone service-list |grep keystone|awk -F "|" '{ print $2}'`
echo "keystone_id:" $keystone_id
nova_id=`keystone service-list |grep nova|awk -F "|" '{ print $2}'`
echo "nova_id:" $nova_id
quantum_id=`keystone service-list |grep quantum|awk -F "|" '{ print $2}'`
echo "quantum_id:" $quantum_id
echo "--------------------------keyston user-list----------------------------------------------------"
user_cinder_id=`keystone user-list |grep cinder|awk -F "|" '{ print $2}'`
echo "user_cinder_id:" $user_cinder_id
user_glance_id=`keystone user-list |grep glance|awk -F "|" '{ print $2}'`
echo "user_glance_id:" $user_glance_id
user_admin_id=`keystone user-list |grep admin|awk -F "|" '{ print $2}'`
echo "user_admin_id:" $user_admin_id
user_nova_id=`keystone user-list |grep nova|awk -F "|" '{ print $2}'`
echo "user_nova_id:" $user_nova_id
user_quantum_id=`keystone user-list |grep quantum|awk -F "|" '{ print $2}'`
echo "user_quantum_id:" $user_quantum_id
echo "--------------------------keyston role-list------------------------------------------------"
role_KeystoneAdmin_id=`keystone role-list |grep KeystoneAdmin|awk -F "|" '{ print $2}'`
echo "role_KeystoneAdmin_id:" $role_KeystoneAdmin_id
role_KeystoneServiceAdmin_id=`keystone role-list |grep KeystoneServiceAdmin|awk -F "|" '{ print $2}'`
echo "role_KeystoneServiceAdmin_id:" $role_KeystoneServiceAdmin_id
role_Member_id=`keystone role-list |grep Member|awk -F "|" '{ print $2}'`
echo "role_Member_id:" $role_Member_id
role__member__id=`keystone role-list |grep _member_ |awk -F "|" '{ print $2}'`
echo "role__member__id:" $role__member__id
role_admin_id=`keystone role-list |grep admin|awk -F "|" '{ print $2}'`
echo "role_admin_id:" $role_admin_id
echo "--------------------------keyston tenant-list------------------------------------------------"
tenant_service_id=`keystone tenant-list |grep service |awk -F "|" '{ print $2}'`
echo "tenant_service_id:" $tenant_service_id
tenant_admin_id=`keystone tenant-list |grep admin|awk -F "|" '{ print $2}'`
echo "tenant_admin_id:" $tenant_admin_id
#9.
#For Nova-api
keystone endpoint-create --region myregion --service_id \
$nova_id --publicurl "http://$HOSTS_IP:8774/v2/%(tenant_id)s" \
--adminurl "http://$HOSTS_IP:8774/v2/%(tenant_id)s" --internalurl "http://$HOSTS_IP:8774/v2/%(tenant_id)s"
#For Glance
keystone endpoint-create --region myregion --service_id \
$glance_id --publicurl "http://$HOSTS_IP:9292/v2" \
--adminurl "http://$HOSTS_IP:9292/v2" --internalurl "http://$HOSTS_IP:9292/v2"
#For keystone
keystone endpoint-create --region myregion --service_id \
$keystone_id --publicurl "http://$HOSTS_IP:5000/v2.0" \
--adminurl "http://$HOSTS_IP:35357/v2.0" --internalurl "http://$HOSTS_IP:5000/v2.0"
#For EC2_compatibility
keystone endpoint-create --region myregion --service_id \
$ec2_id --publicurl "http://$HOSTS_IP:8773/services/Cloud" \
--adminurl "http://$HOSTS_IP:8773/services/Admin" --internalurl "http://$HOSTS_IP:8773/services/Cloud"
#For Cinder
keystone endpoint-create --region myregion --service_id \
$cinder_id --publicurl "http://$HOSTS_IP:8776/v1/%(tenant_id)s" \
--adminurl "http://$HOSTS_IP:8776/v1/%(tenant_id)s" --internalurl "http://$HOSTS_IP:8776/v1/%(tenant_id)s"
#10. 为各个用户加入对应的role(注意user_id, role_id以及tenant_id与前面的保持一致)
#//User admin <> role admin <> tenant admin
keystone user-role-add --user_id $user_admin_id --role_id \
$role_admin_id --tenant_id $tenant_admin_id
#//User nova <> role admin <> tenant service
keystone user-role-add --user_id $user_nova_id --role_id \
$role_admin_id --tenant_id $tenant_service_id
#//User glance <> role admin <> tenant service
keystone user-role-add --user_id $user_glance_id --role_id \
$role_admin_id --tenant_id $tenant_service_id
#//User admin <> role Member <> tenant admin
keystone user-role-add --user_id $user_admin_id --role_id \
$role_Member_id --tenant_id $tenant_admin_id
#//User cinder <> role admin <> tenant service
keystone user-role-add --user_id $user_cinder_id --role_id \
$role_admin_id --tenant_id $tenant_service_id
apt-get install curl openssl
curl -d '{"auth": {"tenantName": "admin", "passwordCredentials":{"username": "admin", "password": "'$MYSQL_PW'"}}}' -H "Content-type: application/json" http://$HOSTS_IP:35357 /v2.0/tokens | python -mjson.tool
#--------------------------------
#--------------------------------
#查看是否添加成功
#mysql>
#mysql -u root -p$MYSQL_PW -e "use keystone;"
mysql -u root -p$MYSQL_PW -e "use keystone;select * from user_tenant_membership;"
#select * from user_tenant_membership;
#+----------------------------------+----------------------------------+
#| user_id | tenant_id |
#+----------------------------------+----------------------------------+
#| 4ad74eff83d24ed1b0da4985b6848407 | 9e9cb9ef4f144ae8b734e1dc9746c60d |
#| 38378b0a1d914b3fa3c021ed69fcc06a | ffaf57cfb40b41ea9e41162485de1159 |
#| 6d159c79c4dc419d8ca12fbe086d6919 | ffaf57cfb40b41ea9e41162485de1159 |
#| ec45e861a4e044bcb98674c6720de5ff | ffaf57cfb40b41ea9e41162485de1159 |
#+----------------------------------+----------------------------------+
#记住,千万不能有重复多余的;如果有,需要删除掉
#delete from endpoint(假设重复的) where service_id="$MYSQL_PW1144(endpoint的id号)"
#三、安装和配置glance
#1. 安装glance相关组件
apt-get install -y glance glance-api python-glanceclient glance-common glance-registry python-glance
echo "-----------------------------begin conf /etc/glance/glance-api.conf------------------------------------"
#2.编辑/etc/glance/glance-api.conf文件
sed -i 's/auth_host = 127.0.0.1/auth_host = '$HOSTS_IP'/' /etc/glance/glance-api.conf
sed -i 's/%SERVICE_TENANT_NAME%/service/' /etc/glance/glance-api.conf
sed -i 's/%SERVICE_USER%/glance/' /etc/glance/glance-api.conf
sed -i 's/%SERVICE_PASSWORD%/'$MYSQL_PW'/' /etc/glance/glance-api.conf
sed -i.orig 's/sqlite:\/\/\/\/var\/lib\/glance\/glance.sqlite/mysql:\/\/glance:'$MYSQL_PW'@'$HOSTS_IP':3306\/glance/' /etc/glance/glance-api.conf
sed -i.orig 's/sqlite_db = \/var\/lib\/glance\/glance.sqlite/sql_connection = mysql:\/\/glance:'$MYSQL_PW'@'$HOSTS_IP':3306\/glance/' /etc/glance/glance-api.conf
echo flavor = keystone >> /etc/glance/glance-api.conf
echo "-----------------------------finished conf /etc/glance/glance-api.conf------------------------------------"
#在glance-api.conf中找到:
#[keystone_authtoken]
#auth_host = $HOSTS_IP
#(改成自己的ip)
#auth_port = 35357
#auth_protocol = http
#admin_tenant_name = service
#admin_user = glance
#admin_password = $MYSQL_PW
#3.编辑/etc/glance/glance-api-paste.ini文件
#文件最后添加
echo "-----------------------------begin conf /etc/glance/glance-api-paste.ini------------------------------------"
echo auth_host = $HOSTS_IP >>/etc/glance/glance-api-paste.ini
#(改成自己的ip)
echo auth_port = 35357 >>/etc/glance/glance-api-paste.ini
echo auth_protocol = http >>/etc/glance/glance-api-paste.ini
echo admin_tenant_name = service >>/etc/glance/glance-api-paste.ini
echo admin_user = glance >>/etc/glance/glance-api-paste.ini
echo admin_password = $MYSQL_PW >>/etc/glance/glance-api-paste.ini
echo "-----------------------------finished conf /etc/glance/glance-api-paste.ini------------------------------------"
#4.编辑/etc/glance/glance-registry.conf文件
echo "-----------------------------begin conf /etc/glance/glance-registry.conf------------------------------------"
sed -i 's/auth_host = 127.0.0.1/auth_host = '$HOSTS_IP'/' /etc/glance/glance-registry.conf
sed -i 's/%SERVICE_TENANT_NAME%/service/' /etc/glance/glance-registry.conf
sed -i 's/%SERVICE_USER%/glance/' /etc/glance/glance-registry.conf
sed -i 's/%SERVICE_PASSWORD%/'$MYSQL_PW'/' /etc/glance/glance-registry.conf
sed -i.orig 's/sqlite:\/\/\/\/var\/lib\/glance\/glance.sqlite/mysql:\/\/glance:'$MYSQL_PW'@'$HOSTS_IP':3306\/glance/' /etc/glance/glance-registry.conf
sed -i.orig 's/sqlite_db = \/var\/lib\/glance\/glance.sqlite/sql_connection = mysql:\/\/glance:'$MYSQL_PW'@'$HOSTS_IP':3306\/glance/' /etc/glance/glance-registry.conf
echo flavor = keystone >> /etc/glance/glance-registry.conf
echo "-----------------------------finished conf /etc/glance/glance-registry.conf------------------------------------"
#在glance-registry.conf中找到:
#[keystone_authtoken]
#auth_host = $HOSTS_IP
#(改成自己的ip)
#auth_port = 35357
#auth_protocol = http
#admin_tenant_name = service
#admin_user = glance
#admin_password = $MYSQL_PW
#3.编辑/etc/glance/glance-registry-paste.ini文件
#文件最后添加
echo "-----------------------------begin conf /etc/glance/glance-registry-paste.ini------------------------------------"
echo auth_host = $HOSTS_IP >>/etc/glance/glance-registry-paste.ini
echo auth_port = 35357 >>/etc/glance/glance-registry-paste.ini
echo auth_protocol = http >>/etc/glance/glance-registry-paste.ini
echo admin_tenant_name = service >>/etc/glance/glance-registry-paste.ini
echo admin_user = glance >>/etc/glance/glance-registry-paste.ini
echo admin_password = $MYSQL_PW >>/etc/glance/glance-registry-paste.ini
echo "-----------------------------finished conf /etc/glance/glance-registry-paste.ini------------------------------------"
#4. 同步数据库,重启服务
echo "-----------------------------begin conf glance-manage db_sync------------------------------------"
service glance-api stop
service glance-registry stop
#(在同步之前先关闭相应服务)
glance-manage db_sync
service glance-api restart
service glance-registry restart
echo "-----------------------------finished conf glance-manage db_sync------------------------------------"
#5. 检查安装
glance index
#-----------------
#-----------------
#如果输出
#ID Name Disk Format Container Format Size
#------------------------------------ ------------------------------ -------------------- -------------------- --------------
# 表示安装正确
#四、安装和配置nova
#1. 安装相关组件包
apt-get install nova-api nova-cert nova-common nova-compute nova-compute-kvm nova-network nova-scheduler python-nova python-novaclient nova-consoleauth rabbitmq-server nova-novncproxy novnc python-novnc websockify nova-console novnc nova-doc
#2. 修改相应文件的权限
#chown -R nova:nova /etc/nova
#chmod 644 /etc/nova/nova.conf
echo "-----------------------------begin conf /etc/nova/nova.conf------------------------------------"
#2. 修改相应文件的权限
cp /etc/nova/nova.conf /etc/nova/nova.conf.bak
chown -R nova:nova /etc/nova
chmod 644 /etc/nova/nova.conf
#3. 配置/etc/nova/nova.conf文件----替换 改IP地址 fixed_range=10.0.0.0/24 //修改网段cat
cat :> /etc/nova/nova.conf
echo [DEFAULT] >>/etc/nova/nova.conf
echo logdir=/var/log/nova >>/etc/nova/nova.conf
echo state_path=/var/lib/nova >>/etc/nova/nova.conf
echo lock_path=/run/lock/nova >>/etc/nova/nova.conf
echo verbose=True >>/etc/nova/nova.conf
echo api_paste_config=/etc/nova/api-paste.ini >>/etc/nova/nova.conf
echo scheduler_driver=nova.scheduler.simple.SimpleScheduler >>/etc/nova/nova.conf
echo s3_host=$HOSTS_IP >>/etc/nova/nova.conf
echo ec2_host=$HOSTS_IP >>/etc/nova/nova.conf
echo ec2_dmz_host=$HOSTS_IP >>/etc/nova/nova.conf
echo rabbit_host=$HOSTS_IP >>/etc/nova/nova.conf
echo metadata_host=$HOSTS_IP >>/etc/nova/nova.conf
echo metadata_listen=0.0.0.0 >>/etc/nova/nova.conf
echo nova_url=http://$HOSTS_IP:8774/v1.1/ >>/etc/nova/nova.conf
echo sql_connection=mysql://nova:$MYSQL_PW@$HOSTS_IP:3306/nova >>/etc/nova/nova.conf
echo ec2_url=http://$HOSTS_IP:8773/services/Cloud >>/etc/nova/nova.conf
echo root_helper=sudo nova-rootwrap /etc/nova/rootwrap.conf >>/etc/nova/nova.conf
#echo [ Auth] >>/etc/nova/nova.conf
echo use_deprecated_auth=false >>/etc/nova/nova.conf
echo auth_strategy=keystone >>/etc/nova/nova.conf
echo keystone_ec2_url=http://$HOSTS_IP:5000/v2.0/ec2tokens >>/etc/nova/nova.conf
#echo [Imaging service] >>/etc/nova/nova.conf
echo glance_api_servers=$HOSTS_IP:9292 >>/etc/nova/nova.conf
echo image_service=nova.image.glance.GlanceImageService >>/etc/nova/nova.conf
#echo [Vnc configuration] >>/etc/nova/nova.conf
echo novnc_enabled=true >>/etc/nova/nova.conf
echo novncproxy_base_url=http://$HOSTS_IP:6080/vnc_auto.html >>/etc/nova/nova.conf
echo novncproxy_port=6080 >>/etc/nova/nova.conf
echo vncserver_proxyclient_address=$HOSTS_IP >>/etc/nova/nova.conf
echo vncserver_listen=$HOSTS_IP >>/etc/nova/nova.conf
#echo #enabled_apis=metadata>>/etc/nova/nova.conf
#echo [ NETWORK] >>/etc/nova/nova.conf
echo libvirt_use_virtio_for_bridges=True >>/etc/nova/nova.conf
echo network_manager=nova.network.manager.FlatDHCPManager >>/etc/nova/nova.conf
echo dhcpbridge_flagfile=/etc/nova/nova.conf >>/etc/nova/nova.conf
echo dhcpbridge=/usr/bin/nova-dhcpbridge >>/etc/nova/nova.conf
echo public_interface=br100 >>/etc/nova/nova.conf
echo flat_interface=eth0 >>/etc/nova/nova.conf
echo flat_network_bridge=br100 >>/etc/nova/nova.conf
echo fixed_range=10.0.0.0/24 >>/etc/nova/nova.conf
echo flat_network_dhcp_start=10.0.0.2 >>/etc/nova/nova.conf
echo network_size=256 >>/etc/nova/nova.conf
echo force_dhcp_release=True >>/etc/nova/nova.conf
echo flat_injected=false >>/etc/nova/nova.conf
echo use_ipv6=false >>/etc/nova/nova.conf
echo multi_host=True >>/etc/nova/nova.conf
#echo [ Compute ] >>/etc/nova/nova.conf
echo compute_driver=libvirt.LibvirtDriver >>/etc/nova/nova.conf
#echo [ Cinder ] >>/etc/nova/nova.conf
echo volume_api_class=nova.volume.cinder.API >>/etc/nova/nova.conf
echo osapi_volume_listen_port=5900 >>/etc/nova/nova.conf
echo "-----------------------------finished conf /etc/nova/nova.conf------------------------------------"
#4. 修改/etc/nova//etc/nova/api-paste.ini
echo "-----------------------------begin conf /etc/nova/api-paste.ini------------------------------------"
sed -i 's/%SERVICE_TENANT_NAME%/service/' /etc/nova/api-paste.ini
sed -i 's/%SERVICE_USER%/nova/' /etc/nova/api-paste.ini
sed -i 's/%SERVICE_PASSWORD%/'$MYSQL_PW'/' /etc/nova/api-paste.ini
#在/etc/nova/api-paste.ini中找到:
#[filter:authtoken]
#paste.filter_factory = keystone.middleware.auth_token:filter_factory
echo auth_host = $HOSTS_IP >> /etc/nova/api-paste.ini
#(改成自己的ip)
echo auth_port = 35357 >> /etc/nova/api-paste.ini
echo auth_protocol = http >> /etc/nova/api-paste.ini
echo admin_tenant_name = service >> /etc/nova/api-paste.ini
echo admin_user = nova >> /etc/nova/api-paste.ini
echo admin_password = $MYSQL_PW >> /etc/nova/api-paste.ini
echo "----------------------------begin conf /etc/nova/nova-computer----------------------"
#sed -i 's/kvm/qemu/g' /etc/nova/nova-compute.conf
echo "----------------------------finished conf /etc/nova/nova-computer-------------------"
echo "-----------------------------finished conf /etc/nova/api-paste.ini------------------------------------"
#5. 同步数据库配置
echo "-----------------------------begin conf nova-manage db sync------------------------------------"
nova-manage db sync
echo "-----------------------------finished conf nova-manage db sync------------------------------------"
#7. 重启相关服务
sudo /etc/init.d/keyston restart
sudo /etc/init.d/glance-api restart
sudo /etc/init.d/glance-registry restart
keystone-manage db_sync
glance-manage db_sync
#cd /etc/init.d/;
#for i in $( ls /etc/init.d/nova-* );
#do sudo service $i restart;
#done
sudo /etc/init.d/nova-api restart
sudo /etc/init.d/nova-cert restart
#sudo /etc/init.d/nova-compute restart
sudo /etc/init.d/nova-console restart
sudo /etc/init.d/nova-consoleauth restart
sudo /etc/init.d/nova-network restart
sudo /etc/init.d/nova-novncproxy restart
sudo /etc/init.d/nova-scheduler restart
sudo /etc/init.d/nova-compute restart
#6. 建立一个网络
echo "-----------------------------begin conf nova-manage network------------------------------------"
nova-manage network create private --multi_host=True --fixed_range_v4=10.0.0.0/24 --bridge=br100 --bridge_interface=eth0 --num_networks=1 --network_size=255
echo "-----------------------------finished conf nova-manage network------------------------------------"
service open-iscsi restart
service novnc restart
#(显示找不到服务,应该是被nova-novncproxy替代了)
service nova-novncproxy restart
#8. 验证服务启动是否成功
echo "-----------------------------begin conf nova-manage service list------------------------------------"
nova-manage service list
echo "-----------------------------finished conf nova-manage service list------------------------------------"
#---------------
#-------------
#Binary Host Zone Status State Updated_At
#nova-cert openstack nova enabled :-) 2014-12-01 14:55:39
#nova-console openstack nova enabled :-) 2014-12-01 14:55:37
#nova-compute openstack nova enabled :-) 2014-12-01 14:55:39
#nova-consoleauth openstack nova enabled :-) 2014-12-01 14:55:39
#nova-scheduler openstack nova enabled :-) 2014-12-01 14:55:37
#nova-network openstack nova enabled :-) 2014-12-01 14:55:40
#-----------------------------
#六、cinder
#1. 安装包
apt-get install cinder-api cinder-scheduler cinder-volume open-iscsi iscsitarget iscsitarget-dkms python-cinderclient linux-headers-`uname -r`
#2、配置并启动iSCSI服务:
service open-iscsi start
echo "-----------------------------begin conf /etc/cinder/api-paste.ini------------------------------------"
#编辑/etc/cinder/api-paste.ini
sed -i 's/%SERVICE_TENANT_NAME%/service/' /etc/cinder/api-paste.ini
sed -i 's/%SERVICE_USER%/cinder/' /etc/cinder/api-paste.ini
sed -i 's/%SERVICE_PASSWORD%/$MYSQL_PW/' /etc/cinder/api-paste.ini
#在/etc/cinder/api-paste.ini找到:
#[filter:authtoken]
#paste.filter_factory = keystone.middleware.auth_token:filter_factory
echo service_protocol = http >> /etc/cinder/api-paste.ini
echo service_host = $HOSTS_IP >> /etc/cinder/api-paste.ini
# (改成自己的ip)
echo service_port = 5000 >> /etc/cinder/api-paste.ini
echo auth_host = $HOSTS_IP >> /etc/cinder/api-paste.ini
# (改成自己的ip)
echo auth_port = 35357 >> /etc/cinder/api-paste.ini
echo auth_protocol = http >> /etc/cinder/api-paste.ini
echo admin_tenant_name = service >> /etc/cinder/api-paste.ini
echo admin_user = cinder >> /etc/cinder/api-paste.ini
echo admin_password = $MYSQL_PW >> /etc/cinder/api-paste.ini
echo "-----------------------------finished conf /etc/cinder/api-paste.ini------------------------------------"
#编辑/etc/cinder/cinder.conf文件,直接执行下面的命令
echo "-----------------------------begin conf /etc/cinder/cinder.conf------------------------------------"
echo sql_connection = mysql://cinder:$MYSQL_PW@$HOSTS_IP:3306/cinder >> /etc/cinder/cinder.conf
echo "-----------------------------finished conf /etc/cinder/cinder.conf------------------------------------"
#同步数据库配置
echo "-----------------------------begin conf cinder-manage db sync------------------------------------"
cinder-manage db sync
echo "-----------------------------finished conf cinder-manage db sync------------------------------------"
#重启服务
service cinder-volume restart
service cinder-api restart
#七、horizon
#1.安装包
apt-get install apache2 libapache2-mod-wsgi openstack-dashboard memcached python-memcache
sed -i 'ServerName '$HOSTS_IP'' >>/etc/apache2/apache2.conf
service apache2 restart
service memcached restart
#cd /usr/lib/python2.7/dist-packages/
#/// (新增加一个目录)
mkdir -p /usr/lib/python2.7/dist-packages/bin
cp /usr/bin/nova-dhcpbridge /usr/lib/python2.7/dist-packages/bin/
#http://$HOSTS_IP/horizon
#测试
#获得镜像
#上传镜像
#先用qemu-img info 查看镜像格式
#如:qemu-img info cirros-0.3.0-x86_64-disk.img
#然后上传镜像
#glance add name="为镜像命名" is_public=true container_format=ovf disk_format=镜像格式 < 镜像路径
#如:
#wget https://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-disk.img -P ~/tools
wget https://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-disk.img -P .
#source admin-openrc.sh
#glance add name="cirros-0.3.0-x86_64" is_public=true container_format=ovf disk_format=qcow2 < ~/tools/cirros-0.3.0-x86_64-disk.img
glance add name="cirros-0.3.0-x86_64" is_public=true container_format=ovf disk_format=qcow2 < cirros-0.3.0-x86_64-disk.img
glance image-list
#apt-get upgrade
#ps:
#/etc/profile 改成本地ip
#格式要对齐
#glance 启用端口
sed -i 's/\(\/root\/tools\/conf.sh\)/\#\/root\/tools\/conf.sh/g' /etc/init.d/rc.local
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
coreopenstack.sh(主运行脚本)
#! /bin/bash
./prev.sh
echo /root/tools/conf.sh >> /etc/init.d/rc.local
init 6
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
unstall_op.sh(模块卸载脚本)
#! /bin/bash
MYSQL_PASSWD=${MYSQL_PASSWD:-"1111"}
mysql -uroot -p$MYSQL_PASSWD -e "DROP DATABASE IF EXISTS nova;"
mysql -uroot -p$MYSQL_PASSWD -e "DROP DATABASE IF EXISTS glance;"
mysql -uroot -p$MYSQL_PASSWD -e "DROP DATABASE IF EXISTS keystone;"
mysql -uroot -p$MYSQL_PASSWD -e "DROP DATABASE IF EXISTS cinder;"
#删除glance
apt-get remove -y glance glance-api glance-client glance-common glance-registry python-glance
#删除nova
apt-get remove -y nova-api nova-cert nova-common nova-compute nova-compute-kvm nova-doc nova-network nova-objectstore nova-scheduler nova-volume python-nova python-novaclient nova-consoleauth python-novnc novnc
删除dashboard
apt-get remove -y libapache2-mod-wsgi openstack-dashboard
#删除mysql数据库
apt-get remove -y mysql-server python-mysqldb
#删除keystone
apt-get remove -y keystone python-keystone python-keystoneclient
dpkg -l |grep keystone|awk '{print $2}'|xargs dpkg -P
dpkg -l |grep glance|awk '{print $2}'|xargs dpkg -P
dpkg -l |grep nova|awk '{print $2}'|xargs dpkg -P
dpkg -l |grep mysql|awk '{print $2}'|xargs dpkg -P
dpkg -l |grep libapache2-mod-wsgi|awk '{print $2}'|xargs dpkg -P
#! /bin/bash
HOSTS_IP=`ifconfig |grep inet| sed -n '1p'|awk '{print $2}'|awk -F ':' '{print $2}'`
echo "HOSTS_IP is:"$HOSTS_IP
MYSQL_PW=1111
echo "MYSQL_PW is :"$MYSQL_PW
#一、准备工作
#1. 配置ubuntu源仓库
cp /etc/apt/sources.list /etc/apt/sources.list.tmp
cat :> /etc/apt/sources.list
echo deb http://mirrors.163.com/ubuntu/ precise main universe restricted multiverse >> /etc/apt/sources.list
echo deb-src http://mirrors.163.com/ubuntu/ precise main universe restricted multiverse >> /etc/apt/sources.list
echo deb http://mirrors.163.com/ubuntu/ precise-security universe main multiverse restricted >> /etc/apt/sources.list
echo deb-src http://mirrors.163.com/ubuntu/ precise-security universe main multiverse restricted >> /etc/apt/sources.list
echo deb http://mirrors.163.com/ubuntu/ precise-updates universe main multiverse restricted >> /etc/apt/sources.list
echo deb http://mirrors.163.com/ubuntu/ precise-proposed universe main multiverse restricted >> /etc/apt/sources.list
echo deb-src http://mirrors.163.com/ubuntu/ precise-proposed universe main multiverse restricted >> /etc/apt/sources.list
echo deb http://mirrors.163.com/ubuntu/ precise-backports universe main multiverse restricted >> /etc/apt/sources.list
echo deb-src http://mirrors.163.com/ubuntu/ precise-backports universe main multiverse restricted >> /etc/apt/sources.list
echo deb-src http://mirrors.163.com/ubuntu/ precise-updates universe main multiverse restricted >> /etc/apt/sources.list
echo deb http://ubuntu-cloud.archive.canonical.com/ubuntu precise-updates/folsom main >> /etc/apt/sources.list
echo deb http://ubuntu-cloud.archive.canonical.com/ubuntu precise-proposed/folsom main >> /etc/apt/sources.list
apt-get install ubuntu-cloud-keyring
apt-get update
#2. 安装ntp等服务(ntp非常重要,第一次安装失败与没有安装ntp服务有很大的关系,当时的想法是在一台机器上进行安装没必要进行时间同步。)
apt-get install vlan bridge-utils ntp mysql-server python-mysqldb
sed -i.orig 's/127.0.0.1/0.0.0.0/g' /etc/mysql/my.cnf
sed -i '/\[client\]/a\default-character-set = utf8' /etc/mysql/my.cnf
#sed -i '/\[mysqld\]/a\init_connect = "SET NAMES utf8"' /etc/mysql/my.cnf
sed -i '/\[mysqld\]/a\skip-name-resolve' /etc/mysql/my.cnf
service mysql restart
sed -i 's/server ntp.ubuntu.com/server ntp.ubuntu.com server 127.127.1.0 fudge 127.127.1.0 stratum 10/g' /etc/ntp.conf
service ntp restart
#chang hosts file
sed -i.orig 's/127.0.1.1/'$HOSTS_IP'/g' /etc/hosts
#add hostname to /etc/hostname
#echo `hostname` >>/etc/hostname
#3.创建数据库
mysql -u root -p$MYSQL_PW -e "create database nova;"
mysql -u root -p$MYSQL_PW -e "create database glance;"
mysql -u root -p$MYSQL_PW -e "create database cinder;"
mysql -u root -p$MYSQL_PW -e "create database keystone;"
#4. 配置数据库访问权限
mysql -u root -p$MYSQL_PW -e "grant all privileges on *.* to root@'%' identified by '$MYSQL_PW';"
mysql -u root -p$MYSQL_PW -e "grant all privileges on nova.* to nova@'%' identified by '$MYSQL_PW';"
mysql -u root -p$MYSQL_PW -e "grant all privileges on glance.* to glance@'%' identified by '$MYSQL_PW';"
mysql -u root -p$MYSQL_PW -e "grant all privileges on keystone.* to keystone@'%' identified by '$MYSQL_PW';"
mysql -u root -p$MYSQL_PW -e "grant all privileges on cinder.* to cinder@'%' identified by '$MYSQL_PW';"
mysql -u root -p$MYSQL_PW -e "flush privileges;"
#二、安装和配置keystone
#1. 安装keystone相关软件包
apt-get install -y keystone python-keystone python-keystoneclient
#2. 配置相关文件
sed -i 's/sqlite:\/\/\/\/var\/lib\/keystone\/keystone.db/mysql:\/\/keystone:'$MYSQL_PW'@'$HOSTS_IP':3306\/keystone/g' /etc/keystone/keystone.conf
#3. 同步数据库
keystone-manage db_sync
#(very important!!)
#4. 设置环境变量
echo export SERVICE_TOKEN=ADMIN >> /etc/profile
echo export OS_TENANT_NAME=admin >> /etc/profile
echo export OS_USERNAME=admin >> /etc/profile
echo export OS_PASSWORD=$MYSQL_PW >> /etc/profile
echo export OS_AUTH_URL=http://$HOSTS_IP:5000/v2.0/ >> /etc/profile
echo export SERVICE_ENDPOINT=http://$HOSTS_IP:35357/v2.0/ >> /etc/profile
echo export OS_NO_CACHE=1 >> /etc/profile
source /etc/profile
#5. 重启机子
#init 6
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
conf.sh(配置脚本)
#! /bin/bash
HOSTS_IP=`ifconfig |grep inet| sed -n '1p'|awk '{print $2}'|awk -F ':' '{print $2}'`
echo "HOSTS_IP is:"$HOSTS_IP
MYSQL_PW=1111
echo "MYSQL_PW is :"$MYSQL_PW
service mysql restart
service ntp restart
#3.创建数据库
mysql -u root -p$MYSQL_PW -e "create database nova;"
mysql -u root -p$MYSQL_PW -e "create database glance;"
mysql -u root -p$MYSQL_PW -e "create database cinder;"
mysql -u root -p$MYSQL_PW -e "create database keystone;"
#4. 配置数据库访问权限
mysql -u root -p$MYSQL_PW -e "grant all privileges on *.* to root@'%' identified by '$MYSQL_PW';"
mysql -u root -p$MYSQL_PW -e "grant all privileges on nova.* to nova@'%' identified by '$MYSQL_PW';"
mysql -u root -p$MYSQL_PW -e "grant all privileges on glance.* to glance@'%' identified by '$MYSQL_PW';"
mysql -u root -p$MYSQL_PW -e "grant all privileges on keystone.* to keystone@'%' identified by '$MYSQL_PW';"
mysql -u root -p$MYSQL_PW -e "grant all privileges on cinder.* to cinder@'%' identified by '$MYSQL_PW';"
mysql -u root -p$MYSQL_PW -e "flush privileges;"
#select * from user_tenant_membership;
#6. 创建keystone中各种用户
keystone user-create --name admin --pass $MYSQL_PW --email admin@foobar.com
keystone user-create --name nova --pass $MYSQL_PW --email nova@foobar.com
keystone user-create --name glance --pass $MYSQL_PW --email glance@foobar.com
keystone user-create --name cinder --pass $MYSQL_PW --email cinder@foobar.com
#7. 创建keystone中的role(admin和Member)
keystone role-create --name admin
keystone role-create --name Member
#8. 创建两个tenant(admin和service)
keystone tenant-create --name=service
keystone tenant-create --name=admin
#9. 创建各种service(每个service对应OpenStack中的相应组件的相关服务)
keystone service-create --name nova --type compute --description "OpenStack Compute Service"
keystone service-create --name glance --type image --description "OpenStack Image Service"
keystone service-create --name keystone --type identity --description "OpenStack Identity Service"
keystone service-create --name ec2 --type ec2 --description "EC2 Service"
keystone service-create --name cinder --type volume --description "Cinder Service"
#10.创建与service相对应的endpoint glance 9292 ;nova 8774 ;volume 8778 ;keystone 5000
keystone service-list
#(查询出所有的service)
#+----------------------------------+----------+----------+----------------------------+
#| id | name | type | description |
#+----------------------------------+-----------+----------------------------+
#| edd09273443a4b1985aa75dee06389b5 | cinder | volume | Cinder Service |
#| d84599a956e24b0a92a895ea1c3ff661 | ec2 | ec2 | EC2 Service |
#| dcde085d9c254ea883191cf5c2f7581a | glance | image | OpenStack Image Service |
#| ae648160579e440db20bca8fd2f34bdf | keystone | identity | OpenStack Identity Service |
#| bdee479544884cdea243d56ffdd050d3 | nova | compute | OpenStack Compute Service |
#+----------------------------------+-
keystone user-list
keystone role-list
keystone tenant-list
echo "--------------------------keyston service-list------------------------------------------------"
cinder_id=`keystone service-list |grep cinder|awk -F "|" '{ print $2}'`
echo "cinder_id:" $cinder_id
ec2_id=`keystone service-list |grep ec2|awk -F "|" '{ print $2}'`
echo "ec2_id:" $ec2_id
glance_id=`keystone service-list |grep glance|awk -F "|" '{ print $2}'`
echo "glance_id:" $glance_id
keystone_id=`keystone service-list |grep keystone|awk -F "|" '{ print $2}'`
echo "keystone_id:" $keystone_id
nova_id=`keystone service-list |grep nova|awk -F "|" '{ print $2}'`
echo "nova_id:" $nova_id
quantum_id=`keystone service-list |grep quantum|awk -F "|" '{ print $2}'`
echo "quantum_id:" $quantum_id
echo "--------------------------keyston user-list----------------------------------------------------"
user_cinder_id=`keystone user-list |grep cinder|awk -F "|" '{ print $2}'`
echo "user_cinder_id:" $user_cinder_id
user_glance_id=`keystone user-list |grep glance|awk -F "|" '{ print $2}'`
echo "user_glance_id:" $user_glance_id
user_admin_id=`keystone user-list |grep admin|awk -F "|" '{ print $2}'`
echo "user_admin_id:" $user_admin_id
user_nova_id=`keystone user-list |grep nova|awk -F "|" '{ print $2}'`
echo "user_nova_id:" $user_nova_id
user_quantum_id=`keystone user-list |grep quantum|awk -F "|" '{ print $2}'`
echo "user_quantum_id:" $user_quantum_id
echo "--------------------------keyston role-list------------------------------------------------"
role_KeystoneAdmin_id=`keystone role-list |grep KeystoneAdmin|awk -F "|" '{ print $2}'`
echo "role_KeystoneAdmin_id:" $role_KeystoneAdmin_id
role_KeystoneServiceAdmin_id=`keystone role-list |grep KeystoneServiceAdmin|awk -F "|" '{ print $2}'`
echo "role_KeystoneServiceAdmin_id:" $role_KeystoneServiceAdmin_id
role_Member_id=`keystone role-list |grep Member|awk -F "|" '{ print $2}'`
echo "role_Member_id:" $role_Member_id
role__member__id=`keystone role-list |grep _member_ |awk -F "|" '{ print $2}'`
echo "role__member__id:" $role__member__id
role_admin_id=`keystone role-list |grep admin|awk -F "|" '{ print $2}'`
echo "role_admin_id:" $role_admin_id
echo "--------------------------keyston tenant-list------------------------------------------------"
tenant_service_id=`keystone tenant-list |grep service |awk -F "|" '{ print $2}'`
echo "tenant_service_id:" $tenant_service_id
tenant_admin_id=`keystone tenant-list |grep admin|awk -F "|" '{ print $2}'`
echo "tenant_admin_id:" $tenant_admin_id
#9.
#For Nova-api
keystone endpoint-create --region myregion --service_id \
$nova_id --publicurl "http://$HOSTS_IP:8774/v2/%(tenant_id)s" \
--adminurl "http://$HOSTS_IP:8774/v2/%(tenant_id)s" --internalurl "http://$HOSTS_IP:8774/v2/%(tenant_id)s"
#For Glance
keystone endpoint-create --region myregion --service_id \
$glance_id --publicurl "http://$HOSTS_IP:9292/v2" \
--adminurl "http://$HOSTS_IP:9292/v2" --internalurl "http://$HOSTS_IP:9292/v2"
#For keystone
keystone endpoint-create --region myregion --service_id \
$keystone_id --publicurl "http://$HOSTS_IP:5000/v2.0" \
--adminurl "http://$HOSTS_IP:35357/v2.0" --internalurl "http://$HOSTS_IP:5000/v2.0"
#For EC2_compatibility
keystone endpoint-create --region myregion --service_id \
$ec2_id --publicurl "http://$HOSTS_IP:8773/services/Cloud" \
--adminurl "http://$HOSTS_IP:8773/services/Admin" --internalurl "http://$HOSTS_IP:8773/services/Cloud"
#For Cinder
keystone endpoint-create --region myregion --service_id \
$cinder_id --publicurl "http://$HOSTS_IP:8776/v1/%(tenant_id)s" \
--adminurl "http://$HOSTS_IP:8776/v1/%(tenant_id)s" --internalurl "http://$HOSTS_IP:8776/v1/%(tenant_id)s"
#10. 为各个用户加入对应的role(注意user_id, role_id以及tenant_id与前面的保持一致)
#//User admin <> role admin <> tenant admin
keystone user-role-add --user_id $user_admin_id --role_id \
$role_admin_id --tenant_id $tenant_admin_id
#//User nova <> role admin <> tenant service
keystone user-role-add --user_id $user_nova_id --role_id \
$role_admin_id --tenant_id $tenant_service_id
#//User glance <> role admin <> tenant service
keystone user-role-add --user_id $user_glance_id --role_id \
$role_admin_id --tenant_id $tenant_service_id
#//User admin <> role Member <> tenant admin
keystone user-role-add --user_id $user_admin_id --role_id \
$role_Member_id --tenant_id $tenant_admin_id
#//User cinder <> role admin <> tenant service
keystone user-role-add --user_id $user_cinder_id --role_id \
$role_admin_id --tenant_id $tenant_service_id
apt-get install curl openssl
curl -d '{"auth": {"tenantName": "admin", "passwordCredentials":{"username": "admin", "password": "'$MYSQL_PW'"}}}' -H "Content-type: application/json" http://$HOSTS_IP:35357 /v2.0/tokens | python -mjson.tool
#--------------------------------
#--------------------------------
#查看是否添加成功
#mysql>
#mysql -u root -p$MYSQL_PW -e "use keystone;"
mysql -u root -p$MYSQL_PW -e "use keystone;select * from user_tenant_membership;"
#select * from user_tenant_membership;
#+----------------------------------+----------------------------------+
#| user_id | tenant_id |
#+----------------------------------+----------------------------------+
#| 4ad74eff83d24ed1b0da4985b6848407 | 9e9cb9ef4f144ae8b734e1dc9746c60d |
#| 38378b0a1d914b3fa3c021ed69fcc06a | ffaf57cfb40b41ea9e41162485de1159 |
#| 6d159c79c4dc419d8ca12fbe086d6919 | ffaf57cfb40b41ea9e41162485de1159 |
#| ec45e861a4e044bcb98674c6720de5ff | ffaf57cfb40b41ea9e41162485de1159 |
#+----------------------------------+----------------------------------+
#记住,千万不能有重复多余的;如果有,需要删除掉
#delete from endpoint(假设重复的) where service_id="$MYSQL_PW1144(endpoint的id号)"
#三、安装和配置glance
#1. 安装glance相关组件
apt-get install -y glance glance-api python-glanceclient glance-common glance-registry python-glance
echo "-----------------------------begin conf /etc/glance/glance-api.conf------------------------------------"
#2.编辑/etc/glance/glance-api.conf文件
sed -i 's/auth_host = 127.0.0.1/auth_host = '$HOSTS_IP'/' /etc/glance/glance-api.conf
sed -i 's/%SERVICE_TENANT_NAME%/service/' /etc/glance/glance-api.conf
sed -i 's/%SERVICE_USER%/glance/' /etc/glance/glance-api.conf
sed -i 's/%SERVICE_PASSWORD%/'$MYSQL_PW'/' /etc/glance/glance-api.conf
sed -i.orig 's/sqlite:\/\/\/\/var\/lib\/glance\/glance.sqlite/mysql:\/\/glance:'$MYSQL_PW'@'$HOSTS_IP':3306\/glance/' /etc/glance/glance-api.conf
sed -i.orig 's/sqlite_db = \/var\/lib\/glance\/glance.sqlite/sql_connection = mysql:\/\/glance:'$MYSQL_PW'@'$HOSTS_IP':3306\/glance/' /etc/glance/glance-api.conf
echo flavor = keystone >> /etc/glance/glance-api.conf
echo "-----------------------------finished conf /etc/glance/glance-api.conf------------------------------------"
#在glance-api.conf中找到:
#[keystone_authtoken]
#auth_host = $HOSTS_IP
#(改成自己的ip)
#auth_port = 35357
#auth_protocol = http
#admin_tenant_name = service
#admin_user = glance
#admin_password = $MYSQL_PW
#3.编辑/etc/glance/glance-api-paste.ini文件
#文件最后添加
echo "-----------------------------begin conf /etc/glance/glance-api-paste.ini------------------------------------"
echo auth_host = $HOSTS_IP >>/etc/glance/glance-api-paste.ini
#(改成自己的ip)
echo auth_port = 35357 >>/etc/glance/glance-api-paste.ini
echo auth_protocol = http >>/etc/glance/glance-api-paste.ini
echo admin_tenant_name = service >>/etc/glance/glance-api-paste.ini
echo admin_user = glance >>/etc/glance/glance-api-paste.ini
echo admin_password = $MYSQL_PW >>/etc/glance/glance-api-paste.ini
echo "-----------------------------finished conf /etc/glance/glance-api-paste.ini------------------------------------"
#4.编辑/etc/glance/glance-registry.conf文件
echo "-----------------------------begin conf /etc/glance/glance-registry.conf------------------------------------"
sed -i 's/auth_host = 127.0.0.1/auth_host = '$HOSTS_IP'/' /etc/glance/glance-registry.conf
sed -i 's/%SERVICE_TENANT_NAME%/service/' /etc/glance/glance-registry.conf
sed -i 's/%SERVICE_USER%/glance/' /etc/glance/glance-registry.conf
sed -i 's/%SERVICE_PASSWORD%/'$MYSQL_PW'/' /etc/glance/glance-registry.conf
sed -i.orig 's/sqlite:\/\/\/\/var\/lib\/glance\/glance.sqlite/mysql:\/\/glance:'$MYSQL_PW'@'$HOSTS_IP':3306\/glance/' /etc/glance/glance-registry.conf
sed -i.orig 's/sqlite_db = \/var\/lib\/glance\/glance.sqlite/sql_connection = mysql:\/\/glance:'$MYSQL_PW'@'$HOSTS_IP':3306\/glance/' /etc/glance/glance-registry.conf
echo flavor = keystone >> /etc/glance/glance-registry.conf
echo "-----------------------------finished conf /etc/glance/glance-registry.conf------------------------------------"
#在glance-registry.conf中找到:
#[keystone_authtoken]
#auth_host = $HOSTS_IP
#(改成自己的ip)
#auth_port = 35357
#auth_protocol = http
#admin_tenant_name = service
#admin_user = glance
#admin_password = $MYSQL_PW
#3.编辑/etc/glance/glance-registry-paste.ini文件
#文件最后添加
echo "-----------------------------begin conf /etc/glance/glance-registry-paste.ini------------------------------------"
echo auth_host = $HOSTS_IP >>/etc/glance/glance-registry-paste.ini
echo auth_port = 35357 >>/etc/glance/glance-registry-paste.ini
echo auth_protocol = http >>/etc/glance/glance-registry-paste.ini
echo admin_tenant_name = service >>/etc/glance/glance-registry-paste.ini
echo admin_user = glance >>/etc/glance/glance-registry-paste.ini
echo admin_password = $MYSQL_PW >>/etc/glance/glance-registry-paste.ini
echo "-----------------------------finished conf /etc/glance/glance-registry-paste.ini------------------------------------"
#4. 同步数据库,重启服务
echo "-----------------------------begin conf glance-manage db_sync------------------------------------"
service glance-api stop
service glance-registry stop
#(在同步之前先关闭相应服务)
glance-manage db_sync
service glance-api restart
service glance-registry restart
echo "-----------------------------finished conf glance-manage db_sync------------------------------------"
#5. 检查安装
glance index
#-----------------
#-----------------
#如果输出
#ID Name Disk Format Container Format Size
#------------------------------------ ------------------------------ -------------------- -------------------- --------------
# 表示安装正确
#四、安装和配置nova
#1. 安装相关组件包
apt-get install nova-api nova-cert nova-common nova-compute nova-compute-kvm nova-network nova-scheduler python-nova python-novaclient nova-consoleauth rabbitmq-server nova-novncproxy novnc python-novnc websockify nova-console novnc nova-doc
#2. 修改相应文件的权限
#chown -R nova:nova /etc/nova
#chmod 644 /etc/nova/nova.conf
echo "-----------------------------begin conf /etc/nova/nova.conf------------------------------------"
#2. 修改相应文件的权限
cp /etc/nova/nova.conf /etc/nova/nova.conf.bak
chown -R nova:nova /etc/nova
chmod 644 /etc/nova/nova.conf
#3. 配置/etc/nova/nova.conf文件----替换 改IP地址 fixed_range=10.0.0.0/24 //修改网段cat
cat :> /etc/nova/nova.conf
echo [DEFAULT] >>/etc/nova/nova.conf
echo logdir=/var/log/nova >>/etc/nova/nova.conf
echo state_path=/var/lib/nova >>/etc/nova/nova.conf
echo lock_path=/run/lock/nova >>/etc/nova/nova.conf
echo verbose=True >>/etc/nova/nova.conf
echo api_paste_config=/etc/nova/api-paste.ini >>/etc/nova/nova.conf
echo scheduler_driver=nova.scheduler.simple.SimpleScheduler >>/etc/nova/nova.conf
echo s3_host=$HOSTS_IP >>/etc/nova/nova.conf
echo ec2_host=$HOSTS_IP >>/etc/nova/nova.conf
echo ec2_dmz_host=$HOSTS_IP >>/etc/nova/nova.conf
echo rabbit_host=$HOSTS_IP >>/etc/nova/nova.conf
echo metadata_host=$HOSTS_IP >>/etc/nova/nova.conf
echo metadata_listen=0.0.0.0 >>/etc/nova/nova.conf
echo nova_url=http://$HOSTS_IP:8774/v1.1/ >>/etc/nova/nova.conf
echo sql_connection=mysql://nova:$MYSQL_PW@$HOSTS_IP:3306/nova >>/etc/nova/nova.conf
echo ec2_url=http://$HOSTS_IP:8773/services/Cloud >>/etc/nova/nova.conf
echo root_helper=sudo nova-rootwrap /etc/nova/rootwrap.conf >>/etc/nova/nova.conf
#echo [ Auth] >>/etc/nova/nova.conf
echo use_deprecated_auth=false >>/etc/nova/nova.conf
echo auth_strategy=keystone >>/etc/nova/nova.conf
echo keystone_ec2_url=http://$HOSTS_IP:5000/v2.0/ec2tokens >>/etc/nova/nova.conf
#echo [Imaging service] >>/etc/nova/nova.conf
echo glance_api_servers=$HOSTS_IP:9292 >>/etc/nova/nova.conf
echo image_service=nova.image.glance.GlanceImageService >>/etc/nova/nova.conf
#echo [Vnc configuration] >>/etc/nova/nova.conf
echo novnc_enabled=true >>/etc/nova/nova.conf
echo novncproxy_base_url=http://$HOSTS_IP:6080/vnc_auto.html >>/etc/nova/nova.conf
echo novncproxy_port=6080 >>/etc/nova/nova.conf
echo vncserver_proxyclient_address=$HOSTS_IP >>/etc/nova/nova.conf
echo vncserver_listen=$HOSTS_IP >>/etc/nova/nova.conf
#echo #enabled_apis=metadata>>/etc/nova/nova.conf
#echo [ NETWORK] >>/etc/nova/nova.conf
echo libvirt_use_virtio_for_bridges=True >>/etc/nova/nova.conf
echo network_manager=nova.network.manager.FlatDHCPManager >>/etc/nova/nova.conf
echo dhcpbridge_flagfile=/etc/nova/nova.conf >>/etc/nova/nova.conf
echo dhcpbridge=/usr/bin/nova-dhcpbridge >>/etc/nova/nova.conf
echo public_interface=br100 >>/etc/nova/nova.conf
echo flat_interface=eth0 >>/etc/nova/nova.conf
echo flat_network_bridge=br100 >>/etc/nova/nova.conf
echo fixed_range=10.0.0.0/24 >>/etc/nova/nova.conf
echo flat_network_dhcp_start=10.0.0.2 >>/etc/nova/nova.conf
echo network_size=256 >>/etc/nova/nova.conf
echo force_dhcp_release=True >>/etc/nova/nova.conf
echo flat_injected=false >>/etc/nova/nova.conf
echo use_ipv6=false >>/etc/nova/nova.conf
echo multi_host=True >>/etc/nova/nova.conf
#echo [ Compute ] >>/etc/nova/nova.conf
echo compute_driver=libvirt.LibvirtDriver >>/etc/nova/nova.conf
#echo [ Cinder ] >>/etc/nova/nova.conf
echo volume_api_class=nova.volume.cinder.API >>/etc/nova/nova.conf
echo osapi_volume_listen_port=5900 >>/etc/nova/nova.conf
echo "-----------------------------finished conf /etc/nova/nova.conf------------------------------------"
#4. 修改/etc/nova//etc/nova/api-paste.ini
echo "-----------------------------begin conf /etc/nova/api-paste.ini------------------------------------"
sed -i 's/%SERVICE_TENANT_NAME%/service/' /etc/nova/api-paste.ini
sed -i 's/%SERVICE_USER%/nova/' /etc/nova/api-paste.ini
sed -i 's/%SERVICE_PASSWORD%/'$MYSQL_PW'/' /etc/nova/api-paste.ini
#在/etc/nova/api-paste.ini中找到:
#[filter:authtoken]
#paste.filter_factory = keystone.middleware.auth_token:filter_factory
echo auth_host = $HOSTS_IP >> /etc/nova/api-paste.ini
#(改成自己的ip)
echo auth_port = 35357 >> /etc/nova/api-paste.ini
echo auth_protocol = http >> /etc/nova/api-paste.ini
echo admin_tenant_name = service >> /etc/nova/api-paste.ini
echo admin_user = nova >> /etc/nova/api-paste.ini
echo admin_password = $MYSQL_PW >> /etc/nova/api-paste.ini
echo "----------------------------begin conf /etc/nova/nova-computer----------------------"
#sed -i 's/kvm/qemu/g' /etc/nova/nova-compute.conf
echo "----------------------------finished conf /etc/nova/nova-computer-------------------"
echo "-----------------------------finished conf /etc/nova/api-paste.ini------------------------------------"
#5. 同步数据库配置
echo "-----------------------------begin conf nova-manage db sync------------------------------------"
nova-manage db sync
echo "-----------------------------finished conf nova-manage db sync------------------------------------"
#7. 重启相关服务
sudo /etc/init.d/keyston restart
sudo /etc/init.d/glance-api restart
sudo /etc/init.d/glance-registry restart
keystone-manage db_sync
glance-manage db_sync
#cd /etc/init.d/;
#for i in $( ls /etc/init.d/nova-* );
#do sudo service $i restart;
#done
sudo /etc/init.d/nova-api restart
sudo /etc/init.d/nova-cert restart
#sudo /etc/init.d/nova-compute restart
sudo /etc/init.d/nova-console restart
sudo /etc/init.d/nova-consoleauth restart
sudo /etc/init.d/nova-network restart
sudo /etc/init.d/nova-novncproxy restart
sudo /etc/init.d/nova-scheduler restart
sudo /etc/init.d/nova-compute restart
#6. 建立一个网络
echo "-----------------------------begin conf nova-manage network------------------------------------"
nova-manage network create private --multi_host=True --fixed_range_v4=10.0.0.0/24 --bridge=br100 --bridge_interface=eth0 --num_networks=1 --network_size=255
echo "-----------------------------finished conf nova-manage network------------------------------------"
service open-iscsi restart
service novnc restart
#(显示找不到服务,应该是被nova-novncproxy替代了)
service nova-novncproxy restart
#8. 验证服务启动是否成功
echo "-----------------------------begin conf nova-manage service list------------------------------------"
nova-manage service list
echo "-----------------------------finished conf nova-manage service list------------------------------------"
#---------------
#-------------
#Binary Host Zone Status State Updated_At
#nova-cert openstack nova enabled :-) 2014-12-01 14:55:39
#nova-console openstack nova enabled :-) 2014-12-01 14:55:37
#nova-compute openstack nova enabled :-) 2014-12-01 14:55:39
#nova-consoleauth openstack nova enabled :-) 2014-12-01 14:55:39
#nova-scheduler openstack nova enabled :-) 2014-12-01 14:55:37
#nova-network openstack nova enabled :-) 2014-12-01 14:55:40
#-----------------------------
#六、cinder
#1. 安装包
apt-get install cinder-api cinder-scheduler cinder-volume open-iscsi iscsitarget iscsitarget-dkms python-cinderclient linux-headers-`uname -r`
#2、配置并启动iSCSI服务:
service open-iscsi start
echo "-----------------------------begin conf /etc/cinder/api-paste.ini------------------------------------"
#编辑/etc/cinder/api-paste.ini
sed -i 's/%SERVICE_TENANT_NAME%/service/' /etc/cinder/api-paste.ini
sed -i 's/%SERVICE_USER%/cinder/' /etc/cinder/api-paste.ini
sed -i 's/%SERVICE_PASSWORD%/$MYSQL_PW/' /etc/cinder/api-paste.ini
#在/etc/cinder/api-paste.ini找到:
#[filter:authtoken]
#paste.filter_factory = keystone.middleware.auth_token:filter_factory
echo service_protocol = http >> /etc/cinder/api-paste.ini
echo service_host = $HOSTS_IP >> /etc/cinder/api-paste.ini
# (改成自己的ip)
echo service_port = 5000 >> /etc/cinder/api-paste.ini
echo auth_host = $HOSTS_IP >> /etc/cinder/api-paste.ini
# (改成自己的ip)
echo auth_port = 35357 >> /etc/cinder/api-paste.ini
echo auth_protocol = http >> /etc/cinder/api-paste.ini
echo admin_tenant_name = service >> /etc/cinder/api-paste.ini
echo admin_user = cinder >> /etc/cinder/api-paste.ini
echo admin_password = $MYSQL_PW >> /etc/cinder/api-paste.ini
echo "-----------------------------finished conf /etc/cinder/api-paste.ini------------------------------------"
#编辑/etc/cinder/cinder.conf文件,直接执行下面的命令
echo "-----------------------------begin conf /etc/cinder/cinder.conf------------------------------------"
echo sql_connection = mysql://cinder:$MYSQL_PW@$HOSTS_IP:3306/cinder >> /etc/cinder/cinder.conf
echo "-----------------------------finished conf /etc/cinder/cinder.conf------------------------------------"
#同步数据库配置
echo "-----------------------------begin conf cinder-manage db sync------------------------------------"
cinder-manage db sync
echo "-----------------------------finished conf cinder-manage db sync------------------------------------"
#重启服务
service cinder-volume restart
service cinder-api restart
#七、horizon
#1.安装包
apt-get install apache2 libapache2-mod-wsgi openstack-dashboard memcached python-memcache
sed -i 'ServerName '$HOSTS_IP'' >>/etc/apache2/apache2.conf
service apache2 restart
service memcached restart
#cd /usr/lib/python2.7/dist-packages/
#/// (新增加一个目录)
mkdir -p /usr/lib/python2.7/dist-packages/bin
cp /usr/bin/nova-dhcpbridge /usr/lib/python2.7/dist-packages/bin/
#http://$HOSTS_IP/horizon
#测试
#获得镜像
#上传镜像
#先用qemu-img info 查看镜像格式
#如:qemu-img info cirros-0.3.0-x86_64-disk.img
#然后上传镜像
#glance add name="为镜像命名" is_public=true container_format=ovf disk_format=镜像格式 < 镜像路径
#如:
#wget https://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-disk.img -P ~/tools
wget https://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-disk.img -P .
#source admin-openrc.sh
#glance add name="cirros-0.3.0-x86_64" is_public=true container_format=ovf disk_format=qcow2 < ~/tools/cirros-0.3.0-x86_64-disk.img
glance add name="cirros-0.3.0-x86_64" is_public=true container_format=ovf disk_format=qcow2 < cirros-0.3.0-x86_64-disk.img
glance image-list
#apt-get upgrade
#ps:
#/etc/profile 改成本地ip
#格式要对齐
#glance 启用端口
sed -i 's/\(\/root\/tools\/conf.sh\)/\#\/root\/tools\/conf.sh/g' /etc/init.d/rc.local
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
coreopenstack.sh(主运行脚本)
#! /bin/bash
./prev.sh
echo /root/tools/conf.sh >> /etc/init.d/rc.local
init 6
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
unstall_op.sh(模块卸载脚本)
#! /bin/bash
MYSQL_PASSWD=${MYSQL_PASSWD:-"1111"}
mysql -uroot -p$MYSQL_PASSWD -e "DROP DATABASE IF EXISTS nova;"
mysql -uroot -p$MYSQL_PASSWD -e "DROP DATABASE IF EXISTS glance;"
mysql -uroot -p$MYSQL_PASSWD -e "DROP DATABASE IF EXISTS keystone;"
mysql -uroot -p$MYSQL_PASSWD -e "DROP DATABASE IF EXISTS cinder;"
#删除glance
apt-get remove -y glance glance-api glance-client glance-common glance-registry python-glance
#删除nova
apt-get remove -y nova-api nova-cert nova-common nova-compute nova-compute-kvm nova-doc nova-network nova-objectstore nova-scheduler nova-volume python-nova python-novaclient nova-consoleauth python-novnc novnc
删除dashboard
apt-get remove -y libapache2-mod-wsgi openstack-dashboard
#删除mysql数据库
apt-get remove -y mysql-server python-mysqldb
#删除keystone
apt-get remove -y keystone python-keystone python-keystoneclient
dpkg -l |grep keystone|awk '{print $2}'|xargs dpkg -P
dpkg -l |grep glance|awk '{print $2}'|xargs dpkg -P
dpkg -l |grep nova|awk '{print $2}'|xargs dpkg -P
dpkg -l |grep mysql|awk '{print $2}'|xargs dpkg -P
dpkg -l |grep libapache2-mod-wsgi|awk '{print $2}'|xargs dpkg -P