openstark搭建
Posted 人间忽晚,山河以秋
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了openstark搭建相关的知识,希望对你有一定的参考价值。
环境准备
两个主机:控制(controller:192.168.100.10)节点和计算(compute:192.168.100.20)节点
两张网卡:一个100网段,一个200网段(使用服务器则插两跟线,安装centos)
硬盘配置:(服务器使用raid5)
控制节点硬盘分区
计算节点的硬盘分区
安装OpenStack
一、修改主机名
192.168.100.10是控制节点
[root@localhost ~]# hostnamectl set-hostname controller
[root@localhost ~]# bash
[root@controller ~]#
192.168.100.20是计算节点
[root@localhost ~]# hostnamectl set-hostname compute
[root@localhost ~]# bash
[root@compute ~]#
二、配置yum源
在控制节点执行:
把原先的yum源移走,再把先点和centos的镜像挂载到/opt下,
[root@controller ~]# mv /etc/yum.repos.d/* /media/
[root@controller ~]# mkdir /opt/{centos,iaas}
[root@controller ~]# echo /root/CentOS-7-x86_64-DVD-1511.iso /opt/centos/ iso9660 loop 0 0 >> /etc/fstab
[root@controller ~]# echo /root/XianDian-IaaS-v2.2.iso /opt/iaas/ iso9660 loop 0 0 >> /etc/fstab
[root@controller ~]# mount -a
编写yum源文件
[root@controller ~]# vi /etc/yum.repos.d/local.repo
[centos]
name=centos
baseurl=file:///opt/centos
gpgcheck=0
enabled=1
[iaas]
name=iaas
baseurl=file:///opt/iaas/iaas-repo
gpgcheck=0
enabled=1
~
~
~
"/etc/yum.repos.d/local.repo" 11L, 143C
清除缓存重新加载一下yum源
[root@controller ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: centos iaas
Cleaning up everything
Cleaning up list of fastest mirrors
[root@controller ~]# yum repolist
Loaded plugins: fastestmirror
centos | 3.6 kB 00:00:00
iaas | 2.9 kB 00:00:00
(1/3): centos/group_gz | 155 kB 00:00:00
(2/3): centos/primary_db | 2.8 MB 00:00:00
(3/3): iaas/primary_db | 2.3 MB 00:00:00
Determining fastest mirrors
repo id repo name status
centos centos 3,723
iaas iaas 1,688
repolist: 5,411
三、关闭防火墙
在控制节点和计算节点都执行
systemctl disable --now firewalld
setenforce 0
四、控制节点安装配置ftp,和计算节点分享yum源
[root@controller ~]# yum install vsftpd -y
[root@controller ~]# echo anon_root=/opt >> /etc/vsftpd/vsftpd.conf
[root@controller ~]# systemctl enable --now vsftpd
ftp的21端口开启则说明ftp安装成功(若是命令不可以使用则需要安装服务,命令:yum install net-tools -y)
[root@controller ~]# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1462/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2223/master
tcp6 0 0 :::21 :::* LISTEN 3117/vsftpd
tcp6 0 0 :::22 :::* LISTEN 1462/sshd
tcp6 0 0 ::1:25 :::* LISTEN 2223/master
配置计算节点的yum源
计算节点执行
将原先的yum源移走
[root@compute ~]# mv /etc/yum.repos.d/* /media/
在编写yum文件
[root@compute ~]# vi /etc/yum.repos.d/local.repo
[centos]
name=centos
baseurl=ftp://192.168.100.10/centos
gpgcheck=0
enabled=1
[iaas]
name=iaas
baseurl=ftp://192.168.100.10/iaas/iaas-repo
gpgcheck=0
enabled=1
看一下是否成功
[root@compute ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: centos iaas
Cleaning up everything
Cleaning up list of fastest mirrors
[root@compute ~]# yum repolist
Loaded plugins: fastestmirror
centos | 3.6 kB 00:00:00
iaas | 2.9 kB 00:00:00
(1/3): centos/group_gz | 155 kB 00:00:00
(2/3): centos/primary_db | 2.8 MB 00:00:00
(3/3): iaas/primary_db | 2.3 MB 00:00:00
Determining fastest mirrors
repo id repo name status
centos centos 3,723
iaas iaas 1,688
repolist: 5,411
出现了centos和iaas和控制节点一样说明yum源可以了
五、计算节点磁盘分区
计算节点执行
[root@compute ~]# parted /dev/sda
进入分区后再(parted)后面输入p可以查看分区情况,然后输入一下命令进行分区
mkpart cinder 3239G 3339G
mkpart swift 3339G 3439G
输入q退出
查看一下分区
[root@compute ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 3.7T 0 disk
├─sda1 8:1 0 1M 0 part
├─sda2 8:2 0 500M 0 part /boot
├─sda3 8:3 0 3T 0 part
│ ├─centos-root 253:0 0 3T 0 lvm /
│ └─centos-swap 253:1 0 16G 0 lvm [SWAP]
├─sda4 8:4 0 93.2G 0 part
└─sda5 8:5 0 93.1G 0 part
六、安装先点和配置文件
两个节点都安装
yum install -y iaas-xiandian
先点的配置文件目录是:/etc/xiandian/openrc.sh
先把配置文件中的注释#号去掉
以下在控制节点执行
[root@controller ~]# sed -i "s/^#//" /etc/xiandian/openrc.sh
编辑配置文件
[root@controller ~]# vi /etc/xiandian/openrc.sh
#--------------------system Config--------------------##
#Controller Server Manager IP. example:x.x.x.x
HOST_IP=192.168.100.10 ## 控制节点的ip
#Controller Server hostname. example:controller
HOST_NAME=controller ## 控制节点的主机名
#Compute Node Manager IP. example:x.x.x.x
HOST_IP_NODE=192.168.100.20 ## 计算节点的ip
#Compute Node hostname. example:compute
HOST_NAME_NODE=compute ## 计算节点的主机名
#--------------------Rabbit Config ------------------##
#user for rabbit. example:openstack
RABBIT_USER=openstack ## 使用默认的
#Password for rabbit user .example:000000
RABBIT_PASS=000000 ## 使用默认的
#--------------------mysql Config---------------------##
#Password for MySQL root user . exmaple:000000
DB_PASS=000000 ## 使用默认的
#--------------------Keystone Config------------------##
#Password for Keystore admin user. exmaple:000000
DOMAIN_NAME=demo ## 填上 demo
ADMIN_PASS=000000 ## 使用默认的
DEMO_PASS=000000 ## 用默认的
#Password for Mysql keystore user. exmaple:000000
KEYSTONE_DBPASS=000000 ## 使用默认的
#--------------------Glance Config--------------------##
#Password for Mysql glance user. exmaple:000000
GLANCE_DBPASS=000000 ## 使用默认的
#Password for Keystore glance user. exmaple:000000
GLANCE_PASS=000000 ## 使用默认的
#--------------------Nova Config----------------------##
#Password for Mysql nova user. exmaple:000000
NOVA_DBPASS=000000 ## 使用默认的
#Password for Keystore nova user. exmaple:000000
NOVA_PASS=000000 ## 使用默认的
#--------------------Neturon Config-------------------##
#Password for Mysql neutron user. exmaple:000000
NEUTRON_DBPASS=000000 ## 使用默认的
#Password for Keystore neutron user. exmaple:000000
NEUTRON_PASS=000000 ## 使用默认的
#metadata secret for neutron. exmaple:000000
METADATA_SECRET=000000 ## 使用默认的
#External Network Interface. example:eth1
INTERFACE_NAME=enp8s0 ## 本机的第二张网卡(200网段的网卡)
#First Vlan ID in VLAN RANGE for VLAN Network. exmaple:101
minvlan=
#Last Vlan ID in VLAN RANGE for VLAN Network. example:200
maxvlan=
#--------------------Cinder Config--------------------##
#Password for Mysql cinder user. exmaple:000000
CINDER_DBPASS=000000
#Password for Keystore cinder user. exmaple:000000
CINDER_PASS=000000
#Cinder Block Disk. example:md126p3
BLOCK_DISK=sda4 ## 刚刚从节点的分区
#--------------------Trove Config--------------------##
#Password for Mysql Trove User. exmaple:000000
TROVE_DBPASS=000000
#Password for Keystore Trove User. exmaple:000000
TROVE_PASS=000000
#--------------------Swift Config---------------------##
#Password for Keystore swift user. exmaple:000000
SWIFT_PASS=000000
#The NODE Object Disk for Swift. example:md126p4.
OBJECT_DISK=sda5 ## 刚刚从节点的分区
#The NODE IP for Swift Storage Network. example:x.x.x.x.
STORAGE_LOCAL_NET_IP=192.168.100.20 ## 填入从节点的ip
#--------------------Heat Config----------------------##
#Password for Mysql heat user. exmaple:000000
HEAT_DBPASS=000000
#Password for Keystore heat user. exmaple:000000
HEAT_PASS=000000
#--------------------Ceilometer Config----------------##
#Password for Mysql ceilometer user. exmaple:000000
CEILOMETER_DBPASS=000000
#Password for Keystore ceilometer user. exmaple:000000
CEILOMETER_PASS=000000
#--------------------AODH Config----------------##
#Password for Mysql AODH user. exmaple:000000
AODH_DBPASS=000000
#Password for Keystore AODH user. exmaple:000000
AODH_PASS=000000
检查一下,避免写错了
[root@controller ~]# egrep -v '^$|^#' /etc/xiandian/openrc.sh
HOST_IP=192.168.100.10
HOST_NAME=controller
HOST_IP_NODE=192.168.100.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=enp8s0
minvlan=
maxvlan=
CINDER_DBPASS=000000
CINDER_PASS=000000
BLOCK_DISK=sda4
TROVE_DBPASS=000000
TROVE_PASS=000000
SWIFT_PASS=000000
OBJECT_DISK=sda5
STORAGE_LOCAL_NET_IP=192.168.100.20
HEAT_DBPASS=000000
HEAT_PASS=000000
CEILOMETER_DBPASS=000000
CEILOMETER_PASS=000000
AODH_DBPASS=000000
AODH_PASS=000000
检查没有问题,可以远程复制给计算节点
[root@controller ~]# scp /etc/xiandian/openrc.sh compute:/etc/xiandian/openrc.sh
接下来,换到计算节点修改以下配置文件
主要是把网卡修改成计算节点的200网段网卡
我的是这样的
[root@compute ~]# egrep -v '^$|^#' /etc/xiandian/openrc.sh
HOST_IP=192.168.100.10
HOST_NAME=controller
HOST_IP_NODE=192.168.100.20
HOST_NAME_NODE=compute
RABBIT_USER=openstack
RABBIT_PASS=000000
DB_PASS=000000
DOMAIN_NAME=demon
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=enp9s0
minvlan=
maxvlan=
CINDER_DBPASS=000000
CINDER_PASS=000000
BLOCK_DISK=sda4
TROVE_DBPASS=000000
TROVE_PASS=000000
SWIFT_PASS=000000
OBJECT_DISK=sda5
STORAGE_LOCAL_NET_IP=192.168.100.20
HEAT_DBPASS=000000
HEAT_PASS=000000
CEILOMETER_DBPASS=000000
CEILOMETER_PASS=000000
AODH_DBPASS=000000
AODH_PASS=000000
七、开始跑脚本
两个节点都执行
控制节点
[root@controller ~]# iaas-pre-host.sh
计算节点
[root@compute ~]# iaas-pre-host.sh
执行后
看一下脚本
[root@controller ~]# ll /usr/local/bin
total 128
-rwxr-xr-x. 1 root root 3289 Nov 5 2017 iaas-install-alarm.sh
-rwxr-xr-x. 1 root root 2837 Nov 5 2017 iaas-install-ceilometer-compute.sh
-rwxr-xr-x. 1 root root 5796 Nov 5 2017 iaas-install-ceilometer-controller.sh
-rwxr-xr-x. 1 root root 2437 Nov 5 2017 iaas-install-cinder-compute.sh
-rwxr-xr-x. 1 root root 4013 Nov 5 2017 iaas-install-cinder-controller.sh
-rwxr-xr-x. 1 root root 1028 Nov 5 2017 iaas-install-dashboard.sh
-rwxr-xr-x. 1 root root 3586 Nov 5 2017 iaas-install-glance.sh
-rwxr-xr-x. 1 root root 4105 Nov 5 2017 iaas-install-heat.sh
-rwxr-xr-x. 1 root root 3841 Nov 5 2017 iaas-install-keystone.sh
-rwxr-xr-x. 1 root root 1945 Nov 5 2017 iaas-install-mysql.sh
-rwxr-xr-x. 1 root root 582 Nov 5 2017 iaas-install-neutron-compute-flat.sh
-rwxr-xr-x. 1 root root 941 Nov 5 2017 iaas-install-neutron-compute-gre.sh
-rwxr-xr-x. 1 root root 4294 Nov 5 2017 iaas-install-neutron-compute.sh
-rwxr-xr-x. 1 root root 883 Nov 5 2017 iaas-install-neutron-compute-vlan.sh
-rwxr-xr-x. 1 root root 1649 Nov 5 2017 iaas-install-neutron-controller-flat.sh
-rwxr-xr-x. 1 root root 2275 Nov 5 2017 iaas-install-neutron-controller-gre.sh
-rwxr-xr-x. 1 root root 7372 Nov 5 2017 iaas-install-neutron-controller.sh
-rwxr-xr-x. 1 root root 2492 Nov 5 2017 iaas-install-neutron-controller-vlan.sh
-rwxr-xr-x. 1 root root 2531 Nov 5 2017 iaas-install-nova-compute.sh
-rwxr-xr-x. 1 root root 3882 Nov 5 2017 iaas-install-nova-controller.sh
-rwxr-xr-x. 1 root root 4428 Nov 5 2017 iaas-install-swift-compute.sh
-rwxr-xr-x. 1 root root 4049 Nov 5 2017 iaas-install-swift-controller.sh
-rwxr-xr-x. 1 root root 11461 Nov 5 2017 iaas-install-trove.sh
-rwxr-xr-x. 1 root root 1358 Nov 5 2017 iaas-pre-host.sh
-rwxr-xr-x. 1 root root 3337 Nov 5 2017 iaas-uninstall-all.sh
控制节点执行
安装mysql
[root@controller ~]# iaas-install-mysql.sh
[root@controller ~]# iaas-install-keystone.sh && iaas-install-glance.sh && iaas-install-nova-controller.sh
在控制节点查看有这四个用户
[root@controller ~]# source /etc/keystone/admin-openrc.sh
[root@controller ~]# openstack user list
+----------------------------------+--------+
| ID | Name |
+----------------------------------+--------+
| 7fcdbb81f75c440080d2236dda784987 | glance |
| ae6a2ec279434a48a4dfd0dd885d80fa | nova |
| b0d318ce09fe4b60b34ac0613dd88ef4 | demo |
| c678293c2f1f4db9bd8a059a8bc81cf3 | admin |
+----------------------------------+--------+
[root@controller ~]#
就可以在计算节点跑nova脚本
计算节点执行
[root@compute ~]# iaas-install-nova-compute.sh
netureon服务
控制节点执行
[root@controller ~]# iaas-install-neutron-controller.sh
在计算节点执行
[root@compute ~]# iaas-install-neutron-compute.sh
控制节点
[root@controller ~]# iaas-install-neutron-controller-gre.sh
计算节点
[root@compute ~]# iaas-install-neutron-compute-gre.sh
dashbord服务
控制节点
[root@controller ~]# iaas-install-dashboard.sh
安装cinder服务
控制节点
[root@controller ~]# iaas-install-cinder-controller.sh
计算节点
[root@compute ~]# iaas-install-cinder-compute.sh
swift服务
控制节点
[root@controller ~]# iaas-install-swift-controller.sh
计算节点
[root@compute ~]# iaas-install-swift-compute.sh
计算节点会出现如下询问,输入yes在输入控制节点的密码
ceilometer服务
控制节点
[root@controller ~]# iaas-install-ceilometer-controller.sh
等他执行完在执行计算节点
计算节点
[root@compute ~]# iaas-install-ceilometer-compute.sh
控制节点
[root@controller ~]# iaas-install-alarm.sh && iaas-install-heat.sh
安装trove服务
(安装Trove服务之前需要配置好网络(flat或gre),创建好子网,并确认系统已经安装swift和cinder两个服务,否则安装会失败。)
控制节点
编写一下脚本
[root@controller ~]# vi /usr/local/bin/iaas-install-trove.sh
这个主要在web页面创建一个
1、创建外网
登录平台
域是: demo
用户名:admin
密码: 000000
在系统的网络界面里,点击创建网络
按照下面的填写然后提交,不要忘了点击外部网络
创建子网
点击创建子网
按照下图的填写,然后下一步
填写分配池
出现成功即表示创建成功
2、创建内网
3、在创建一个网络
在创建子网
3、创建路由
按照图片填入,然后新建路由
点击
4、配置安全组
把全部的规则都删除
重新添加规则
规则添加所有的ICMP协议,点击添加
入口方向按照以上同样的方式在添加所有的TCP协议和UDP协议
添加完后如图
在添加出口的
同样,ICMP、TCP、UDP协议的全部添加
创建完网络后回到命令界面查看网络列表
int开头的是内部网络,ext开头的是外部网络
[root@controller ~]# source /etc/keystone/admin-openrc.sh
[root@controller ~]#
[root@controller ~]# openstack network list
+-------------------------+----------+--------------------------+
| ID | Name | Subnets |
+-------------------------+----------+--------------------------+
| 706ba0d7-d01c-4121 | int-net1 | 222e0a6f-781a- |
| -b7aa-cbd711358631 | | 4f79-b401-e64e95a980af |
| 8866f180-b5bc-4682 | int-net2 | 35414dcc-11ca-4845-8545- |
| -b75b-eb5cfa9d62de | | 4d391ab420e6 |
| 33cd595e-cc06-4a28 | ext-net | 60a96b85-5125-4e65-a954- |
| -b7ca-12cc2543c6f0 | | c8847f78b10a |
+-------------------------+----------+--------------------------+
[root@controller ~]#
然后配置trove脚本
[root@controller ~]# vi /usr/local/bin/iaas-install-trove.sh
#!/bin/bash
source /etc/xiandian/openrc.sh
source /etc/keystone/admin-openrc.sh
default_network_id=706ba0d7-d01c-4121-b7aa-cbd711358631 # 填写第一个内部网络的ID
#------------------------------------------------------------------------------------------------
printf "\\033[35mPlease wait...\\n\\033[0m"
if [[ `openstack endpoint list | grep -w 'volume' ` == '' ]];then
printf "\\033[35mPlease install the cinder service first! \\n\\033[0m"
exit 1
fi
if [[ `openstack endpoint list | grep -w 'object-store' ` == '' ]];then
printf "\\033[35mPlease install the swift service first! \\n\\033[0m"
exit 1
fi
if [[ `neutron net-list` == '' ]];then
printf "\\033[35mPlease create network first!\\n\\033[0m"
exit 1
fi
if [[ $default_network_id == '' ]]; then
network_mode=`cat /etc/neutron/plugin.ini |grep ^tenant_network_types |awk -F= '{print $2}'`
if [[ $network_mode == 'flat' ]];then
default_network_id=`neutron net-list | sed -e '1,3d' -e '$d' |awk '{print $2}'`
elif [[ $network_mode == 'gre' ]];then
# neutron net-list | sed -e '1,3d' -e '$d' |awk '{print $2}'
for net_name in `neutron net-list | sed -e '1,3d' -e '$d' |awk '{print $2}'`;
do
mode=`neutron net-show $net_name |grep "router:external"`
if [[ `echo $mode |grep -w "False"` != "" ]];then
default_network_id=706ba0d7-d01c-4121-b7aa-cbd711358631 # 与上面的一样,填写第一个内部网络的ID
break
fi
done
# elif [[ $network_mode == 'vlan' ]] ;then
# echo 'vlan'
fi
fi
"/usr/local/bin/iaas-install-trove.sh" 176L, 11524C written
然后执行脚本
控制节点
[root@controller ~]# iaas-install-trove.sh
执行完后修改控制节点的先点文件
[root@controller ~]# vi /etc/xiandian/openrc.sh
#--------------------system Config--------------------##
#Controller Server Manager IP. example:x.x.x.x
HOST_IP=192.168.100.10
#Controller Server hostname. example:controller
HOST_NAME=controller
#Compute Node Manager IP. example:x.x.x.x
HOST_IP_NODE=192.168.100.10 ## 这里修改成控制节点的
#Compute Node hostname. example:compute
HOST_NAME_NODE=controller ## 主机名也修改
#--------------------Rabbit Config ------------------##
#user for rabbit. example:openstack
RABBIT_USER=openstack
#Password for rabbit user .example:000000
RABBIT_PASS=000000
#--------------------MySQL Config---------------------##
#Password for MySQL root user . exmaple:000000
DB_PASS=000000
#--------------------Keystone Config------------------##
#Password for Keystore admin user. exmaple:000000
DOMAIN_NAME=demo
ADMIN_PASS=000000
DEMO_PASS=000000
#Password for Mysql keystore user. exmaple:000000
KEYSTONE_DBPASS=000000
#--------------------Glance Config--------------------##
"/etc/xiandian/openrc.sh" 113L, 3047C written
控制节点执行命令
[root@controller ~]# iaas-install-nova-compute.sh
[root@controller ~]# setenforce 0
到这里全部安装完成
以上是关于openstark搭建的主要内容,如果未能解决你的问题,请参考以下文章