本次,我们采用命令行的方式来创建云主机
镜像采用:cirros-0.3.4-x86_64-disk.img
镜像的创建
[root@controller ~]# glance image-create --name cirros --disk-format qcow2 --container-format bare --progress < /root/cirros-0.3.4-x86_64-disk.img
[=============================>] 100%
glance image-create 固定格式
--name 指定镜像名称
--disk-format 指定镜像格式 qcow2 比较常用
--container-format 指定容器的格式 bare 比较常用
--progress 指定镜像所在的路径
查看效果
[root@controller ~]# openstack image list
+--------------------------------------+--------+--------+
| ID | Name | Status |
+--------------------------------------+--------+--------+
| b6fb950c-15a6-49dc-8969-b7ba0cc259db | cirros | active |
+--------------------------------------+--------+--------+
外部网络的创建
[root@controller ~]# openstack network create external --provider-physical-network
外部网络子网的创建
[root@controller ~]# openstack subnet create external-1 --network external --gateway 192.168.200.1 --subnet-range 192.168.200.0/24 --allocation-pool start=192.168.200.50,end=192.168.200.60 --dhcp
内部网络的创建
[root@controller ~]# openstack network create inside --provider-network-type vxlan --provider-segment 1
内部网络子网的创建
[root@controller ~]# openstack subnet create inside-1 --network inside --gateway 10.0.0.1 --subnet-range 10.0.0.0/24 --allocation-pool start=10.0.0.10,end=10.0.0.20 --dhcp s
查看创建的效果
[root@controller ~]# openstack network list
+--------------------------------------+----------+--------------------------------------+
| ID | Name | Subnets |
+--------------------------------------+----------+--------------------------------------+
| 8a61c865-4557-414f-b214-39bb2c49e653 | inside | 558884df-0a15-49f5-a9d8-8f648f0b350b |
| c0d546e0-e750-400a-90eb-1f32b9730ec5 | external | 0ae16f04-a8d8-4cda-a9a0-a8011a5cc56b |
+--------------------------------------+----------+--------------------------------------+
[root@controller ~]# openstack subnet list
+--------------------------------------+------------+--------------------------------------+------------------+
| ID | Name | Network | Subnet |
+--------------------------------------+------------+--------------------------------------+------------------+
| 0ae16f04-a8d8-4cda-a9a0-a8011a5cc56b | external-1 | c0d546e0-e750-400a-90eb-1f32b9730ec5 | 192.168.200.0/24 |
| 558884df-0a15-49f5-a9d8-8f648f0b350b | inside-1 | 8a61c865-4557-414f-b214-39bb2c49e653 | 10.0.0.0/24 |
+--------------------------------------+------------+--------------------------------------+------------------+
网络创建命令参数详解
名称 | 作用 |
---|---|
openstack network create | 创建网络需要的,固定 |
openstack subnet create | 创建子网需要的,固定 |
provider-physical-network | 指定设备名称,配置文件中有所定义 |
provider-network-type | 指定网络的类型,如:flat,vlan等 |
provider-segment | 指定的vlan的ID号 |
external | 外部网络 |
share | 开启分享 |
allocation-pool | start=开始IP地址,end=最后IP地址 |
创建路由
[root@controller ~]# openstack router create route
路由绑定外部网络
[root@controller ~]# openstack router set route --external-gateway external
route 为路由的名称
external 为外部网络的名称
关联内部网络的子网
[root@controller ~]# openstack router add subnet route inside-1
inside-1 为内部网络的名称
创建安全组
[root@controller ~]# openstack security group create all
openstack security group create 是固定格式
all 为安全组的名称
为安全组放行对应的协议
ingress:入站
egress:出战
[root@controller ~]# openstack security group rule create --ingress --protocol tcp all
[root@controller ~]# openstack security group rule create --egress --protocol tcp all
[root@controller ~]# openstack security group rule create --ingress --protocol udp all
[root@controller ~]# openstack security group rule create --egress --protocol udp all
[root@controller ~]# openstack security group rule create --ingress --protocol icmp all
[root@controller ~]# openstack security group rule create --egress --protocol icmp all
openstakc security group rule create 固定格式
--ingress 入站
--egress 出站
--protocol 指定协议
all 为安全组的名称
创建资源规格
[root@controller ~]# nova flavor-create ciross 1 1024 1 1
nova flavor-create 固定格式
ciross 名称 自定义
1 编号,云主机通过编号来引用该规格
1024 内存容量 默认单位为MB
1 硬盘容量 默认单位为GB
1 vCPU的数量
查看创建的效果
[root@controller ~]# openstack flavor list
+----+--------+------+------+-----------+-------+-----------+
| ID | Name | RAM | Disk | Ephemeral | VCPUs | Is Public |
+----+--------+------+------+-----------+-------+-----------+
| 1 | ciross | 1024 | 1 | 0 | 1 | True |
+----+--------+------+------+-----------+-------+-----------+
cirros云主机创建
[root@controller ~]# openstack server create --image cirros --flavor 1 --nic net-id=8a61c865-4557-414f-b214-39bb2c49e653,v4-fixed-ip=10.0.0.15 --security-group all cirros
openstack server create 固定格式 还可以用 nova boot 来创建
--image 指定镜像
--flavor 指定规格
--nic 指定网络参数
net-id=指定内部网络的id号
v4-fixed-ip= 指定固定IP地址,也可以不指定,这样就DHCP自动分配
--security-group 指定安全组
cirros 为云主机的名称
查看创建的状态
[root@controller ~]# openstack server list
+--------------------------------------+--------+--------+------------------+--------+--------+
| ID | Name | Status | Networks | Image | Flavor |
+--------------------------------------+--------+--------+------------------+--------+--------+
| 33f84d2e-a1c3-4103-bc5d-21b34c1d675b | cirros | ACTIVE | inside=10.0.0.15 | cirros | ciross |
+--------------------------------------+--------+--------+------------------+--------+--------+
当前状态下只存在内部网络的IP地址,我们需要绑定外部网络的浮动IP地址,这样管理员就可以通过外网连接到该云主机了
创建浮动IP地址
[root@controller ~]# openstack floating ip create external --floating-ip-address 192.168.200.150
openstack floating ip create 固定格式
external 为外部网络的名称
--floating-ip-address 指定浮动IP地址 为外部网络网段的
查看创建的浮动IP地址
[root@controller ~]# openstack floating ip list
+--------------------------------------+---------------------+------------------+------+--------------------------------------+----------------------------------+
| ID | Floating IP Address | Fixed IP Address | Port | Floating Network | Project |
+--------------------------------------+---------------------+------------------+------+--------------------------------------+----------------------------------+
| 8bbbbcab-e218-4657-a718-306cfe582608 | 192.168.200.150 | None | None | c0d546e0-e750-400a-90eb-1f32b9730ec5 | bd70097ab9fc49aea9921f4b7165fc38 |
+--------------------------------------+---------------------+------------------+------+--------------------------------------+----------------------------------+
云主机绑定浮动IP地址
[root@controller ~]# openstack server add floating ip cirros 192.168.200.150
openstack server add floating ip 固定格式
cirros 指定云主机的名称
后面的IP地址表示浮动IP地址
查看绑定是否成功
[root@controller ~]# openstack server list
+--------------------------------------+--------+--------+-----------------------------------+--------+--------+
| ID | Name | Status | Networks | Image | Flavor |
+--------------------------------------+--------+--------+-----------------------------------+--------+--------+
| 33f84d2e-a1c3-4103-bc5d-21b34c1d675b | cirros | ACTIVE | inside=10.0.0.15, 192.168.200.150 | cirros | ciross |
+--------------------------------------+--------+--------+-----------------------------------+--------+--------+