在openstack云平台中,使用命令行创建云主机操作步骤

2022-12-13 13:51:33 浏览数 (1)

在openstack云平台中,使用命令行创建云主机操作步骤 创建镜像

代码语言:javascript复制
[root@controller ~]# source /etc/keystone/admin-openrc.sh 
[root@controller ~]# 
[root@controller ~]# glance image-create --name "cirros" --disk-format qcow2 --container-format bare --progress < cirros-0.5.1-x86_64-disk.img 
[=============================>] 100%
 ------------------ -------------------------------------- 
| Property         | Value                                |
 ------------------ -------------------------------------- 
| checksum         | 1d3062cd89af34e419f7100277f38b2b     |
| container_format | bare                                 |
| created_at       | 2020-11-12T02:56:58Z                 |
| disk_format      | qcow2                                |
| id               | 911ddbd7-4e23-4b8b-b575-932f55925b72 |
| min_disk         | 0                                    |
| min_ram          | 0                                    |
| name             | cirros                               |
| owner            | 1bf8b326eb3c4fb1b6fa2aa7370bed64     |
| protected        | False                                |
| size             | 16338944                             |
| status           | active                               |
| tags             | []                                   |
| updated_at       | 2020-11-12T02:56:58Z                 |
| virtual_size     | None                                 |
| visibility       | shared                               |
 ------------------ -------------------------------------- 
[root@controller ~]# openstack image list
 -------------------------------------- ----------- -------- 
| ID                                   | Name      | Status |
 -------------------------------------- ----------- -------- 
| 606be300-ec09-4427-9cf2-3185c56a2ac3 | centos7.5 | active |
| 911ddbd7-4e23-4b8b-b575-932f55925b72 | cirros    | active |
| fceb546b-2258-40cf-98c3-bbaf77c1d932 | rabbitmq1 | active |
| 6a5dce2e-0c68-41d4-9e87-7e45aeb66210 | rabbitmq2 | active |
| 37ff3c1c-861e-4001-b5ac-e3ab4839b6c5 | rabbitmq3 | active |

创建云主机类型

代码语言:javascript复制
[root@controller ~]# nova help flavor-create
usage: nova flavor-create <name> <id> <ram> <disk> <vcpus>
[root@controller ~]# nova flavor-create Fine 3 1024 10 1
 ---- ------ ----------- ------ ----------- ------ ------- ------------- ----------- ------------- 
| ID | Name | Memory_MB | Disk | Ephemeral | Swap | VCPUs | RXTX_Factor | Is_Public | Description |
 ---- ------ ----------- ------ ----------- ------ ------- ------------- ----------- ------------- 
| 3  | Fine | 1024      | 10   | 0         |      | 1     | 1.0         | True      | -           |
 ---- ------ ----------- ------ ----------- ------ ------- ------------- ----------- ------------- 

创建云主机外部网络

代码语言:javascript复制
# 创建网络
[root@controller ~]# openstack help network create
[root@controller ~]# openstack network create --project admin --provider-network-type flat --provider-physical-network provider --external  extnet
 --------------------------- -------------------------------------- 
| Field                     | Value                                |
 --------------------------- -------------------------------------- 
| admin_state_up            | UP                                   |
| availability_zone_hints   |                                      |
| availability_zones        |                                      |
| created_at                | 2020-11-12T03:18:51Z                 |
| description               |                                      |
| dns_domain                | None                                 |
| id                        | ba728255-c364-4e60-924e-0c3f4da28ba1 |
| ipv4_address_scope        | None                                 |
| ipv6_address_scope        | None                                 |
| is_default                | False                                |
| is_vlan_transparent       | None                                 |
| mtu                       | 1500                                 |
| name                      | extnet                               |
| port_security_enabled     | True                                 |
| project_id                | 1bf8b326eb3c4fb1b6fa2aa7370bed64     |
| provider:network_type     | flat                                 |
| provider:physical_network | provider                             |
| provider:segmentation_id  | None                                 |
| qos_policy_id             | None                                 |
| revision_number           | 5                                    |
| router:external           | External                             |
| segments                  | None                                 |
| shared                    | False                                |
| status                    | ACTIVE                               |
| subnets                   |                                      |
| tags                      |                                      |
| updated_at                | 2020-11-12T03:18:53Z                 |
 --------------------------- -------------------------------------- 

