iaas操作笔记

这篇博客记录了在OpenStack环境中进行的一系列操作,包括上传cirros镜像、创建云主机类型、构建网络(外部网络flat和内部网络vxlan)、创建路由、分配浮动IP、开放安全组规则以允许SSH访问,并最终成功通过SSH连接到云主机。此外,还涉及到云主机类型变更的问题,通过调整配置文件和设置SSH密钥解决了 nova 之间的通信问题,以及创建快照、创建卷类型和搭建主从数据库的步骤。

openstack部分题目操作

上传镜像

[root@controller ~]# source  /etc/keystone/admin-openrc.sh 
[root@controller ~]# glance image-create --name cirros --disk-format qcow2 --container-format bare --file cirros-0.3.3-x86_64-disk.img 
+------------------+--------------------------------------+
| Property         | Value                                |
+------------------+--------------------------------------+
| checksum         | ee1eca47dc88f4879d8a229cc70a07c6     |
| container_format | bare                                 |
| created_at       | 2022-03-15T08:03:43Z                 |
| disk_format      | qcow2                                |
| id               | 32d5dbba-6634-4a4a-a35c-6224931b786c |
| min_disk         | 0                                    |
| min_ram          | 0                                    |
| name             | cirros                               |
| owner            | 0c05a59bc07945dcb63f1b5e7d82cc5d     |
| protected        | False                                |
| size             | 13287936                             |
| status           | active                               |
| tags             | []                                   |
| updated_at       | 2022-03-15T08:03:43Z                 |
| virtual_size     | None                                 |
| visibility       | shared                               |
+------------------+--------------------------------------+

创建云主机类型

[root@controller ~]# openstack flavor create --id 1  --ram 1024 --disk 10 --vcpus 1 Fmin 
+----------------------------+-------+
| Field                      | Value |
+----------------------------+-------+
| OS-FLV-DISABLED:disabled   | False |
| OS-FLV-EXT-DATA:ephemeral  | 0     |
| disk                       | 10    |
| id                         | 1     |
| name                       | Fmin  |
| os-flavor-access:is_public | True  |
| properties                 |       |
| ram                        | 1024  |
| rxtx_factor                | 1.0   |
| swap                       |       |
| vcpus                      | 1     |
+----------------------------+-------+

创建网络类型和路由

# 创建外部网络 测试环境类型 flat 考试环境类型为vlan
[root@controller ~]# openstack network create --provider-network-type flat --provider-physical-network provider --external  extnet
+---------------------------+--------------------------------------+
| Field                     | Value                                |
+---------------------------+--------------------------------------+
| admin_state_up            | UP                                   |
| availability_zone_hints   |                                      |
| availability_zones        |                                      |
| created_at                | 2022-03-15T08:06:54Z                 |
| description               |                                      |
| dns_domain                | None                                 |
| id                        | 1f25744d-a423-4743-8c54-3f5b4e18e91c |
| 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                | 0c05a59bc07945dcb63f1b5e7d82cc5d     |
| 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                | 2022-03-15T08:06:54Z                 |
+---------------------------+--------------------------------------+

# 创建外部网络的子网内容
[root@controller ~]# openstack subnet create --subnet-range 172.16.88.0/24 --gateway 172.16.88.1 --network extnet extsubnet
+-------------------+--------------------------------------+
| Field             | Value                                |
+-------------------+--------------------------------------+
| allocation_pools  | 172.16.88.2-172.16.88.254            |
| cidr              | 172.16.88.0/24                       |
| created_at        | 2022-03-15T08:08:12Z                 |
| description       |                                      |
| dns_nameservers   |                                      |
| enable_dhcp       | True                                 |
| gateway_ip        | 172.16.88.1                          |
| host_routes       |                                      |
| id                | 9efc1955-5e8e-45d8-9fa3-9fe295826c44 |
| ip_version        | 4                                    |
| ipv6_address_mode | None                                 |
| ipv6_ra_mode      | None                                 |
| name              | extsubnet                            |
| network_id        | 1f25744d-a423-4743-8c54-3f5b4e18e91c |
| project_id        | 0c05a59bc07945dcb63f1b5e7d82cc5d     |
| revision_number   | 0                                    |
| segment_id        | None                                 |
| service_types     |                                      |
| subnetpool_id     | None                                 |
| tags              |                                      |
| updated_at        | 2022-03-15T08:08:12Z                 |
+-------------------+--------------------------------------+

