对象存储 独立部署快速入门

这篇档主要提供 GooseFS 快速部署、调试的相关指引,提供在本地机器上部署 GooseFS,并将对象存储(Cloud Object Storage,COS)作为远端存储的步骤指引。

相关产品
对象存储 产品页,含版本规格、价格与购买入口。

一、前提条件

在使用 GooseFS 之前,你还需要准备以下工作:

1. 在 COS 服务上创建一个存储桶以作为远端存储,操作指引请参见 控制台快速入门。

2. 安装 Java 8 或者更高的版本。

3. 安装 SSH,确保能通过 SSH 连接到 localhost,并远程登录。

4. 在 CVM 服务上购买一台实例,操作指引详见 购买云服务器,并确保磁盘已经挂载到实例上。

二、下载并配置 GooseFS

1. 新建本地目录并进入该目录下(你也可以按需选择其他目录),从仓库下载 GooseFS 安装包到本地。安装包 GitHub 地址:goosefs-1.4.5-bin.tar.gz。

$ cd /usr/local$ mkdir service$ cd service$ wget https://downloads.tencentgoosefs.cn/goosefs/1.4.5/release/goosefs-1.4.5-bin.tar.gz

2. 执行如下命令,对安装包进行解压,解压后进入安装包目录下。

$ tar -zxvf goosefs-1.4.5-bin.tar.gz$ cd goosefs-1.4.5

解压后,得到 goosefs-1.4.5,即 GooseFS 的主目录。下文将以 ${GOOSEFS_HOME} 代指该目录的绝对路径。

3. 在 ${GOOSEFS_HOME}/conf 的目录下,创建 conf/goosefs-site.properties 的配置文件。GooseFS 提供 AI 和大数据两个场景的配置模板,可以使用任意上述内置模板,然后进入编辑模式修改配置:

·使用 AI 场景模板,更多信息可参考 GooseFS AI 场景生产环境配置实践。

$ cp conf/goosefs-site.properties.ai_template conf/goosefs-site.properties$ vim conf/goosefs-site.properties

·使用大数据场景模板,更多信息可参考 GooseFS 大数据场景生产环境配置实践。

$ cp conf/goosefs-site.properties.bigdata_template conf/goosefs-site.properties$ vim conf/goosefs-site.properties

4. 在配置文件 conf/goosefs-site.properties 中,调整如下配置项:

·AI 场景模板

# Master propertiesgoosefs.master.rpc.addresses=<master1>:9200,<master2>:9200,<master3>:9200goosefs.master.embedded.journal.addresses=<master1>:9202,<master2>:9202,<master3>:9202goosefs.master.journal.folder=<path>goosefs.master.metastore.dir=<path># 建议与 goosefs.master.metastore.dir 放在不同的 nvme 盘goosefs.master.metastore.block.locations=<path># Worker propertiesgoosefs.master.worker.register.lease.count=4goosefs.worker.tieredstore.level0.dirs.path=<path>,<path>,<path>goosefs.worker.tieredstore.level0.dirs.quota=<capacity>,<capacity>,<capacity># Client propertiesgoosefs.user.file.delete.unchecked=truegoosefs.user.file.passive.cache.enabled=falsegoosefs.user.file.master.client.pool.size.max=100goosefs.client.list.status.executor.pool.size=200# Common Propertiesgoosefs.network.ip.address.used=true# Custom Properties

·大数据场景模板

# Master propertiesgoosefs.master.rpc.addresses=<master1>:9200,<master2>:9200,<master3>:9200goosefs.master.embedded.journal.addresses=<master1>:9202,<master2>:9202,<master3>:9202goosefs.master.journal.folder=<path># Zookeeper Connection# goosefs.zookeeper.enabled=true# goosefs.zookeeper.address=<zk_quorum_1>:<zk_client_port>,<zk_quorum_2>:<zk_client_port>,<zk_quorum_3>:<zk_client_port># goosefs.master.journal.type=UFS# goosefs.master.journal.folder=<hdfs_path>goosefs.master.metastore.dir=<path># 建议与 goosefs.master.metastore.dir放在不同的 nvme 盘goosefs.master.metastore.block.locations=<path>goosefs.underfs.hdfs.configuration=${HADOOP_HOME}/etc/hadoop/core-site.xml:${HADOOP_HOME}/etc/hadoop/hdfs-site.xml# Worker propertiesgoosefs.worker.tieredstore.level0.dirs.path=<path>,<path>,<path>goosefs.worker.tieredstore.level0.dirs.quota=<capacity>,<capacity>,<capacity># Security propertiesgoosefs.security.authorization.permission.enabled=truegoosefs.security.authentication.type=SIMPLE# Client propertiesgoosefs.user.client.transparent_acceleration.scope=GFSgoosefs.user.client.transparent_acceleration.enabled=true# Custom Properties