#创建子网
[root@controller ~]# openstack help subnet create
[root@controller ~]# openstack subnet create --network extnet --subnet-range 192.168.200.0/24 --gateway 192.168.200.1 --allocation-pool start=192.168.200.100,end=192.168.200.200 --dhcp extsubnet
 ------------------- -------------------------------------- 
| Field             | Value                                |
 ------------------- -------------------------------------- 
| allocation_pools  | 192.168.200.100-192.168.200.200      |
| cidr              | 192.168.200.0/24                     |
| created_at        | 2020-11-12T03:28:36Z                 |
| description       |                                      |
| dns_nameservers   |                                      |
| enable_dhcp       | True                                 |
| gateway_ip        | 192.168.200.1                        |
| host_routes       |                                      |
| id                | 454889bd-fe51-4fd1-9747-18524f82bf8f |
| ip_version        | 4                                    |
| ipv6_address_mode | None                                 |
| ipv6_ra_mode      | None                                 |
| name              | extsubnet                            |
| network_id        | ba728255-c364-4e60-924e-0c3f4da28ba1 |
| project_id        | 1bf8b326eb3c4fb1b6fa2aa7370bed64     |
| revision_number   | 0                                    |
| segment_id        | None                                 |
| service_types     |                                      |
| subnetpool_id     | None                                 |
| tags              |                                      |
| updated_at        | 2020-11-12T03:28:36Z                 |
 ------------------- -------------------------------------- 
[root@controller ~]# neutron subnet-list
 -------------------------------------- ------------ ---------------------------------- ------------------ -------------------------------------------------------- 
| id                                   | name       | tenant_id                        | cidr             | allocation_pools                                       |
 -------------------------------------- ------------ ---------------------------------- ------------------ -------------------------------------------------------- 
| 454889bd-fe51-4fd1-9747-18524f82bf8f | extsubnet  | 1bf8b326eb3c4fb1b6fa2aa7370bed64 | 192.168.200.0/24 | {"start": "192.168.200.100", "end": "192.168.200.200"} |
 -------------------------------------- ------------ ---------------------------------- ------------------ -------------------------------------------------------- 

创建云主机内部网络

代码语言:javascript复制
#创建网络
[root@controller ~]# openstack network create --internal intnet
 --------------------------- -------------------------------------- 
| Field                     | Value                                |
 --------------------------- -------------------------------------- 
| admin_state_up            | UP                                   |
| availability_zone_hints   |                                      |
| availability_zones        |                                      |
| created_at                | 2020-11-12T03:35:43Z                 |
| description               |                                      |
| dns_domain                | None                                 |
| id                        | 2d7c0af4-3ce9-458f-9594-6b9a15f738a7 |
| ipv4_address_scope        | None                                 |
| ipv6_address_scope        | None                                 |
| is_default                | False                                |
| is_vlan_transparent       | None                                 |
| mtu                       | 1450                                 |
| name                      | intnet                               |
| port_security_enabled     | True                                 |
| project_id                | 1bf8b326eb3c4fb1b6fa2aa7370bed64     |
| provider:network_type     | vxlan                                |
| provider:physical_network | None                                 |
| provider:segmentation_id  | 193                                  |
| qos_policy_id             | None                                 |
| revision_number           | 2                                    |
| router:external           | Internal                             |
| segments                  | None                                 |
| shared                    | False                                |
| status                    | ACTIVE                               |
| subnets                   |                                      |
| tags                      |                                      |
| updated_at                | 2020-11-12T03:35:43Z                 |
 --------------------------- -------------------------------------- 
