OpenStack——共享文件服务(Manila)服务介绍与安装

OpenStack共享文件服务(Manila)是一个用于提供共享文件存储的组件。它允许用户在OpenStack云环境中创建和管理共享文件系统,以供多个实例或虚拟机之间共享数据。

Manila就像是一个云存储服务,你可以将它想象成一个“共享文件夹”。它的作用是让你可以在云环境中创建一个文件夹,并且允许多个虚拟机或实例同时访问这个文件夹中的文件。

使用Manila,你可以创建一个共享文件系统,就像在你的电脑上创建一个文件夹一样。然后,你可以选择将这个文件夹共享给其他虚拟机或实例。这样,这些虚拟机或实例就可以通过网络连接到这个共享文件系统,读取和写入其中的文件。这样就实现了多个虚拟机或实例之间共享数据的需求。

Manila的好处是它提供了一种灵活而方便的方式来管理共享文件系统。你可以根据需要创建、删除和调整共享文件系统的大小。同时,Manila还提供了权限控制和安全性功能,以确保只有有权限的用户可以访问共享文件系统。

安装和配置(controller)

官方文档

准备

在安装和配置共享文件系统服务之前,您必须创建数据库、服务凭证和API 端点

(1)创建数据库

①在操作系统终端连接数据库

[root@controller ~]# mysql -u root -p000000

②创建manila数据库

MariaDB [(none)]> CREATE DATABASE manila;

③授权

MariaDB [(none)]> GRANT ALL PRIVILEGES ON manila.* TO 'manila'@'localhost' IDENTIFIED BY '000000' ;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON manila.* TO 'manila'@'%'  IDENTIFIED BY '000000';

④退出数据库

(2)加载 admin user 的环境变量

[root@controller ~]# source admin-openrc.sh

(3)创建服务凭证

①创建manila用户

[root@controller ~]# openstack user create --domain default --password 000000 manila
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| domain_id           | default                          |
| enabled             | True                             |
| id                  | 2d6b2600158e430e8fdaaaab332e6203 |
| name                | manila                           |
| options             | {}                               |
| password_expires_at | None                             |
+---------------------+----------------------------------+

admin为用户添加角色manila

[root@controller ~]# openstack role add --project service --user manila admin

③创建manilamanilav2服务实体

[root@controller ~]# openstack service create --name manila --description "OpenStack Shared File Systems" share
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Shared File Systems    |
| enabled     | True                             |
| id          | 132a4a9113af497cb65553f5eb75463d |
| name        | manila                           |
| type        | share                            |
+-------------+----------------------------------+


[root@controller ~]# openstack service create --name manilav2 --description "OpenStack Shared File Systems V2" sharev2
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Shared File Systems V2 |
| enabled     | True                             |
| id          | c52f309714a9410f833207442aebff09 |
| name        | manilav2                         |
| type        | sharev2                          |
+-------------+----------------------------------+

(4)创建共享文件系统服务 API 端点

[root@controller ~]# openstack endpoint create --region RegionOne share public http://controller:8786/v1/%\(tenant_id\)s
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | e1a46d73168f45e3b0d6a4f5b55983ed |
| interface    | public                           |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 132a4a9113af497cb65553f5eb75463d |
| service_name | manila                           |
| service_type | share                            |
| url          | http://:8786/v1/%(tenant_id)s    |
+--------------+----------------------------------+

[root@controller ~]# openstack endpoint create --region RegionOne share internal http://controller:8786/v1/%\(tenant_id\)s
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 243bdc7db29b428080018957c6d79862 |
| interface    | internal                         |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 132a4a9113af497cb65553f5eb75463d |
| service_name | manila                           |
| service_type | share                            |
| url          | http://:8786/v1/%(tenant_id)s    |
+--------------+----------------------------------+

[root@controller ~]# openstack endpoint create --region RegionOne share admin http://controller:8786/v1/%\(tenant_id\)s
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 9816a474ae4a419fb8211cfc6d0f64da |
| interface    | admin                            |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 132a4a9113af497cb65553f5eb75463d |
| service_name | manila                           |
| service_type | share                            |
| url          | http://:8786/v1/%(tenant_id)s    |
+--------------+----------------------------------+


