前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >openstack manila服务折腾笔记

openstack manila服务折腾笔记

作者头像
用户1057912
发布2020-12-22 16:48:04
2.5K0
发布2020-12-22 16:48:04
举报
文章被收录于专栏:老安的博客老安的博客

    国庆在家折腾了一把openstack manila,看了下现网还没有中文的manila入门介绍,于是决定写个笔记贴出来

一、manila简介

     和我们传统存储服务器一样,openstack的存储也分为3种:块存储(cinder),对象存储(swift),文件存储(manila).manila 提供的是带有完整文件系统的存储服务.可以提供的类型有:nfs,cifs,glusterfs,hdfs等.云主机可以直接在系统里面挂载manila启动的实例

下面就是已经被虚拟机挂载的实例

代码语言:javascript
复制
[root@centos centos]# df -Th
Filesystem                                                    Type      Size  Used Avail Use% Mounted on
/dev/vda1                                                     xfs        10G  1.2G  8.9G  12% /
devtmpfs                                                      devtmpfs  900M     0  900M   0% /dev
10.254.0.7:/shares/share-f898d9b0-77b8-4231-9919-27b12e34cfa3 nfs4      976M  1.3M  908M   1% /mnt

二 manila的组件

默认情况下manila有3个组件

manila-api 接受并验证REST请求,通过客户端及路由进行转发  manila-scheduler 决定共享创建的后端(后端及pool)  manila-share 基于后端创建共享的服务 (类似于cinder volume 只是创建服务,并不一定提供服务)

以上3行 引用http://blog.csdn.net/Miss_yang_Cloud/article/details/51376480

二、manila-share的典型模式

(一)单独一个或若干个manila-share节点上通过lvm划分并格式化出一个ext4的卷通过external网络给云主机访问

典型架构如下

wKioL1nYj6SR8J6PAAAqQnE6mrc452.png-wh_50
wKioL1nYj6SR8J6PAAAqQnE6mrc452.png-wh_50

(二) 虚拟机模式

具体流程看第三段

架构图如下

wKioL1nYSebSpuk5AABb5j-pLpg928.png-wh_50
wKioL1nYSebSpuk5AABb5j-pLpg928.png-wh_50

(三)nas存储

wKioL1nYjX6D8uaxAABXqVqjGQA711.png-wh_50
wKioL1nYjX6D8uaxAABXqVqjGQA711.png-wh_50

manila share 节点通过管理网络连接nas存储的api管理口

用户云主机通过vrouter(可选)连接nas

三、虚拟机模式架构

笔者主要对openstack中vm as a service的模式有着比较大的兴趣,折腾完trove(虚拟机当数据库实例)和octavia(虚拟机当lb)之后花了几天时间折腾了一下manila的虚拟机+nfs模式

(一) 流程

系统会为manila创建一个manila networks,

用户创建manila 实例时会进行如下步骤,其中任何一个步骤出错都会导致创建实例出错

1 将manila网络接入和指定网络同一个vrouter下

2 调用nova 创建一个manila云主机,绑定安全组,创建cinder 卷

3 manila share会在5分钟内不停的 通过 manila networks 尝试ssh 连接manila虚拟机,

4 连接上之后进行nfs初始化

5 用户虚拟机 用过用户网络 到vrouter 到manila网络 实现对nfs的访问

(二)关键点的代码

1 检查manila网络有没有和用户指定网络有没有接入同一个vrouter

manila/share/drivers/service_instance.py

代码语言:javascript
复制
    def _get_private_router(self, neutron_net_id, neutron_subnet_id):
        """Returns router attached to private subnet gateway."""
        private_subnet = self.neutron_api.get_subnet(neutron_subnet_id)
        if not private_subnet['gateway_ip']:
            raise exception.ServiceInstanceException(
                _('Subnet must have gateway.'))
        private_network_ports = [p for p in self.neutron_api.list_ports(
                                 network_id=neutron_net_id)]
        for p in private_network_ports:
            fixed_ip = p['fixed_ips'][0]
            if (fixed_ip['subnet_id'] == private_subnet['id'] and
                    fixed_ip['ip_address'] == private_subnet['gateway_ip']):
                private_subnet_gateway_port = p
                break
        else:
            raise exception.ServiceInstanceException(
                _('Subnet gateway is not attached to the router.'))
        private_subnet_router = self.neutron_api.show_router(
            private_subnet_gateway_port['device_id'])
        return private_subnet_router

先检查subnet 有没有gateway 有的话在检查有没有接入路由器

