5.3、操作云主机
5.3.1、创建云主机
$ openstack server create --image cirros --flavor m1.tiny --network ext-net test_name(云主机/实例 名称)
参数说明:
–image: 创建云主机所使用镜像启动盘(名称或 ID)
–flavor: 创建云主机所使用的flavor(名称或 ID)
–network: 在云主机上创建一个 NIC 并将其连接到网络。
- 多次指定选项以创建多个 NIC。
–network是 ‘–nic net-id=<network>’ 的包装,为标准提供简单语法的参数。
有关更高级的用例,请参阅’–nic’参数。
5.3.2、列出实例,实例状态
$ openstack server list
5.3.3、查看云主机的控制台日志
$ openstack console log show NAME(实例名称)
5.3.4、显示云主机的远程控制台 URL
$ openstack console url show test
5.3.5、重启
$ openstack server reboot NAME
5.3.6、关机
$ openstack server stop NAME
5.3.7、启动
$ openstack server start NAME
5.3.8、暂停
$ openstack server pause NAME
5.3.9、挂起
$ openstack server suspend NAME
5.3.10、取消挂起
$ openstack server unpause NAME
5.3.11、重建
$ openstack server rebuild NAME IMAGE
5.3.12、创建快照
$ openstack server stop test(实例名称) $ openstack server image create test (实例名称)–name testSnapshot (创建快照)
5.3.13、下载快照
$ openstack image save --file csccvm.qcow2 testSnapshot
5.3.14、调整大小
修改/etc/nova/nova.conf配置文件,添加调整类型大小的参数
$ openstack-config --set /etc/nova/nova.conf DEFAULT scheduler_default_filters AvailabilityZoneFilter,ComputeFilter,ComputeCapabilitiesFilter,ImagePropertiesFilter,ServerGroupAntiAffinityFilter,ServerGroupAffinityFilter # 重启生效配置 $ systemctl restart openstack-nova*
$ openstack server resize NAME(实例 id/名称) FLAVOR(flavor id/名称) # 确认服务器调整大小完成 $ openstack server resize --confirm NAME(实例名称)
5.3.15、云主机挂载云硬盘
$ openstack server add volume test_name(实例id/name) 8aa66c0b-72e8-4a2a-a305-1a1de50a505c(磁盘id/name)
5.3.16、创建秘钥对
$ openstack keypair create test > test.pem $ chmod 600 test.pem
给实例注入一个密钥对并通过密钥对来访问实例
启动实例
$ openstack server create --image cirros-0.3.5-x86_64 --flavor m1.small \ --key-name test MyFirstServer
使用ssh连接到实例
# ip netns exec qdhcp-98f09f1e-64c4-4301-a897-5067ee6d544f \ ssh -i test.pem cirros@10.0.0.4
六、cinder(块存储)
6.1、创建卷lvm类型
[root@controller ~]# cinder type-create lvm
6.2、创建一个新卷
$ openstack volume create --type lvm --size SIZE_IN_GB NAME(卷名称)
参数说明:
–size: 以 GB 为单位的卷大小
–type: 设置卷类型
6.3、列出所有卷,卷状态
$ openstack volume list
6.4、将卷连接到实例
实例为正常状态且卷为可用状态
$ $ openstack server add volume test_name(实例id/name) 8aa66c0b-72e8-4a2a-a305-1a1de50a505c(磁盘id/name)
6.5、扩展卷
[root@controller ~]# openstack volume list +--------------------------------------+---------------+-----------+------+------------------------------------+ | ID | Name | Status | Size | Attached to | +--------------------------------------+---------------+-----------+------+------------------------------------+ | f3678c4a-87cf-438e-bf49-4c37076d1a0e | aa | available | 1 | | [root@controller ~]# openstack volume set --size 2 aa(卷名称) [root@controller ~]# openstack volume list +--------------------------------------+---------------+-----------+------+------------------------------------+ | ID | Name | Status | Size | Attached to | +--------------------------------------+---------------+-----------+------+------------------------------------+ | f3678c4a-87cf-438e-bf49-4c37076d1a0e | aa | available | 2 | |
参数说明:
–size: 以 GB 为单位扩展卷大小
七、Swift(对象存储)
7.1、创建容器
$ openstack container create test_name
7.2、列出容器
$ openstack container list
7.3、查看容器详情
$ openstack container show test_name
7.4、创建对象、上传对象
创建对象的过程也是向容器中上传对象的过程
$ openstack object create test_name(容器名称) test/anaconda-ks.cfg (上传的文件)
7.5、列出容器中的对象
$ openstack object list test_name +----------------------+ | Name | +----------------------+ | test/anaconda-ks.cfg | +----------------------+
7.6、查看对象详情
通过查询命令可以看出,在通过命令上传对象时,本地路径即为容器内对象路径
$ openstack object show test_name test/anaconda-ks.cfg +----------------+---------------------------------------+ | Field | Value | +----------------+---------------------------------------+ | account | AUTH_13b5e35202d54a84ae7a5ae5c57b9846 | | container | test_name | | content-length | 6880 | | content-type | application/octet-stream | | etag | 41656296ae6768ae924a5b5f3fe15bf0 | | last-modified | Thu, 10 Feb 2022 06:54:30 GMT | | object | test/anaconda-ks.cfg | +----------------+---------------------------------------+
7.7、下载对象
$ openstack object save test_name test/anaconda-ks.cfg
7.8、删除对象
$ openstack object delete test_name test/anaconda-ks.cfg
7.9、删除空容器
下列命令只能删除空容器,如果容器内有对象,无法直接删除
$ openstack container delete test_name
7.10、递归删除容器
$ openstack container delete --recursive swift-test
参数说明:
–recursive: 递归删除对象和容器
7.11、swift分片存储
$ swift upload test -S 10000000 cirros-0.5.2-x86_64-disk.img cirros-0.3.4-x86_64-disk.img segment 0 cirros-0.3.4-x86_64-disk.img segment 1 cirros-0.3.4-x86_64-disk.img
参数说明:
-S: 每一个片的大小,单位字节(B)
查看存储路径中的数据片
[root@controller ~]# openstack container list +---------------+ | Name | +---------------+ | test_segments | +---------------+ [root@controller ~]# openstack object list test_segments +---------------------------------------------------------------------------+ | Name | +---------------------------------------------------------------------------+ | cirros-0.5.2-x86_64-disk.img/1656827975.223582/16300544/10000000/00000000 | | cirros-0.5.2-x86_64-disk.img/1656827975.223582/16300544/10000000/00000001 | +---------------------------------------------------------------------------+
7.12、查看服务、容器以及对象的状态信息
$ swift stat $ swift stat CONTAINER(容器名称) $ swift stat OBJECT(对象名称)
八、Heat(编排)
8.1、编排创建cinder
$ cat cinder.yaml heat_template_version: "2018-08-31" description: "version 2017-09-01 created by HOT Generator at Sun, 03 Jul 2022 13:14:37 GMT." resources: Volume_1: type: "OS::Cinder::Volume" properties: name: heat_test1 size: 2 volume_type: "d21b433b-cdd9-4a4f-a759-9131094514f5" #创建堆栈,并创建cinder $ openstack stack create -t cinder.yaml cinder-1(栈名称)
参数说明:
-t: 模板路径
8.2、编排创建swift
$ cat swift.yaml heat_template_version: "2018-08-31" description: "version 2017-09-01 created by HOT Generator at Sun, 03 Jul 2022 13:19:50 GMT." resources: Container_1: type: "OS::Swift::Container" properties: name: heat_swift "X-Container-Write": true #创建堆栈,并创建swift $ openstack stack create -t swift.yaml swift-1(栈名称)
参数说明:
-t: 模板路径
8.3、编排创建network和subnet
heat_template_version: "2018-08-31" description: "version 2017-09-01 created by HOT Generator at Sun, 03 Jul 2022 13:28:04 GMT." resources: Net_1: type: "OS::Neutron::Net" properties: admin_state_up: true name: Heat_Network shared: true Subnet_1: type: "OS::Neutron::Subnet" properties: name: "Heat-Subnet" ip_version: 4 cidr: "10.32.10.0/24" network_id: get_resource: Net_1 # #创建堆栈,并创建网络 $ openstack stack create -t network.yaml network(栈名称)
参数说明:
-t: 模板路径
8.4、编排创建flavor
$ cat falvor.ayml heat_template_version: "2018-08-31" description: "version 2017-09-01 created by HOT Generator at Sun, 03 Jul 2022 13:43:44 GMT." resources: nova_flavor: type: OS::Nova::Flavor properties: name: m1.flavor disk: 20 is_public: True ram: 1024 vcpus: 2 # 创建堆栈,并创建falvor $ openstack stack create -t falvor.ayml falvor
8.5、编排创建server
$ cat server.yaml heat_template_version: "2018-08-31" description: "version 2017-09-01 created by HOT Generator at Sun, 03 Jul 2022 13:33:42 GMT." resources: Server_1: type: "OS::Nova::Server" properties: networks: - network: "2cd557b4-0a35-4226-8f42-274e100d52e2" flavor: "m1.tiny" name: Heat_Server image: "ac64f3c2-5705-4962-9fdb-6ce97b1b7876" # #创建堆栈,并创建server $ openstack stack create -t server.yaml server(栈名称)
参数说明:
-t: 模板路径
8.6、编排创建user
$ cat user.yaml heat_template_version: "2018-08-31" description: "version 2017-09-01 created by HOT Generator at Sun, 03 Jul 2022 13:33:42 GMT." resources: user: type: OS::Keystone::User properties: name: "Heat-User" password: "123456" domain: "default" default_project: "admin" roles: [{"role": admin, "project": admin}] # 创建堆栈,并创建user $ openstack stack create -t user.yaml user(栈名称)
8.7、列出所有堆栈
$ openstack stack list +--------------------------------------+------------+----------------------------------+-----------------+----------------------+--------------+ | ID | Stack Name | Project | Stack Status | Creation Time | Updated Time | +--------------------------------------+------------+----------------------------------+-----------------+----------------------+--------------+ | 5b6dd6ff-02bf-4ae9-b933-7b628ffbb94c | falvor | 4209800f33d94f61bdfc8b487f219f06 | CREATE_COMPLETE | 2022-07-03T13:38:50Z | None | | b06ca53d-c30b-4f0d-95d8-83b8f406766a | server | 4209800f33d94f61bdfc8b487f219f06 | CREATE_COMPLETE | 2022-07-03T13:34:09Z | None | | 4229a9b0-f278-4e22-bcad-0cded20af297 | network | 4209800f33d94f61bdfc8b487f219f06 | CREATE_COMPLETE | 2022-07-03T13:28:33Z | None | | a7904f37-c967-4531-9cc6-3bb098fa95e9 | cinder-1 | 4209800f33d94f61bdfc8b487f219f06 | CREATE_COMPLETE | 2022-07-03T13:15:56Z | None | | 347f0741-c9a6-46b1-9fd1-03d270ff435d | swift-1 | 4209800f33d94f61bdfc8b487f219f06 | CREATE_COMPLETE | 2022-07-03T13:15:31Z | None | +--------------------------------------+------------+----------------------------------+-----------------+----------------------+--------------+
8.8、列出堆栈详情
$ openstack stack show network(堆栈名称)
8.9、删除堆栈
$ openstack stack delete network(堆栈名称)
九、Manila(共享文件系统)
9.1、创建禁用 DHSS 的默认共享类型
driver_handles_share_servers在使用 LVM 驱动程序创建共享之前禁用 DHSS
$ cat /etc/manila/manila.conf [lvm] ... driver_handles_share_servers = False ...
默认共享类型允许您使用此驱动程序创建共享,而无需再创建共享时指定共享类型。
语法:manila type-create <spec_driver_handles_share_servers>
$ manila type-create default_share_type False +----------------------+--------------------------------------+ | Property | Value | +----------------------+--------------------------------------+ | required_extra_specs | driver_handles_share_servers : False | | Name | default_share_type | | Visibility | public | | is_default | YES | | ID | be070d83-e632-4c36-9839-0cb6079d3b77 | | optional_extra_specs | | | Description | None | +----------------------+--------------------------------------+
9.2、列出共享类型
$ manila type-list
9.3、创建共享目录
语法:manila create <share_protocol> <size>
$ manila create NFS 1 --name share1
参数说明:
<share_protocol> : 共享协议(NFS、CIFS、CephFS、GlusterFS、HDFS、MAPRFS)。
<size>: 以 GiB 为单位的共享大小。
–name: 共享名称。
9.4、列出共享目录
$ manila list
9.5、查看共享目录详情
$ manila show share_name(共享名称)
9.6、允许访问共享目录
语法:manila access-allow <share> <access_type> <access_to>
manila access-allow share1 ip 10.43.8.0/22
参数说明:
<share> : 共享的名称或 ID
<access_type> : 访问规则类型仅“ip”、“user”(用户或组)、支持“cert”或“cephx”)
<access_to>: 定义访问的网段/ip
–access-level: 共享访问级别(“rw”和“ro”访问级别是支持的)。 默认为 rw。
9.7、查看共享目录权限及开放网段
$ manila access-list share1(共享名称)
9.8、挂载共享目录
获取共享目录路径
$ manila show share1 |grep path | | path = 10.43.8.35:/var/lib/manila/mnt/share-c530b7d7-c028-4980-86de-4aea1140c148 |
compute节点挂载共享目录
$ mount -t nfs 10.43.8.35:/var/lib/manila/mnt/share-c530b7d7-c028-4980-86de-4aea1140c148 /mnt/ $ df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 3.8G 0 3.8G 0% /dev tmpfs 3.9G 4.0K 3.9G 1% /dev/shm tmpfs 3.9G 145M 3.7G 4% /run tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup /dev/vda1 100G 3.1G 97G 4% / tmpfs 783M 0 783M 0% /run/user/0 /dev/vdb2 20G 49M 20G 1% /swift/node/vdb2 /dev/dm-8 976M 2.6M 907M 1% /var/lib/manila/mnt/share-c530b7d7-c028-4980-86de-4aea1140c148 10.43.8.35:/var/lib/manila/mnt/share-c530b7d7-c028-4980-86de-4aea1140c148 976M 2.0M 907M 1% /mnt
参考资料
https://docs.openstack.org/zh_CN/user-guide/index.html
最后
我是无名小歌,欢迎大家一键三连
加入云社区一起学习云计算,走向年薪50万。
如果对你有帮助,还望赏个关注鸭!!! 😜
(⊙o⊙),我们下期再见!!!