版本说明:
Trino 版本 trino-0.416
Presto 版本 presto-0.280
Alluxio 版本 alluxio-2.7.4
Presto接入Alluxio缓存
Presto使用Alluxio作为数据缓存有两种模式分布式Presto on Alluxio Cluster 和Presto on Alluxio local Cache
Presto on Alluxio local Cache
这种模式集群中只有Presto的coordinator和worker进程,无需额外部署Alluxio集群,比较轻量,但是只有磁盘缓存,没有内存级别的缓存,而且缓存目录只能配置一个,如果需要充分利用多磁盘性能必需把多块磁盘挂载在同一个目录下。但是Presto集群扩缩容时无法命中缓存
Presto on Alluxio Cluster
Presto 集群和 Alluxio集群相互独立,Presto和Alluxio各自有各自的角色进程,Presto有coordinator和worker进程,Alluxio有AlluxioMaster 和 AlluxioWorker进程,这些进程可以混合部署在同一批机器上。Alluxio Cluster可以配置多级缓存,如内存,SSD,HHD等,如下图所示:
Presto配置与部署
Presto on Alluxio local Cache配置与部署
配置presto的hive catalog 文件
这种模式不需要启动Alluxio 相关进程,直接在presto的${presto_home}/etc/catalog/hive.properties配置添加以下配置
hive.node-selection-strategy=SOFT_AFFINITY
cache.enabled=true
cache.base-directory=file:///data/presto
cache.type=ALLUXIO
cache.alluxio.max-cache-size=300GB
注意:缓存目录(cache.base-directory)只能配置一个,如果需要充分利用多磁盘性能必需把多块磁盘挂载在同一个目录下
问题
查询hive表时遇到以下问题:
hdfs is not supported as the external filesystem
解决方案:把alluxio-2.9.3-hadoop2-client.jar 替换原来的alluxio jar包,jar包的位置在${presto_home}/plugin/hive-hadoop2,后面要部署Presto on Alluxio Cluster 又需要把alluxio-2.9.3-hadoop2-client.jar 删除,把原来的alluxio jar包替换回来,不然会报下面错误:
java.lang.NoClassDefFoundError: alluxio/conf/AlluxioConfiguration
at com.facebook.presto.hive.metastore.HiveMetastoreModule.setup(HiveMetastoreModule.java:50)
at com.facebook.airlift.configuration.AbstractConfigurationAwareModule.configure(AbstractConfigurationAwareModule.java:43)
at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:344)
监控缓存命中率
这里主要配置 Alluxio的缓存命中率,步骤如下文:
https://blog.csdn.net/Alluxio/article/details/127073139
普罗米修斯数据采集配置
- job_name: "presto_local_cache"
scrape_interval: 15s
static_configs:
- targets: ["10.192.1.1:7080","10.192.1.2:7080","10.192.1.2:7080","10.192.1.4:7080","10.192.1.5:7080"]
labels:
appname: "presto_local_cache"
通过Curl查看普罗米修斯的数据
例如查看指标com_facebook_alluxio_Client_CacheHitRate_${hostname}_Value当前值
curl -G http://localhost:8080/api/v1/query --data-urlencode 'query=com_facebook_alluxio_Client_CacheHitRate_${hostname}_Value{job="presto_local_cache"}'
查看普罗米修斯 所有指标名称
curl -G http://localhost:8080/api/v1/label/__name__/values
Presto on Alluxio Cluster配置与部署
1、部署配置Alluxio Cluster
Alluxio 2.9.3 之后不支持以下方式,访问现有的hive表,具体步骤官网没有明确说明
Presto 官网接入Alluxio Cluster的文档:https://prestodb.io/docs/current/cache/service.html?highlight=alluxio
具体部署步骤不再赘述链接:https://docs.alluxio.io/os/user/2.7.4/cn/deploy/Running-Alluxio-on-a-Cluster.html,缓存配置如下:
alluxio.master.hostname=10.192.168.12
alluxio.master.mount.table.root.ufs=hdfs:/xxx/tmp
alluxio.underfs.hdfs.configuration=/bigdata/presto-server-0.280-SNAPSHOT/etc/hadoop_conf/core-site.xml:/bigdata/presto-server-0.280-SNAPSHOT/etc/hadoop_conf/hdfs-site.xml
alluxio.master.security.impersonation.presto.users=hdfs
alluxio.master.security.impersonation.presto.groups=hdfs
# Worker properties
alluxio.worker.tieredstore.levels=2
alluxio.worker.tieredstore.level0.alias=MEM
alluxio.worker.tieredstore.level0.dirs.path=/Volumes/ramdisk
alluxio.worker.tieredstore.level0.dirs.quota=25GB
alluxio.worker.tieredstore.level1.alias=HDD
alluxio.worker.tieredstore.level1.dirs.path=/data1/alluxio,/data2/alluxio
alluxio.worker.tieredstore.level1.dirs.quota=2TB,2TB
# User properties
alluxio.user.file.readtype.default=CACHE
alluxio.user.file.writetype.default=CACHE_THROUGH
注意点
- 启动Alluxio进程的用户 最好使用hdfs用户,避免后面出现权限问题
- alluxio.underfs.hdfs.configuration配置的hdfs配置文件最好与presto保持一样
2、绑定hive表
如果想让presto查询现有的hive表数据,需要把hive表的路径挂载到alluxio文件系统中,并且需要在presto端配置对应的catalog
把库(tpch_300x_orc)里的所有表挂载到alluxio文件系统中,命令如下:
绑定
/bigdata/alluxio-2.7.4/bin/alluxio table attachdb hive thrift://10.192.10.13:9083 tpch_300x_orc
解绑
/bigdata/alluxio-2.7.4/bin/alluxio table detachdb tpch_300x_orc
alluxio相关文件命令
https://docs.alluxio.io/os/user/2.7.4/en/operation/User-CLI.html#table-operations
绑定hive表相关文档
https://blog.csdn.net/Alluxio/article/details/127075639
https://zhuanlan.zhihu.com/p/165162481
3、Presto创建catalog
想让Presto通过Alluxio访问hdfs数据需要配置相应的catalog,在presto集群每个节点添加文件${presto_home}/etc/catalog/alluxio.properties,内容如下:
connector.name=hive-hadoop2
hive.metastore=alluxio
hive.metastore.alluxio.master.address=10.192.168.12:19998
注意:connector.name 配置的还是hive-hadoop2
presto-0.280 cli访问alluxio catalog内部表如下:
/home/presto/presto --server http://10.192.10.21:8080 --catalog alluxio --user hive
4、遇到的问题
权限相关文档:https://docs.alluxio.io/os/user/2.7.4/cn/operation/Security.html
问题1:通过presto-cli 查询hive表时报如下错误
Query 20230730_161949_00002_qwisq failed: Failed to list directory: alluxio://10.192.168.12:19998/catalog/tpch_300x_orc/tables/lineitem/hive. Plain authentication failed: Failed to authenticate client user=“presto” connecting to Alluxio master and impersonating as impersonationUser=“hdfs” to access Alluxio file system. user=“presto” is not configured to impersonate as impersonationUser=“hdfs”.Please read the guide to configure impersonation at https://docs.alluxio.io/os/user/2.7/en/operation/Security.html
由于Presto进程是使用presto用户启动的,所以Presto进程作为Alluxio客户端会通过presto用户模拟hdfs访问Alluxio集群,需要在Alluxio的alluxio-site.properties配置允许presto 用户模拟hdfs访问Alluxio集群
alluxio.master.security.impersonation.presto.users=hdfs
alluxio.master.security.impersonation.presto.groups=hdfs
问题2:通过presto-cli 查询hive表时报如下错误
Query 20230730_161755_00001_qwisq failed: Failed to list directory: alluxio://10.192.168.12:19998/catalog/tpch_300x_orc/tables/lineitem/hive. alluxio.exception.AccessControlException: Permission denied: user=hdfs, access=r–, path=/catalog/tpch_300x_orc/tables/lineitem/hive: failed at hive, inode owner=0001, inode group=supergroup, inode mode=rwxrwx–x
由于Alluxio 的进程是使用alluxio用户启动的,在挂载alluxio文件目录时,也会用alluxio用户创建目录。最后在查询数据时会出现权限问题,在官网推荐使用hdfs 用户启动alluxio进程
sudo groupadd hdfs
sudo useradd hdfs
sudo usermod -aG hdfs hdfs
Trino缓存配置
本地缓存
Trino提供本地缓存策略,与presto不同的是,他自己实现了缓存,而不是基于Alluxio的缓存,并且能配置多个目录(presto只能配置一个数据目录),这样可以充分利用本地磁盘性能,配置方法如下:
https://trino.io/docs/current/connector/hive-caching.html?highlight=cache
connector.name=hive
hive.cache.enabled=true
hive.cache.location=/data1/trino,/data2/trino
问题1:在启动Trino进程时 报:Any way make HDFS impersonation compatible with Hive caching?
1、去除模拟hdfs用户访问hdfs
hive.hdfs.impersonation.enabled=true
2、使用hdfs用户启动 trino进程
Alluxio Cluster缓存
官方文档:https://docs.alluxio.io/ee/user/2.7.0/en/compute/Trino.html?utm_source=trino&utm_medium=trinodocs
通过 Alluxio Catalog Service 接入
跟Presto方式一样通过Alluxio Catalog Service方式访问Alluxio 集群 存在问题:https://github.com/Alluxio/alluxio/issues/17916
最新trino 插件必须实现这个接口:io.trino.spi.Plugin,而Alluxio提供的jar包没有实现这个接口的类,说明trino没有主动对Alluxio通过catalog方式访问Alluxio 集群
通过把hive表LOCATION修改成Alluxio文件系统的path的方式接入
挂载hive表hdfs路径到Alluxio文件系统
/bigdata/alluxio-2.7.4/bin/alluxio fs mount /tmp/tpch-generate/300/lineitem hdfs://nameservice1/tmp/tpch-generate/300/lineitem
修改表的location
use tpch_text_300;
alter table lineitem set location 'alluxio://alluxioHost:19998/tpch-generate/300/lineitem'
相关问题
问题1:找不到Alluxio文件系统,把alluxio-2.7.4-client.jar放在hive的lib下,重启hive matastore
报错:FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(message:Got exception: java.io.IOException No FileSystem for scheme: alluxio)
问题2 : hive用户没有权限访问Alluxio,
hive> CREATE TABLE u_user (
> userid INT,
> age INT,
> gender CHAR(1),
> occupation STRING,
> zipcode STRING)
> ROW FORMAT DELIMITED
> FIELDS TERMINATED BY '|'
> STORED AS TEXTFILE
> LOCATION 'alluxio://alluxioHost:19998/ml-100k';
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(message:Got exception: alluxio.exception.status.UnauthenticatedException Channel authentication failed with code:UNAUTHENTICATED. Channel: GrpcChannelKey{ClientType=FileSystemMasterClient, ClientHostname=hostName, ServerAddress=GrpcServerAddress{HostName=alluxioHost, SocketAddress=alluxioHost:19998}, ChannelId=124ebe03-2aee-4b30-b9bf-3df1256292bd}, AuthType: SIMPLE, Error: alluxio.exception.status.UnauthenticatedException: Plain authentication failed: Failed to authenticate client user="hive" connecting to Alluxio server and impersonating as impersonationUser="hdfs" to access Alluxio file system. User "hive" is not configured to allow any impersonation. Please read the guide to configure impersonation at https://docs.alluxio.io/os/user/2.7/en/operation/Security.html)
修改Alluxio配置解决
alluxio.master.security.impersonation.hive.users=hdfs
alluxio.master.security.impersonation.hive.groups=hdfs
问题3:修改表路径 必须使用hostName 不能使用ip:10.192.100.28 不然会报下面错误
Query 20230808_123525_00004_ktsyr failed: Invalid host or port: 10.192.100.28 19998