Ozone命令行接口详解

命令行接口简介

Ozone Shell是命令行与Ozone交互的主要界面,底层用的是Java

有些功能只能通过Ozone Shell进行操作:

  1. 创建带有限额限制的Volume
  2. 管理内部ACLs(访问控制列表)
  3. 创建带有加密密钥的存储桶

大部分操作除了Shell操作之外,还可以使用hadoop、s3等方式操作。

在学习Ozone Shell命令的时候,可以借助help命令。
比如查看volume所有可用的命令:

ozone sh volume --help

Usage: ozone sh volume [-hV] [COMMAND]
Volume specific operations
  -h, --help      Show this help message and exit.
  -V, --version   Print version information and exit.
Commands:
  info       returns information about a specific volume
  list, ls   List the volumes of a given user
  create     Creates a volume for the specified user
  update     Updates parameter of the volumes
  delete     deletes a volume if it is empty
  addacl     Add one or more new ACLs.
  removeacl  Remove one or more existing ACLs.
  setacl     Set one or more ACLs, replacing the existing ones.
  getacl     List all ACLs.
  setquota   Set quota of the volumes. At least one of the quota set flag is
               mandatory.
  clrquota   clear quota of the volume. At least one of the quota clear flag is
               mandatory.

或者查看volume相关命令详细的使用说明:

ozone sh volume create --help

Usage: ozone sh volume create [-hV] [--namespace-quota=<quotaInNamespace>]
                              [--quota=<quotaInBytes>] [-u=<ownerName>] <value>
Creates a volume for the specified user
      <value>              URI of the volume.
                           Ozone URI could either be a full URI or short URI.
                           Full URI should start with o3://, in case of non-HA
                           clusters it should be followed by the host name and
                           optionally the port number. In case of HA clusters
                           the service id should be used. Service id provides a
                           logical name for multiple hosts and it is defined
                           in the property ozone.om.service.ids.
                           Example of a full URI with host name and port number
                           for a key:
                           o3://omhostname:9862/vol1/bucket1/key1
                           With a service id for a volume:
                           o3://omserviceid/vol1/
                           Short URI should start from the volume.
                           Example of a short URI for a bucket:
                           vol1/bucket1
                           Any unspecified information will be identified from
                           the config files.

  -h, --help               Show this help message and exit.
      --namespace-quota=<quotaInNamespace>
                           For volume this parameter represents the number of
                             buckets, and for buckets represents the number of
                             keys (eg. 5)
      --quota, --space-quota=<quotaInBytes>
                           The maximum space quota can be used (eg. 1GB)
  -u, --user=<ownerName>   Owner of the volume
  -V, --version            Print version information and exit.

Shell命令格式

Ozone Shell命令常用格式:

ozone sh object action url

参数详解:

  • ozone sh
    Ozone通过ozone sh调用其所有的命令。
  • object
    object可以是volume, bucket or key。
  • action
    action可以是各种操作,如create, list, delete等等。
  • url
    url会指向volume, bucket or key,格式如下:
    [schema][server:port]/volume/bucket/key
    
    schema是一个访问Ozone的PRC协议,是可选的。
    server:port是Ozone Manager的地址,如果省略了端口,则将使用ozone-site.xml中的默认端口。

Ozone的层次结构

Ozone的层次结构如下:

  1. 集群(Cluster):Ozone集群是Ozone的最高级别,由一组物理或虚拟服务器组成。集群中的各个节点协同工作,处理存储和访问数据的请求。

  2. 卷(Volume):卷是Ozone中的一个逻辑概念,代表一块连续的存储空间,类似于文件系统中的一个分区。每个卷都有自己的容量限制,并且可以独立地设置数据冗余和复制策略。卷是桶(Bucket)的容器。

  3. 桶(Bucket):桶是Ozone中存储对象的基本单元。用户可以在卷中创建多个桶并将对象存储在这些桶中。桶具有全局唯一的名称,并且可以设置访问权限控制以限制对桶中对象的访问。

  4. 对象(Object):对象是在桶中存储的实际数据。每个对象都由唯一的键(key)标识,并且可以具有其他元数据和属性。对象可以通过桶和键来进行检索和访问。

注意:Ozone还有更多的层次结构和概念,如存储单元(Storage Unit)、容器(Container)、块(Block)等。但以上列出的是Ozone最常用和关键的层次结构。

Volume 操作

