一、环境介绍:

Linux版本:CentOS 7.9 ,查看如下

1
2
[root@controller ~]# cat /etc/redhat-release 
CentOS Linux release 7.9.2009 (Core)

OpenStack版本:T(train)版本

1
2
#查看centos7.9支持的所有的CentOS版本链接如下:
https://mirrors.tuna.tsinghua.edu.cn/centos-vault/7.9.2009/cloud/x86_64/

Linux主机:2台

节点 IP
控制节点(controller) 192.168.10.222
计算节点(Compute) 192.168.10.223

二、基础配置

注:基础配置控制节点和计算节点都要配置。

1、配置主机名

1
2
3
#控制节点配置
[root@localhost ~]# hostnamectl set-hostname controller
[root@localhost ~]# bash
1
2
3
#计算节点配置
[root@compute ~]# hostnamectl set-hostname compute
[root@compute ~]# bash

2、修改hosts文件

1
2
3
4
#控制节点配置
[root@controller ~]# cat /etc/hosts
192.168.10.222 controller
192.168.10.223 compute
1
2
3
4
#计算节点配置
[root@compute ~]# cat /etc/hosts
192.168.10.222 controller
192.168.10.223 compute

3、关闭防火墙selinux

1
2
3
4
#控制节点和计算节点都执行以下步骤
[root@controller ~]# systemctl stop firewalld
[root@controller ~]# setenforce 0
setenforce: SELinux is disabled

4、配置清华yum源

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#控制节点和计算节点都执行以下步骤
[root@controller ~]# mkdir /etc/yum.repos.d.bak
[root@controller ~]# cp /etc/yum.repos.d/* /etc/yum.repos.d.bak
[root@controller ~]# rm -rf /etc/yum.repos.d/*
[root@controller ~]# cd /etc/yum.repos.d/

#配置 CentOS-Base.repo
[root@controller yum.repos.d]# vim CentOS-Base.repo

[base]
name=CentOS-$releasever - Base
baseurl=http://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=http://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=http://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=http://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

# 配置 epel.repo
[root@controller yum.repos.d]# vim epel.repo

[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=http://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch/debug
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=http://mirrors.tuna.tsinghua.edu.cn/epel/7/SRPMS
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1


# 配置 CentOS-QEMU-EV.repo
[root@controller yum.repos.d]# vi /etc/yum.repos.d/CentOS-QEMU-EV.repo
# CentOS-QEMU-EV.repo
#
# Please see http://wiki.centos.org/SpecialInterestGroup/Virtualization for more
# information

[centos-qemu-ev]
name=CentOS-$releasever - QEMU EV
baseurl=http://mirror.centos.org/$contentdir/$releasever/virt/$basearch/kvm-common/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-Virtualization

[centos-qemu-ev-test]
name=CentOS-$releasever - QEMU EV Testing
baseurl=http://buildlogs.centos.org/centos/$releasever/virt/$basearch/kvm-common/
gpgcheck=0
enabled=0

#添加RPM-GPG-KEY-EPEL-7
[root@controller ~]# curl https://mirrors.tuna.tsinghua.edu.cn/epel/RPM-GPG-KEY-EPEL-7 > /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1662 100 1662 0 0 291 0 0:00:05 0:00:05 --:--:-- 397

#运行以下命令生成缓存
[root@controller ~]# yum clean all
[root@controller ~]# yum makecache

5、检查是否有openstack包

1
2
3
4
5
6
7
8
#控制节点和计算节点都执行以下步骤

[root@controller ~]# yum list | grep openstack
ansible-openstack-modules.noarch 0-20140902git79d751a.el7 epel
centos-release-openstack-queens.noarch 1-2.el7.centos extras
centos-release-openstack-rocky.noarch 1-1.el7.centos extras
centos-release-openstack-stein.noarch 1-1.el7.centos extras
centos-release-openstack-train.noarch 1-1.el7.centos extras

6、安装OpenStack T版

1
2
3
#控制节点和计算节点都执行以下步骤

[root@controller ~]# yum -y install centos-release-openstack-train.noarch

7、安装OpenStack依赖包

1
2
3
4
5
#控制节点和计算节点都执行以下步骤

[root@controller ~]# yum install -y python-openstackclient openstack-selinux

#注:CentOS8 使用 yum install -y python3-openstackclient 安装openstackclient

8、配置时间同步

(1) 控制节点配置

a. 安装chrony

1
[root@controller ~]# yum install chrony -y

b. 编辑"/etc/chrony.conf"文件,配置server,允许访问和本地同步

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@controller ~]# vi /etc/chrony.conf

# 注释掉下面内容
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server 192.168.10.222 iburst

# Allow NTP client access from local network.
allow 192.168.0.0/16

# Serve time even if not synchronized to a time source.
local stratum 10

c. 设置时间同步服务开机自启动,并检查服务当前是否监听123端口

1
2
3
4
[root@controller ~]# systemctl enable chronyd
[root@controller ~]# systemctl restart chronyd
[root@controller ~]# ss -ltunp | grep 123
udp UNCONN 0 0 *:123 *:* users:(("chronyd",pid=31485,fd=7))

(2) 计算节点配置

a. 安装chrony

1
[root@compute ~]# yum install chrony -y

b. 编辑"/etc/chrony.conf" 文件并注释除 “server” 键之外的所有内容。修改它引用控制节点

1
2
[root@compute ~]# vi /etc/chrony.conf
server controller iburst