#创建子网
[root@controller ~]# openstack subnet create --subnet-range 10.10.0.0/24  --gateway 10.10.0.1 --dhcp --network intnet intsubnet
 ------------------- -------------------------------------- 
| Field             | Value                                |
 ------------------- -------------------------------------- 
| allocation_pools  | 10.10.0.2-10.10.0.254                |
| cidr              | 10.10.0.0/24                         |
| created_at        | 2020-11-12T03:39:04Z                 |
| description       |                                      |
| dns_nameservers   |                                      |
| enable_dhcp       | True                                 |
| gateway_ip        | 10.10.0.1                            |
| host_routes       |                                      |
| id                | 0d409a46-213d-4502-8a82-930120aca955 |
| ip_version        | 4                                    |
| ipv6_address_mode | None                                 |
| ipv6_ra_mode      | None                                 |
| name              | intsubnet                            |
| network_id        | 2d7c0af4-3ce9-458f-9594-6b9a15f738a7 |
| project_id        | 1bf8b326eb3c4fb1b6fa2aa7370bed64     |
| revision_number   | 0                                    |
| segment_id        | None                                 |
| service_types     |                                      |
| subnetpool_id     | None                                 |
| tags              |                                      |
| updated_at        | 2020-11-12T03:39:04Z                 |
 ------------------- -------------------------------------- 

添加路由

代码语言:javascript复制
[root@controller ~]# openstack router create ext-router
 ------------------------- -------------------------------------- 
| Field                   | Value                                |
 ------------------------- -------------------------------------- 
| admin_state_up          | UP                                   |
| availability_zone_hints |                                      |
| availability_zones      |                                      |
| created_at              | 2020-11-12T03:46:28Z                 |
| description             |                                      |
| distributed             | False                                |
| external_gateway_info   | None                                 |
| flavor_id               | None                                 |
| ha                      | False                                |
| id                      | 26da212b-b340-443c-b16e-e59c347e0dc5 |
| name                    | ext-router                           |
| project_id              | 1bf8b326eb3c4fb1b6fa2aa7370bed64     |
| revision_number         | 0                                    |
| routes                  |                                      |
| status                  | ACTIVE                               |
| tags                    |                                      |
| updated_at              | 2020-11-12T03:46:28Z                 |
 ------------------------- -------------------------------------- 
[root@controller ~]# openstack router set  --enable --enable-snat --external-gateway extnet ext-router
[root@controller ~]# openstack router add subnet ext-router intsubnet
或者
[root@controller ~]# neutron router-interface-add ext-router intsubnet
Added interface 74072f7b-a021-4718-82e2-08225433e0f9 to router ext-router.

启动云主机

代码语言:javascript复制
[root@controller ~]# nova boot --image cirros --flavor Fine --nic net-name=intnet VM1 
 -------------------------------------- ----------------------------------------------- 
| Property                             | Value                                         |
 -------------------------------------- ----------------------------------------------- 
