Top

NSD CLOUD DAY02

  1. 案例1:配置yum仓库
  2. 案例2:测试时间服务器
  3. 案例3:配置yum仓库
  4. 案例4:检查基础环境
  5. 案例5:部署Openstack
  6. 案例6:网络管理
  7. 案例7:登录openstack

1 案例1:配置yum仓库

1.1 问题

本案例要求配置基本环境:

1.2 方案

此实验的整体方案需要三台机器,openstack作为主节点,nova01 和 nova02作为额外节点,真机做为DNS转发和NTP的服务器(这里不再在表-1中体现),提供域名解析和时间同步服务,具体情况如表-1所示:

表-1

1.3 步骤

实现此案例需要按照如下步骤进行。

步骤一:准备三台虚拟机

[student@room9pc01 images]$base-vm openstack nova01 nova02
[student@room9pc01 images]$virsh start openstack
[student@room9pc01 images]$virsh start nova01
[student@room9pc01 images]$virsh start nova02

2)opensatck主机扩容为50G

[student@room9pc01 images]$ virsh blockresize --path /var/lib/libvirt/images/openstack.img --size 100G openstack
[student@room9pc01 images]$ virsh console openstack
[root@localhost ~]# /usr/bin/growpart /dev/vda 1
[root@localhost ~]# /usr/sbin/xfs_growfs /
[root@localhost ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        50G  914M   50G   2% /

3)nova01 和 nova02 主机扩容为100G(以nova01为例)

[student@room9pc01 images]$ virsh blockresize --path /var/lib/libvirt/images/nova01.img --size 50G nova01
重新定义 '/var/lib/libvirt/images/nova01.img' 块设备大小
[root@localhost ~]# /usr/bin/growpart /dev/vda 1
[root@localhost ~]# /usr/sbin/xfs_growfs  /
[root@localhost ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1       100G  917M  100G   1% /

4)三台主机配置静态ip(以一台为例)

openstack:192.168.1.10

nova01: 192.168.1.11

nova02: 192.168.1.12

[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# vim ifcfg-eth0
# Generated by dracut initrd
DEVICE="eth0"
ONBOOT="yes"
NM_CONTROLLED="no"
TYPE="Ethernet"
BOOTPROTO="static"
PERSISTENT_DHCLIENT="yes"
IPADDR=192.168.1.10
NEMASK=255.255.255.0
GATEWAY=192.168.1.254

5)三台主机修改主机名,配置/etc/hosts,和/etc/resolv.conf文件(以一台为例)

[root@localhost ~]# hostname openstack
[root@localhost ~]# echo openstack > /etc/hostname 

[root@localhost ~]# vim /etc/hosts
192.168.1.10 openstack
192.168.1.11 nova01
192.168.1.12 nova02

[root@localhost ~]# vim /etc/resolv.conf  //去掉search开头的行
; generated by /usr/sbin/dhclient-script
nameserver 192.168.1.254

6)修改三台主机的内存(openstack6G,nova01 和nova02 4G)

[student@room9pc01 ~]$ virsh edit openstack
... 
 <memory unit='KiB'>6588282</memory>
  <currentMemory unit='KiB'>6588282</currentMemory>
...


[student@room9pc01 ~]$ virsh edit nova01
...
  <memory unit='KiB'>4588282</memory>
  <currentMemory unit='KiB'>4588282</currentMemory>
...

[student@room9pc01 ~]$ virsh start  openstack
域 openstack 已开始
[student@room9pc01 ~]$ virsh start  nova01
域 nova01 已开始

[student@room9pc01 ~]$ virsh start  nova02
域 nova02 已开始

2 案例2:测试时间服务器

2.1 问题

本案例要求掌握时间服务的配置:

2.2 步骤

实现此案例需要按照如下步骤进行。

步骤一:修改openstack,nova01 和 nova02 的时间服务器(以一台为例)

[root@openstack ~]# vim /etc/chrony.conf
...
server 192.168.1.254 iburst
[root@openstack ~]# systemctl restart chronyd

步骤二:验证

[root@openstack ~]# chronyc sources -v
...
||                                 |    |           \
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^* gateway                       3   6    37     6    -93ns[ +903ns] +/-   26ms


步骤三:两台虚拟机配置静态ip

注意:两台主机同样操作,改一下ip即可(以openstack.tedu.cn为例)