2 检查 manila share 节点 有没有打通网络

前面所述manila share 进程是可以直接ssh 进mannila vm的,因此需要打通manila share 节点和manila networks 这个租户网络

 network/linux/interface.py

代码语言:javascript
复制
    def plug(self, device_name, port_id, mac_address,
             bridge=None, namespace=None, prefix=None):
        """Plugin the interface."""
        ip = ip_lib.IPWrapper()
        if prefix:
            tap_name = device_name.replace(prefix, 'tap')
        else:
            tap_name = device_name.replace(self.DEV_NAME_PREFIX, 'tap')

        if not ip_lib.device_exists(device_name,
                                    namespace=namespace):
            # Create ns_veth in a namespace if one is configured.
            root_veth, ns_veth = ip.add_veth(tap_name, device_name,
                                             namespace2=namespace)
            ns_veth.link.set_address(mac_address)

        else:
            ns_veth = ip.device(device_name)
            root_veth = ip.device(tap_name)
            LOG.warning("Device %s already exists.", device_name)

        root_veth.link.set_up()
        ns_veth.link.set_up()

 先检查 是否存在这样的设备,如果不存在,就创建一个

最终会发现manila share 节点上生成一个 ns开头的tap设备

代码语言:javascript
复制
ns-7a203bcb-40: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.254.0.10  netmask 255.255.255.240  broadcast 10.254.0.15
        inet6 fe80::f816:3eff:fe56:b6f7  prefixlen 64  scopeid 0x20<link>
        ether fa:16:3e:56:b6:f7  txqueuelen 1000  (Ethernet)
        RX packets 1190  bytes 193963 (189.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2236  bytes 135968 (132.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

通过他 我们可以直接在manila share 节点 访问 manila vm

3 主要创建过程

 share/drivers/generic.py

代码语言:javascript
复制
   def create_share(self, context, share, share_server=None):
        """Creates share."""
        return self._create_share(
            context, share,
            snapshot=None,
            share_server=share_server,
        )
    def _create_share(self, context, share, snapshot, share_server=None):
        helper = self._get_helper(share)
        server_details = share_server['backend_details']
        volume = self._allocate_container(
            self.admin_context, share, snapshot=snapshot)
        volume = self._attach_volume(
            self.admin_context, share, server_details['instance_id'], volume)
        if not snapshot:
            self._format_device(server_details, volume)

        self._mount_device(share, server_details, volume)
        export_locations = helper.create_exports(
            server_details, share['name'])
        return export_locations

总体过程就是 :

(1)创建虚拟机

(2)创建volume

(3)挂载 volume

4 虚拟机创建后的操作

(1)manila share 在虚拟机被创建后不同的尝试ssh连接 虚拟机

share/drivers/service_instance.p

代码语言:javascript
复制
    def _check_server_availability(self, instance_details):
        t = time.time()
        while time.time() - t < self.max_time_to_build_instance:
            LOG.debug('Checking server availability.')
            if not self._test_server_connection(instance_details):
                time.sleep(5)
            else:
                return True
        return False

    def _test_server_connection(self, server):
        try:
            socket.socket().connect((server['ip'], 22))
            LOG.debug('Server %s is available via SSH.',
                      server['ip'])
            return True
        except socket.error as e:
            LOG.debug(e)
            LOG.debug("Server %s is not available via SSH. Waiting...",
                      server['ip'])
            return False

如果规定时间连接不成功直接把 状态由creating变成error

代码语言:javascript
复制
    def set_up_service_instance(self, context, network_info):
        """Finds or creates and sets up service vm.

        :param context: defines context, that should be used
        :param network_info: network info for getting allocations
        :returns: dict with service instance details
        :raises: exception.ServiceInstanceException
        """
        instance_name = network_info['server_id']
        server = self._create_service_instance(
            context, instance_name, network_info)
        instance_details = self._get_new_instance_details(server)

        if not self._check_server_availability(instance_details):
            e = exception.ServiceInstanceException(
                _('%(conn_proto)s connection has not been '
                  'established to %(server)s in %(time)ss. Giving up.') % {
                      'conn_proto': self._INSTANCE_CONNECTION_PROTO,
                      'server': server['ip'],
                      'time': self.max_time_to_build_instance})
            e.detail_data = {'server_details': instance_details}
            raise e

        return instance_details

ssh连上之后的操作

检查cinder volume 是否存在

代码语言:javascript
复制
    def _is_device_file_available(self, server_details, volume):
        """Checks whether the device file is available"""
        command = ['sudo', 'test', '-b', volume['mountpoint']]
        self._ssh_exec(server_details, command)

检测到存在之后进行格式化

代码语言:javascript
复制
    def _format_device(self, server_details, volume):
        """Formats device attached to the service vm."""
        self._is_device_file_available(server_details, volume)
        command = ['sudo', 'mkfs.%s' % self.configuration.share_volume_fstype,
                   volume['mountpoint']]
        self._ssh_exec(server_details, command)

格式化后进行挂载

代码语言:javascript
复制
    def _is_device_mounted(self, mount_path, server_details, volume=None):
        """Checks whether volume already mounted or not."""
        log_data = {
            'mount_path': mount_path,
            'server_id': server_details['instance_id'],
        }
        if volume and volume.get('mountpoint', ''):
            log_data['volume_id'] = volume['id']
            log_data['dev_mount_path'] = volume['mountpoint']
            msg = ("Checking whether volume '%(volume_id)s' with mountpoint "
                   "'%(dev_mount_path)s' is mounted on mount path '%(mount_p"
                   "ath)s' on server '%(server_id)s' or not." % log_data)
        else:
            msg = ("Checking whether mount path '%(mount_path)s' exists on "
                   "server '%(server_id)s' or not." % log_data)
        LOG.debug(msg)
        mounts_list_cmd = ['sudo', 'mount']
        output, __ = self._ssh_exec(server_details, mounts_list_cmd)
        mounts = output.split('\n')
        for mount in mounts:
            mount_elements = mount.split(' ')
            if (len(mount_elements) > 2 and mount_path == mount_elements[2]):
                if volume:
                    # Mount goes with device path and mount path
                    if (volume.get('mountpoint', '') == mount_elements[0]):
                        return True
                else:
                    # Unmount goes only by mount path
                    return True
        return False

5 权限控制

虚拟机模式的权限控制主要依靠nfs 自己的权限控制来进行

代码语言:javascript
复制
manila access-allow demo-share1 ip 172.16.1.11

share 节点 会ssh连接上  demo-share1所在虚拟机 的/etc/export加上一行

代码语言:javascript
复制
manila@ubuntu:~$ cat /etc/exports 
/shares/share-f898d9b0-77b8-4231-9919-27b12e34cfa3	172.16.1.11(rw,sync,wdelay,hide,nocrossmnt,secure,no_root_squash,no_all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534,sec=sys,rw,no_root_squash,no_all_squash)

上文说的安全组规则只是是通用规则,mannila 并不会会对每台虚拟机应用不同的安全组规则

share/drivers/helpers.py

代码语言:javascript
复制
    def update_access(self, server, share_name, access_rules, add_rules,
                      delete_rules):

        local_path = os.path.join(self.configuration.share_mount_path,
                                  share_name)
        out, err = self._ssh_exec(server, ['sudo', 'exportfs'])
        # Recovery mode
        if not (add_rules or delete_rules):

            self.validate_access_rules(
                access_rules, ('ip',),
                (const.ACCESS_LEVEL_RO, const.ACCESS_LEVEL_RW))

            hosts = self.get_host_list(out, local_path)
            for host in hosts:
                self._ssh_exec(server, ['sudo', 'exportfs', '-u',
                                        ':'.join((host, local_path))])
            self._sync_nfs_temp_and_perm_files(server)
            for access in access_rules:
                rules_options = '%s,no_subtree_check'
                if access['access_level'] == const.ACCESS_LEVEL_RW:
                    rules_options = ','.join((rules_options, 'no_root_squash'))
                access_to = self._get_parsed_address_or_cidr(
                    access['access_to'])
                self._ssh_exec(
                    server,
                    ['sudo', 'exportfs', '-o',
                     rules_options % access['access_level'],
                     ':'.join((access_to, local_path))])
                     self._sync_nfs_temp_and_perm_files(server)

主要是通过  exportfs命令来进行 nfs权限管理

四 对manila目前状态的评价

     堪用.在流程上没有大的bug,但是在安全,容错,高可用,文档,代码可读性等方面还有很多路要走.其实以上这些也是整个openstack项目的通病,但是反过来一想,如果没有这些问题,openstack还能吸引这么多人关注吗?

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017-10-07 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云服务器
云服务器(Cloud Virtual Machine,CVM)提供安全可靠的弹性计算服务。 您可以实时扩展或缩减计算资源,适应变化的业务需求,并只需按实际使用的资源计费。使用 CVM 可以极大降低您的软硬件采购成本,简化 IT 运维工作。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档