# 创建内部网络内部网络 vxlan
[root@controller ~]# openstack network create --internal --provider-network-type vxlan intnet
+---------------------------+--------------------------------------+
| Field                     | Value                                |
+---------------------------+--------------------------------------+
| admin_state_up            | UP                                   |
| availability_zone_hints   |                                      |
| availability_zones        |                                      |
| created_at                | 2022-03-15T08:09:06Z                 |
| description               |                                      |
| dns_domain                | None                                 |
| id                        | 2c80eb67-4552-429f-836e-a5274258998c |
| 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                | 0c05a59bc07945dcb63f1b5e7d82cc5d     |
| provider:network_type     | vxlan                                |
| provider:physical_network | None                                 |
| provider:segmentation_id  | 142                                  |
| qos_policy_id             | None                                 |
| revision_number           | 2                                    |
| router:external           | Internal                             |
| segments                  | None                                 |
| shared                    | False                                |
| status                    | ACTIVE                               |
| subnets                   |                                      |
| tags                      |                                      |
| updated_at                | 2022-03-15T08:09:06Z                 |
+---------------------------+--------------------------------------+
 
# 设置内网子网
[root@controller ~]# openstack subnet create --subnet-range 10.10.10.0/24 --gateway 10.10.10.1 --network intnet intsubnet
+-------------------+--------------------------------------+
| Field             | Value                                |
+-------------------+--------------------------------------+
| allocation_pools  | 10.10.10.2-10.10.10.254              |
| cidr              | 10.10.10.0/24                        |
| created_at        | 2022-03-15T08:09:56Z                 |
| description       |                                      |
| dns_nameservers   |                                      |
| enable_dhcp       | True                                 |
| gateway_ip        | 10.10.10.1                           |
| host_routes       |                                      |
| id                | 6439529e-bfe7-41c4-832c-29c9d77e3114 |
| ip_version        | 4                                    |
| ipv6_address_mode | None                                 |
| ipv6_ra_mode      | None                                 |
| name              | intsubnet                            |
| network_id        | 2c80eb67-4552-429f-836e-a5274258998c |
| project_id        | 0c05a59bc07945dcb63f1b5e7d82cc5d     |
| revision_number   | 0                                    |
| segment_id        | None                                 |
| service_types     |                                      |
| subnetpool_id     | None                                 |
| tags              |                                      |
| updated_at        | 2022-03-15T08:09:56Z                 |
+-------------------+--------------------------------------+
    
# 创建路由
[root@controller ~]# openstack router create r1
+-------------------------+--------------------------------------+
| Field                   | Value                                |
+-------------------------+--------------------------------------+
| admin_state_up          | UP                                   |
| availability_zone_hints |                                      |
| availability_zones      |                                      |
| created_at              | 2022-03-15T08:10:13Z                 |
| description             |                                      |
| distributed             | False                                |
| external_gateway_info   | None                                 |
| flavor_id               | None                                 |
| ha                      | False                                |
| id                      | 47cf9d73-fc84-4e84-b58f-14962d8464f8 |
| name                    | r1                                   |
| project_id              | 0c05a59bc07945dcb63f1b5e7d82cc5d     |
| revision_number         | 1                                    |
| routes                  |                                      |
| status                  | ACTIVE                               |
| tags                    |                                      |
| updated_at              | 2022-03-15T08:10:13Z                 |
+-------------------------+--------------------------------------+

# 绑定外部网络网关到路由
[root@controller ~]# openstack router set --external-gateway extnet r1

# 绑定内部子网到路由器
[root@controller ~]# openstack router add subnet r1 intsubnet

创建云主机