注意:配置 goosefs.worker.tieredstore.level0.dirs.path该路径参数前,需要先新建这一路径。

三、启用 GooseFS

启用 GooseFS 前,需要进入到 GooseFS 目录下执行启动指令:

$ cd /usr/local/service/goosefs-1.4.5$ ./bin/goosefs-start.sh all

执行该指令后,可以看到如下页面:

该命令执行完毕后,可以访问 http://localhost:9201 和 http://localhost:9204,分别查看 Master 和 Worker 的运行状态。

四、使用 GooseFS 挂载 COS(COSN) 或腾讯云 HDFS(CHDFS)

如果 GooseFS 需要挂载 COS(COSN)或腾讯云 HDFS(CHDFS)到 GooseFS 的根路径上,则需要先在 conf/core-site.xml 配置中指定 COSN 或 CHDFS 的必需配置项,其中包括但不限于:fs.cosn.impl 、 fs.AbstractFileSystem.cosn.impl 以及 fs.cosn.userinfo.secretId 和 fs.cosn.userinfo.secretKey 等,如下所示:

<!– COSN related configurations –><property> <name>fs.cosn.impl</name> <value>org.apache.hadoop.fs.CosFileSystem</value></property><property> <name>fs.AbstractFileSystem.cosn.impl</name> <value>com.qcloud.cos.goosefs.CosN</value></property><property> <name>fs.cosn.userinfo.secretId</name> <value></value></property><property> <name>fs.cosn.userinfo.secretKey</name> <value></value></property><property> <name>fs.cosn.bucket.region</name> <value></value></property><!– CHDFS related configurations –><property> <name>fs.AbstractFileSystem.ofs.impl</name> <value>com.qcloud.chdfs.fs.CHDFSDelegateFSAdapter</value></property><property> <name>fs.ofs.impl</name> <value>com.qcloud.chdfs.fs.CHDFSHadoopFileSystemAdapter</value></property><property> <name>fs.ofs.tmp.cache.dir</name> <value>/data/chdfs_tmp_cache</value></property><!–appId–> <property> <name>fs.ofs.user.appid</name> <value>1250000000</value></property>

注意:说明:

下面将介绍一下如何通过创建 Namespace 来挂载 COS 或 CHDFS 的方法和步骤。

1. 创建一个命名空间 namespace 并挂载 COS:

$ goosefs ns create myNamespace cosn://bucketName-1250000000/ \\–secret fs.cosn.userinfo.secretId=AKXXXXXXXXXXX \\–secret fs.cosn.userinfo.secretKey=XXXXXXXXXXXX \\–attribute fs.cosn.bucket.region=ap-xxx \\

同理,也可以创建一个命名空间 namespace 用于挂载腾讯云 HDFS:

goosefs ns create MyNamespaceCHDFS ofs://xxxxx-xxxx.chdfs.ap-guangzhou.myqcloud.com/ \\–attribute fs.ofs.user.appid=1250000000–attribute fs.ofs.tmp.cache.dir=/tmp/chdfs

2. 创建成功后,可以通过 ls 命令列出集群中创建的所有 namespace:

$ goosefs ns lsnamespace mountPoint ufsPath creationTime wPolicy rPolicy TTL ttlActionmyNamespace /myNamespace cosn://bucketName-125xxxxxx/3TB 03-11-2021 11:43:06:239 CACHE_THROUGH CACHE -1 DELETEmyNamespaceCHDFS /myNamespaceCHDFS ofs://xxxxx-xxxx.chdfs.ap-guangzhou.myqcloud.com/3TB 03-11-2021 11:45:12:336 CACHE_THROUGH CACHE -1 DELETE

3. 执行如下命令,指定 namespace 的详细信息。

