CentOS上搭建OpenStack云平台只需8G内存!!!

Hello!大家好,今天阿坤为大家带来8G内存的云平台搭建,按照官方的标准是需要32G,最少也是16G内存的,但是阿坤觉的还不是极限,所以今天带大家挑战8G内存搭建最小云平台!

环境准备

1.总共需要三台虚拟机配置如下:
openstack主机配置:
2个CPU,6G内存(空闲内存),50G硬盘
nova1主机配置:
2个CPU,3.9G内存(空闲内存),100G硬盘
nova2主机配置:
2个CPU,3.9G内存(空闲内存),100G硬盘
2.配置静态IP:
openstack:192.168.1.20
nova1:192.168.1.21
nova2:192.168.1.22
3.配置主机名/etc/hosts
4.确保互相ping通
5.配置dns服务器/etc/resolv.conf
6.配置时间同步/etc/chrony.conf
7.配置专用Yum源
8.装包并安装openstack

具体步骤

所有操作以openstack主机操作为例
1.创建虚拟机

[root@room9pc01 ~]# sh vc.sh         //这个是自己写的创建虚拟机觉本
vm-manager> vmcreate 
请输入虚拟机名字: openstack8
请输入虚拟机大小: 50G
Formatting '/var/lib/libvirt/images/openstack8.img', fmt=qcow2 size=53687091200 backing_file='.node_base.qcow2' encryption=off cluster_size=65536 lazy_refcounts=off 
定义域 openstack8(从 /etc/libvirt/qemu/openstack8.xml)
vm-manager> vmcreate
请输入虚拟机名字: nova1
请输入虚拟机大小: 100G
Formatting '/var/lib/libvirt/images/nova1.img', fmt=qcow2 size=107374182400 backing_file='.node_base.qcow2' encryption=off cluster_size=65536 lazy_refcounts=off 
定义域 nova1(从 /etc/libvirt/qemu/nova1.xml)

vm-manager> vmcreate
请输入虚拟机名字: nova2
请输入虚拟机大小: 100G
Formatting '/var/lib/libvirt/images/nova2.img', fmt=qcow2 size=107374182400 backing_file='.node_base.qcow2' encryption=off cluster_size=65536 lazy_refcounts=off 
定义域 nova2(从 /etc/libvirt/qemu/nova2.xml)

vm-manager> quit
[root@room9pc01 ~]# vim /etc/libvirt/qemu/openstack8.xml
...
  8188928                       //大小设置成8G就可以
  8188284  //虚拟内存一般都和真实内存相同(切记不可大于真实内存设置)
...
[root@room9pc01 ~]# vim /etc/libvirt/qemu/nova1.xml     //nova2和nova1内存设置一样
...
  4698112               //4.5G即可
  4697088
...

2.配置IP就不带着大家浪费时间啦
3.配置主机名/etc/hosts

[root@openstack8 ~]# vim /etc/hosts      //nova1,nova2进行一样操作,或者直接scp
# ::1           localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1       localhost localhost.localdomain localhost4 localhost4.localdomain4
192.168.1.20    openstack8     //主机名+IP
192.168.1.21    nova1
192.168.1.22    nova2
:wq   //保存退出

4.确保互相ping通

[root@openstack8 ~]# ping -c 2 nova1
PING nova1 (192.168.1.21) 56(84) bytes of data.
64 bytes from nova1 (192.168.1.21): icmp_seq=1 ttl=255 time=0.513 ms
64 bytes from nova1 (192.168.1.21): icmp_seq=2 ttl=255 time=0.636 ms

--- nova1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 0.513/0.574/0.636/0.066 ms
[root@openstack8 ~]# ping -c 2 nova2
PING nova2 (192.168.1.22) 56(84) bytes of data.
64 bytes from nova2 (192.168.1.22): icmp_seq=1 ttl=255 time=2.02 ms
64 bytes from nova2 (192.168.1.22): icmp_seq=2 ttl=255 time=0.608 ms