[root@controller ~]# openstack server create vm1 --flavor Fmin --image cirros --nic net-id=2c80eb67-4552-429f-836e-a5274258998c --security-group 4202eac5-06aa-4874-938f-17eb7a5b0d69  
+-------------------------------------+-----------------------------------------------+
| Field                               | Value                                         |
+-------------------------------------+-----------------------------------------------+
| OS-DCF:diskConfig                   | MANUAL                                        |
| OS-EXT-AZ:availability_zone         |                                               |
| OS-EXT-SRV-ATTR:host                | None                                          |
| OS-EXT-SRV-ATTR:hypervisor_hostname | None                                          |
| OS-EXT-SRV-ATTR:instance_name       |                                               |
| OS-EXT-STS:power_state              | NOSTATE                                       |
| OS-EXT-STS:task_state               | scheduling                                    |
| OS-EXT-STS:vm_state                 | building                                      |
| OS-SRV-USG:launched_at              | None                                          |
| OS-SRV-USG:terminated_at            | None                                          |
| accessIPv4                          |                                               |
| accessIPv6                          |                                               |
| addresses                           |                                               |
| adminPass                           | Pu7tsS9R4bEr                                  |
| config_drive                        |                                               |
| created                             | 2022-03-15T08:15:38Z                          |
| flavor                              | Fmin (1)                                      |
| hostId                              |                                               |
| id                                  | 5759c44c-6264-45cd-841b-c9980fd2f2ad          |
| image                               | cirros (32d5dbba-6634-4a4a-a35c-6224931b786c) |
| key_name                            | None                                          |
| name                                | vm1                                           |
| progress                            | 0                                             |
| project_id                          | 0c05a59bc07945dcb63f1b5e7d82cc5d              |
| properties                          |                                               |
| security_groups                     | name='4202eac5-06aa-4874-938f-17eb7a5b0d69'   |
| status                              | BUILD                                         |
| updated                             | 2022-03-15T08:15:38Z                          |
| user_id                             | 7613c7a515ac4e7f999fbc1e57826614              |
| volumes_attached                    |                                               |
+-------------------------------------+-----------------------------------------------+
[root@controller ~]# 

绑定浮动IP

# 创建个外部网络的浮动IP
[root@controller ~]# openstack floating ip create extnet
+---------------------+--------------------------------------+
| Field               | Value                                |
+---------------------+--------------------------------------+
| created_at          | 2022-03-15T09:21:35Z                 |
| description         |                                      |
| fixed_ip_address    | None                                 |
| floating_ip_address | 172.16.88.9                          |
| floating_network_id | 1f25744d-a423-4743-8c54-3f5b4e18e91c |
| id                  | 80a8ece1-4d74-4155-b4c0-50d868cdc092 |
| name                | 172.16.88.9                          |
| port_id             | None                                 |
| project_id          | 0c05a59bc07945dcb63f1b5e7d82cc5d     |
| qos_policy_id       | None                                 |
| revision_number     | 0                                    |
| router_id           | None                                 |
| status              | DOWN                                 |
| subnet_id           | None                                 |
| updated_at          | 2022-03-15T09:21:35Z                 |
+---------------------+--------------------------------------+

# 绑定浮动IP 
[root@controller ~]# openstack server add floating ip vm1 172.16.88.9
[root@controller ~]# 

ssh登录

# 先测试能不能ping通  查看安全组是否开放了所有的ICMP协议 入口 还有要开放ssh登录端口
[root@controller ~]# ping 172.16.88.9
PING 172.16.88.9 (172.16.88.9) 56(84) bytes of data.
# 开放协议后
[root@controller ~]# ping 172.16.88.9
PING 172.16.88.9 (172.16.88.9) 56(84) bytes of data.
64 bytes from 172.16.88.9: icmp_seq=1 ttl=63 time=1.36 ms
64 bytes from 172.16.88.9: icmp_seq=2 ttl=63 time=1.30 ms
64 bytes from 172.16.88.9: icmp_seq=3 ttl=63 time=1.22 ms
64 bytes from 172.16.88.9: icmp_seq=4 ttl=63 time=1.18 ms
64 bytes from 172.16.88.9: icmp_seq=5 ttl=63 time=1.32 ms
^C
--- 172.16.88.9 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4005ms
rtt min/avg/max/mdev = 1.189/1.279/1.361/0.071 ms
[root@controller ~]# 

命令开放安全组

# egress是出口 ingress是入口

