11-视频-OpenStack网络及使用–不可思议团队

11-视频-OpenStack网络及使用--小铁笔记

视频笔记:

1、环境准备

-->cd

-->./start-all.sh  确保启动成功

2、安装网络

-->cd /opt/openstack/tools

-->cp -rf create.network.sh ~/

-->cd ~

-->cp -rf cinderrc adminrc

-->vim adminrc   #修改为如下结果

export OS_TENANT_NAME=admin
export OS_USERNAME=admin
export OS_PASSWORD=admin_user_password   #要和第9章中的localrc文件中的密码相同
export OS_AUTH_URL="http://192.168.56.180:5000/v2.0/"

-->source adminrc

-->keystone user-list

+----------------------------------+---------+---------+---------------------+
|                id                |   name  | enabled |        email        |
+----------------------------------+---------+---------+---------------------+
| d3545d749bde4ad8be4046d62ac2d456 |  admin  |   True  |  admin@example.com  |
| 182e5810b6404cf08a6e8d5698bcef21 |  cinder |   True  |  cinder@example.com |
| 83413eb168444897abac489f76db7185 |   demo  |   True  |   demo@example.com  |
| 3bc75ad83fe54a8588a1ae2d2a06fbe6 |  glance |   True  |  glance@example.com |
| 0c4cedf391004baaaf03ff8834e72d6b |   nova  |   True  |   nova@example.com  |
| 5ccfd7f5ba05482ba06d3afa2defec40 | quantum |   True  | quantum@example.com |
| a8bdd93bd82545e4a9a06f65b08b9331 |  swift  |   True  |  swift@example.com  |
+----------------------------------+---------+---------+---------------------+

-->keystone endpoint-list

+----------------------------------+-----------+---------------------------------------------------------+---------------------------------------------------------+---------------------------------------------------------+----------------------------------+
|                id                |   region  |                        publicurl                        |                       internalurl                       |                         adminurl                        |            service_id            |
+----------------------------------+-----------+---------------------------------------------------------+---------------------------------------------------------+---------------------------------------------------------+----------------------------------+
| 1a12dd40a59c4ed18948b43e82eace89 | RegionOne |     http://192.168.56.180:8080/v1/AUTH_$(tenant_id)s    |     http://192.168.56.180:8080/v1/AUTH_$(tenant_id)s    |              http://192.168.56.180:8080/v1              | 5284a61fe83242b3a52c964e5c58b183 |
| 33f3d028c88b48dea40053ea67ad04b5 | RegionOne |               http://192.168.56.180:9696/               |               http://192.168.56.180:9696/               |               http://192.168.56.180:9696/               | 082db8a0a03548db98e6e983de2496df |
| 5c93930c726a4419ada9070dba267bca | RegionOne |                http://192.168.56.180:9292               |                http://192.168.56.180:9292               |                http://192.168.56.180:9292               | 35832f4dde9a4fc1a9f1dcb9983a62ab |
| 605ad92d703949deab7f5dd4715c815c | RegionOne |        http://192.168.56.180:8773/services/Cloud        |        http://192.168.56.180:8773/services/Cloud        |        http://192.168.56.180:8773/services/Admin        | 158a8a338c7642a699a7f188fdf9b252 |
| 63f96208552e4d4c9fa0cd42820010be | RegionOne |                  http://192.168.56.180:                 |                  http://192.168.56.180:                 |                  http://192.168.56.180:                 | 7ff1bb6322354e26a3dd6550bd193ba4 |
| 862ebff9b51c48f294e88cad64a89ccd | RegionOne |       http://192.168.56.180:8776/v1/$(tenant_id)s       |       http://192.168.56.180:8776/v1/$(tenant_id)s       |       http://192.168.56.180:8776/v1/$(tenant_id)s       | 9356ac6f26634d569c51faa58ad80f1c |
| db2d31a35fce4fc1a394a226118017c2 | RegionOne | http://192.168.56.180:$(compute_port)s/v2/$(tenant_id)s | http://192.168.56.180:$(compute_port)s/v2/$(tenant_id)s | http://192.168.56.180:$(compute_port)s/v2/$(tenant_id)s | 9370557c744f4857a7f21ca56869467f |
| fedb3087318d4e138f76cb3dddf0b990 | RegionOne |        http://192.168.56.180:$(public_port)s/v2.0       |        http://192.168.56.180:$(admin_port)s/v2.0        |        http://192.168.56.180:$(admin_port)s/v2.0        | 16d4d5db7a2e458fb4f5acdb25bd0d8c |
+----------------------------------+-----------+---------------------------------------------------------+---------------------------------------------------------+---------------------------------------------------------+----------------------------------+