| OS-DCF:diskConfig                    | MANUAL                                        |
| OS-EXT-AZ:availability_zone          |                                               |
| OS-EXT-SRV-ATTR:host                 | -                                             |
| OS-EXT-SRV-ATTR:hostname             | vm1                                           |
| OS-EXT-SRV-ATTR:hypervisor_hostname  | -                                             |
| OS-EXT-SRV-ATTR:instance_name        |                                               |
| OS-EXT-SRV-ATTR:kernel_id            |                                               |
| OS-EXT-SRV-ATTR:launch_index         | 0                                             |
| OS-EXT-SRV-ATTR:ramdisk_id           |                                               |
| OS-EXT-SRV-ATTR:reservation_id       | r-9uj6yq3x                                    |
| OS-EXT-SRV-ATTR:root_device_name     | -                                             |
| OS-EXT-SRV-ATTR:user_data            | -                                             |
| OS-EXT-STS:power_state               | 0                                             |
| OS-EXT-STS:task_state                | scheduling                                    |
| OS-EXT-STS:vm_state                  | building                                      |
| OS-SRV-USG:launched_at               | -                                             |
| OS-SRV-USG:terminated_at             | -                                             |
| accessIPv4                           |                                               |
| accessIPv6                           |                                               |
| adminPass                            | se2mFnGeWT6g                                  |
| config_drive                         |                                               |
| created                              | 2020-11-12T04:04:37Z                          |
| description                          | -                                             |
| flavor:disk                          | 10                                            |
| flavor:ephemeral                     | 0                                             |
| flavor:extra_specs                   | {}                                            |
| flavor:original_name                 | Fine                                          |
| flavor:ram                           | 1024                                          |
| flavor:swap                          | 0                                             |
| flavor:vcpus                         | 1                                             |
| hostId                               |                                               |
| host_status                          |                                               |
| id                                   | 635db1f4-af98-464f-aec6-dee06249faca          |
| image                                | cirros (911ddbd7-4e23-4b8b-b575-932f55925b72) |
| key_name                             | -                                             |
| locked                               | False                                         |
| metadata                             | {}                                            |
| name                                 | VM1                                           |
| os-extended-volumes:volumes_attached | []                                            |
| progress                             | 0                                             |
| security_groups                      | default                                       |
| status                               | BUILD                                         |
| tags                                 | []                                            |
| tenant_id                            | 1bf8b326eb3c4fb1b6fa2aa7370bed64              |
| updated                              | 2020-11-12T04:04:37Z                          |
| user_id                              | 23938c4e943d4aca82184b72e8626ad1              |
 -------------------------------------- ----------------------------------------------- 

创建浮动IP地址

代码语言:javascript复制
[root@controller ~]# neutron help  floatingip-create
[root@controller ~]# neutron floatingip-create extnet
neutron CLI is deprecated and will be removed in the future. Use openstack CLI instead.
Created a new floatingip:
 --------------------- -------------------------------------- 
| Field               | Value                                |
 --------------------- -------------------------------------- 
| created_at          | 2020-11-12T05:40:15Z                 |
| description         |                                      |
| fixed_ip_address    |                                      |
| floating_ip_address | 192.168.200.109                      |
| floating_network_id | ba728255-c364-4e60-924e-0c3f4da28ba1 |
| id                  | 9fb1f908-167c-4f48-9113-1d061136eff1 |
| port_id             |                                      |
| project_id          | 1bf8b326eb3c4fb1b6fa2aa7370bed64     |
| revision_number     | 0                                    |
| router_id           |                                      |
| status              | DOWN                                 |
| tags                |                                      |
| tenant_id           | 1bf8b326eb3c4fb1b6fa2aa7370bed64     |
| updated_at          | 2020-11-12T05:40:15Z                 |
 --------------------- -------------------------------------- 
[root@controller ~]# neutron floatingip-list 
neutron CLI is deprecated and will be removed in the future. Use openstack CLI instead.
 -------------------------------------- ---------------------------------- ------------------ --------------------- --------- 
| id                                   | tenant_id                        | fixed_ip_address | floating_ip_address | port_id |
 -------------------------------------- ---------------------------------- ------------------ --------------------- --------- 
| 9fb1f908-167c-4f48-9113-1d061136eff1 | 1bf8b326eb3c4fb1b6fa2aa7370bed64 |                  | 192.168.200.109     |         |
 -------------------------------------- ---------------------------------- ------------------ --------------------- --------- 

绑定浮动IP地址

代码语言:javascript复制
[root@controller ~]# neutron help | grep floatingip
neutron CLI is deprecated and will be removed in the future. Use openstack CLI instead.
  floatingip-associate               Create a mapping between a floating IP and a fixed IP.
  floatingip-create                  Create a floating IP for a given tenant.
  floatingip-delete                  Delete a given floating IP.
  floatingip-disassociate            Remove a mapping from a floating IP to a fixed IP.
  floatingip-list                    List floating IPs that belong to a given tenant.
  floatingip-show                    Show information of a given floating IP.