--- nova2 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 0.608/1.315/2.023/0.708 ms
[root@openstack8 ~]# ping -c 2 openstack8
PING openstack8 (192.168.1.20) 56(84) bytes of data.
64 bytes from openstack8 (192.168.1.20): icmp_seq=1 ttl=255 time=0.147 ms
64 bytes from openstack8 (192.168.1.20): icmp_seq=2 ttl=255 time=0.095 ms

--- openstack8 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 0.095/0.121/0.147/0.026 ms
[root@openstack8 ~]# 

5.配置dns服务器/etc/resolv.conf

[root@openstack8 ~]# vim /etc/resolv.conf       //nova1,nova2进行一样操作,或者直接scp
; generated by /usr/sbin/dhclient-script
#search localhost        //必须注释掉或者删掉,否则安装后会导致某些功能报错
nameserver 192.168.1.254
:wq   //保存退出

6.配置时间同步/etc/chrony.conf

[root@openstack8 ~]# vim /etc/chrony.conf    //nova1,nova2进行一样操作,或直接scp
...
server 192.168.1.254 iburst    //修改成真机ip保持时间一致
...
:wq   //保存退出
[root@openstack8 ~]# systemctl restart chronyd      //改完配置文件必须重启服务,三台都做
[root@openstack8 ~]# chkconfig chronyd on            //并设置开机自启(个人习惯6、7混合用),三台都做
注意:正在将请求转发到“systemctl enable chronyd.service”。
[root@openstack8 ~]# chronyc sources -v    //三台机器都执行一遍用来检查时间是否同步成功
210 Number of sources = 1

  .-- Source mode  '^' = server, '=' = peer, '#' = local clock.
 / .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| /   '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
||                                                 .- xxxx [ yyyy ] +/- zzzz
||      Reachability register (octal) -.           |  xxxx = adjusted offset,
||      Log2(Polling interval) --.      |          |  yyyy = measured offset,
||                                \     |          |  zzzz = estimated error.
||                                 |    |           \
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^* gateway                       3   6   377    58   +108us[ +153us] +/-   15ms
// 如果gateway前面符号为^*说明同步OJBK,若为^~则同步NOJBK

7.配置专用Yum源
1)真机上操作
从网上下载好所需要用的包,这里我吧它分成了两个目录分别是,extras和opentsack目录,并搭建ftp服务器使虚拟机可以挂载yum源,实际上我们用到的主要是extras源以及rhel-7-server-openstack-10-rpms源和rhel-7-server-openstack-10-devtools-rpms源.

[root@room9pc01 ~]# ls /var/ftp/{extras,openstack}/
/var/ftp/extras/:
comps.xml  Packages  repodata  version.txt

/var/ftp/openstack/:
docs                                      rhel-7-server-rhceph-2-osd-rpms
rhel-7-server-openstack-10-devtools-rpms  rhel-7-server-rhceph-2-tools-rpms
rhel-7-server-openstack-10-optools-rpms   rhel-7-server-rhscon-2-agent-rpms
rhel-7-server-openstack-10-rpms           rhel-7-server-rhscon-2-installer-rpms
rhel-7-server-openstack-10-tools-rpms     rhel-7-server-rhscon-2-main-rpms
rhel-7-server-rhceph-2-mon-rpms           version.txt

2)openstack服务器操作