c. 启动 NTP 服务并将其配置为随系统启动

1
2
[root@compute ~]# systemctl enable chronyd.service
[root@compute ~]# systemctl restart chronyd.service

9、检查NTP服务

1
2
3
4
5
6
7
#控制节点和计算节点都执行以下步骤进行NTP服务检查

[root@compute ~]# chronyc sources
210 Number of sources = 1
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* controller 11 6 7 1 +56ns[ +86us] +/- 872us

三、高阶配置

注:只需要控制节点进行配置

1、数据库

OpenStack 服务使用 SQL 数据库来存储信息。 数据库通常在控制器节点上运行。 本指南中的过程根据发行版使用 MariaDB 或 MySQL。 OpenStack 服务还支持其他 SQL 数据库,包括 PostgreSQL。


(1) 安装数据库

1
[root@controller ~]# yum install mariadb mariadb-server python2-PyMySQL -y

(2) 配置数据库

1
2
3
4
5
6
7
8
[root@controller ~]# cat /etc/my.cnf.d/openstack.cnf
[mysqld]
bind-address = 192.168.10.222
default-storage-engine = innodb
innodb_file_per_table = on
max_connections = 4096
collation-server = utf8_general_ci
character-set-server = utf8

(3) 启动数据库

1
2
[root@controller ~]# systemctl start mariadb
[root@controller ~]# systemctl enable mariadb

(4) 配置安全初始化

1
2
3
4
5
6
7
[root@controller ~]# mysql_secure_installation
Enter current password for root (enter for none): 回车
Set root password? [Y/n] n
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y

(5) 验证数据库状态

1
2
[root@controller ~]# netstat -lntup|grep 3306
tcp 0 0 192.168.10.222:3306 0.0.0.0:* LISTEN 32494/mysqld

2、消息队列

OpenStack 使用消息队列来协调服务之间的操作和状态信息。 消息队列服务通常在控制器节点上运行。 OpenStack 支持多种消息队列服务,包括 RabbitMQ、Qpid 和 ZeroMQ。 但是,大多数打包 OpenStack 的发行版都支持特定的消息队列服务。 本文档实现了 RabbitMQ 消息队列服务,因为大多数发行版都支持它。 如果您更喜欢实现不同的消息队列服务,请查阅与之相关的文档。

(1) 安装rabbitmq

1
[root@controller ~]# yum install rabbitmq-server -y

(2) 启动

1
2
[root@controller ~]# systemctl start rabbitmq-server.service 
[root@controller ~]# systemctl enable rabbitmq-server.service

(3) 检查服务状态

1
2
3
[root@controller ~]# netstat -lntup|grep 5672
tcp 0 0 0.0.0.0:25672 0.0.0.0:* LISTEN 17599/beam.smp
tcp6 0 0 :::5672 :::* LISTEN 17599/beam.smp

(4) 创建用户 , 并为用户配置权限(所有权限)

1
2
3
4
5
#创建用户,用户名为 openstack , 密码为 RABBIT_PASS
[root@controller ~]# rabbitmqctl add_user openstack RABBIT_PASS

#为用户配置权限(所有权限)
[root@controller ~]# rabbitmqctl set_permissions openstack ".*" ".*" ".*"

3、Memcache缓存

Memcached是一个自由开源的,高性能,分布式内存对象缓存系统。

Memcached是一种基于内存的key-value存储,用来存储小块的任意数据(字符串、对象)。这些数据可以是数据库调用、API调用或者是页面渲染的结果。

Memcached简洁而强大。它的简洁设计便于快速开发,减轻开发难度,解决了大数据量缓存的很多问题。它的API兼容大部分流行的开发语言。

一般的使用目的是,通过缓存数据库查询结果,减少数据库访问次数,以提高动态Web应用的速度、提高可扩展性。还可以用 Memcached 缓存服务的身份服务认证机制使用的令牌。

(1) 安装

1
[root@controller ~]# yum install memcached python-memcached -y

(2) 修改 /etc/sysconfig/memcached 配置文件

1
2
3
4
5
6
[root@controller ~]# vi /etc/sysconfig/memcached
PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="64"
OPTIONS="-l 192.168.10.222,controller"

(3) 启动memcached,并配置开机自启动

1
2
[root@controller ~]# systemctl start memcached.service 
[root@controller ~]# systemctl enable memcached.service

(4) 验证memcached服务

1
2
[root@controller ~]# netstat -lntup|grep 11211
tcp 0 0 192.168.10.222:11211 0.0.0.0:* LISTEN 23473/memcached

4、Etcd

OpenStack 服务可使用 Etcd(分布式可靠的密钥价值存储)进行分布式密钥锁定、存储配置、跟踪服务实时性和其他场景。

(1) 安装

1
[root@controller ~]# yum install etcd -y

(2) 修改 /etc/etcd/etcd.conf 配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@controller ~]# vi /etc/etcd/etcd.conf

#[Member]
#ETCD_CORS=""
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="http://192.168.10.222:2380"
ETCD_LISTEN_CLIENT_URLS="http://192.168.10.222:2379"
ETCD_NAME="controller"

#[Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.10.222:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.10.222:2379"
ETCD_INITIAL_CLUSTER="controller=http://192.168.10.222:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-01"
ETCD_INITIAL_CLUSTER_STATE="new"

(3) 开机自启动并重启etcd

1
2
[root@controller ~]# systemctl enable etcd
[root@controller ~]# systemctl restart etcd