$ goosefs ns stat myNamespaceNamespaceStatus{name=myNamespace, path=/myNamespace, ttlTime=-1, ttlAction=DELETE, ufsPath=cosn://bucketName-125xxxxxx/3TB, creationTimeMs=1615434186076, lastModificationTimeMs=1615436308143, lastAccessTimeMs=1615436308143, persistenceState=PERSISTED, mountPoint=true, mountId=4948824396519771065, acl=user::rwx,group::rwx,other::rwx, defaultAcl=, owner=user1, group=user1, mode=511, writePolicy=CACHE_THROUGH, readPolicy=CACHE}

元数据中记录的信息包括如下内容:

序号 参数 描述
1 name namespace 的名字
2 path namespace 在 GooseFS 中的路径
3 ttlTime namespace 下目录和文件的 ttl 周期
4 ttlAction namespace 下目录和文件的 ttl 处理动作,有两种处理动作:FREE 和 DELETE,默认是 FREE
5 ufsPath namespace 在 ufs 上的挂载路径
6 creationTimeMs namespace 的创建时间,单位是毫秒
7 lastModificationTimeMs namespace 下目录和文件的最后修改时间,单位是毫秒
8 persistenceState namespace 的持久化状态
9 mountPoint namespace 是否是一个挂载点,始终为 true
10 mountId namespace 挂载点 ID
11 acl namespace 的访问控制列表
12 defaultAcl namespace 的默认访问控制列表
13 owner namespace 的 owner
14 group namespace 的 owner 所属的 group
15 mode namespace 的 POSIX 权限
16 writePolicy namespace 的 写策略
17 readPolicy namespace 的 读策略

五、使用 GooseFS 预热 Table 中的数据

1. GooseFS 支持将 Hive Table 中的数据预热到 GooseFS 中,在预热之前需要先将相关的 DB 关联到 GooseFS 上,相关命令如下:

$ goosefs table attachdb –db test_db hive thrift://172.16.16.22:7004 test_for_demo

注意:命令中的 thrift 需要填写实际的 Hive Metastore 的地址。

2. 添加完 DB 后,可以通过 ls 命令查看当前关联的 DB 和 Table 的信息:

$ goosefs table ls test_db web_pageOWNER: hadoopDBNAME.TABLENAME: testdb.web_page (wp_web_page_sk bigint,wp_web_page_id string,wp_rec_start_date string,wp_rec_end_date string,wp_creation_date_sk bigint,wp_access_date_sk bigint,wp_autogen_flag string,wp_customer_sk bigint,wp_url string,wp_type string,wp_char_count int,wp_link_count int,wp_image_count int,wp_max_ad_count int,)PARTITIONED BY ()LOCATION (gfs://172.16.16.22:9200/myNamespace/3000/web_page)PARTITION LIST ({partitionName: web_pagelocation: gfs://172.16.16.22:9200/myNamespace/3000/web_page})

3. 通过 load 命令预热 Table 中的数据:

$ goosefs table load test_db web_pageAsynchronous job submitted successfully, jobId: 1615966078836

预热 Table 中的数据是一个异步任务,因此会返回一个任务 ID。可以通过 goosefs job stat <Job Id>命令查看预热作业的执行进度。当状态为 "COMPLETED" 后,则整个预热过程完成。

六、使用 GooseFS 进行文件上传和下载操作

1. GooseFS 支持绝大部分文件系统操作命令,可以通过以下命令来查询当前支持的命令列表:

$ goosefs fs

2. 可以通过 ls 命令列出 GooseFS 中的文件,以下示例展示如何列出根目录下的所有文件:

$ goosefs fs ls /

3. 可以通过 copyFromLocal 命令将数据从本地拷贝到 GooseFS 中:

$ goosefs fs copyFromLocal LICENSE /LICENSECopied LICENSE to /LICENSE$ goosefs fs ls /LICENSE-rw-r–r– hadoop supergroup 20798 NOT_PERSISTED 03-26-2021 16:49:37:215 0% /LICENSE

4. 可以通过 cat 命令查看文件内容:

$ goosefs fs cat /LICENSE Apache LicenseVersion 2.0, January 2004http://www.apache.org/licenses/TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION…

5. GooseFS 默认使用本地磁盘作为底层文件系统,默认文件系统路径为 ./underFSStorage,可以通过 persist 命令将文件持久化存储到本地文件系统中:

$ goosefs fs persist /LICENSEpersisted file /LICENSE with size 26847

七、使用 GooseFS 加速文件上传和下载操作

1. 检查文件存储状态,确认文件是否已被缓存。文件状态 PERSISTED 代表文件已在内存中,文件状态 NOT_PERSISTED 则代表文件不在内存中:

$ goosefs fs ls /data/cos/sample_tweets_150m.csv-r-x—— staff staff 157046046 NOT_PERSISTED 01-09-2018 16:35:01:002 0% /data/cos/sample_tweets_150m.csv

2. 统计文件中有多少单词 “tencent”,并计算操作耗时:

$ time goosefs fs cat /data/s3/sample_tweets_150m.csv | grep-c tencent889real 0m22.857suser 0m7.557ssys 0m1.181s

3. 将该数据缓存到内存中可以有效提升查询速度,详细示例如下:

$ goosefs fs ls /data/cos/sample_tweets_150m.csv-r-x—— staff staff 157046046 ED 01-09-2018 16:35:01:002 0% /data/cos/sample_tweets_150m.csv$ time goosefs fs cat /data/s3/sample_tweets_150m.csv | grep-c tencent889real 0m1.917suser 0m2.306ssys 0m0.243s

可见,系统处理延迟从1.181s减少到了0.243s,得到了显著的提升。

八、关闭 GooseFS

注意:关闭 GooseFS 会导致业务中断,请谨慎操作。

通过如下命令可以关闭 GooseFS:

$ ./bin/goosefs-stop.sh local

赞 (0)
上一篇 5天前
下一篇 5天前