[root@openstack8 ~]# vim /etc/yum.repos.d/local.repo   //三台都配置,或者直接scp
[local_repo]                                        //本地正常源
name=CentOS-$releasever - Base
baseurl="ftp://192.168.1.254/centos-1804"
enabled=1
gpgcheck=0
[extras]                                            //以下三个都是openstack需要用的三个源
name=CentOS-$releasever - Base
baseurl="ftp://192.168.1.254/extras"
enabled=1
gpgcheck=0
[openstack1]
name=CentOS-$releasever - Base
baseurl="ftp://192.168.1.254/openstack/rhel-7-server-openstack-10-rpms"
enabled=1
gpgcheck=0
[openstack2]
name=CentOS-$releasever - Base
baseurl="ftp://192.168.1.254/openstack/rhel-7-server-openstack-10-devtools-rpms"
enabled=1
gpgcheck=0
:wq   //保存退出
[root@openstack8 ~]# for i in openstack8 nova1 nova2
> do
> scp /etc/yum.repos.d/local.repo $i:/etc/yum.repos.d/
> done
local.repo                                                               100%  488   324.7KB/s   00:00    
local.repo                                                               100%  488   192.2KB/s   00:00    
local.repo                                                               100%  488   313.0KB/s   00:00 
[root@openstack8 ~]# for i in openstack8 nova1 nova2   //检查三台机器源是否成功加载
> do
> ssh $i 'yum repolist'
> done
已加载插件:fastestmirror
Determining fastest mirrors
源标识                             源名称                                  状态
extras                             CentOS-7 - Base                            76
local_repo                         CentOS-7 - Base                         9,911
openstack1                         CentOS-7 - Base                           680
openstack2                         CentOS-7 - Base                             3
repolist: 10,670                                //都显示10670个包yum源就搭建完毕啦
已加载插件:fastestmirror
Determining fastest mirrors
源标识                             源名称                                  状态
extras                             CentOS-7 - Base                            76
local_repo                         CentOS-7 - Base                         9,911
openstack1                         CentOS-7 - Base                           680
openstack2                         CentOS-7 - Base                             3
repolist: 10,670
已加载插件:fastestmirror
Determining fastest mirrors
源标识                             源名称                                  状态
extras                             CentOS-7 - Base                            76
local_repo                         CentOS-7 - Base                         9,911
openstack1                         CentOS-7 - Base                           680
openstack2                         CentOS-7 - Base                             3
repolist: 10,670

8.装包并安装openstack
1)装包
nova1,nova2服务器

[root@nova1 ~]# yum -y install qemu-kvm libvirtdaemon libvirt-daemon-driver-qemu libvirt-client  //nova2做相同操作,总计87个包
...

openstack服务器

[root@openstack8 ~]# yum -y install qemu-kvm libvirtdaemon libvirt-daemon-driver-qemu libvirt-client python-setuptools    //openstack服务器上装五个包,总计91个
....

2)安装openstack

[root@openstack8 ~]# yum install -y openstack-packstack   //安装openstack包,总计77个包
...
[root@openstack8 ~]# packstack --gen-answer-file=answer.ini   //创建通用应答文件
 [root@openstack8 ~]# vim answer.ini
 ...
42   CONFIG_SWIFT_INSTALL=n      //swift对象存储的安装,因为没有,所以使用本地硬盘
45   CONFIG_CEILOMETER_INSTALL=n     //计费模块
49   CONFIG_AODH_INSTALL=n			//计费模块
53   CONFIG_GNOCCHI_INSTALL=n			//计费模块
75   CONFIG_NTP_SERVERS=192.168.1.254		// ntp服务器地址
98   CONFIG_COMPUTE_HOSTS=192.168.1.11	    //nova组件安装的主机地址
102  CONFIG_NETWORK_HOSTS=192.168.1.10,192.168.1.11     //neutron组件安装的主机地址
333  CONFIG_KEYSTONE_ADMIN_PW=a				//默认的管理员密码 330是用户名
840  CONFIG_NEUTRON_ML2_TYPE_DRIVERS=vxlan,flat      //支持的网络协议, flat直连网络,vxlan-->valn的扩展模式vlan支持1-4096个用户,vxlan比较大
910  CONFIG_NEUTRON_OVS_BRIDGE_MAPPINGS=physnet1:br-ex    //虚拟交换机的名称
921  CONFIG_NEUTRON_OVS_BRIDGE_IFACES=br-ex:eth0		//指定br-ex交换机外网出口的网卡
1179 CONFIG_PROVISION_DEMO=n                //演示demo 关闭
 ...
 :wq
[root@openstack8 ~]# packstack --answer-file=answer.ini       //一键部署openstack,时间大概20分钟~40分钟不等
Welcome to the Packstack setup utility

The installation log file is available at: /var/tmp/packstack/20191009-112804-UhwdSh/openstack-setup.log