[root@controller ~]# openstack endpoint create --region RegionOne sharev2 public http://controller:8786/v2/%\(tenant_id\)s
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | d19d550ddc944a529de9db9e25d8926c |
| interface    | public                           |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | c52f309714a9410f833207442aebff09 |
| service_name | manilav2                         |
| service_type | sharev2                          |
| url          | http://:8786/v2/%(tenant_id)s    |
+--------------+----------------------------------+


[root@controller ~]# openstack endpoint create --region RegionOne  sharev2 internal http://controller:8786/v2
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | c8cacf15e72c443cb28b00bead4be4a4 |
| interface    | internal                         |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 36b06f7d3af54475ba0a2eed55dc33a4 |
| service_name | manilav2                         |
| service_type | sharev2                          |
| url          | http://controller:8786/v2        |
+--------------+----------------------------------+

[root@controller ~]# openstack endpoint create --region RegionOne  sharev2 admin http://controller:8786/v2
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | df0a6cb2995b4fac8fed4bc325c8cc92 |
| interface    | admin                            |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 36b06f7d3af54475ba0a2eed55dc33a4 |
| service_name | manilav2                         |
| service_type | sharev2                          |
| url          | http://controller:8786/v2        |
+--------------+----------------------------------+

安装和配置组件

(1)安装软件包

[root@controller ~]#  yum install  -y openstack-manila python3-manilaclient

(2)配置文件

编辑/etc/manila/manila.conf文件并完成以下操作

①在[database]部分中,配置数据库访问:

[root@controller ~]# vim /etc/manila/manila.conf 
[database]
connection = mysql+pymysql://manila:000000@controller/manila

②在[DEFAULT]部分中,配置RabbitMQ 消息队列访问

[DEFAULT]
transport_url = rabbit://openstack:000000@controller

③在[DEFAULT]部分中,设置以下配置值:

[DEFAULT]
transport_url = rabbit://openstack:000000@controller
state_path = /var/lib/manila
default_share_type = default_share_type
share_name_template = share-%s
rootwrap_config = /etc/manila/rootwrap.conf
api_paste_config = /etc/manila/api-paste.ini
auth_strategy = keystone
my_ip = 192.168.200.10

④在[DEFAULT][keystone_authtoken]部分中,配置身份服务访问

[DEFAULT]
auth_strategy = keystone

[keystone_authtoken]
memcached_servers = controller:11211
www_authenticate_uri = http://controller:5000
auth_url = http://controller:5000
auth_type = password
project_domain_name = Default
user_domain_name = Default
project_name = service
username = manila
password = 000000

⑤在[oslo_concurrency]部分中,配置锁定路径

[oslo_concurrency]
lock_path = /var/lib/manila/manila

(3)同步数据库

[root@controller ~]# su -s /bin/sh -c "manila-manage db sync" manila

完成安装

[root@controller ~]# systemctl enable openstack-manila-api.service openstack-manila-scheduler.service && systemctl restart openstack-manila-api.service openstack-manila-scheduler.service

安装和配置共享节点(compute)

(1)安装软件包

[root@compute ~]# yum -y install openstack-manila-share python2-PyMySQL libtalloc python-manilaclient MySQL-python

(2)配置文件

编辑/etc/manila/manila.conf文件并完成以下操作

①在[database]部分中

[database]
connection = mysql+pymysql://manila:000000@controller/manila

②在[DEFAULT][keystone_authtoken]部分中,配置身份服务访问

[DEFAULT]
transport_url = rabbit://openstack:000000@controller
my_ip = 192.168.200.20
api_paste_config = /etc/manila/api-paste.ini
rootwrap_config = /etc/manila/rootwrap.conf
state_path = /var/lib/manila
auth_strategy = keystone
default_share_type = default_share_type
enabled_share_protocols = NFS,CIFS

[keystone_authtoken]部分

[keystone_authtoken]
memcached_servers = controller:11211
www_authenticate_uri = http://controller:5000
auth_url = http://controller:5000
auth_type = password
project_domain_name = Default
user_domain_name = Default
project_name = service
username = manila
password = 000000

④在[oslo_concurrency]部分中,配置锁路径

[oslo_concurrency]
lock_path = /var/lib/manila/tmp

⑤创建目录并设置属主