Volume 作为整个层级结构中最顶级的管理单位,只有管理员可以操作它,并且可以选择性地指定配额和所有者用户来控制卷的容量和权限。

  1. Volume是Ozone对象存储系统中的最高级别的容器。它可以包含多个桶(buckets),而桶又可以包含多个路径(paths)。

  2. 只有管理员(administrators)可以管理Volume,例如创建、删除、列出等操作。

  3. 可以选择性地为Volume指定配额(quota),用于限制该Volume的存储容量。如果没有指定配额,则Volume的容量将没有限制。

  4. 可以选择性地为Volume指定所有者用户(owner user)。所有者用户具有特殊的权限,例如管理Volume内桶和路径的权限。

  • 创建Volume
    只有管理员才能创建Volume
    命令:
    ozone sh volume create /vol1
    
    如果不是管理员,则会报错:
    PERMISSION_DENIED User xxx doesn't have CREATE permission to access volume Volume:vol1
    
  • 查询Volume详细信息
    命令:
    ozone sh volume info /vol1
    
    结果:
    {
    "metadata" : { },
    "name" : "vol1",
    "admin" : "hadoop",
    "owner" : "hadoop",
    "creationTime" : "2020-07-28T12:31:50.112Z",
    "modificationTime" : "2020-07-28T12:31:50.112Z",
    "acls" : [ {
    "type" : "USER",
    "name" : "hadoop",
    "aclScope" : "ACCESS",
    "aclList" : [ "ALL" ]
    }, {
    "type" : "GROUP",
    "name" : "users",
    "aclScope" : "ACCESS",
    "aclList" : [ "ALL" ]
    } ],
    "quota" : 1152921504606846976
    }
    
  • 列出所有Volumn
    命令:
    ozone sh volume list /
    
    结果:
    {
      "metadata" : { },
      "name" : "s3v",
      "admin" : "hadoop",
      "owner" : "hadoop",
      "creationTime" : "2020-07-27T11:32:22.314Z",
      "modificationTime" : "2020-07-27T11:32:22.314Z",
      "acls" : [ {
        "type" : "USER",
        "name" : "hadoop",
        "aclScope" : "ACCESS",
        "aclList" : [ "ALL" ]
      }, {
        "type" : "GROUP",
        "name" : "users",
        "aclScope" : "ACCESS",
        "aclList" : [ "ALL" ]
      } ],
      "quota" : 1152921504606846976
    }
    

Bucket操作

在Ozone中,桶(Bucket)是对象层次结构的第二级,类似于AWS S3中的桶(buckets)。用户可以在卷(volume)中创建桶,前提是他们具有所需的权限。

简单来说,Ozone中的对象层次结构如下:

卷(Volume)是最高级别的容器,在卷中可以创建桶。

桶(Bucket)是存储对象的容器,类似于AWS S3中的桶。用户可以在卷中创建多个桶,并将对象存储在这些桶中。

  • 创建桶

    ozone sh bucket create /vol1/bucket1
    
  • 查询桶的详细信息
    命令:

    ozone sh bucket info /vol1/bucket1
    

    结果:

    {
      "metadata" : { },
      "volumeName" : "vol1",
      "name" : "bucket1",
      "storageType" : "DISK",
      "versioning" : false,
      "creationTime" : "2020-07-28T13:14:45.091Z",
      "modificationTime" : "2020-07-28T13:14:45.091Z",
      "encryptionKeyName" : null,
      "sourceVolume" : null,
      "sourceBucket" : null
    }
    

Key操作

Key是存储数据的对象。

  • 上传数据

    ozone sh key put /vol1/bucket1/README.md README.md
    

    注意:在Ozone中使用命令行工具时,命令的语法ozone sh <object_type> <action> <url>可能会有些困惑,因为它导致了ozone sh key put <destination> <source>这样的语法结构,而不是更自然的<source> <destination>的顺序。
    换句话说,对于文件的上传操作,一般来讲,人们可能更习惯使用类似于ozone put <source> <destination>的语法,其中<source>表示源文件的位置,<destination>表示目标位置。但是在Ozone的命令行工具中,使用了ozone sh key put <destination> <source>的语法,将<destination>作为目标Key的位置,<source>作为源文件的位置。
    这可能在一开始会令人困惑,因为与通常的命令语法不同。但是一旦了解了这种语法结构,并且熟悉了Ozone的命令行工具的使用方式,就能够正确地指定文件的源和目标位置,实现文件的上传等操作。

  • 查询key的详细信息
    命令:

    ozone sh key info /vol1/bucket1/README.md
    

    结果:

    {
      "volumeName" : "vol1",
      "bucketName" : "bucket1",
      "name" : "README.md",
      "dataSize" : 3841,
      "creationTime" : "2020-07-28T13:17:20.749Z",
      "modificationTime" : "2020-07-28T13:17:21.979Z",
      "replicationType" : "RATIS",
      "replicationFactor" : 1,
      "ozoneKeyLocations" : [ {
        "containerID" : 1,
        "localID" : 104591670688743424,
        "length" : 3841,
        "offset" : 0
      } ],
      "metadata" : { },
      "fileEncryptionInfo" : null
    }
    
  • 下载数据

    ozone sh key get /vol1/bucket1/README.md /tmp/
    

参考文献

Command Line Interface

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

SunnyRivers

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值