[root@localhost ~]# echo openstack.tedu.cn > /etc/hostname 
[root@localhost ~]# hostname openstack.tedu.cn	
//另外一台主机改名为nova.tedu.cn,配置ip为1.20
 [root@openstack ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
# Generated by dracut initrd
DEVICE="eth0"
ONBOOT="yes"
IPV6INIT="no"
IPV4_FAILURE_FATAL="no"
NM_CONTROLLED="no"
TYPE="Ethernet"
BOOTPROTO="static"
IPADDR="192.168.1.10"
PREFIX=24
GATEWAY=192.168.1.254
[root@openstack ~]# systemctl restart network


3 案例3:配置yum仓库

3.1 问题

本案例要求配置yum仓库:

3.2 步骤

实现此案例需要按照如下步骤进行。

步骤一:三台主机配置yum源(以一台主机为例,共10670个软件包)

[student@room9pc01 ~]$ cd /linux-soft/04/openstack/
[student@room9pc01 openstack]$ ls
cirros.qcow2  RHEL7-extras.iso  RHEL7OSP-10.iso  small.qcow2
[student@room9pc01 openstack]$ mkdir /var/ftp/RHEL7-extras
[student@room9pc01 openstack]$ mkdir /var/ftp/RHEL7OSP-10
[student@room9pc01 openstack]$ mount RHEL7-extras.iso  /var/ftp/RHEL7-extras/
mount: /dev/loop1 写保护,将以只读方式挂载
[student@room9pc01 openstack]$ mount RHEL7OSP-10.iso /var/ftp/RHEL7OSP-10/
mount: /dev/loop2 写保护,将以只读方式挂载

[root@openstack ~]# vim /etc/yum.repos.d/local.repo
[local_repo]
name=CentOS-$releasever - Base
baseurl="ftp://192.168.1.254/centos-1804"
enabled=1
gpgcheck=1

[RHEL7-extras]
name=RHEL7-extras
baseurl="ftp://192.168.1.254/RHEL7-extras"
enabled=1
gpgcheck=0

[RHEL7OSP-package]
name=RHEL7OSP-package
baseurl="ftp://192.168.1.254/RHEL7OSP-10/rhel-7-server-openstack-10-rpms"
enabled=1
gpgcheck=0

[RHEL7OSP-devtools]
name=RHEL7OSP-devtools
baseurl="ftp://192.168.1.254/RHEL7OSP-10/rhel-7-server-openstack-10-devtools-rpms"
enabled=1
gpgcheck=0

[root@openstack ~]# scp /etc/yum.repos.d/local.repo 192.168.1.11:/etc/yum.repos.d/
root@192.168.1.11's password: 
local.repo                                                                                          100%  490   484.4KB/s   00:00    
[root@openstack ~]# scp /etc/yum.repos.d/local.repo 192.168.1.12:/etc/yum.repos.d/
root@192.168.1.12's password: 
local.repo


4 案例4:检查基础环境

4.1 问题

本案例要求准备基础环境,为安装openstack做准备:

4.2 步骤

实现此案例需要按照如下步骤进行。

步骤一:检查基础环境

1)安装额外软件包(三台机器操作,这里以一台为例)

[root@openstack yum.repos.d]# yum install -y qemu-kvm libvirt-client libvirt-daemon libvirt-daemon-driver-qemu python-setuptools

2)是否卸载firewalld 和 NetworkManager

[root@openstack ~]# rpm -qa  | grep NetworkManager*
[root@openstack ~]# rpm -qa  | grep firewalld*   

3)检查配置主机网络参数

[root@openstack ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 
# Generated by dracut initrd
DEVICE="eth0"
ONBOOT="yes"
NM_CONTROLLED="no"
TYPE="Ethernet"
BOOTPROTO="static"
PERSISTENT_DHCLIENT="yes"
IPADDR=192.168.1.10
NEMASK=255.255.255.0
GATEWAY=192.168.1.254

4)验证主机名是否互通

[root@openstack ~]# ping openstack
...
64 bytes from openstack (192.168.1.10): icmp_seq=1 ttl=255 time=0.023 ms
64 bytes from openstack (192.168.1.10): icmp_seq=2 ttl=255 time=0.027 ms
...

[root@openstack ~]# ping nova01
PING nova01 (192.168.1.11) 56(84) bytes of data.
64 bytes from nova01 (192.168.1.11): icmp_seq=1 ttl=255 time=0.139 ms
...

[root@openstack ~]# ping nova02
PING nova02 (192.168.1.12) 56(84) bytes of data.
64 bytes from nova02 (192.168.1.12): icmp_seq=1 ttl=255 time=0.251 ms
...