[root@controller ~]# neutron help  floatingip-associate
neutron CLI is deprecated and will be removed in the future. Use openstack CLI instead.
usage: neutron floatingip-associate [-h] [--fixed-ip-address FIXED_IP_ADDRESS]
                                    FLOATINGIP_ID PORT

Create a mapping between a floating IP and a fixed IP.

positional arguments:
  FLOATINGIP_ID         ID of the floating IP to associate.
  PORT                  ID or name of the port to be associated with the
                        floating IP.

optional arguments:
  -h, --help            show this help message and exit
  --fixed-ip-address FIXED_IP_ADDRESS
                        IP address on the port (only required if port has
                        multiple IPs).
                       
[root@controller ~]# neutron floatingip-list
neutron CLI is deprecated and will be removed in the future. Use openstack CLI instead.
 -------------------------------------- ---------------------------------- ------------------ --------------------- --------- 
| id                                   | tenant_id                        | fixed_ip_address | floating_ip_address | port_id |
 -------------------------------------- ---------------------------------- ------------------ --------------------- --------- 
| 9fb1f908-167c-4f48-9113-1d061136eff1 | 1bf8b326eb3c4fb1b6fa2aa7370bed64 |                  | 192.168.200.109     |         |
 -------------------------------------- ---------------------------------- ------------------ --------------------- --------- 

[root@controller ~]# neutron port-list
neutron CLI is deprecated and will be removed in the future. Use openstack CLI instead.
 -------------------------------------- ------ ---------------------------------- ------------------- ---------------------------------------------------------------------------------------- 
| id                                   | name | tenant_id                        | mac_address       | fixed_ips                                                                              |
 -------------------------------------- ------ ---------------------------------- ------------------- ---------------------------------------------------------------------------------------- 
| 098f73d4-62f1-470c-8239-bc99e29da966 |      | 1bf8b326eb3c4fb1b6fa2aa7370bed64 | fa:16:3e:4e:e6:57 | {"subnet_id": "65a2feb3-f4bc-4300-b0d5-a1d0cfa6045d", "ip_address": "10.0.0.2"}        |
| 2c773859-32cb-47f3-80c2-79432bd8e6e3 |      | 1bf8b326eb3c4fb1b6fa2aa7370bed64 | fa:16:3e:ef:50:f4 | {"subnet_id": "0d409a46-213d-4502-8a82-930120aca955", "ip_address": "10.10.0.3"}       |
| 3d784819-c977-4a70-a331-8e3c92117d69 |      | 1bf8b326eb3c4fb1b6fa2aa7370bed64 | fa:16:3e:f9:32:3e | {"subnet_id": "65a2feb3-f4bc-4300-b0d5-a1d0cfa6045d", "ip_address": "10.0.0.7"}        |
| 46f615e7-ad4c-4cd3-ba12-9d65bdbfff9c |      | 1bf8b326eb3c4fb1b6fa2aa7370bed64 | fa:16:3e:f2:37:92 | {"subnet_id": "0d409a46-213d-4502-8a82-930120aca955", "ip_address": "10.10.0.1"}       |
| 5f98cdd5-ffff-452b-9777-6170ab4edc66 |      |                                  | fa:16:3e:ce:56:ca | {"subnet_id": "454889bd-fe51-4fd1-9747-18524f82bf8f", "ip_address": "192.168.200.106"} |
| 64c60398-d6fc-46f7-92b7-d153cd295f9c |      | 1bf8b326eb3c4fb1b6fa2aa7370bed64 | fa:16:3e:3d:d1:16 | {"subnet_id": "454889bd-fe51-4fd1-9747-18524f82bf8f", "ip_address": "192.168.200.100"} |
| 7a784aab-666e-4fad-b80c-7a2e106c16b0 |      | 1bf8b326eb3c4fb1b6fa2aa7370bed64 | fa:16:3e:e2:de:d2 | {"subnet_id": "65a2feb3-f4bc-4300-b0d5-a1d0cfa6045d", "ip_address": "10.0.0.11"}       |
| 7dc4797a-8b1d-4f1b-a5ad-b764d42d335e |      | 1bf8b326eb3c4fb1b6fa2aa7370bed64 | fa:16:3e:29:3f:d0 | {"subnet_id": "0d409a46-213d-4502-8a82-930120aca955", "ip_address": "10.10.0.2"}       |
| 8ea5657f-e283-40ff-8f4d-b2725269ab5a |      |                                  | fa:16:3e:fd:a1:0f | {"subnet_id": "454889bd-fe51-4fd1-9747-18524f82bf8f", "ip_address": "192.168.200.109"} |
| e6e8832e-03eb-4043-a4be-eed57c24e021 |      | 1bf8b326eb3c4fb1b6fa2aa7370bed64 | fa:16:3e:61:16:03 | {"subnet_id": "65a2feb3-f4bc-4300-b0d5-a1d0cfa6045d", "ip_address": "10.0.0.3"}        |
 -------------------------------------- ------ ---------------------------------- ------------------- ----------------------------------------------------------------------------------------            
