trino的安装和使用

trino作用:

trino可以同时连接多个数据源,然后将数据拉取过来,使用SQL查询这些数据。

需求:

由于工作需要同时连接hive 和 mysql ,为了减少代码量,安装了trino 。

现在需要通过python 的trino 客户端连接trino ,然后操作mysql和hive的数据。

操作内容:

所以我自己搭建了trino的serve 和client ,然后python3 安装了trino的客户端trino包,连接和操作trino

操作经验:

安装过程一波三折,首先是找了一篇博文,按照里面的步骤安装和配置,结果报错配置有问题。然后找来官方文档,按照官方文档中的配置,一次性直接成功了。

本次安装使单台服务器,主节点和从节点都安装再同一个台服务器。最新版本的trino要求jdk17以上。原来按照博客里面的安装方法装了jdk11,后面启动trino的时候直接报错了,说要求jdk17以上,后来换成jkd18好了。

需要安装的包:

1.jdk18

wget https://repo.huaweicloud.com/java/jdk/11+28/jdk-11_linux-x64_bin.tar.gz

2.trino-server

wget https://repo1.maven.org/maven2/io/trino/trino-server/418/trino-server-418.tar.gz

3.trino-client

trino-cli-418-executable.jar

4.python 安装triono包

pip3 intall trino

5.想用trino连接hive ,所以下载了hadoop和hive 的包

wget https://mirrors.ustc.edu.cn/apache/hadoop/common/hadoop-3.3.1/hadoop-3.3.1.tar.gz

wget https://mirrors.ustc.edu.cn/apache/hive/hive-3.1.3/apache-hive-3.1.3-bin.tar.gz

安装步骤:

1.jdk18安装

(1)TUNA镜像

https://mirrors.tuna.tsinghua.edu.cn/AdoptOpenJDK/

(2)HUAWEI镜像

Index of java-local/jdk

(3)injdk

https://www.injdk.cn

下载

wget https://d6.injdk.cn/openjdk/openjdk/18/openjdk-18.0.2_linux-x64_bin.tar.gz

解压到对应的目录

/opt/jdk/jdk-18.0.2

配置java home

export JAVA_HOME=/opt/jdk/jdk-18.0.2 export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export PATH=$PATH:$JAVA_HOME/bin

  1. 安装trino server

解压

tar -zxvf trino-server-418.tar.gz -C /opt/presto

创建配置文件

cd /opt/presto/trino-server-418

touch config.properties touch jvm.config touch log.properties touch node.properties

修改配置文件

vi node.properties

node.environment=production node.id=ffffffff-ffff-ffff-ffff-ffffffffffff node.data-dir=/var/trino/data

vi jvm.config

-server -Xmx16G -XX:InitialRAMPercentage=80 -XX:MaxRAMPercentage=80 -XX:G1HeapRegionSize=32M -XX:+ExplicitGCInvokesConcurrent -XX:+ExitOnOutOfMemoryError -XX:+HeapDumpOnOutOfMemoryError -XX:-OmitStackTraceInFastThrow -XX:ReservedCodeCacheSize=512M -XX:PerMethodRecompilationCutoff=10000 -XX:PerBytecodeRecompilationCutoff=10000 -Djdk.attach.allowAttachSelf=true -Djdk.nio.maxCachedBufferSize=2000000 -XX:+UnlockDiagnosticVMOptions -XX:+UseAESCTRIntrinsics Disable Preventive GC for performance reasons (JDK-8293861) -XX:-G1UsePreventiveGC

vi config.properties

coordinator=true #one single machine for test ,add this node-scheduler.include-coordinator=true http-server.http.port=8080 discovery.uri=http://ip:8080

vi log.properties

io.trino=INFO mkdir catalogc vi atalog/jmx.properties connector.name=jmx

3.启动trino server

bin/launcher run

4.客户端连接trino

./trino-cli-418-executable.jar --server http://ip:8080

5.python 连接trino

安装python trino 客户端

pip3 install trino

通过代码连接

from trino.dbapi import connect

conn = connect( host="localhost", port=8080, user="trino", )

cur = conn.cursor()

cur.execute("show catalogs")

rows = cur.fetchall()

for row in rows:

        print(row)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值