5)检查配置主机yum源

[root@openstack ~]# yum repolist
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
源标识                                                          源名称                                                           状态
RHEL7-extras                                                    RHEL7-extras                                                        76
RHEL7OSP-devtools                                               RHEL7OSP-devtools                                                    3
RHEL7OSP-package                                                RHEL7OSP-package                                                   680
local_repo                                                      CentOS-7 - Base                                                  9,911
repolist: 10,670

6)检查时间同步是否可用

[root@openstack ~]# chronyc  sources -v
210 Number of sources = 1

....
||                                 |    |           \
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^* gateway                       3   7   377    28    +31us[  +89us] +/-   25ms
[root@openstack ~]#

7)检查/etc/resolv.conf 不能有 search 开头的行

[root@openstack ~]# cat /etc/resolv.conf 
; generated by /usr/sbin/dhclient-script
nameserver 192.168.1.254

5 案例5:部署Openstack

5.1 问题

本案例要求通过packstack完成以下配置:

5.2 步骤

实现此案例需要按照如下步骤进行。

步骤一:安装packstack

[root@openstack ~]# yum install -y openstack-packstack
[root@openstack ~]# packstack --gen-answer-file answer.ini  
//answer.ini与answer.txt是一样的,只是用vim打开answer.ini文件有颜色
Packstack changed given value  to required value /root/.ssh/id_rsa.pub
[root@openstack ~]# vim answer.ini
42  CONFIG_SWIFT_INSTALL=n
45  CONFIG_CEILOMETER_INSTALL=n                   //计费相关模块
49  CONFIG_AODH_INSTALL=n                         //计费相关模块
53  CONFIG_GNOCCHI_INSTALL=n                     //计费相关模块
75  CONFIG_NTP_SERVERS=192.168.1.254   //时间服务器的地址
98  CONFIG_COMPUTE_HOSTS=192.168.1.11
102 CONFIG_NETWORK_HOSTS=192.168.1.10,192.168.1.11
 333 CONFIG_KEYSTONE_ADMIN_PW=a     //修改管理员的密码
840 CONFIG_NEUTRON_ML2_TYPE_DRIVERS=flat,vxlan   //驱动类型
 876 CONFIG_NEUTRON_ML2_VXLAN_GROUP=239.1.1.5  
//设置组播地址,最后一个随意不能为0和255,其他固定
 910 CONFIG_NEUTRON_OVS_BRIDGE_MAPPINGS=physnet1:br-ex  //物理网桥的名称
 921 CONFIG_NEUTRON_OVS_BRIDGE_IFACES=br-ex:eth0   
//br-ex桥的名称与eth0连接,管理eth0,网桥与哪个物理网卡连接
1179 CONFIG_PROVISION_DEMO=n   //DEMO是否测试
 [root@openstack ~]# packstack --answer-file=answer.ini 
Welcome to the Packstack setup utility

The installation log file is available at: /var/tmp/packstack/20190423-170603-b43g_i/openstack-setup.log

Installing:
Clean Up                                             [ DONE ]
Discovering ip protocol version                      [ DONE ]
root@192.168.1.11's password: 
root@192.168.1.10's password: 
Setting up ssh keys
 **** Installation completed successfully ******		//出现这个为成功

6 案例6:网络管理

6.1 问题

本案例要求运用OVS完成以下配置:

6.2 步骤

实现此案例需要按照如下步骤进行。

步骤一:查看外部OVS网桥

1)查看br-ex网桥配置(br-ex为OVS网桥设备)

[root@openstack ~]# cat /etc/sysconfig/network-scripts/ifcfg-br-ex 
ONBOOT="yes"
NM_CONTROLLED="no" 
IPADDR="192.168.1.10"
PREFIX=24
GATEWAY=192.168.1.254
DEVICE=br-ex
NAME=br-ex
DEVICETYPE=ovs
OVSBOOTPROTO="static"
TYPE=OVSBridge

2)查看eth0网卡配置(该网卡为OVS网桥的接口)

[root@openstack ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 
DEVICE=eth0
NAME=eth0
DEVICETYPE=ovs
TYPE=OVSPort
OVS_BRIDGE=br-ex
ONBOOT=yes
BOOTPROTO=none

3)验证OVS配置

[root@openstack ~]# ovs-vsctl show
    Bridge br-ex
        Controller "tcp:127.0.0.1:6633"
            is_connected: true
        fail_mode: secure
        Port br-ex
            Interface br-ex
                type: internal
        Port phy-br-ex
            Interface phy-br-ex
                type: patch
                options: {peer=int-br-ex}
        Port "eth0"
            Interface "eth0"
    ovs_version: "2.5.0"