-->keystone service-list  #查看服务列表

+----------------------------------+----------+--------------+---------------------------+
|                id                |   name   |     type     |        description        |
+----------------------------------+----------+--------------+---------------------------+
| 9356ac6f26634d569c51faa58ad80f1c |  cinder  |    volume    |       Cinder Service      |
| 158a8a338c7642a699a7f188fdf9b252 |   ec2    |     ec2      |  EC2 Compatibility Layer  |
| 35832f4dde9a4fc1a9f1dcb9983a62ab |  glance  |    image     |    Glance Image Service   |
| 16d4d5db7a2e458fb4f5acdb25bd0d8c | keystone |   identity   | Keystone Identity Service |
| 9370557c744f4857a7f21ca56869467f |   nova   |   compute    |    Nova Compute Service   |
| 082db8a0a03548db98e6e983de2496df | quantum  |   network    |      Quantum Service      |
| 7ff1bb6322354e26a3dd6550bd193ba4 |    s3    |      s3      |             S3            |
| 5284a61fe83242b3a52c964e5c58b183 |  swift   | object-store |       Swift Service       |
+----------------------------------+----------+--------------+---------------------------+

参考create.network步骤去操作

-->cat create.network.sh

#!/bin/bash
#!/bin/bash

set -e

# Step 1: register cirros

# Step 2: create network.
neutron router-create router01
Router_ID=`neutron router-list | grep router01 | awk '{ print $2 }'`
neutron net-create int_net
neutron subnet-create \
--gateway 192.168.100.1 --dns-nameserver 8.8.8.8 int_net 192.168.100.0/24

Int_Subnet_ID=`neutron net-list | grep int_net | awk '{ print $6 }'`
neutron router-interface-add $Router_ID $Int_Subnet_ID

neutron net-create ext_net --router:external=True

neutron subnet-create ext_net \
--allocation-pool start=10.0.2.150,end=10.0.2.254 \
--gateway 10.0.2.1 --dns-nameserver 8.8.8.8 10.0.2.0/24

Ext_Net_ID=`neutron net-list | grep ext_net | awk '{ print $2 }'`
neutron router-gateway-set $Router_ID $Ext_Net_ID
Int_Net_ID=`neutron net-list | grep int_net | awk '{ print $2 }'`

exit 0
# Step 3: Create  VM
nova boot --flavor 1 --image cirros.img --security_group default --nic net-id=$Int_Net_ID Ubuntu_Trusty

# Ste p4: Create floating ip
neutron floatingip-create ext_net
Device_ID=`nova list | grep Ubuntu_Trusty | awk '{ print $2 }'`
Port_ID=`neutron port-list -- --device_id $Device_ID | grep 192.168.100.2 | awk '{ print $2 }'`
Floating_ID=`neutron floatingip-list | grep 10.0.2.101 | awk '{ print $2 }'`
neutron floatingip-associate $Floating_ID $Port_ID
neutron floatingip-show $Floating_ID

3、安装网络

(1)注册cirros

-->cd /opt/openstack/tools

-->./register_cirros.sh

85087aed32a34fed9ad57b4b63a1d5fd
+-----------------------+--------------------------------------+
| Property              | Value                                |
+-----------------------+--------------------------------------+
| Property 'kernel_id'  | bad3fb90-df23-4b32-8f50-5dc519e2b432 |
| Property 'ramdisk_id' | d1db7407-4b1f-485d-a1fa-6b27b54273f8 |
| checksum              | 2f81976cae15c16ef0010c51e3a6c163     |
| container_format      | ami                                  |
| created_at            | 2015-03-20T07:51:41                  |
| deleted               | False                                |
| deleted_at            | None                                 |
| disk_format           | ami                                  |
| id                    | 41e719f7-3688-4ea0-b703-9a08c802c7ed |
| is_public             | True                                 |
| min_disk              | 0                                    |
| min_ram               | 0                                    |
| name                  | cirros.img                           |
| owner                 | 6214c9d9c78648309ae7a59f5e719360     |
| protected             | False                                |
| size                  | 25165824                             |
| status                | active                               |
| updated_at            | 2015-03-20T07:51:42                  |
+-----------------------+--------------------------------------+
keystone_glance_password
http://192.168.56.180:5000/v2.0/

