一、简介
什么是openstack?它是干嘛用的?
简单说openstack是云计算管理平台,主要对云环境中的虚拟机做增删查改;它能够将多台物理设备的资源(cpu/内存等)整合成一个大的资源池,然后根据openstack提供的api接口向用户提供使用;用户可以根据openstack提供的资源池接口来启动虚拟机,管理虚拟机;openstack 主要组成由控制节点和计算节点组成;其中控制节点由多个组件组成,每个组件都是以api的形式向外提供服务,这多个组件共同组成了控制节点,所以控制节点上运行了很多服务;计算节点通常是指提供物理硬件,用于启动虚拟机的物理设备;
二、架构
提示:openstack主要把底层的多台server的资源分为了三类,计算,网络和存储;用户可以通过openstack提供的web界面直接在openstack上启动虚拟机实例;
三、openstack基础环境准备
本次实验是以openstack R版为例,其中各服务器角色如下
主机名 | 角色 | ip地址 |
node01 | 控制节点 | 192.168.0.41/24 |
node02 | 数据库服务器 | 192.168.0.42/24 |
node03 | 计算节点 | 192.168.0.43/24 |
1、各server上的基础环境配置
1)时间同步
[root@node01 ~]# grep server /etc/chrony.conf # Use public servers from the pool.ntp.org project. server time.test.org iburst # Serve time even if not synchronized to any NTP server. [root@node01 ~]# scp /etc/chrony.conf node02:/etc/ chrony.conf 100% 1141 992.7KB/s 00:00 [root@node01 ~]# scp /etc/chrony.conf node03:/etc/ chrony.conf 100% 1141 663.6KB/s 00:00 [root@node01 ~]# chronyc sources 210 Number of sources = 1 MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== ^* time.test.org 3 6 377 40 -15us[ -86us] +/- 20ms [root@node01 ~]# ssh node02 \'chronyc sources\' 210 Number of sources = 1 MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== ^* time.test.org 3 6 377 49 -6552ns[ -15us] +/- 20ms [root@node01 ~]# ssh node03 \'chronyc sources\' 210 Number of sources = 1 MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== ^* time.test.org 3 6 377 52 -30us[ -103us] +/- 20ms [root@node01 ~]#
2)主机名解析
[root@node01 ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.0.99 time.test.org time-node 192.168.0.41 node01.test.org node01 controller 192.168.0.42 node02.test.org node02 192.168.0.43 node03.test.org node03 192.168.0.44 node04.test.org node04 192.168.0.45 node05.test.org node05 192.168.0.46 node06.test.org node06 [root@node01 ~]# scp /etc/hosts node02:/etc/ hosts 100% 423 29.5KB/s 00:00 [root@node01 ~]# scp /etc/hosts node03:/etc/ hosts 100% 423 46.5KB/s 00:00 [root@node01 ~]#
3)关闭selinux、iptables和NetworkManager
[root@node01 ~]# sed -i \'s@SELINUX=enforcing@SELINUX=disabled@g\' /etc/selinux/config [root@node01 ~]# setenforce 0 [root@node01 ~]# getenforce Permissive [root@node01 ~]# ssh node02 \'sed -i \'s@SELINUX=enforcing@SELINUX=disabled@g\' /etc/selinux/config\' [root@node01 ~]# ssh node02 \'setenforce 0 && getenforce\' Permissive [root@node01 ~]# ssh node03 \'sed -i \'s@SELINUX=enforcing@SELINUX=disabled@g\' /etc/selinux/config\' [root@node01 ~]# ssh node03 \'setenforce 0 && getenforce\' Permissive [root@node01 ~]# systemctl stop firewalld NetworkManager [root@node01 ~]# systemctl disable firewalld NetworkManager Removed symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.service. Removed symlink /etc/systemd/system/dbus-org.freedesktop.NetworkManager.service. Removed symlink /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service. [root@node01 ~]# ssh node02 \'systemctl stop firewalld NetworkManager && systemctl disable firewalld NetworkManager\' Removed symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.service. Removed symlink /etc/systemd/system/dbus-org.freedesktop.NetworkManager.service. Removed symlink /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service. [root@node01 ~]# ssh node03 \'systemctl stop firewalld NetworkManager && systemctl disable firewalld NetworkManager\' Removed symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.service. Removed symlink /etc/systemd/system/dbus-org.freedesktop.NetworkManager.service. Removed symlink /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service. [root@node01 ~]#
提示:如果你的系统是最小化安装,这里还需要安装一些基础的包;yum install -y vim wget tree lrzsz gcc gcc-c++ automake pcre pcre-devel zlib zlib-devel openssl openssl-devel iproute net-tools iotop lsof ntpdate telnet bridge-utils;
4)各服务器配置阿里云的base仓库和epel仓库包
[root@node01 ~]# rm -rf /etc/yum.repos.d/*.repo [root@node01 ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo --2020-10-27 22:43:42-- http://mirrors.aliyun.com/repo/Centos-7.repo Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 118.116.3.238, 118.123.164.244, 118.123.164.119, ... Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|118.116.3.238|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 2523 (2.5K) [application/octet-stream] Saving to: ‘/etc/yum.repos.d/CentOS-Base.repo’ 100%[====================================================================================>] 2,523 --.-K/s in 0s 2020-10-27 22:43:42 (180 MB/s) - ‘/etc/yum.repos.d/CentOS-Base.repo’ saved [2523/2523] [root@node01 ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo --2020-10-27 22:43:51-- http://mirrors.aliyun.com/repo/epel-7.repo Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 118.116.3.248, 118.123.164.120, 125.64.102.239, ... Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|118.116.3.248|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 664 [application/octet-stream] Saving to: ‘/etc/yum.repos.d/epel.repo’ 100%[====================================================================================>] 664 --.-K/s in 0s 2020-10-27 22:43:51 (95.0 MB/s) - ‘/etc/yum.repos.d/epel.repo’ saved [664/664] [root@node01 ~]# ll /etc/yum.repos.d/ total 8 drwxr-xr-x. 2 root root 219 Oct 27 22:42 bak -rw-r--r--. 1 root root 2523 Jun 16 2018 CentOS-Base.repo -rw-r--r--. 1 root root 664 May 11 2018 epel.repo [root@node01 ~]#
提示:在node02和node03上都要做以上操作;
2、在各节点上配置openstack R版的yum仓库
[root@node01 ~]# yum install centos-release-openstack-rocky -y
提示:以上操作会在/etc/yum.repos.d/目录下生成很多repo文件;
验证:查看/etcyum.repos.d/目录下是否多了很多repo文件?
[root@node01 ~]# ll /etc/yum.repos.d/ total 56 drwxr-xr-x. 2 root root 219 Oct 27 22:42 bak -rw-r--r--. 1 root root 2523 Jun 16 2018 CentOS-Base.repo -rw-r--r--. 1 root root 850 Jul 31 2018 CentOS-Ceph-Luminous.repo -rw-r--r--. 1 root root 1309 Apr 8 2020 CentOS-CR.repo -rw-r--r--. 1 root root 649 Apr 8 2020 CentOS-Debuginfo.repo -rw-r--r--. 1 root root 314 Apr 8 2020 CentOS-fasttrack.repo -rw-r--r--. 1 root root 630 Apr 8 2020 CentOS-Media.repo -rw-r--r--. 1 root root 1186 Aug 29 2018 CentOS-OpenStack-rocky.repo -rw-r--r--. 1 root root 612 Feb 1 2019 CentOS-QEMU-EV.repo -rw-r--r--. 1 root root 1331 Apr 8 2020 CentOS-Sources.repo -rw-r--r--. 1 root root 353 Jul 31 2018 CentOS-Storage-common.repo -rw-r--r--. 1 root root 7577 Apr 8 2020 CentOS-Vault.repo -rw-r--r--. 1 root root 616 Apr 8 2020 CentOS-x86_64-kernel.repo -rw-r--r--. 1 root root 664 May 11 2018 epel.repo [root@node01 ~]#
提示:这里面的repo文件仓库地址都是指向centos的官方仓库,如果国内下载速度慢,可以把对应的地址指向阿里云;
把centos-openstack-rocky.repo地址指向阿里云
提示:这里只需要改第一个就行,后面的仓库都是禁用了的,不用更改;
把node01上的centos-openstack-rocky.repo文件复制给node02和node03
[root@node01 ~]# scp /etc/yum.repos.d/CentOS-OpenStack-rocky.repo node02:/etc/yum.repos.d/CentOS-OpenStack-rocky.repo CentOS-OpenStack-rocky.repo 100% 1261 832.6KB/s 00:00 [root@node01 ~]# scp /etc/yum.repos.d/CentOS-OpenStack-rocky.repo node03:/etc/yum.repos.d/CentOS-OpenStack-rocky.repo CentOS-OpenStack-rocky.repo 100% 1261 387.4KB/s 00:00 [root@node01 ~]#
提示:复制要在后两个节点都装了centos-release-openstack-rocky这个包以后,以免后续装包覆盖仓库地址文件;
3、在各节点安装python-openstackclient和openstack-selinux包
[root@node01 ~]# yum install -y python-openstackclient openstack-selinux
4、在node02上部署mariadb-server
先查看mariadb-server这个包是否来自openstack-rocky这个仓库
提示:如果能够看到mariadb-server这个包来自centos-openstack-rocky这个仓库,说明我们配置的仓库没有问题;这里建议尽量使用openstacke-rocky仓库中提供的包,如果其他仓库提供的包可能存在不兼容的问题;
下载安装mairadb-server
[root@node02 ~]# yum install mariadb-server -y Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * centos-qemu-ev: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com Resolving Dependencies --> Running transaction check ---> Package mariadb-server.x86_64 3:10.1.20-2.el7 will be installed --> Processing Dependency: mariadb-common(x86-64) = 3:10.1.20-2.el7 for package: 3:mariadb-server-10.1.20-2.el7.x86_64 --> Processing Dependency: mariadb-errmsg(x86-64) = 3:10.1.20-2.el7 for package: 3:mariadb-server-10.1.20-2.el7.x86_64 --> Processing Dependency: mysql(x86-64) for package: 3:mariadb-server-10.1.20-2.el7.x86_64 --> Processing Dependency: mysql-compat-client(x86-64) for package: 3:mariadb-server-10.1.20-2.el7.x86_64 --> Processing Dependency: perl(DBD::mysql) for package: 3:mariadb-server-10.1.20-2.el7.x86_64 --> Processing Dependency: perl(DBI) for package: 3:mariadb-server-10.1.20-2.el7.x86_64 --> Processing Dependency: perl(Data::Dumper) for package: 3:mariadb-server-10.1.20-2.el7.x86_64 --> Processing Dependency: rsync for package: 3:mariadb-server-10.1.20-2.el7.x86_64 --> Processing Dependency: socat for package: 3:mariadb-server-10.1.20-2.el7.x86_64 --> Running transaction check ---> Package mariadb.x86_64 3:10.1.20-2.el7 will be installed --> Processing Dependency: mariadb-libs(x86-64) = 3:10.1.20-2.el7 for package: 3:mariadb-10.1.20-2.el7.x86_64 ……省略部分内容…… Installed: mariadb-server.x86_64 3:10.1.20-2.el7 Dependency Installed: mariadb.x86_64 3:10.1.20-2.el7 mariadb-common.x86_64 3:10.1.20-2.el7 mariadb-config.x86_64 3:10.1.20-2.el7 mariadb-errmsg.x86_64 3:10.1.20-2.el7 perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7 perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7 perl-DBD-MySQL.x86_64 0:4.023-6.el7 perl-DBI.x86_64 0:1.627-4.el7 perl-Data-Dumper.x86_64 0:2.145-3.el7 perl-IO-Compress.noarch 0:2.061-2.el7 perl-Net-Daemon.noarch 0:0.48-5.el7 perl-PlRPC.noarch 0:0.2020-14.el7 rsync.x86_64 0:3.1.2-10.el7 socat.x86_64 0:1.7.3.2-2.el7 Dependency Updated: mariadb-libs.x86_64 3:10.1.20-2.el7 Complete! [root@node02 ~]#
配置数据库
[root@node02 ~]# cat /etc/my.cnf.d/openstack.cnf [mysqld] bind-address = 0.0.0.0 default-storage-engine = innodb innodb_file_per_table = on max_connections = 4096 collation-server = utf8_general_ci character-set-server = utf8 [root@node02 ~]#
设置mariadb-server开机启动,并启动mairadb-server
[root@node02 ~]# systemctl enable mariadb.service Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service. [root@node02 ~]# systemctl start mariadb.service [root@node02 ~]# ss -tnl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:22 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 *:3306 *:* LISTEN 0 128 :::22 :::* LISTEN 0 100 ::1:25 :::* [root@node02 ~]#
5、在node01上安装python2-PyMySQL包,用于控制节点连接数据库驱动
[root@node01 ~]# yum install -y python2-PyMySQL Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * centos-qemu-ev: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com Resolving Dependencies --> Running transaction check ---> Package python2-PyMySQL.noarch 0:0.9.3-1.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ============================================================================================================================== Package Arch Version Repository Size ============================================================================================================================== Installing: python2-PyMySQL noarch 0.9.3-1.el7 epel 91 k Transaction Summary ============================================================================================================================== Install 1 Package Total download size: 91 k Installed size: 372 k Downloading packages: python2-PyMySQL-0.9.3-1.el7.noarch.rpm | 91 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : python2-PyMySQL-0.9.3-1.el7.noarch 1/1 Verifying : python2-PyMySQL-0.9.3-1.el7.noarch 1/1 Installed: python2-PyMySQL.noarch 0:0.9.3-1.el7 Complete! [root@node01 ~]#
6、在node02上部署memcached
[root@node02 ~]# yum install memcached -y Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * centos-qemu-ev: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com Resolving Dependencies --> Running transaction check ---> Package memcached.x86_64 0:1.5.6-1.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ============================================================================================================================== Package Arch Version Repository Size ============================================================================================================================== Installing: memcached x86_64 1.5.6-1.el7 centos-openstack-rocky 124 k Transaction Summary ============================================================================================================================== Install 1 Package Total download size: 124 k Installed size: 268 k Downloading packages: memcached-1.5.6-1.el7.x86_64.rpm | 124 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : memcached-1.5.6-1.el7.x86_64 1/1 Verifying : memcached-1.5.6-1.el7.x86_64 1/1 Installed: memcached.x86_64 0:1.5.6-1.el7 Complete! [root@node02 ~]#
配置memcached
[root@node02 ~]# cat /etc/sysconfig/memcached PORT="11211" USER="memcached" MAXCONN="4096" CACHESIZE="1024" OPTIONS="-l 0.0.0.0,::1" [root@node02 ~]#
设置memcached开机启动,并启动memcached服务
[root@node02 ~]# systemctl enable memcached.service Created symlink from /etc/systemd/system/multi-user.target.wants/memcached.service to /usr/lib/systemd/system/memcached.service. [root@node02 ~]# systemctl start memcached.service [root@node02 ~]# ss -tnl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:11211 *:* LISTEN 0 128 *:22 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 *:3306 *:* LISTEN 0 128 ::1:11211 :::* LISTEN 0 128 :::22 :::* LISTEN 0 100 ::1:25 :::* [root@node02 ~]#
7、在node01上安装连接memcached驱动,python-memcached
[root@node01 ~]# yum install -y python-memcached Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * centos-qemu-ev: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com Resolving Dependencies --> Running transaction check ---> Package python-memcached.noarch 0:1.58-1.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ============================================================================================================================== Package Arch Version Repository Size ============================================================================================================================== Installing: python-memcached noarch 1.58-1.el7 centos-openstack-rocky 38 k Transaction Summary ============================================================================================================================== Install 1 Package Total download size: 38 k Installed size: 123 k Downloading packages: python-memcached-1.58-1.el7.noarch.rpm | 38 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : python-memcached-1.58-1.el7.noarch 1/1 Verifying : python-memcached-1.58-1.el7.noarch 1/1 Installed: python-memcached.noarch 0:1.58-1.el7 Complete! [root@node01 ~]#
8、在node02上部署rabbitmq-server
[root@node02 ~]# yum install rabbitmq-server -y Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * centos-qemu-ev: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com Resolving Dependencies --> Running transaction check ---> Package rabbitmq-server.noarch 0:3.6.16-1.el7 will be installed --> Processing Dependency: erlang-eldap >= 18 for package: rabbitmq-server-3.6.16-1.el7.noarch --> Processing Dependency: erlang-erts >= 18 for package: rabbitmq-server-3.6.16-1.el7.noarch --> Processing Dependency: erlang-kernel >= 18 for package: rabbitmq-server-3.6.16-1.el7.noarch --> Processing Dependency: erlang-mnesia >= 18 for package: rabbitmq-server-3.6.16-1.el7.noarch --> Processing Dependency: erlang-os_mon >= 18 for package: rabbitmq-server-3.6.16-1.el7.noarch --> Processing Dependency: erlang-public_key >= 18 for package: rabbitmq-server-3.6.16-1.el7.noarch ……省略部分内容…… Installed: rabbitmq-server.noarch 0:3.6.16-1.el7 Dependency Installed: erlang-asn1.x86_64 0:19.3.6.4-1.el7 erlang-compiler.x86_64 0:19.3.6.4-1.el7 erlang-crypto.x86_64 0:19.3.6.4-1.el7 erlang-eldap.x86_64 0:19.3.6.4-1.el7 erlang-erts.x86_64 0:19.3.6.4-1.el7 erlang-hipe.x86_64 0:19.3.6.4-1.el7 erlang-inets.x86_64 0:19.3.6.4-1.el7 erlang-kernel.x86_64 0:19.3.6.4-1.el7 erlang-mnesia.x86_64 0:19.3.6.4-1.el7 erlang-os_mon.x86_64 0:19.3.6.4-1.el7 erlang-otp_mibs.x86_64 0:19.3.6.4-1.el7 erlang-public_key.x86_64 0:19.3.6.4-1.el7 erlang-runtime_tools.x86_64 0:19.3.6.4-1.el7 erlang-sasl.x86_64 0:19.3.6.4-1.el7 erlang-sd_notify.x86_64 0:1.0-2.el7 erlang-snmp.x86_64 0:19.3.6.4-1.el7 erlang-ssl.x86_64 0:19.3.6.4-1.el7 erlang-stdlib.x86_64 0:19.3.6.4-1.el7 erlang-syntax_tools.x86_64 0:19.3.6.4-1.el7 erlang-tools.x86_64 0:19.3.6.4-1.el7 erlang-xmerl.x86_64 0:19.3.6.4-1.el7 lksctp-tools.x86_64 0:1.0.17-2.el7 Complete! [root@node02 ~]#
设置rabbitmq-server开机启动,并启动mabbitmq-server服务
[root@node02 ~]# systemctl enable rabbitmq-server.service Created symlink from /etc/systemd/system/multi-user.target.wants/rabbitmq-server.service to /usr/lib/systemd/system/rabbitmq-server.service. [root@node02 ~]# systemctl start rabbitmq-server.service [root@node02 ~]# ss -tnl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:11211 *:* LISTEN 0 128 *:4369 *:* LISTEN 0 128 *:22 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 *:25672 *:* LISTEN 0 128 *:3306 *:* LISTEN 0 128 ::1:11211 :::* LISTEN 0 128 :::22 :::* LISTEN 0 100 ::1:25 :::* LISTEN 0 128 :::5672 :::* [root@node02 ~]#
创建openstack用户并设置密码为openstack123
[root@node02 ~]# rabbitmqctl add_user openstack openstack123 Creating user "openstack" [root@node02 ~]# rabbitmqctl list_users Listing users openstack [] guest [administrator] [root@node02 ~]#
授权openstack用户对/下的所有文件有读写
[root@node02 ~]# rabbitmqctl set_permissions openstack ".*" ".*" ".*" Setting permissions for user "openstack" in vhost "/" [root@node02 ~]# rabbitmqctl list_permissions Listing permissions in vhost "/" guest .* .* .* openstack .* .* .* [root@node02 ~]#
到此,openstack的基础环境和数据库节点就准备ok了,后续我们就可以在逐一安装各个控制节点上的服务和计算节点上的服务;
本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:云计算管理平台之OpenStack简介及基础环境搭建 - Python技术站