您的位置:首页 > 运维架构

用命令测试安装好的OpenStack环境

2016-08-16 16:38 218 查看
首先要明确几个概念:

外网:可分配floating ip绑定到虚拟机,外部就可以访问虚拟机。

虚拟网络(内部网络,私有网络):虚拟机的虚拟网卡所在的私有网络。

子网:用户创建的每个网络至少要有一个子网(也可以有多个子网)

路由:用户创建的每个网络至少有一个路由,该路由的接口要关联这个网络

fixed ip:虚拟机网卡在虚拟网络上的ip

floating ip:虚拟网络对应的外部网络上的ip

interface:一个网络接口

端口:子网有多个端口(一般会有MAC地址和IP地址),在GRE模式中子网中一般会有qdhcp端口,qrouter端口和为虚拟机实例分配的端口,它们的ip地址属于这个子网


一、查看nova和neutron服务,确保都是笑脸

#Nova-manage service list

#neutron agent-list


二、创建租户和用户

创建租户

# keystone tenant-create --name TenantA

创建用户

# keystone user-create --name=UserA --pass=password --tenant-id TenantA --email=usera@test.com

为租户添加用户

#keystone user-role-add --tenant TenantA --user UserA --role Member


三、准备neutron网络

创建外网

# neutron net-create Ext-Net --provider:network_type gre --provider:segmentation_id 1 --router:external true

创建外网的子网

# neutron subnet-create --allocation-pool start=10.1.101.80,end=10.1.101.100 --gateway 10.1.101.254 Ext-Net 10.1.101.0/24 --enable_dhcp=False

接下来创建租户的子网和虚拟路由

创建租户网络

# neutron --os-tenant-name TenantA --os-username UserA --os-password password --os-auth-url=http://localhost:5000/v2.0 net-create tenantA-Net

创建租户子网

# neutron --os-tenant-name TenantA --os-username UserA --os-password password --os-auth-url=http://localhost:5000/v2.0 subnet-create tenantA-Net 10.0.0.0/24

创建租户虚拟路由

neutron --os-tenant-name TenantA --os-username UserA --os-password password --os-auth-url=http://localhost:5000/v2.0 router-create tenant-R1

增加路由接口

(替换${subnet_id}为子网ID)

neutron --os-tenant-name TenantA --os-username UserA --os-password password --os-auth-url=http://localhost:5000/v2.0 router-interface-add tenant-R1 ${subnet_id}

给路由增加网关

# neutron router-gateway-set tenant-R1 Ext-Net

到此为止UserA看到的网络拓扑如下:





四、安全组规则

安全组规则会影响到外面ping虚拟机和ssh登录虚拟机,所以在controller节点中为openstack设置好ICMP和TCP规则。

获得TenantA的default安全组规则

# neutron --os-tenant-name TenantA --os-username UserA --os-password password --os-auth-url=http://localhost:5000/v2.0 security-group-list

默认default规则:





设置nova中default的 ICMP/TCP/UDP安全组规则

# nova --os-tenant-name TenantA --os-username UserA --os-password password --os-auth-url=http://localhost:5000/v2.0 secgroup-add-rule default tcp 1 65535 0.0.0.0/0

# nova --os-tenant-name TenantA --os-username UserA --os-password password --os-auth-url=http://localhost:5000/v2.0 secgroup-add-rule default udp 1 65535 0.0.0.0/0

# nova --os-tenant-name TenantA --os-username UserA --os-password password --os-auth-url=http://localhost:5000/v2.0 secgroup-add-rule default icmp -1 -1 0.0.0.0/0


五、起虚拟机

查看镜像:

# glance index

起虚拟机,替换{the cirros ID from Glance}为镜像ID

#root@controller:~# nova --os-tenant-name TenantA --os-username UserA --os-password password --os-auth-url=http://localhost:5000/v2.0 boot --flavor 1 --image{the cirros
ID from Glance} vm001

检查虚拟机状态为ACTIVE

# nova --os-tenant-name TenantA --os-username UserA --os-password password --os-auth-url=http://localhost:5000/v2.0 list


六、为虚拟机分配浮动IP

创建一个浮动IP

# neutron --os-tenant-name TenantA --os-username UserA --os-password password --os-auth-url=http://localhost:5000/v2.0 floatingip-create Ext-Net

查看floating-ip

# nova --os-tenant-name TenantA --os-username UserA --os-password password --os-auth-url=http://localhost:5000/v2.0 floating-ip-list

我创建了一个新的浮动IP10.1.101.82,分配的是10.1.101.82

分配浮动IP给虚拟机,替换{the vm id}为虚拟机ID

# nova --os-tenant-name TenantA --os-username UserA --os-password password --os-auth-url=http://localhost:5000/v2.0 floating-ip-associate {the vm id} 10.1.101.82

检查虚拟机状态,现在就可以看到浮动ip了。

# nova --os-tenant-name TenantA --os-username UserA --os-password password --os-auth-url=http://localhost:5000/v2.0 list


七、SSH到虚拟机(虚拟机状态为ACTIVE,密码是cubswin:))

替换{put_floating_ip_here}为虚拟机的浮动IP

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  openstack