7 案例7:登录openstack

7.1 问题

本案例要求通过Horizon完成以下操作:

7.2 步骤

实现此案例需要按照如下步骤进行。

步骤一:浏览器访问openstack

1)浏览器访问

[root@openstack ~]# firefox 192.168.1.10  //访问失败

2)需要改配置文件并重新加载

[root@openstack ~]# 
[root@openstack conf.d]# vi 15-horizon_vhost.conf
     35   WSGIProcessGroup apache
     36   WSGIApplicationGroup %{GLOBAL}     //添加这一行
[root@openstack conf.d]# apachectl  graceful  //重新载入配置文件

3)浏览器访问,出现页面,如图-6所示:

图-6

3)查看用户名和密码

[root@openstack conf.d]# cd
[root@openstack ~]# ls
answer.ini   keystonerc_admin   //keystonerc_admin生成的文件,里面有用户名和密码
[root@openstack ~]# cat keystonerc_admin 
unset OS_SERVICE_TOKEN
    export OS_USERNAME=admin  //用户名
    export OS_PASSWORD=a  //密码
    export OS_AUTH_URL=http://192.168.1.10:5000/v2.0
    export PS1='[\u@\h \W(keystone_admin)]\$ '

export OS_TENANT_NAME=admin
export OS_REGION_NAME=RegionOne

4)在火狐浏览器中输入用户名和密码,登录后页面如图-7所示:

图-7

安装openstack可能会出现的错误以及排错方法

1)ntp时间不同步,如图-2所示:

图-2

解决办法:查看ntp时间服务器,是否出现*号,若没有,查看配置文件,配置ntp服务器步骤在案例3,可以参考

[root@room9pc01 ~]# chronyc sources -v    //出现*号代表NTP时间可用
^* 120.25.115.20 2   6   17    62   -753us[-7003us] +/-   24ms
[root@openstack ~]# chronyc sources -v
^* 192.168.1.254 3   9   377   504  +50us[-20us] +/-   24ms
[root@nova ~]# chronyc sources -v
^* 192.168.1.254 3   9   377   159  -202us[-226us] +/-   24ms

2)网桥名称写错,如图-3所示:

图-3

解决办法:检查配置文件

[root@openstack ~]# vim answer.ini
...
921 CONFIG_NEUTRON_OVS_BRIDGE_IFACES=br-ex:eth0   
//br-ex桥的名称与eth0连接,管理eth0,网桥与哪个物理网卡连接
...

3)若/root/.ssh/id_rsa.pub,提示password,同样是配置文件没有写对,如图-4所示:

图-4

4)yum源没有配置正确,如图-5所示:

图-5

解决办法:检查yum是否为10853个软件包,查看是否是yum源没有配置正确,之后安装oprnstack-dashboard

5)出现Cannot allocate memory,如图-6所示:

图-6

解决办法:

内存不足,重新启动主机

6)出现/usr/bin/systemctl start openvswith ... falied,说明是ssse3指令集的错误,如图-7所示:

图-7

解决办法:编辑openstack的xml文件,在里面添加

  <cpu mode='host-passthrough'>
  </cpu>

7)若出现 Could not prefetch... ‘openstack’。 如图-8所示:

图-8

配置文件里面有中文符号

9)访问openstack出错

图-9

没有修改Apache配置文件

4)创建名为myproject的项目

[root@openstack ~]# source ~/keystonerc_admin  //初始化环境变量
[root@openstack ~(keystone_admin)]# openstack project create myproject
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | None                             |
| enabled     | True                             |
| id          |f73949e2701346328faf5c1272414cd0|
| name        | myproject                        |
+-------------+----------------------------------+

5)查看项目信息

[root@openstack ~(keystone_admin)]# openstack project list
+----------------------------------+-----------+
| ID                                  | Name      |
+----------------------------------+-----------+
| 3fd5bffd734543d39cf742492273a47f | services  |
| 7f0b43274a9f4e149357fc8393ff2c68 | admin     |
| f73949e2701346328faf5c1272414cd0 | myproject |
+----------------------------------+-----------+

6)更新vcpu配额为30

[root@openstack ~(keystone_admin)]# nova quota-update --cores 30 myproject

7)删除myproject

[root@openstack ~(keystone_admin)]# openstack project delete myproject