环境:

系统                      硬盘        IP            hostname

redhat 7               sda 20G     192.168.0.70      openstack.com

64位                 sdb 20G 

 

配置网卡

[root@openstack ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens192

TYPE="Ethernet"
BOOTPROTO=static
NAME="ens192"
ONBOOT="yes"
IPADDR=192.168.0.70
NETMASK=255.255.255.0
GATEWAY=192.168.0.1
DNS1=114.114.114.114

重启网络服务

[root@openstack ~]# systemctl restart network

设置服务器主机名:

[root@localhost ~]# vim /etc/hostname
openstack.com

使用vim编辑器写入主机名(域名)与IP地址的映射文件:

[root@localhost ~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.0.70 openstack.com openstack

创建镜像挂载目录

[root@localhost ~]# mkdir -p /media/cdrom

写入镜像挂载信息

[root@localhost ~]# vim /etc/fstab 

UUID=77d472ee-2af8-476e-a660-26476775c8f3 /                       ext4    defaults        1 1
UUID=cfe4ac94-5552-4c94-a707-4bfdac1b4d6f /boot                   ext4    defaults        1 2
UUID=9d7e20e7-8226-45f2-9015-51beec3c508e swap                    swap    defaults        0 0
/dev/cdrom                     /media/cdrom         iso9660 defaults        0 0

下载所需要的软件:

Openstack Juno——云计算平台软件

Openstack云计算软件能够将诸如计算能力、存储、网络和软件等资源抽象成服务,以便让用户可以通过互联网远程来享用,付费的形式也变得因需而定,拥有极强的虚拟可扩展性。

EPEL——系统的软件源仓库

EPEL是企业版额外的资源包,提供了默认不提供的软件安装包

Cirros——精简的操作系统

Cirros是一款极为精简的操作系统,一般用于灌装到Openstack服务平台中。

下载地址:http://pan.baidu.com/s/1dENbzjz

 

下载完成后解压缩到/media目录下

[root@localhost ~]# ls /media
cdrom  EPEL  openstack-juno

 

挂载镜像

[root@localhost ~]# mount -a
mount: /dev/sr0 is write-protected, mounting read-only

配置本地yum源

[root@localhost ~]# vim /etc/yum.repos.d/rhel.repo 

[base]
name=base
baseurl=file:///media/cdrom
enabled=1
gpgcheck=0

配置EPEL源

[root@localhost ~]# vim /etc/yum.repos.d/epel.repo

[epel]
name=epel
baseurl=file:///media/EPEL
enabled=1
gpgcheck=0

配置openstack源

[root@localhost ~]# vim /etc/yum.repos.d/openstack.repo 

[openstack]
name=openstack
baseurl=file:///media/openstack-juno
enabled=1
gpgcheck=0

将/dev/sdb创建成逻辑卷,卷组名称为cinder-volumes:

[root@localhost ~]# pvcreate /dev/sdb
  Physical volume "/dev/sdb" successfully created
[root@localhost ~]# vgcreate cinder-volumes /dev/sdb
  Volume group "cinder-volumes" successfully created

重启系统

[root@localhost ~]# reboot

安装Openstack的应答文件:

[root@openstack ~]# yum install openstack-packstack -y

安装openstack服务程序

[root@openstack ~]# packstack --allinone --provision-demo=n --nagios-install=n
Welcome to Installer setup utility
Packstack changed given value  to required value /root/.ssh/id_rsa.pub

Installing:
Clean Up                                             [ DONE ]
Setting up ssh keys                                  [ DONE ]
Discovering hosts' details                           [ DONE ]
Adding pre install manifest entries                  [ DONE ]
Preparing servers                                    [ DONE ]
Adding AMQP manifest entries                         [ DONE ]
Adding MySQL manifest entries                        [ DONE ]
Adding Keystone manifest entries                     [ DONE ]
Adding Glance Keystone manifest entries              [ DONE ]
Adding Glance manifest entries                       [ DONE ]
Adding Cinder Keystone manifest entries              [ DONE ]
Adding Cinder manifest entries                       [ DONE ]
Checking if the Cinder server has a cinder-volumes vg[ DONE ]
Adding Nova API manifest entries                     [ DONE ]
Adding Nova Keystone manifest entries                [ DONE ]
...............
192.168.0.70_ceilometer.pp:                          [ DONE ]         
Applying 192.168.0.70_postscript.pp
192.168.0.70_postscript.pp:                          [ DONE ]         
Applying Puppet manifests                            [ DONE ]
Finalizing                                           [ DONE ]

 **** Installation completed successfully ******


Additional information:
 * A new answerfile was created in: /root/packstack-answers-20160818-190030.txt
 * Time synchronization installation was skipped. Please note that unsynchronized time on server instances might be problem for some OpenStack components.
 * Did not create a cinder volume group, one already existed
 * File /root/keystonerc_admin has been created on OpenStack client host 192.168.0.70. To use the command line tools you need to source the file.
 * To access the OpenStack Dashboard browse to http://192.168.0.70/dashboard .
Please, find your login credentials stored in the keystonerc_admin in your home directory.
 * Because of the kernel update the host 192.168.0.70 requires reboot.
 * The installation log file is available at: /var/tmp/packstack/20160818-190030-e7R9hq/openstack-setup.log
 * The generated manifests are available at: /var/tmp/packstack/20160818-190030-e7R9hq/manifests

 ps:中间不要任何操作,需要的时间会有点长。

创建云平台的网卡配置文件:

[root@openstack network-scripts]# vim /etc/sysconfig/network-scriptsifcfg-br-ex 

DEVICE=br-ex
IPADDR=192.168.0.70
NETMASK=255.255.255.0
BOOTPROTO=static
DNS1=114.114.114.114
GATEWAY=192.168.0.1
BROADCAST=192.168.0.254
NM_CONTROLLED=no
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
ONBOOT=yes
DEVICETYPE=ovs
TYPE="OVSIntPort"
OVS_BRIDGE=br-ex

修改网卡参数信息为:

[root@openstack ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens192

DEVICE="ifcfg-ens192"
ONBOOT=yes
TYPE=OVSPort
DEVICETYPE=ovs
OVS_BRIDGE=br-ex
NM_CONTROLLED=no
IPV6INIT=no

将网卡设备添加到OVS网络中,如果是用ssh连接的主机,可能会断开连接,需要进入主机重启。

[root@openstack network-scripts]# ovs-vsctl add-port br-ex ens192

查看OVS网络

[root@openstack ~]# ovs-vsctl show
49e1a51d-7a57-4a4e-8f56-888d04aa738a
    Bridge br-int
        fail_mode: secure
        Port patch-tun
            Interface patch-tun
                type: patch
                options: {peer=patch-int}
        Port br-int
            Interface br-int
                type: internal
    Bridge br-ex
        Port "ifcfg-ens192"
            Interface "ifcfg-ens192"
        Port "ens192"
            Interface "ens192"
        Port br-ex
            Interface br-ex
                type: internal
    Bridge br-tun
        Port br-tun
            Interface br-tun
                type: internal
        Port patch-int
            Interface patch-int
                type: patch
                options: {peer=patch-tun}
    ovs_version: "2.1.3"

重启系统让网络设备同步:

[root@openstack ~]# reboot

执行身份认证脚本:

[root@openstack ~(keystone_admin)]# openstack-status
== Nova services ==
openstack-nova-api:                     active
openstack-nova-cert:                    active
openstack-nova-compute:                 active
openstack-nova-network:                 inactive  (disabled on boot)
openstack-nova-scheduler:               active
openstack-nova-volume:                  inactive  (disabled on boot)
openstack-nova-conductor:               active
== Glance services ==
openstack-glance-api:                   active
openstack-glance-registry:              active
== Keystone service ==
openstack-keystone:                     active
== Horizon service ==
openstack-dashboard:                    active
== neutron services ==
neutron-server:                         active
neutron-dhcp-agent:                     active
neutron-l3-agent:                       active
neutron-metadata-agent:                 active
neutron-lbaas-agent:                    inactive  (disabled on boot)
neutron-openvswitch-agent:              active
neutron-linuxbridge-agent:              inactive  (disabled on boot)
neutron-ryu-agent:                      inactive  (disabled on boot)
neutron-nec-agent:                      inactive  (disabled on boot)
neutron-mlnx-agent:                     inactive  (disabled on boot)
== Swift services ==
openstack-swift-proxy:                  active
openstack-swift-account:                active
openstack-swift-container:              active
openstack-swift-object:                 active
== Cinder services ==
openstack-cinder-api:                   active
openstack-cinder-scheduler:             active
openstack-cinder-volume:                active
openstack-cinder-backup:                active
== Ceilometer services ==
openstack-ceilometer-api:               active
openstack-ceilometer-central:           active
openstack-ceilometer-compute:           active
openstack-ceilometer-collector:         active
openstack-ceilometer-alarm-notifier:    active
openstack-ceilometer-alarm-evaluator:   active
== Support services ==
libvirtd:                               active
openvswitch:                            active
dbus:                                   active
tgtd:                                   inactive  (disabled on boot)
rabbitmq-server:                        active
memcached:                              active
== Keystone users ==
+----------------------------------+------------+---------+----------------------+
|                id                |    name    | enabled |        email         |
+----------------------------------+------------+---------+----------------------+
| 929ba701d3684df482f38f50049b90b1 |   admin    |   True  |    test@test.com     |
| 81d8717c3ec64a90875943b6269f41c6 | ceilometer |   True  | ceilometer@localhost |
| 407f301cfb1f4ec4b342395dbbccf936 |   cinder   |   True  |   cinder@localhost   |
| 0258522bd7054991bf97f0088172fc4f |   glance   |   True  |   glance@localhost   |
| d0ea154d896d4130b0ffff96a3259045 |  neutron   |   True  |  neutron@localhost   |
| 929cb4518608498e8b05ee1b0b3dba0d |    nova    |   True  |    nova@localhost    |
| f06a5593077b475a9192d9a83710487b |   swift    |   True  |   swift@localhost    |
+----------------------------------+------------+---------+----------------------+
== Glance images ==
+----+------+-------------+------------------+------+--------+
| ID | Name | Disk Format | Container Format | Size | Status |
+----+------+-------------+------------------+------+--------+
+----+------+-------------+------------------+------+--------+
== Nova managed services ==
+----+------------------+---------------+----------+---------+-------+----------------------------+-----------------+
| Id | Binary           | Host          | Zone     | Status  | State | Updated_at                 | Disabled Reason |
+----+------------------+---------------+----------+---------+-------+----------------------------+-----------------+
| 1  | nova-consoleauth | openstack.com | internal | enabled | up    | 2016-08-19T02:05:36.000000 | -               |
| 2  | nova-scheduler   | openstack.com | internal | enabled | up    | 2016-08-19T02:05:36.000000 | -               |
| 3  | nova-conductor   | openstack.com | internal | enabled | up    | 2016-08-19T02:05:35.000000 | -               |
| 4  | nova-compute     | openstack.com | nova     | enabled | up    | 2016-08-19T02:05:43.000000 | -               |
| 5  | nova-cert        | openstack.com | internal | enabled | up    | 2016-08-19T02:05:36.000000 | -               |
+----+------------------+---------------+----------+---------+-------+----------------------------+-----------------+
== Nova networks ==
+----+-------+------+
| ID | Label | Cidr |
+----+-------+------+
+----+-------+------+
== Nova instance flavors ==
+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+
| ID | Name      | Memory_MB | Disk | Ephemeral | Swap | VCPUs | RXTX_Factor | Is_Public |
+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+
| 1  | m1.tiny   | 512       | 1    | 0         |      | 1     | 1.0         | True      |
| 2  | m1.small  | 2048      | 20   | 0         |      | 1     | 1.0         | True      |
| 3  | m1.medium | 4096      | 40   | 0         |      | 2     | 1.0         | True      |
| 4  | m1.large  | 8192      | 80   | 0         |      | 4     | 1.0         | True      |
| 5  | m1.xlarge | 16384     | 160  | 0         |      | 8     | 1.0         | True      |
+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+
== Nova instances ==
+----+------+--------+------------+-------------+----------+
| ID | Name | Status | Task State | Power State | Networks |
+----+------+--------+------------+-------------+----------+
+----+------+--------+------------+-------------+----------+

打开浏览器,进入: http://192.168.0.70/dashboard

使用openstack部署云计算服务环境

 

 查看登陆的帐号密码:

[root@openstack ~(keystone_admin)]# cat keystonerc_admin
export OS_USERNAME=admin
export OS_TENANT_NAME=admin
export OS_PASSWORD=ad26d0df1e5a4287
export OS_AUTH_URL=http://192.168.0.70:5000/v2.0/
export PS1='[\u@\h \W(keystone_admin)]\$ '

输入账户密码进入管理中心

使用openstack部署云计算服务环境

 

使用Openstack服务

1.配置虚拟网络

要想让云平台中的虚拟实例机能够互相通信,并且让外部的用户访问到里面的数据,我们首先就必需配置好云平台中的网络环境。

Openstack创建网络:

使用openstack部署云计算服务环境

    编辑网络配置:

  使用openstack部署云计算服务环境

点击创建子网:

使用openstack部署云计算服务环境

子网信息

使用openstack部署云计算服务环境

填写子网详情(DHCP地址池中的IP地址用逗号间隔):

使用openstack部署云计算服务环境

 

 子网详情

使用openstack部署云计算服务环境

创建私有网络:

使用openstack部署云计算服务环境

创建网络

使用openstack部署云计算服务环境

填写网络信息:

使用openstack部署云计算服务环境

设置网络详情:

使用openstack部署云计算服务环境

查看网络信息:

使用openstack部署云计算服务环境

添加路由信息:

使用openstack部署云计算服务环境

 

填写路由名称:

使用openstack部署云计算服务环境

设置路由的网关信息:

使用openstack部署云计算服务环境

设置网关:

使用openstack部署云计算服务环境

在网络拓扑中添加接口:

使用openstack部署云计算服务环境

 

添加接口信息:

使用openstack部署云计算服务环境

路由的接口信息(需要等待几秒钟后,刷新下网页,内部接口的状态会变成ACTIVE):

使用openstack部署云计算服务环境

创建云主机类型

我们可以预先设置多个云主机类型的模板,这样可以灵活的满足用户的需求,先来创建云主机类型:

使用openstack部署云计算服务环境

 

 

填写云主机的基本信息:

使用openstack部署云计算服务环境

创建上传镜像:

使用openstack部署云计算服务环境

Cirros是一款极为精简的操作系统,非常小巧精简的Linux系统镜像,一般会在搭建Openstack后测试云计算平台可用性的系统,特点是体积小巧,速度极快,那么来上传Cirros系统镜像吧:

使用openstack部署云计算服务环境

查看已上传的镜像(Cirros系统上传速度超级快吧!):

使用openstack部署云计算服务环境

创建主机实例

使用openstack部署云计算服务环境

填写云主机详情

使用openstack部署云计算服务环境

查看云主机的访问与安全规则:

使用openstack部署云计算服务环境

将私有网络网卡添加到云主机:

使用openstack部署云计算服务环境

查看安装后的脚本数据:

使用openstack部署云计算服务环境

查看磁盘的分区方式:

使用openstack部署云计算服务环境

主机实例的孵化过程大约需要10-30秒,然后查看已经运行的实例:

ps:注意要设置好系统的语言环境为英文环境,否则这里会报错:ascii' codec can't decode byte 0xe5 in position 0: ordinal not in range(128)

使用openstack部署云计算服务环境

查看实例主机的网络拓扑(当前仅在内网中):

 使用openstack部署云计算服务环境

 

为实例主机绑定浮动IP地址:

使用openstack部署云计算服务环境

为主机实例添加浮动IP

使用openstack部署云计算服务环境

选择绑定的IP地址:

使用openstack部署云计算服务环境

将主机实例与IP地址关联:

使用openstack部署云计算服务环境

 

此时再查看实例的信息,IP地址段就多了一个数据值(192.168.0.52):

使用openstack部署云计算服务环境

尝试从外部ping云主机实例(结果是失败的):

原因是我们没有设置安全组规则,需要让外部流量允许进入到主机实例中:

使用openstack部署云计算服务环境

 

填写策略组的名称与描述:

使用openstack部署云计算服务环境

管理安全组的规则:

使用openstack部署云计算服务环境

添加安全规则

使用openstack部署云计算服务环境

允许所有的ICMP数据包流入(当然根据工作有时还需要选择TCP或UDP协议,此时仅为验证网络连通性):

使用openstack部署云计算服务环境

编辑实例的安全策略组:

使用openstack部署云计算服务环境

将新建的安全组策略作用到主机实例上:

使用openstack部署云计算服务环境

再次尝试从外部ping虚拟实例主机:

[root@openstack ~]# ping 192.168.0.52
PING 192.168.0.52 (192.168.0.52) 56(84) bytes of data.
64 bytes from 192.168.0.52: icmp_seq=524 ttl=63 time=3.12 ms
64 bytes from 192.168.0.52: icmp_seq=525 ttl=63 time=0.988 ms
添加云硬盘

云计算平台的特性就是要能够灵活的,弹性的调整主机实例使用的资源,我们可以来为主机实例多挂载一块云硬盘,首先来创建云硬盘设备:

使用openstack部署云计算服务环境

填写云硬盘的信息(以10GB为例):

使用openstack部署云计算服务环境

编辑挂载设备到主机云实例:

使用openstack部署云计算服务环境

将云硬盘挂载到主机实例中:

使用openstack部署云计算服务环境

查看云主机实例中的硬盘信息:

使用openstack部署云计算服务环境

控制云主机实例

经过上面的一系列配置,我们此时已经创建出了一台能够交付给用户使用的云主机实例了,查看下云平台的信息:

使用openstack部署云计算服务环境

编辑安全策略,允许TCP和UDP协议的数据流入到云主机实例中:

使用openstack部署云计算服务环境

分别添加TCP和UDP的允许规则:

使用openstack部署云计算服务环境

成功登陆到云主机实例中(默认帐号为"cirros",密码为:"cubswin:)"):

[root@openstack ~]# ssh cirros@192.168.0.52
cirros@192.168.0.52's password: 
Permission denied, please try again.
cirros@192.168.0.52's password: 
$ 

查看云主机实例的网络情况:

$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether fa:16:3e:9e:86:da brd ff:ff:ff:ff:ff:ff
    inet 10.10.10.52/24 brd 10.10.10.255 scope global eth0
    inet6 fe80::f816:3eff:fe9e:86da/64 scope link 
       valid_lft forever preferred_lft forever
$ 

挂载刚刚创建的云硬盘设备:

$ df -h
Filesystem                Size      Used Available Use% Mounted on
/dev                    494.3M         0    494.3M   0% /dev
/dev/vda1                23.2M     18.0M      4.1M  82% /
tmpfs                   497.8M         0    497.8M   0% /dev/shm
tmpfs                   200.0K     68.0K    132.0K  34% /run
$ mkdir disk
$ sudo mkfs.ext4 /dev/vdb
mke2fs 1.42.2 (27-Mar-2012)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 2621440 blocks
131072 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done 

$ sudo mount /dev/vdb disk/
$ df -h
Filesystem                Size      Used Available Use% Mounted on
/dev                    494.3M         0    494.3M   0% /dev
/dev/vda1                23.2M     18.0M      4.1M  82% /
tmpfs                   497.8M         0    497.8M   0% /dev/shm
tmpfs                   200.0K     68.0K    132.0K  34% /run
/dev/vdb                  9.8G    150.5M      9.2G   2% /home/cirros/disk
$