[root@controller ~]#  neutron floatingip-associate --fixed-ip-address 10.10.0.3 9fb1f908-167c-4f48-9113-1d061136eff1 2c773859-32cb-47f3-80c2-79432bd8e6e3
neutron CLI is deprecated and will be removed in the future. Use openstack CLI instead.
Associated floating IP 9fb1f908-167c-4f48-9113-1d061136eff1

创建卷lvm

代码语言:javascript复制
[root@controller ~]# cinder create --display-name lvm 40
 -------------------------------- -------------------------------------- 
| Property                       | Value                                |
 -------------------------------- -------------------------------------- 
| attachments                    | []                                   |
| availability_zone              | nova                                 |
| bootable                       | false                                |
| consistencygroup_id            | None                                 |
| created_at                     | 2020-11-12T07:19:14.000000           |
| description                    | None                                 |
| encrypted                      | False                                |
| id                             | 184ab55d-a1cb-4fa9-8aec-885db1feb7ee |
| metadata                       | {}                                   |
| migration_status               | None                                 |
| multiattach                    | False                                |
| name                           | lvm                                  |
| os-vol-host-attr:host          | None                                 |
| os-vol-mig-status-attr:migstat | None                                 |
| os-vol-mig-status-attr:name_id | None                                 |
| os-vol-tenant-attr:tenant_id   | 1bf8b326eb3c4fb1b6fa2aa7370bed64     |
| replication_status             | None                                 |
| size                           | 40                                   |
| snapshot_id                    | None                                 |
| source_volid                   | None                                 |
| status                         | creating                             |
| updated_at                     | None                                 |
| user_id                        | 23938c4e943d4aca82184b72e8626ad1     |
| volume_type                    | None                                 |
 -------------------------------- -------------------------------------- 
[root@controller ~]# cinder list
 -------------------------------------- ----------- ------ ------ ------------- ---------- ------------- 
| ID                                   | Status    | Name | Size | Volume Type | Bootable | Attached to |
 -------------------------------------- ----------- ------ ------ ------------- ---------- ------------- 
| 184ab55d-a1cb-4fa9-8aec-885db1feb7ee | available | lvm  | 40   | -           | false    |             |
| 79f72f3b-5de7-46fe-902c-1f2cb233adc8 | available | lvm4 | 20   | -           | false    |             |
| 8ae8b2b6-430d-4dc0-a0e4-618d9e0a2345 | available | lvm  | 40   | -           | false    |             |
| ccf6cf00-2a59-4c6d-b6bb-1e1bffcc4e68 | available | lvm2 | 20   | -           | false    |             |
| da1525f3-10af-4ec4-b3e1-33e65c92414a | available | lvm3 | 20   | -           | false    |             |
| e727aead-1b70-498a-b268-9e643b47d2bf | available | lvm1 | 20   | -           | false    |             |
 -------------------------------------- ----------- ------ ------ ------------- ---------- ------------- 

