OpenStack命令创建云主机上传镜像创建网络实例类型及常用命令等
OpenStack
命令创建云主机上传镜像创建网络实例类型及常用命令等
参考
https://www.cnblogs.com/hoyeong/p/16225963.html
前言
简单创建云主机实例只需要上传一个测试镜像、创建一张外网卡、创建一个实例类型、修改安全组规则即可
一. 上传镜像
常规上传镜像方式
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29# openstack上传raw镜像命令
# 将镜像传到计算节点
centos8.3.raw
centos8.4.raw
ubuntu20.04.raw
ubuntu22.04.raw
scp -rp ubuntu22.04.raw root@ceph1:/root/zxw
scp -rp ubuntu20.04.raw root@ceph1:/root/zxw
scp -rp centos*.raw root@ceph1:/root/zxw
# 刷新环境
source /etc/kolla/admin-openrc.sh
# 普通方式上传镜像 (在其他显示)
openstack image create --disk-format raw --container-format bare --public --property os_type=linux --property hw_qemu_guest_agent=yes --property hw_scsi_model=virtio-scsi --property hw_disk_bus=scsi --property hw_qemu_guest_agent=yes --property os_require_quiesce=yes --file /root/zxw/ubuntu22.04.raw ubuntu22.04-zxw.raw
# 指定tag的方式上传linux镜像(在对应tag下显示)
openstack image create --disk-format raw --container-format bare --public --min-disk 10 --min-ram 512 --property os_type=linux --property hw_qemu_guest_agent=yes --property hw_scsi_model=virtio-scsi --property hw_disk_bus=scsi --property os_require_quiesce=yes --property os_distro=ubuntu --property os_version=20.04 --file /opt/openstack_mirror/ubuntu20.04.raw ubuntu20.04.raw
# 指定tag的方式上传windows镜像(在对应tag下显示)
openstack image create --disk-format qcow2 --public --property hw_qemu_guest_agent=yes --property os_distro=windows --property os_version=2012 --property os_admin_user=Administrator --file windows_server_2016_x64.qcow2 windows_server_2016_x64.qcow2
openstack image create --disk-format qcow2 --public --min-disk 20 --min-ram 1024 --property hw_qemu_guest_agent=yes --property os_distro=windows --property os_version=2016 --property os_admin_user=Administrator --file /opt/openstack_mirror/windows2016.qcow2 windows2016.qcow2
# 优化空格如下
openstack image create --disk-format qcow2 --public --min-disk 20 --min-ram 1024 --property hw_qemu_guest_agent=yes --property os_distro=windows --property os_version=2016 --property os_admin_user=Administrator --file /opt/openstack_mirror/windows2016.qcow2 windows2016.qcow2
# uploading centos7.9.raw
running command: openstack image create --disk-format raw --container-format bare --public --min-disk 10 --min-ram 512 --property os_type=linux --property hw_qemu_guest_agent=yes --property hw_scsi_model=virtio-scsi --property hw_disk_bus=scsi --property os_require_quiesce=yes --property os_distro=centos --property os_version=7.9 --property os_admin_user=root --file /opt/openstack_mirror/centos7.9.raw centos7.9.raw上传
cirros
镜像(本文是有此镜像)1
2
3
4
5
6# 上传cirros镜像
openstack image create "cirros-0.4.0-x86_64" --file cirros-0.4.0-x86_64-disk.img --disk-format qcow2 --container-format bare --public
# 查看镜像
openstack image list
# 删除镜像
openstack image delete my-image
二. 环境准备
创建一个名为
test0
的实例类型1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21# 创建一个名为test0的实例
openstack flavor create --disk 1 --ram 512 --vcpu 1 --id 99999 test0
//返回
+----------------------------+-------+
| Field | Value |
+----------------------------+-------+
| OS-FLV-DISABLED:disabled | False |
| OS-FLV-EXT-DATA:ephemeral | 0 |
| description | None |
| disk | 1 |
| id | 99999 |
| name | test0 |
| os-flavor-access:is_public | True |
| properties | |
| ram | 512 |
| rxtx_factor | 1.0 |
| swap | |
| vcpus | 1 |
+----------------------------+-------+
# 删除实例类型
openstack flavor delete 99999创建外网网卡
注:若使用 虚拟机 搭建,外部网络类型请选择
Flat
;若使用 服务器 搭建,外部网络类型请选择VLAN
;注意不要重复执行命令,二选一执行。1
2
3
4
5
6
7
8# 网络类型选择vlan
openstack network create --provider-network-type vlan --provider-physical-network provider ext-net --provider-segment 200
# 虚拟机指定为并指定物理网络为physnet1(本机使用)
openstack network create --provider-network-type flat --provider-physical-network physnet1 ext-net
# 删除此网络
openstack network delete ext-net参数
效果
创建子网
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31# 查看子网
openstack subnet list
# 创建子网
openstack subnet create --network ext-net --allocation-pool start=10.60.3.10,end=10.60.3.200 --gateway 10.60.3.1 --subnet-range 10.60.3.0/24 ext-subnet
// 返回
+----------------------+--------------------------------------+
| Field | Value |
+----------------------+--------------------------------------+
| allocation_pools | 10.60.3.10-10.60.3.200 |
| cidr | 10.60.3.0/24 |
| created_at | 2023-12-14T11:36:45Z |
| description | |
| dns_nameservers | |
| dns_publish_fixed_ip | None |
| enable_dhcp | True |
| gateway_ip | 10.60.3.1 |
| host_routes | |
| id | 4bc1726a-c9de-4b3d-a1a8-aff08165bcd0 |
| ip_version | 4 |
| ipv6_address_mode | None |
| ipv6_ra_mode | None |
| name | ext-subnet |
| network_id | 39c9a1fb-748f-4b62-b0b3-8f6a03d43dd1 |
| project_id | 19f9e05ce593402abb16b57b4fead48b |
| revision_number | 0 |
| segment_id | None |
| service_types | |
| subnetpool_id | None |
| tags | |
| updated_at | 2023-12-14T11:36:45Z |
+----------------------+--------------------------------------+创建网络使用如下即可(本文档需要使用 >> physnet1类型网络)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46# 在控制节点执行以下操作进行验证。
source /etc/keystone/admin-openrc.sh
# 列出成功启动的 Neutron 代理
openstack network agent list
+--------------------------------------+--------------------+------------+-------------------+-------+-------+---------------------------+
| ID | Agent Type | Host | Availability Zone | Alive | State | Binary |
+--------------------------------------+--------------------+------------+-------------------+-------+-------+---------------------------+
| 1334a7b0-5436-4041-bc36-95f194a140f0 | Linux bridge agent | compute01 | None | :-) | UP | neutron-linuxbridge-agent |
| 5667c78a-19dd-40b1-a2df-5f361e5a04c4 | Linux bridge agent | compute02 | None | :-) | UP | neutron-linuxbridge-agent |
| d314afcc-2604-4b56-a4eb-4b9076de017f | DHCP agent | controller | nova | :-) | UP | neutron-dhcp-agent |
| d93948d3-3e1b-488f-9e58-5c8d53e626a1 | Linux bridge agent | controller | None | :-) | UP | neutron-linuxbridge-agent |
| f7927a9f-da78-4a38-8f59-9e78382dd26c | Metadata agent | controller | None | :-) | UP | neutron-metadata-agent |
+--------------------------------------+--------------------+------------+-------------------+-------+-------+---------------------------+
/*
说明:上面 agent list 中没有 L3 agent,说明 neutron-l3-agent.service 没有启动
*/
# 创建一个 Flat 网络
openstack network create --share --external --provider-network-type flat public --provider-physical-network provider
说明:在 linuxbridge_agent.ini 文件中的 physical_interface_mappings = provider:ens33,所以当前创建的 flat 类型的物理网络
--provider-physical-network 要指定为 provider 本文档需要使用 >> physnet1
# 创建子网在类型为 Flat 名称为 public 网络下创建子网
openstack subnet create --network public \
--allocation-pool start=192.168.59.100,end=192.168.59.240 \
--dns-nameserver 223.5.5.5 \
--gateway 192.168.59.2 \
--subnet-range 192.168.59.0/24 subnet_192.168.59
# 创建网络接口
openstack port create --network public --fixed-ip subnet=subnet_192.168.59 ip-address=192.168.59.110
# 查看网络
openstack network list
# 查看子网
openstack subnet list
# 查看网络接口
openstack port list
# 删除网络
openstack port delete ip-address=192.168.59.110
openstack subnet delete subnet_192.168.59
openstack network delete public
# 说明:删除网络前,要先后顺序删除,即先要删除子网下的网络接口-->删除子网-->删除网络
openstack network create --share --external --provider-network-type flat public --provider-physical-network provider
# 创建内网网络
openstack subnet create --network public \
--allocation-pool start=192.168.59.100,end=192.168.59.240 \
--dns-nameserver 223.5.5.5 \
--gateway 192.168.59.2 \
--subnet-range 192.168.59.0/24 subnet_192.168.59效果
修改安全组规则
添加所有的udp、icmp、tcp的出入口 >> 后面为安全组ID
查看安全组idopenstack security group list
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29# 创建安全组
openstack security group create my-security-group --description "My-Security-Group"
# 查看安全组id
openstack security group list
//返回
+--------------------------------------+-------------------+------------------------+----------------------------------+------+
| ID | Name | Description | Project | Tags |
+--------------------------------------+-------------------+------------------------+----------------------------------+------+
| 89a9d87c-03ae-4315-854f-a1c817a2979d | default | Default security group | 19f9e05ce593402abb16b57b4fead48b | [] |
| 95e1dc64-4b62-4a87-af57-440e9a80375a | my-security-group | My-Security-Group | 19f9e05ce593402abb16b57b4fead48b | [] |
+--------------------------------------+-------------------+------------------------+----------------------------------+------+
# 添加所有icmp规则入口
openstack security group rule create --protocol icmp --ingress 89a9d87c-03ae-4315-854f-a1c817a2979d
# 添加所有icmp规则出口
openstack security group rule create --protocol icmp --egress 89a9d87c-03ae-4315-854f-a1c817a2979d
# 添加所有udp规则入口
openstack security group rule create --protocol udp --ingress 89a9d87c-03ae-4315-854f-a1c817a2979d
# 添加所有udp规则出口
openstack security group rule create --protocol udp --egress 89a9d87c-03ae-4315-854f-a1c817a2979d
# 添加所有tcp规则入口
openstack security group rule create --protocol tcp --ingress 89a9d87c-03ae-4315-854f-a1c817a2979d
# 添加所有tcp规则出口
openstack security group rule create --protocol tcp --egress 89a9d87c-03ae-4315-854f-a1c817a2979d
# 放通入方向22端口
openstack security group rule create --ingress --protocol tcp --dst-port 22:22 89a9d87c-03ae-4315-854f-a1c817a2979d
# 放通10.0.0.30入方向80端口
openstack security group rule create --ingress --protocol tcp --dst-port 80:80 --remote-ip 10.0.0.30/32 89a9d87c-03ae-4315-854f-a1c817a2979d
# 查看安全组规则
openstack security group rule list 89a9d87c-03ae-4315-854f-a1c817a2979d
三. 创建云主机实例
创建云主机实例
1
2# 创建云主机实例
openstack server create --image cirros --flavor test1 --network demo --security-group 89a9d87c-03ae-4315-854f-a1c817a2979d test查看并测试
1
2
3
4# 查看实例
openstack server list
# 检测连通性
ping 192.168.59.100
四. cinder
常用命令
1 | # 创建存储卷 |
五. 查看实例常用命令及创建云主机删除网络规则
1 | # 刷新环境变量 |
fighting!
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 ZzNnWn!
评论