1、创建share type
为了支持两种存储后端,这儿的share类型名字设置为generic_share_type,避免和default_share_type冲突,default_share_type对应存储后端lvm
# manila type-create generic_share_type True
+----------------------+--------------------------------------+
| Property | Value |
+----------------------+--------------------------------------+
| required_extra_specs | driver_handles_share_servers : True |
| Name | generic_share_type |
| Visibility | public |
| is_default | - |
| ID | b815b012-29ad-4644-bc7b-2058959b3d23 |
| optional_extra_specs | |
| Description | None |
+----------------------+--------------------------------------+
[root@openstack4k8s work(keystone_admin)]# manila type-list
+--------------------------------------+--------------------+------------+------------+--------------------------------------+----------------------+-------------+
| ID | Name | visibility | is_default | required_extra_specs | optional_extra_specs | Description |
+--------------------------------------+--------------------+------------+------------+--------------------------------------+----------------------+-------------+
| b815b012-29ad-4644-bc7b-2058959b3d23 | generic_share_type | public | - | driver_handles_share_servers : True | | None |
| e6876193-e743-43c3-968b-1af2a47f6f52 | default_share_type | public | YES | driver_handles_share_servers : False | | None |
+--------------------------------------+--------------------+------------+------------+--------------------------------------+----------------------+-------------+
2、创建demo租户
# openstack project create --domain default --description "Demo Project" demo
+-------------+----------------------------------+
| Field | Value |
+-------------+----------------------------------+
| description | Demo Project |
| domain_id | default |
| enabled | True |
| id | 8e9f4288a98b46cc881b9e8bcc1659f5 |
| is_domain | False |
| name | demo |
| options | {} |
| parent_id | default |
| tags | [] |
+-------------+----------------------------------+
[root@openstack4k8s work(keystone_admin)]# openstack user create --domain default --password-prompt demo
User Password:
Repeat User Password:
+---------------------+----------------------------------+
| Field | Value |
+---------------------+----------------------------------+
| domain_id | default |
| enabled | True |
| id | cdd65fbe8be24b3fba5bf0ff0f14bc7c |
| name | demo |
| options | {} |
| password_expires_at | None |
+---------------------+----------------------------------+
[root@openstack4k8s work(keystone_admin)]# openstack role create user
+-------------+----------------------------------+
| Field | Value |
+-------------+----------------------------------+
| description | None |
| domain_id | None |
| id | 3566b850ce9a4e9e8fe0c2caf8a6b5a0 |
| name | user |
| options | {} |
+-------------+----------------------------------+
[root@openstack4k8s work(keystone_admin)]# openstack role add --project demo --user demo user
# openstack project list
+----------------------------------+----------+
| ID | Name |
+----------------------------------+----------+
| 23a40789342d4de6bc06d0b0bef7069c | admin |
| 8e9f4288a98b46cc881b9e8bcc1659f5 | demo |
| 99671b33717d4be5a6ee2227c39da017 | services |
+----------------------------------+----------+
# openstack network list
+--------------------------------------+------------------------+--------------------------------------+
| ID | Name | Subnets |
+--------------------------------------+------------------------+--------------------------------------+
| 04cb080f-3290-46c3-82a2-3b24bdcfbab0 | manila_service_network | |
| 3c83fdd8-c1d6-441b-8163-84d5daa18931 | ext-net | 778fa9ea-2ef6-463b-894a-f456e90399aa |
| 9ee4e64a-da83-4cfd-aded-f6542bbd3937 | net_api | cf87d2b1-7fb3-4f90-996a-c7600ed0f27d |
+--------------------------------------+------------------------+--------------------------------------+
3、创建共享网络
共享网络对接net_api租户网络,net_api租户网络已经挂接到router上
# openstack network list
+--------------------------------------+---------+--------------------------------------+
| ID | Name | Subnets |
+--------------------------------------+---------+--------------------------------------+
| 3c83fdd8-c1d6-441b-8163-84d5daa18931 | ext-net | 778fa9ea-2ef6-463b-894a-f456e90399aa |
| 9ee4e64a-da83-4cfd-aded-f6542bbd3937 | net_api | cf87d2b1-7fb3-4f90-996a-c7600ed0f27d |
+--------------------------------------+---------+--------------------------------------+
# source ~/keystonerc_demo
# manila share-network-create --name demo-share-network1 --neutron-net-id 9ee4e64a-da83-4cfd-aded-f6542bbd3937 --neutron-subnet-id cf87d2b1-7fb3-4f90-996a-c7600ed0f27d
+-----------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Property | Value |
+-----------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| description | None |
| name | demo-share-network1 |
| share_network_subnets | [{u'availability_zone': None, u'neutron_net_id': u'9ee4e64a-da83-4cfd-aded-f6542bbd3937', u'created_at': u'2020-05-18T19:08:40.000000', u'neutron_subnet_id': u'cf87d2b1-7fb3-4f90-996a-c7600ed0f27d', u'updated_at': None, u'mtu': None, u'id': u'7fba0be0-e7b0-4147-beb7-427cff9b8866', u'segmentation_id': None, u'ip_version': None, u'cidr': None, u'network_type': None, u'gateway': None}] |
| created_at | 2020-05-18T19:08:40.000000 |
| project_id | 8e9f4288a98b46cc881b9e8bcc1659f5 |
| updated_at | None |
| id | 80ee729c-a454-4760-9928-2601af555b98 |
+-----------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
4、创建共享文件系统
指定共享网络和share type
# manila create NFS 1 --name demo-share1 --share-network demo-share-network1 --share-type generic_share_type
+---------------------------------------+--------------------------------------+
| Property | Value |
+---------------------------------------+--------------------------------------+
| status | creating |
| share_type_name | generic_share_type |
| description | None |
| availability_zone | None |
| share_network_id | 80ee729c-a454-4760-9928-2601af555b98 |
| share_group_id | None |
| 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 | 172e3333-8960-4599-9f43-f8edc2156143 |
| size | 1 |
| source_share_group_snapshot_member_id | None |
| user_id | cdd65fbe8be24b3fba5bf0ff0f14bc7c |
| name | demo-share1 |
| share_type | b815b012-29ad-4644-bc7b-2058959b3d23 |
| has_replicas | False |
| replication_type | None |
| created_at | 2020-05-18T19:13:09.000000 |
| share_proto | NFS |
| mount_snapshot_support | False |
| project_id | 8e9f4288a98b46cc881b9e8bcc1659f5 |
| metadata | {} |
+---------------------------------------+--------------------------------------+
# manila list
+--------------------------------------+-------------+------+-------------+----------+-----------+--------------------+------+-------------------+
| ID | Name | Size | Share Proto | Status | Is Public | Share Type Name | Host | Availability Zone |
+--------------------------------------+-------------+------+-------------+----------+-----------+--------------------+------+-------------------+
| 172e3333-8960-4599-9f43-f8edc2156143 | demo-share1 | 1 | NFS | creating | False | generic_share_type | | nova |
+--------------------------------------+-------------+------+-------------+----------+-----------+--------------------+------+-------------------+
[root@openstack4k8s ~(keystone_demo)]# manila list
+--------------------------------------+-------------+------+-------------+-----------+-----------+--------------------+------+-------------------+
| ID | Name | Size | Share Proto | Status | Is Public | Share Type Name | Host | Availability Zone |
+--------------------------------------+-------------+------+-------------+-----------+-----------+--------------------+------+-------------------+
| 172e3333-8960-4599-9f43-f8edc2156143 | demo-share1 | 1 | NFS | available | False | generic_share_type | | nova |
+--------------------------------------+-------------+------+-------------+-----------+-----------+--------------------+------+-------------------+
5、使用共享文件系统
连接net_api网络的租户虚拟机ip为192.168.1.243
[root@k8s-m2 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 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 1442 qdisc pfifo_fast state UP group default qlen 1000
link/ether fa:16:3e:0a:46:9f brd ff:ff:ff:ff:ff:ff
inet 192.168.1.243/24 brd 192.168.1.255 scope global noprefixroute dynamic eth0
valid_lft 30984sec preferred_lft 30984sec
inet6 fe80::f816:3eff:fe0a:469f/64 scope link
valid_lft forever preferred_lft forever
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:15:55:9f:6d brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
为共享文件系统增加访问规则
# manila access-allow demo-share1 ip 192.168.1.243
+--------------+--------------------------------------+
| Property | Value |
+--------------+--------------------------------------+
| access_key | None |
| share_id | 172e3333-8960-4599-9f43-f8edc2156143 |
| created_at | 2020-05-19T09:32:54.000000 |
| updated_at | None |
| access_type | ip |
| access_to | 192.168.1.243 |
| access_level | rw |
| state | queued_to_apply |
| id | 2df3953c-6b70-4ea0-b8e1-498748fabbea |
| metadata | {} |
+--------------+--------------------------------------+
[root@openstack4k8s ~(keystone_demo)]# manila access-list demo-share1
+--------------------------------------+-------------+---------------+--------------+--------+------------+----------------------------+------------+
| id | access_type | access_to | access_level | state | access_key | created_at | updated_at |
+--------------------------------------+-------------+---------------+--------------+--------+------------+----------------------------+------------+
| 2df3953c-6b70-4ea0-b8e1-498748fabbea | ip | 192.168.1.243 | rw | active | None | 2020-05-19T09:32:54.000000 | None |
+--------------------------------------+-------------+---------------+--------------+--------+------------+----------------------------+------------+
进入manila share server查看规则已经生效
# ssh manila@10.254.0.8
manila@10.254.0.8's password:
Welcome to Ubuntu 18.04.4 LTS (GNU/Linux 4.15.0-96-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
Last login: Tue May 19 09:15:14 2020 from 10.254.0.10
manila@ubuntu:~$ sudo cat /etc/exports
/shares/share-bb80d66f-2764-465b-a5bf-ff0ca6047375 192.168.1.243(rw,sync,wdelay,hide,nocrossmnt,secure,no_root_squash,no_all_squash,no_subtree_check,secure_locks,acl,no_pnfs,anonuid=65534,anongid=65534,sec=sys,rw,secure,no_root_squash,no_all_squash)
manila@ubuntu:~$ sudo exportfs -v
/shares/share-bb80d66f-2764-465b-a5bf-ff0ca6047375
192.168.1.243(rw,wdelay,no_root_squash,no_subtree_check,sec=sys,rw,secure,no_root_squash,no_all_squash)
获取访问共享文件系统的path
# manila show 172e3333-8960-4599-9f43-f8edc2156143
+---------------------------------------+----------------------------------------------------------------------+
| Property | Value |
+---------------------------------------+----------------------------------------------------------------------+
| status | available |
| share_type_name | generic_share_type |
| description | None |
| availability_zone | nova |
| share_network_id | 80ee729c-a454-4760-9928-2601af555b98 |
| export_locations | |
| | path = 10.254.0.8:/shares/share-bb80d66f-2764-465b-a5bf-ff0ca6047375 |
| | id = 52a88bec-5fe4-483d-af72-b2117d0eb2a8 |
| | preferred = False |
| share_group_id | None |
| 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 | 172e3333-8960-4599-9f43-f8edc2156143 |
| size | 1 |
| source_share_group_snapshot_member_id | None |
| user_id | cdd65fbe8be24b3fba5bf0ff0f14bc7c |
| name | demo-share1 |
| share_type | b815b012-29ad-4644-bc7b-2058959b3d23 |
| has_replicas | False |
| replication_type | None |
| created_at | 2020-05-18T19:13:09.000000 |
| share_proto | NFS |
| mount_snapshot_support | False |
| project_id | 8e9f4288a98b46cc881b9e8bcc1659f5 |
| metadata | {} |
+---------------------------------------+----------------------------------------------------------------------+
客户端挂载共享文件系统
# mount -vt nfs 10.254.0.8:/shares/share-bb80d66f-2764-465b-a5bf-ff0ca6047375 /home/manila_mnt/
mount.nfs: timeout set for Tue May 19 05:36:21 2020
mount.nfs: trying text-based options 'vers=4.1,addr=10.254.0.8,clientaddr=192.168.1.243'
# df
10.254.0.8:/shares/share-bb80d66f-2764-465b-a5bf-ff0ca6047375 999424 2048 928768 1% /home/manila_mnt
# touch /home/manila_mnt/test
# echo "hello manila with share server" > /home/manila_mnt/test
文件内容已经在share server上生效
manila@ubuntu:~$ cat /shares/share-bb80d66f-2764-465b-a5bf-ff0ca6047375/test
hello manila with share server