登录之前创建的云主机“VM1”

代码语言:javascript复制
[C:~]$ ssh 192.168.200.109


Connecting to 192.168.200.109:22...
Connection established.
To escape to local shell, press Ctrl Alt ].

sh: /usr/bin/xauth: not found
$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc pfifo_fast qlen 1000
    link/ether fa:16:3e:ef:50:f4 brd ff:ff:ff:ff:ff:ff
    inet 10.10.0.3/24 brd 10.10.0.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::f816:3eff:feef:50f4/64 scope link 
       valid_lft forever preferred_lft forever

查看是否连接成功

代码语言:javascript复制
$ lsblk 
NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda     252:0    0  10G  0 disk 
|-vda1  252:1    0  10G  0 part /
`-vda15 252:15   0   8M  0 part 
vdb     252:16   0  40G  0 disk 

创建RAID 5 前期准备

代码语言:javascript复制
Connecting to 192.168.200.101:22...
Connection established.
To escape to local shell, press Ctrl Alt ].

WARNING! The remote SSH server rejected X11 forwarding request.
Last login: Fri Jul 26 13:49:02 2019


 #########################
 #  Welcome to XianDian  #
 #########################



[root@vm2 ~]# lsblk 
NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda    253:0    0  50G  0 disk 
└─vda1 253:1    0  50G  0 part /
vdb    253:16   0  40G  0 disk 
[root@vm2 ~]# 
代码语言:javascript复制
[root@vm2 ~]# mdadm -Cv /dev/md5 -l 5 -n 3 /dev/vdb1 /dev/vdb2 /dev/vdb3 --spare-devices=1 /dev/vdb4
mdadm: layout defaults to left-symmetric
mdadm: layout defaults to left-symmetric
mdadm: chunk size defaults to 512K
mdadm: partition table exists on /dev/vdb4
mdadm: partition table exists on /dev/vdb4 but will be lost or
       meaningless after creating array
mdadm: size set to 10475520K
Continue creating array? 
Continue creating array? (y/n) y
mdadm: Fail create md5 when using /sys/module/md_mod/parameters/new_array
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md5 started.
[root@vm2 ~]# mdadm -Ds
ARRAY /dev/md5 metadata=1.2 spares=2 name=vm2.novalocal:5 UUID=f5f81036:00c3aee7:33b1ebdf:f7fbf9c3
[root@vm2 ~]# mdadm -D /dev/md5 
/dev/md5:
           Version : 1.2
     Creation Time : Thu Nov 12 07:48:03 2020
        Raid Level : raid5
        Array Size : 20951040 (19.98 GiB 21.45 GB)
     Used Dev Size : 10475520 (9.99 GiB 10.73 GB)
      Raid Devices : 3
     Total Devices : 4
       Persistence : Superblock is persistent

       Update Time : Thu Nov 12 07:48:04 2020
             State : clean, degraded, recovering 
    Active Devices : 2
   Working Devices : 4
    Failed Devices : 0
     Spare Devices : 2

            Layout : left-symmetric
        Chunk Size : 512K

Consistency Policy : resync

    Rebuild Status : 3% complete

              Name : vm2.novalocal:5  (local to host vm2.novalocal)
              UUID : f5f81036:00c3aee7:33b1ebdf:f7fbf9c3
            Events : 1

    Number   Major   Minor   RaidDevice State
       0     253       17        0      active sync   /dev/vdb1
       1     253       18        1      active sync   /dev/vdb2
       4     253       19        2      spare rebuilding   /dev/vdb3

       3     253       20        -      spare   /dev/vdb4
[root@vm2 ~]# mdadm -D /dev/md5 
/dev/md5:
           Version : 1.2
     Creation Time : Thu Nov 12 07:48:03 2020
        Raid Level : raid5
        Array Size : 20951040 (19.98 GiB 21.45 GB)
     Used Dev Size : 10475520 (9.99 GiB 10.73 GB)
      Raid Devices : 3
     Total Devices : 4
       Persistence : Superblock is persistent

       Update Time : Thu Nov 12 07:52:22 2020
             State : clean 
    Active Devices : 3
   Working Devices : 4
    Failed Devices : 0
     Spare Devices : 1

            Layout : left-symmetric
        Chunk Size : 512K

Consistency Policy : resync

              Name : vm2.novalocal:5  (local to host vm2.novalocal)
              UUID : f5f81036:00c3aee7:33b1ebdf:f7fbf9c3
            Events : 18

    Number   Major   Minor   RaidDevice State
       0     253       17        0      active sync   /dev/vdb1
       1     253       18        1      active sync   /dev/vdb2
       4     253       19        2      active sync   /dev/vdb3

       3     253       20        -      spare   /dev/vdb4
[root@vm2 ~]# 

模拟磁盘损坏

代码语言:javascript复制
[root@vm2 ~]# mdadm -f /dev/md5 /dev/vdb1
mdadm: set /dev/vdb1 faulty in /dev/md5
[root@vm2 ~]# mdadm -D /dev/md5 
/dev/md5:
           Version : 1.2
     Creation Time : Thu Nov 12 07:48:03 2020
        Raid Level : raid5
        Array Size : 20951040 (19.98 GiB 21.45 GB)
     Used Dev Size : 10475520 (9.99 GiB 10.73 GB)
      Raid Devices : 3
     Total Devices : 4
       Persistence : Superblock is persistent

       Update Time : Thu Nov 12 07:55:04 2020
             State : clean, degraded, recovering 
    Active Devices : 2
   Working Devices : 3
    Failed Devices : 1
     Spare Devices : 1

            Layout : left-symmetric
        Chunk Size : 512K

Consistency Policy : resync

    Rebuild Status : 0% complete

              Name : vm2.novalocal:5  (local to host vm2.novalocal)
              UUID : f5f81036:00c3aee7:33b1ebdf:f7fbf9c3
            Events : 20

    Number   Major   Minor   RaidDevice State
       3     253       20        0      spare rebuilding   /dev/vdb4
       1     253       18        1      active sync   /dev/vdb2
       4     253       19        2      active sync   /dev/vdb3

       0     253       17        -      faulty   /dev/vdb1

[root@vm2 ~]# mdadm -D /dev/md5 
/dev/md5:
           Version : 1.2
     Creation Time : Thu Nov 12 07:48:03 2020
        Raid Level : raid5
        Array Size : 20951040 (19.98 GiB 21.45 GB)
     Used Dev Size : 10475520 (9.99 GiB 10.73 GB)
      Raid Devices : 3
     Total Devices : 4
       Persistence : Superblock is persistent

       Update Time : Thu Nov 12 08:00:57 2020
             State : clean 
    Active Devices : 3
   Working Devices : 3
    Failed Devices : 1
     Spare Devices : 0

            Layout : left-symmetric
        Chunk Size : 512K

Consistency Policy : resync

              Name : vm2.novalocal:5  (local to host vm2.novalocal)
              UUID : f5f81036:00c3aee7:33b1ebdf:f7fbf9c3
            Events : 37

    Number   Major   Minor   RaidDevice State
       3     253       20        0      active sync   /dev/vdb4
       1     253       18        1      active sync   /dev/vdb2
       4     253       19        2      active sync   /dev/vdb3

       0     253       17        -      faulty   /dev/vdb1
[root@vm2 ~]# 

0 人点赞