[root@controller ~]# openstack  security group rule create   4202eac5-06aa-4874-938f-17eb7a5b0d69  --protocol icmp   --ingress  --remote-ip 0.0.0.0/0
+-------------------+--------------------------------------+
| Field             | Value                                |
+-------------------+--------------------------------------+
| created_at        | 2022-03-15T09:32:01Z                 |
| description       |                                      |
| direction         | ingress                              |
| ether_type        | IPv4                                 |
| id                | c9d9539f-58ef-4a43-b59c-d6e1eebee288 |
| name              | None                                 |
| port_range_max    | None                                 |
| port_range_min    | None                                 |
| project_id        | 0c05a59bc07945dcb63f1b5e7d82cc5d     |
| protocol          | icmp                                 |
| remote_group_id   | None                                 |
| remote_ip_prefix  | 0.0.0.0/0                            |
| revision_number   | 0                                    |
| security_group_id | 4202eac5-06aa-4874-938f-17eb7a5b0d69 |
| updated_at        | 2022-03-15T09:32:01Z                 |
+-------------------+--------------------------------------+

# 开放ssh安全组命令
[root@controller ~]# openstack  security group rule create 4202eac5-06aa-4874-938f-17eb7a5b0d69  --protocol tcp --dst-port 22  --remote-ip 0.0.0.0/0
+-------------------+--------------------------------------+
| Field             | Value                                |
+-------------------+--------------------------------------+
| created_at        | 2022-03-15T09:30:37Z                 |
| description       |                                      |
| direction         | ingress                              |
| ether_type        | IPv4                                 |
| id                | 3cfd3ab2-a215-4ee2-9462-72540934369c |
| name              | None                                 |
| port_range_max    | 22                                   |
| port_range_min    | 22                                   |
| project_id        | 0c05a59bc07945dcb63f1b5e7d82cc5d     |
| protocol          | tcp                                  |
| remote_group_id   | None                                 |
| remote_ip_prefix  | 0.0.0.0/0                            |
| revision_number   | 0                                    |
| security_group_id | 4202eac5-06aa-4874-938f-17eb7a5b0d69 |
| updated_at        | 2022-03-15T09:30:37Z                 |
+-------------------+--------------------------------------+

遇到该问题?如何解决?

image-20220315161700275

[root@compute ~]# vi /etc/nova/nova.conf 
[DEFAULT]
enabled_apis = osapi_compute,metadata
transport_url = rabbit://openstack:000000@controller
my_ip = 172.16.89.40
use_neutron = True
firewall_driver = nova.virt.firewall.NoopFirewallDriver

#.............................................................................................
   #.............................................................................................

/cpu_mode

cpu_mode=none

#.............................................................................................
/type=
#.............................................................................................

/type=
#.............................................................................................
/type=
#.............................................................................................
/type=
#.............................................................................................
    
/type=
#.............................................................................................

[pci]
search hit BOTTOM, continuing at TOP
#.............................................................................................
/kvm
#.............................................................................................
virt_type=qemu
[root@compute ~]# systemctl restart openstack-nova-compute.service

GRUB 解决方法

# 修改compute节点的nova配置文件 去掉下面2个注释并修改
#virt_type=kvm  修改为  virt_type=qemu
#cpu_mode=<None> 修改为 cpu_mode=none
# 然后重启openstack-nova-compute.service后重新实例就可以了

openstack 更换实例类型失败

[root@controller ~]# nova resize vm1 2
ERROR (BadRequest): No valid host was found. No valid host found for resize (HTTP 400) (Request-ID: req-c229fe5b-baf0-4fbe-94d1-36f45c920545)

解决方法

# 修改控制节点和计算节点的nova配置文件
# 修改以下参数
#allow_resize_to_same_host=false 修改为 allow_resize_to_same_host=True
# Deprecated group;name - DEFAULT;scheduler_default_filters
#去掉注释或者去掉注释将enabled_filters=修改为scheduler_default_filters=
#enabled_filters=RetryFilter,AvailabilityZoneFilter,ComputeFilter,ComputeCapabilitiesFilter,ImagePropertiesFilter,ServerGroupAntiAffinityFilter,ServerGroupAffinityFilter

#...............................................................................................
# 重启每个节点的nova服务

还是无法更改?nova之间无法通信 报错内容大致如下 关键词(Host key)

  1. 这是无法进行通信 重新配置nova的ssh