查看

-->glance index

ID                                   Name                           Disk Format          Container Format     Size
------------------------------------ ------------------------------ -------------------- -------------------- --------------
d1db7407-4b1f-485d-a1fa-6b27b54273f8 cirros                         ari                  ari                         2254249
41e719f7-3688-4ea0-b703-9a08c802c7ed cirros.img                     ami                  ami                        25165824
bad3fb90-df23-4b32-8f50-5dc519e2b432 cirros                         aki                  aki                         4731440

(2)注册network

-->cp -rf /usr/local/bin/quantum /usr/local/bin/neutron

。创建router

-->neutron router-create router01

Created a new router:
+-----------------------+--------------------------------------+
| Field                 | Value                                |
+-----------------------+--------------------------------------+
| admin_state_up        | True                                 |
| external_gateway_info |                                      |
| id                    | 16967955-f7e8-4593-a6b4-d08eb8a41101 |
| name                  | router01                             |
| status                | ACTIVE                               |
| tenant_id             | 5b20239e80754195aa92b87aa8f96d5a     |
+-----------------------+--------------------------------------+

。创建router_id

-->Router_ID=`neutron router-list | grep router01 | awk '{ print $2 }'`

-->echo  $Router_ID

16967955-f7e8-4593-a6b4-d08eb8a41101   #此处的ID和上面表中ID是一样的

。创建网络

--> neutron net-create int_net

Created a new network:
+---------------------------+--------------------------------------+
| Field                     | Value                                |
+---------------------------+--------------------------------------+
| admin_state_up            | True                                 |
| id                        | 21181e18-a70f-4740-aca4-6b870930cc6c |
| name                      | int_net                              |
| provider:network_type     | vlan                                 |
| provider:physical_network | phynet1                              |
| provider:segmentation_id  | 3                                    |
| router:external           | False                                |
| shared                    | False                                |
| status                    | ACTIVE                               |
| subnets                   |                                      |
| tenant_id                 | 5b20239e80754195aa92b87aa8f96d5a     |
+---------------------------+--------------------------------------+

。创建虚拟子网 (此处的网络和hostname -I这些网络没关系,不要一样)

-->neutron subnet-create \
--gateway 192.168.100.1 --dns-nameserver 8.8.8.8 int_net 192.168.100.0/24

Created a new subnet:
+------------------+------------------------------------------------------+
| Field            | Value                                                |
+------------------+------------------------------------------------------+
| allocation_pools | {"start": "192.168.100.2", "end": "192.168.100.254"} |
| cidr             | 192.168.100.0/24                                     |
| dns_nameservers  | 8.8.8.8                                              |
| enable_dhcp      | True                                                 |
| gateway_ip       | 192.168.100.1                                        |
| host_routes      |                                                      |
| id               | 047ac96f-facb-4eee-9d5f-2084c54e3cc9                 |
| ip_version       | 4                                                    |
| name             |                                                      |
| network_id       | 21181e18-a70f-4740-aca4-6b870930cc6c                 |
| tenant_id        | 5b20239e80754195aa92b87aa8f96d5a                     |
+------------------+------------------------------------------------------+

。获取子网ID

-->Int_Subnet_ID=`neutron net-list | grep int_net | awk '{ print $6 }'`

-->echo $Int_Subnet_ID

047ac96f-facb-4eee-9d5f-2084c54e3cc9  #为上面创建好的ID

。去dashboard查看网络拓扑图

-->打开浏览器:http://192.168.56.180

User Name:admin

Passowrd:admin_user_password

-->管理员-->Networks-->可以看到已经有一个网络了:admin

查看网络拓扑结构