[root@compute ~]# mkdir /var/lib/manila
[root@compute ~]# chown manila. /var/lib/manila

两种驱动模式

共享节点可以支持两种模式,有和没有共享服务器的处理。该模式取决于驱动程序支持

选项一

在没有驱动程序支持的情况下部署服务以进行共享服务器管理。在此模式下,服务不执行任何与网络相关的操作。运营商必须确保实例和基于NAS协议的服务器之间的网络连接。

本教程演示如何设置 LVM 驱动程序,该驱动程序在共享节点上创建 LVM 卷,并在共享节点本地安装的 NFS 服务器的帮助下导出它们。因此,它需要 LVM 和 NFS 软件包以及用于manila-shareLVM 卷组的附加磁盘。

选项二

部署具有共享服务器管理驱动程序支持的服务。在此模式下,服务与创建和管理共享服务器的后端驱动程序一起运行。本教程演示了如何设置Generic驱动程序。该驱动程序需要计算服务(nova)、图像服务(glance)和网络服务(neutron)来创建和管理共享服务器;用于创建共享的块存储服务(cinder)。

官方文档

我们选择第一种

(1)安装软件包

[root@compute ~]# yum -y install lvm2 nfs-utils nfs4-acl-tools portmap targetcli

(2)启动LVM并设置开机自启

[root@compute ~]# systemctl enable lvm2-lvmetad.service target.service && systemctl restart lvm2-lvmetad.service target.service

(3)创建LVM物理卷和卷组

[root@compute ~]# pvcreate /dev/sdd
  Physical volume "/dev/sdd" successfully created.
[root@compute ~]# vgcreate manila-volumes /dev/sdd
  Volume group "manila-volumes" successfully created

(4)配置组件

编辑/etc/manila/manila.conf文件并完成以下操作

[DEFAULT]部分中,启用 LVM 驱动程序

[root@compute ~]# vim /etc/manila/manila.conf
[DEFAULT]
enabled_share_backends = lvm

[lvm]部分中,配置 LVM 驱动程序

[lvm]
share_backend_name = LVM
share_driver = manila.share.drivers.lvm.LVMShareDriver
driver_handles_share_servers = False
lvm_share_volume_group = manila-volumes
lvm_share_export_ips = 192.168.200.20

完成安装

[root@compute ~]# systemctl restart lvm2-lvmetad.service target.service openstack-manila-share nfs-server

验证

(1)加载环境变量

[root@controller ~]# source admin-openrc.sh 

(2)列出服务组件以验证每个进程是否成功启动

[root@controller ~]# manila service-list
+----+------------------+-------------+------+---------+-------+----------------------------+
| Id | Binary           | Host        | Zone | Status  | State | Updated_at                 |
+----+------------------+-------------+------+---------+-------+----------------------------+
| 1  | manila-scheduler | controller  | nova | enabled | up    | 2023-07-02T08:51:58.000000 |
| 2  | manila-share     | compute@lvm | nova | enabled | up    | 2023-07-02T08:52:00.000000 |
+----+------------------+-------------+------+---------+-------+----------------------------+

Manila的使用

(1)创建共享类型

[root@controller ~]# 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                   | ed4ac5e1-55eb-459c-a859-00825b017049 |
| optional_extra_specs |                                      |
| Description          | None                                 |
+----------------------+--------------------------------------+
[root@controller ~]# manila type-list
+--------------------------------------+--------------------+------------+------------+--------------------------------------+----------------------+-------------+
| ID                                   | Name               | visibility | is_default | required_extra_specs                 | optional_extra_specs | Description |
+--------------------------------------+--------------------+------------+------------+--------------------------------------+----------------------+-------------+
| ed4ac5e1-55eb-459c-a859-00825b017049 | default_share_type | public     | YES        | driver_handles_share_servers : False |                      | None        |
+--------------------------------------+--------------------+------------+------------+--------------------------------------+----------------------+-------------+

(2)创建 NFS 共享

