雲端計算管理平臺之OpenStack簡介及基礎環境搭建
一、簡介
什麼是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了,後續我們就可以在逐一安裝各個控制節點上的服務和計算節點上的服