-->项目-->Manager Network-->Network Topology-->发现网络拓扑已经有了

。创建路由

-->neutron router-interface-add $Router_ID $Int_Subnet_ID

Added interface to router 16967955-f7e8-4593-a6b4-d08eb8a41101

再次在Web上查看是否有路由:

-->项目-->Manager Network-->Network Topology-->发现有个路由:router01
router

。创建外网名称

-->neutron net-list
+--------------------------------------+---------+-------------------------------------------------------+
| id                                   | name    | subnets                                               |
+--------------------------------------+---------+-------------------------------------------------------+
| 21181e18-a70f-4740-aca4-6b870930cc6c | int_net | 047ac96f-facb-4eee-9d5f-2084c54e3cc9 192.168.100.0/24 |
+--------------------------------------+---------+-------------------------------------------------------+

-->neutron net-create ext_net --router:external=True

Created a new network:
+---------------------------+--------------------------------------+
| Field                     | Value                                |
+---------------------------+--------------------------------------+
| admin_state_up            | True                                 |
| id                        | 9d835a80-61da-4165-8d07-59e0eb2b3b01 |
| name                      | ext_net                              |
| provider:network_type     | vlan                                 |
| provider:physical_network | phynet1                              |
| provider:segmentation_id  | 1                                    |
| router:external           | True                                 |
| shared                    | False                                |
| status                    | ACTIVE                               |
| subnets                   |                                      |
| tenant_id                 | 5b20239e80754195aa92b87aa8f96d5a     |
+---------------------------+--------------------------------------+

-->neutron subnet-create ext_net \
--allocation-pool start=10.0.2.150,end=10.0.2.254 \
--gateway 10.0.2.1 --dns-nameserver 8.8.8.8 10.0.2.0/24

Created a new subnet:
+------------------+----------------------------------------------+
| Field            | Value                                        |
+------------------+----------------------------------------------+
| allocation_pools | {"start": "10.0.2.150", "end": "10.0.2.254"} |
| cidr             | 10.0.2.0/24                                  |
| dns_nameservers  | 8.8.8.8                                      |
| enable_dhcp      | True                                         |
| gateway_ip       | 10.0.2.1                                     |
| host_routes      |                                              |
| id               | 0c26c695-6bc9-46e3-bbf4-33d320600e10         |
| ip_version       | 4                                            |
| name             |                                              |
| network_id       | 9d835a80-61da-4165-8d07-59e0eb2b3b01         |
| tenant_id        | 5b20239e80754195aa92b87aa8f96d5a             |
+------------------+----------------------------------------------+

再次查看网络拓扑结构

-->项目-->Manager Network-->Network Topology-->已经有2个网段和一个路由

绿色:外网  ext net(external)   10.0.2.0/24

蓝色:内网  int net 192.168.100.0/24   (竖向)

192.168.100.1 (横向)

 

查看内网ID

-->Ext_Net_ID=`neutron net-list | grep ext_net | awk '{ print $2 }'`

-->echo $Ext_Net_ID

9d835a80-61da-4165-8d07-59e0eb2b3b01

。添加路由器

-->neutron router-gateway-set $Router_ID $Ext_Net_ID

Set gateway for router 16967955-f7e8-4593-a6b4-d08eb8a41101

。获取内网ID

-->Int_Net_ID=`neutron net-list | grep int_net | awk '{ print $2 }'`

-->echo $Int_Net_ID

21181e18-a70f-4740-aca4-6b870930cc6c  #同创建网络的ID相同(上面)neutron net-create int_net

4、创建虚拟机

-->nova flavor-list

+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+-------------+
| ID | Name      | Memory_MB | Disk | Ephemeral | Swap | VCPUs | RXTX_Factor | Is_Public | extra_specs |
+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+-------------+
| 1  | m1.tiny   | 512       | 0    | 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 boot --flavor 1 --image cirros.img --security_group default --nic net-id=$Int_Net_ID Ubuntu_Trusty