[root@controller ~]# manila create NFS 2 --name test-nfs-csq
+---------------------------------------+--------------------------------------+
| Property                              | Value                                |
+---------------------------------------+--------------------------------------+
| status                                | creating                             |
| share_type_name                       | default_share_type                   |
| description                           | None                                 |
| availability_zone                     | None                                 |
| share_network_id                      | None                                 |
| share_server_id                       | None                                 |
| share_group_id                        | None                                 |
| host                                  |                                      |
| revert_to_snapshot_support            | False                                |
| access_rules_status                   | active                               |
| snapshot_id                           | None                                 |
| create_share_from_snapshot_support    | False                                |
| is_public                             | False                                |
| task_state                            | None                                 |
| snapshot_support                      | False                                |
| id                                    | b4ad1964-45a3-4fa7-9233-9cee3b24bb11 |
| size                                  | 2                                    |
| source_share_group_snapshot_member_id | None                                 |
| user_id                               | fef5f8c16d3d4b9d849bc1488bf50a21     |
| name                                  | test-nfs-csq                         |
| share_type                            | ed4ac5e1-55eb-459c-a859-00825b017049 |
| has_replicas                          | False                                |
| replication_type                      | None                                 |
| created_at                            | 2023-07-02T09:01:11.000000           |
| share_proto                           | NFS                                  |
| mount_snapshot_support                | False                                |
| project_id                            | 0769b940829c4078a4aa573e83d6520c     |
| metadata                              | {}                                   |
+---------------------------------------+--------------------------------------+

(3)查看共享状态

注意共享状态必须为available

[root@controller ~]# manila list
+--------------------------------------+--------------+------+-------------+-----------+-----------+--------------------+-----------------------------+-------------------+
| ID                                   | Name         | Size | Share Proto | Status    | Is Public | Share Type Name    | Host                        | Availability Zone |
+--------------------------------------+--------------+------+-------------+-----------+-----------+--------------------+-----------------------------+-------------------+
| b4ad1964-45a3-4fa7-9233-9cee3b24bb11 | test-nfs-csq | 2    | NFS         | available | False     | default_share_type | compute@lvm#lvm-single-pool | nova              |
+--------------------------------------+--------------+------+-------------+-----------+-----------+--------------------+-----------------------------+-------------------+

确定共享的导出IP地址

[root@controller ~]# manila show test-nfs-csq
+---------------------------------------+--------------------------------------------------------------------------------------+
| Property                              | Value                                                                                |
+---------------------------------------+--------------------------------------------------------------------------------------+
| status                                | available                                                                            |
| share_type_name                       | default_share_type                                                                   |
| description                           | None                                                                                 |
| availability_zone                     | nova                                                                                 |
| share_network_id                      | None                                                                                 |
| export_locations                      |                                                                                      |
|                                       | path = 192.168.200.20:/var/lib/manila/mnt/share-90987ec8-8ec6-4a3f-bbd7-0ae2dd3c822e |
|                                       | preferred = False                                                                    |
|                                       | is_admin_only = False                                                                |
|                                       | id = cad5e351-2cd0-411e-bcfc-16f25bae35ff                                            |
|                                       | share_instance_id = 90987ec8-8ec6-4a3f-bbd7-0ae2dd3c822e                             |
| share_server_id                       | None                                                                                 |
| share_group_id                        | None                                                                                 |
| host                                  | compute@lvm#lvm-single-pool                                                          |
| revert_to_snapshot_support            | False                                                                                |
| access_rules_status                   | active                                                                               |
| snapshot_id                           | None                                                                                 |
| create_share_from_snapshot_support    | False                                                                                |
| is_public                             | False                                                                                |
| task_state                            | None                                                                                 |
| snapshot_support                      | False                                                                                |
| id                                    | b4ad1964-45a3-4fa7-9233-9cee3b24bb11                                                 |
| size                                  | 2                                                                                    |
| source_share_group_snapshot_member_id | None                                                                                 |
| user_id                               | fef5f8c16d3d4b9d849bc1488bf50a21                                                     |
| name                                  | test-nfs-csq                                                                         |
| share_type                            | ed4ac5e1-55eb-459c-a859-00825b017049                                                 |
| has_replicas                          | False                                                                                |
| replication_type                      | None                                                                                 |
| created_at                            | 2023-07-02T09:01:11.000000                                                           |
| share_proto                           | NFS                                                                                  |
| mount_snapshot_support                | False                                                                                |
| project_id                            | 0769b940829c4078a4aa573e83d6520c                                                     |
| metadata                              | {}                                                                                   |
+---------------------------------------+--------------------------------------------------------------------------------------+