Installing:
Clean Up                                             [ DONE ]
Discovering ip protocol version                      [ DONE ]
Setting up ssh keys                                  [ DONE ]
Preparing servers                                    [ DONE ]
Pre installing Puppet and discovering hosts' details [ DONE ]
Preparing pre-install entries                        [ DONE ]
Installing time synchronization via NTP              [ DONE ]
Setting up CACERT                                    [ DONE ]
Preparing AMQP entries                               [ DONE ]
Preparing MariaDB entries                            [ DONE ]
Fixing Keystone LDAP config parameters to be undef if empty[ DONE ]
Preparing Keystone entries                           [ DONE ]
Preparing Glance entries                             [ DONE ]
Checking if the Cinder server has a cinder-volumes vg[ DONE ]
Preparing Cinder entries                             [ DONE ]
Preparing Nova API entries                           [ DONE ]
Creating ssh keys for Nova migration                 [ DONE ]
Gathering ssh host keys for Nova migration           [ DONE ]
Preparing Nova Compute entries                       [ DONE ]
Preparing Nova Scheduler entries                     [ DONE ]
Preparing Nova VNC Proxy entries                     [ DONE ]
Preparing OpenStack Network-related Nova entries     [ DONE ]
Preparing Nova Common entries                        [ DONE ]
Preparing Neutron LBaaS Agent entries                [ DONE ]
Preparing Neutron API entries                        [ DONE ]
Preparing Neutron L3 entries                         [ DONE ]
Preparing Neutron L2 Agent entries                   [ DONE ]
Preparing Neutron DHCP Agent entries                 [ DONE ]
Preparing Neutron Metering Agent entries             [ DONE ]
Checking if NetworkManager is enabled and running    [ DONE ]
Preparing OpenStack Client entries                   [ DONE ]
Preparing Horizon entries                            [ DONE ]
Preparing Puppet manifests                           [ DONE ]
Copying Puppet modules and manifests                 [ DONE ]
Applying 192.168.1.20_controller.pp
192.168.1.20_controller.pp:                          [ DONE ]         
Applying 192.168.1.20_network.pp
Applying 192.168.1.21_network.pp
192.168.1.20_network.pp:                             [ DONE ]      
192.168.1.21_network.pp:                             [ DONE ]      
Applying 192.168.1.21_compute.pp
192.168.1.21_compute.pp:                             [ DONE ]      
Applying Puppet manifests                            [ DONE ]
Finalizing                                           [ DONE ]

 **** Installation completed successfully ******                        //出现successfully就成功啦

Additional information:
 * File /root/keystonerc_admin has been created on OpenStack client host 192.168.1.20. To use the command line tools you need to source the file.
 * To access the OpenStack Dashboard browse to http://192.168.1.20/dashboard .
Please, find your login credentials stored in the keystonerc_admin in your home directory.
 * The installation log file is available at: /var/tmp/packstack/20191009-112804-UhwdSh/openstack-setup.log
 * The generated manifests are available at: /var/tmp/packstack/20191009-112804-UhwdSh/manifests
[root@openstack8 ~]# 
[root@openstack8 ~]# vim /etc/httpd/conf.d/15-horizon_vhost.conf    //Horizon 存在一个软件的配置BUG
WSGIApplicationGroup %{GLOBAL}         //在35行后下面加上这一行就可以解决
[root@openstack8 ~]#apachectl graceful     //重新加载配置

最后在真机上登入网站

[root@room9pc01 ~]# firefox 192.168.1.20   //出现如图首页

用户默认admin,密码是你当时改的密码
CentOS上搭建OpenStack云平台只需8G内存!!!_第1张图片
登入成功后显示界面
CentOS上搭建OpenStack云平台只需8G内存!!!_第2张图片
到这呢阿坤的8G openstack云平台就挑战成功辽,至于为什么没nova1,nova2一起安装呢,是因为电脑内存不允许呀,小编怕爆内存,所以安全起见就只先安装了nova1,至于nova2配置够的小伙伴可以一试哦!

你可能感兴趣的:(linux)