+-------------------------------------+--------------------------------------+
| Property                            | Value                                |
+-------------------------------------+--------------------------------------+
| OS-EXT-STS:task_state               | scheduling                           |
| image                               | cirros.img                           |
| OS-EXT-STS:vm_state                 | building                             |
| OS-EXT-SRV-ATTR:instance_name       | instance-00000001                    |
| flavor                              | m1.tiny                              |
| id                                  | 1020fb54-d592-4771-ab97-fbc1cdde14bd |
| security_groups                     | [{u'name': u'default'}]              |
| user_id                             | d3545d749bde4ad8be4046d62ac2d456     |
| OS-DCF:diskConfig                   | MANUAL                               |
| accessIPv4                          |                                      |
| accessIPv6                          |                                      |
| progress                            | 0                                    |
| OS-EXT-STS:power_state              | 0                                    |
| OS-EXT-AZ:availability_zone         | nova                                 |
| config_drive                        |                                      |
| status                              | BUILD                                |
| updated                             | 2015-03-20T08:35:04Z                 |
| hostId                              |                                      |
| OS-EXT-SRV-ATTR:host                | None                                 |
| key_name                            | None                                 |
| OS-EXT-SRV-ATTR:hypervisor_hostname | None                                 |
| name                                | Ubuntu_Trusty                        |
| adminPass                           | BsBn87TxnfP4                         |
| tenant_id                           | 5b20239e80754195aa92b87aa8f96d5a     |
| created                             | 2015-03-20T08:35:04Z                 |
| metadata                            | {}                                   |
+-------------------------------------+--------------------------------------+

。查看虚拟机的创建状态

-->nova list
+--------------------------------------+---------------+--------+-----------------------+
| ID                                   | Name          | Status | Networks              |
+--------------------------------------+---------------+--------+-----------------------+
| 1020fb54-d592-4771-ab97-fbc1cdde14bd | Ubuntu_Trusty | BUILD  | int_net=192.168.100.2 |
+--------------------------------------+---------------+--------+-----------------------+

。查看底层VNC端口

-->virsh list --all

Id    Name                           State
----------------------------------------------------
2     instance-00000001              running

-->virsh vncdisplay 2  #查看id为2的机器端口为0

:0

-->hostname -I

192.168.56.180 192.168.57.2 192.168.58.2 10.0.2.100 192.168.122.1

。通过VNC访问

windows机器安装:VNC-Viewer-5.2.0-Windows

打开登录:

-->VNC Server:  192.168.56.180:0

Encryption:Let VNC Server choose

-->Connect-->Continue (勾选Don't warn me about this again.)

-->username:cirros   #从web界面可以看到

password:cubswin

。查看相关信息

-->ifconfig

-->ping www.baidu.com  #查看是否可以访问公网

使用控制台访问虚拟机

-->项目-->当前项目admin-->Instances-->点击虚拟机名”Ubuntu_Trusty“-->Console--> 点击”Click here to show only console“ 连接,一般有问题

。查看虚拟机日志

-->项目-->当前项目admin-->Instances-->点击虚拟机名”Ubuntu_Trusty“-->Log

5、创建第2台虚拟机,测试2台机器之间是否可以访问

-->nova boot --flavor 1 --image cirros.img --security_group default --nic net-id=$Int_Net_ID Ubuntu_Trusty_2

-->nova list  #可以看到2台虚拟机

。测试与第二台虚拟机之间的连通性

-->就在刚才VNC连接的第1台虚拟机上执行

-->ssh cirros@192.168.100.4 -->yes-->password-->ifconfig -f

6、从外网访问内网虚拟机

-->neutron floatingip-create ext_net

Created a new floatingip:
+---------------------+--------------------------------------+
| Field               | Value                                |
+---------------------+--------------------------------------+
| fixed_ip_address    |                                      |
| floating_ip_address | 10.0.2.152                           |
| floating_network_id | 9d835a80-61da-4165-8d07-59e0eb2b3b01 |
| id                  | 2fa57165-202b-42b8-934b-21173d99bc48 |
| port_id             |                                      |
| router_id           |                                      |
| tenant_id           | 5b20239e80754195aa92b87aa8f96d5a     |
+---------------------+--------------------------------------+

取Device_ID

-->nova list

-->Device_ID=

博主

让学习成为习惯,坚持-共享-开源-自由! 成功者决不放弃,放弃者绝不成功!

相关推荐

嗨、骚年、快来消灭0回复。