(4)允许访问共享

[root@controller ~]#  manila access-allow test-nfs-csq ip 192.168.200.0/24  --access-level rw
+--------------+--------------------------------------+
| Property     | Value                                |
+--------------+--------------------------------------+
| access_key   | None                                 |
| share_id     | b4ad1964-45a3-4fa7-9233-9cee3b24bb11 |
| created_at   | 2023-07-02T09:04:03.000000           |
| updated_at   | None                                 |
| access_type  | ip                                   |
| access_to    | 192.168.200.0/24                     |
| access_level | rw                                   |
| state        | queued_to_apply                      |
| id           | 7f82c995-5e67-465d-afce-6af62479b8dc |
| metadata     | {}                                   |
+--------------+--------------------------------------+
[root@controller ~]#  manila access-list test-nfs-csq
+--------------------------------------+-------------+------------------+--------------+--------+------------+----------------------------+------------+
| id                                   | access_type | access_to        | access_level | state  | access_key | created_at                 | updated_at |
+--------------------------------------+-------------+------------------+--------------+--------+------------+----------------------------+------------+
| 7f82c995-5e67-465d-afce-6af62479b8dc | ip          | 192.168.200.0/24 | rw           | active | None       | 2023-07-02T09:04:03.000000 | None       |
+--------------------------------------+-------------+------------------+--------------+--------+------------+----------------------------+------------+

(5)挂载共享

[root@controller ~]# mount -t nfs 192.168.200.20:/var/lib/manila/mnt/share-90987ec8-8ec6-4a3f-bbd7-0ae2dd3c822e /mnt/
[root@controller ~]# df -HT
文件系统                                                                      类型      容量  已用  可用 已用% 挂载点
devtmpfs                                                                      devtmpfs  4.1G     0  4.1G    0% /dev
tmpfs                                                                         tmpfs     4.1G     0  4.1G    0% /dev/shm
tmpfs                                                                         tmpfs     4.1G   13M  4.1G    1% /run
tmpfs                                                                         tmpfs     4.1G     0  4.1G    0% /sys/fs/cgroup
/dev/mapper/centos-root                                                       xfs        54G  3.6G   51G    7% /
/dev/mapper/centos-home                                                       xfs        45G   34M   45G    1% /home
/dev/sda1                                                                     xfs       1.1G  205M  860M   20% /boot
tmpfs                                                                         tmpfs     819M     0  819M    0% /run/user/0
192.168.200.20:/var/lib/manila/mnt/share-90987ec8-8ec6-4a3f-bbd7-0ae2dd3c822e nfs4      2.1G  6.3M  2.0G    1% /mnt

(6)在挂载的目录中创建文件

[root@controller ~]# cd /mnt/
[root@controller mnt]# dd if=/dev/zero of=csq bs=1M count=20
记录了20+0 的读入
记录了20+0 的写出
20971520字节(21 MB)已复制,2.91808 秒,7.2 MB/秒
[root@controller mnt]# df -h
文件系统                                                                       容量  已用  可用 已用% 挂载点
devtmpfs                                                                       3.8G     0  3.8G    0% /dev
tmpfs                                                                          3.9G     0  3.9G    0% /dev/shm
tmpfs                                                                          3.9G   12M  3.8G    1% /run
tmpfs                                                                          3.9G     0  3.9G    0% /sys/fs/cgroup
/dev/mapper/centos-root                                                         50G  3.3G   47G    7% /
/dev/mapper/centos-home                                                         42G   33M   42G    1% /home
/dev/sda1                                                                     1014M  195M  820M   20% /boot
tmpfs                                                                          781M     0  781M    0% /run/user/0
192.168.200.20:/var/lib/manila/mnt/share-90987ec8-8ec6-4a3f-bbd7-0ae2dd3c822e  2.0G   26M  1.8G    2% /mnt
[root@controller ~]# umount /mnt/
[root@controller ~]# ls /mnt/
[root@controller ~]# mount -t nfs 192.168.200.20:/var/lib/manila/mnt/share-90987ec8-8ec6-4a3f-bbd7-0ae2dd3c822e /mnt/
[root@controller ~]# ls /mnt/
csq  lost+found
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