tailf /var/log/nova/nova-compute.log

2022-03-15 15:00:32.088 28511 ERROR oslo_messaging.rpc.server     raise error.inner_exception
2022-03-15 15:00:32.088 28511 ERROR oslo_messaging.rpc.server ResizeError: Resize error: not able to execute ssh command: Unexpected error while running command.
2022-03-15 15:00:32.088 28511 ERROR oslo_messaging.rpc.server Command: ssh -o BatchMode=yes x.x.x.x mkdir -p /var/lib/nova/instances/a3477397-66a5-4f53-9010-a8413c1a8b70
2022-03-15 15:00:32.088 28511 ERROR oslo_messaging.rpc.server Exit code: 255
2022-03-15 15:00:32.088 28511 ERROR oslo_messaging.rpc.server Stdout: u''
2022-03-15 15:00:32.088 28511 ERROR oslo_messaging.rpc.server Stderr: u'Host key verification failed.\r\n'

操作如下 配置双向认证

[root@controller ~]# usermod  -s /bin/bash nova   # 允许nova登录 
[root@controller ~]# echo "nova"|passwd --stdin nova  # 设置nova密码为nova可无视 默认应该是 000000
[root@controller ~]# su - nova  # 登录
-bash-4.2$ ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa     # 生成ssh密钥
-bash-4.2$ ssh-copy-id  nova@x.x.x.x  ```# 发送ssh密钥到nova节点 

更换实例主机类型

[root@controller ~]# nova show vm1
+--------------------------------------+----------------------------------------------------------+
| Property                             | Value                                                    |
+--------------------------------------+----------------------------------------------------------+
| OS-DCF:diskConfig                    | AUTO                                                     |
| OS-EXT-AZ:availability_zone          | nova                                                     |
| OS-EXT-SRV-ATTR:host                 | compute                                                  |
| OS-EXT-SRV-ATTR:hostname             | vm1                                                      |
| OS-EXT-SRV-ATTR:hypervisor_hostname  | compute                                                  |
| OS-EXT-SRV-ATTR:instance_name        | instance-00000001                                        |
| 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-2unam55d                                               |
| OS-EXT-SRV-ATTR:root_device_name     | /dev/vda                                                 |
| OS-EXT-SRV-ATTR:user_data            | -                                                        |
| OS-EXT-STS:power_state               | 1                                                        |
| OS-EXT-STS:task_state                | -                                                        |
| OS-EXT-STS:vm_state                  | resized                                                  |
| OS-SRV-USG:launched_at               | 2022-03-15T09:04:01.000000                               |
| OS-SRV-USG:terminated_at             | -                                                        |
| accessIPv4                           |                                                          |
| accessIPv6                           |                                                          |
| config_drive                         |                                                          |
| created                              | 2022-03-15T08:15:38Z                                     |
| description                          | vm1                                                      |
| flavor:disk                          | 10                                                       |
| flavor:ephemeral                     | 0                                                        |
| flavor:extra_specs                   | {}                                                       |
| flavor:original_name                 | Fmin                                                     |
| flavor:ram                           | 1024                                                     |
| flavor:swap                          | 0                                                        |
| flavor:vcpus                         | 1                                                        |
| hostId                               | a9b0d623af38fd303ce61e85efec0fc53eda1b6bbc5510e28a2d5875 |
| host_status                          | UP                                                       |
| id                                   | 5759c44c-6264-45cd-841b-c9980fd2f2ad                     |
| image                                | cirros (32d5dbba-6634-4a4a-a35c-6224931b786c)            |
| intnet network                       | 10.10.10.3                                               |
| key_name                             | -                                                        |
| locked                               | False                                                    |
| metadata                             | {}                                                       |
| name                                 | vm1                                                      |
| os-extended-volumes:volumes_attached | []                                                       |
| progress                             | 0                                                        |
| security_groups                      | default                                                  |
| status                               | VERIFY_RESIZE                                            |
| tags                                 | []                                                       |
| tenant_id                            | 0c05a59bc07945dcb63f1b5e7d82cc5d                         |
| updated                              | 2022-03-15T09:04:01Z                                     |
| user_id                              | 7613c7a515ac4e7f999fbc1e57826614                         |
+--------------------------------------+----------------------------------------------------------+
# 更改云主机类型 2为 云主机类型ID
[root@controller ~]# nova resize vm1 2
[root@controller ~]# nova show vm1
+--------------------------------------+----------------------------------------------------------+
| Property                             | Value                                                    |
+--------------------------------------+----------------------------------------------------------+
| OS-DCF:diskConfig                    | AUTO                                                     |
| OS-EXT-AZ:availability_zone          | nova                                                     |
| OS-EXT-SRV-ATTR:host                 | compute                                                  |
| OS-EXT-SRV-ATTR:hostname             | vm1                                                      |
| OS-EXT-SRV-ATTR:hypervisor_hostname  | compute                                                  |
| OS-EXT-SRV-ATTR:instance_name        | instance-00000001                                        |
| 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-2unam55d                                               |
| OS-EXT-SRV-ATTR:root_device_name     | /dev/vda                                                 |
| OS-EXT-SRV-ATTR:user_data            | -                                                        |
| OS-EXT-STS:power_state               | 1                                                        |
| OS-EXT-STS:task_state                | -                                                        |
| OS-EXT-STS:vm_state                  | resized                                                  |
| OS-SRV-USG:launched_at               | 2022-03-15T09:05:00.000000                               |
| OS-SRV-USG:terminated_at             | -                                                        |
| accessIPv4                           |                                                          |
| accessIPv6                           |                                                          |
| config_drive                         |                                                          |
| created                              | 2022-03-15T08:15:38Z                                     |
| description                          | vm1                                                      |
| flavor:disk                          | 10                                                       |
| flavor:ephemeral                     | 0                                                        |
| flavor:extra_specs                   | {}                                                       |
| flavor:original_name                 | Fmins                                                    |
| flavor:ram                           | 2048                                                     |
| flavor:swap                          | 0                                                        |
| flavor:vcpus                         | 1                                                        |
| hostId                               | a9b0d623af38fd303ce61e85efec0fc53eda1b6bbc5510e28a2d5875 |
| host_status                          | UP                                                       |
| id                                   | 5759c44c-6264-45cd-841b-c9980fd2f2ad                     |
| image                                | cirros (32d5dbba-6634-4a4a-a35c-6224931b786c)            |
| intnet network                       | 10.10.10.3                                               |
| key_name                             | -                                                        |
| locked                               | False                                                    |
| metadata                             | {}                                                       |
| name                                 | vm1                                                      |
| os-extended-volumes:volumes_attached | []                                                       |
| progress                             | 0                                                        |
| security_groups                      | default                                                  |
| status                               | VERIFY_RESIZE                                            |
| tags                                 | []                                                       |
| tenant_id                            | 0c05a59bc07945dcb63f1b5e7d82cc5d                         |
| updated                              | 2022-03-15T09:05:01Z                                     |
| user_id                              | 7613c7a515ac4e7f999fbc1e57826614                         |
+--------------------------------------+----------------------------------------------------------+
[root@controller ~]#

如果出现这个问题 就先去云平台确认或者取消调节或迁移云主机

[root@controller ~]# nova resize vm1 2
ERROR (Conflict): Cannot 'resize' instance 5759c44c-6264-45cd-841b-c9980fd2f2ad while it is in vm_state resized (HTTP 409) (Request-ID: req-d99df3b2-8cdd-4cd0-97cd-9fade47c2d7f)

创建快照保存到/root目录下

[root@controller ~]# openstack server image create vm1 >/root/vm1.qcow2
[root@controller ~]# ls
anaconda-ks.cfg  CentOS_7.5_x86_64_XD.qcow2  cirros-0.3.3-x86_64-disk.img  vm1.qcow2
[root@controller ~]# 

废弃云主机和恢复

废弃

[root@controller ~]# openstack server shelve vm1
[root@controller ~]# 

恢复云主机

[root@controller ~]# openstack server unshelve vm1
[root@controller ~]# 

创建卷类型

# 创建类型
[root@controller ~]# openstack volume type create lvm
+-------------+--------------------------------------+
| Field       | Value                                |
+-------------+--------------------------------------+
| description | None                                 |
| id          | 1066d766-0514-4d29-9155-37c7a515f19e |
| is_public   | True                                 |
| name        | lvm                                  |
+-------------+--------------------------------------+

# 创建块存储40G 类型 lvm
[root@controller ~]# openstack volume create --size 40 --type lvm blok
+---------------------+--------------------------------------+
| Field               | Value                                |
+---------------------+--------------------------------------+
| attachments         | []                                   |
| availability_zone   | nova                                 |
| bootable            | false                                |
| consistencygroup_id | None                                 |
| created_at          | 2022-03-15T11:09:33.000000           |
| description         | None                                 |
| encrypted           | False                                |
| id                  | b36033e2-bddf-4355-be4a-fb4c32b7cdf0 |
| migration_status    | None                                 |
| multiattach         | False                                |
| name                | blok                                 |
| properties          |                                      |
| replication_status  | None                                 |
| size                | 40                                   |
| snapshot_id         | None                                 |
| source_volid        | None                                 |
| status              | creating                             |
| type                | lvm                                  |
| updated_at          | None                                 |
| user_id             | 7613c7a515ac4e7f999fbc1e57826614     |
+---------------------+--------------------------------------+

# 添加到vm1
[root@controller ~]# openstack server add volume vm1 blok
[root@controller ~]#

raid5

# 如果没有安装mdadm先安装
# yum -y install mdadm
[root@vm1 ~]# mdadm -Cv /dev/md5 -l5 -n3 -x1 /dev/vdb[1-4]
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 5237760K
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md5 started.
[root@vm1 ~]# mdadm --detail /dev/md5 
/dev/md5:
           Version : 1.2
     Creation Time : Wed Mar 16 02:15:51 2022
        Raid Level : raid5
        Array Size : 10475520 (9.99 GiB 10.73 GB)
     Used Dev Size : 5237760 (5.00 GiB 5.36 GB)
      Raid Devices : 3
     Total Devices : 4
       Persistence : Superblock is persistent

       Update Time : Wed Mar 16 02:16:58 2022
             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 : 44% complete

              Name : vm1.novalocal:5  (local to host vm1.novalocal)
              UUID : 7b49dc4d:6164e1b4:51663747:a1eec8ea
            Events : 8

    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@vm1 ~]# 

主从数据库

vm1配置

[root@vm1 ~]# vim /etc/my.cnf
# ....................................................................................................
[mysqld]
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
server-id=9
log_bin=mysql-bin
binlog_ignore_db=mysql
# ....................................................................................................
~
~
[root@vm1 ~]# systemctl restart mariadb
[root@vm1 ~]# mysql -uroot -p000000

MariaDB [(none)]> grant all privileges on *.* to root@'%' identified by '000000';
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> grant replication slave on *.* to 'user'@'vm2' identified by '000000';
Query OK, 0 rows affected (0.06 sec)

MariaDB [(none)]> 

vm2

[root@vm2 ~]# vim /etc/my.cnf
[mysqld]
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log_bin=mysql-bin
binlog_ignore=mysql
server_id=15
#
# include all files from the config directory
                             
[root@vm2 ~]# systemctl restart mariadb
[root@vm2 ~]# mysql -uroot -p000000
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.1.20-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> change master to master_host='vm1',master_user='user',master_password='000000';
Query OK, 0 rows affected (0.11 sec)

MariaDB [(none)]> start slave;
Query OK, 0 rows affected (0.04 sec)
# 查询主从数据库是否成功
# Slave_IO_Running: Yes
# Slave_SQL_Running: Yes
# 当这两个为yes则表示成功
MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: vm1
                  Master_User: user
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 1666
               Relay_Log_File: mariadb-relay-bin.000002
                Relay_Log_Pos: 1954
        Relay_Master_Log_File: mysql-bin.000001
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 1666
              Relay_Log_Space: 2254
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File: 
           Master_SSL_CA_Path: 
              Master_SSL_Cert: 
            Master_SSL_Cipher: 
               Master_SSL_Key: 
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 9
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
                   Using_Gtid: No
                  Gtid_IO_Pos: 
      Replicate_Do_Domain_Ids: 
  Replicate_Ignore_Domain_Ids: 
                Parallel_Mode: conservative
1 row in set (0.00 sec)

MariaDB [(none)]> 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值