【雲原生】Presto/Trino on k8s 環境部署

語言: CN / TW / HK

一、概述

Presto是Facebook開源的MPP(Massively Parallel Processing:大規模並行處理)架構的OLAP(on-line transaction processing:聯機事務處理),完全基於記憶體的並⾏計算,可針對不同資料來源,執行大容量資料集的一款分散式SQL互動式查詢引擎。 它是為了解決Hive的MapReduce模型太慢以及不能通過BI或Dashboards直接展現HDFS資料等問題。

但是Presto目前有兩大分支:PrestoDB(背靠Facebook)和PrestoSQL現在改名為Trino(Presto的創始團隊),雖然PrestoDB背靠Facebook,但是社群活躍度和使用群體還是遠不如Trino。所以這裡以Trino為主展開講解。

PrestoDB官方文件:http://prestodb.io/docs/current/

Trino官方文件:http://trino.io/docs/current/

瞭解更多也可以參考我這篇文章:大資料Hadoop之——基於記憶體型SQL查詢引擎Presto(Presto-Trino環境部署)

在這裡插入圖片描述

二、環境部署

地址:http://artifacthub.io/packages/helm/trino/trino

1)新增源並下載編排部署包

bash helm repo add trino http://trinodb.github.io/charts/ helm pull trino/trino --version 0.8.0 tar -xf trino-0.8.0.tgz

2)構建映象

Dockerfile ```bash FROM myharbor.com/bigdata/centos:7.9.2009

RUN rm -f /etc/localtime && ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" > /etc/timezone

RUN export LANG=zh_CN.UTF-8

建立使用者和使用者組,跟yaml編排裡的spec.template.spec.containers. securityContext.runAsUser: 1000

RUN groupadd --system --gid=1000 admin && useradd --system --home-dir /home/admin --uid=1000 --gid=admin admin

安裝sudo

RUN yum -y install sudo ; chmod 640 /etc/sudoers

給admin新增sudo許可權

RUN echo "admin ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers

RUN yum -y install install net-tools telnet wget

RUN mkdir /opt/apache/

JDK

wget http://cdn.azul.com/zulu/bin/zulu17.36.17-ca-jdk17.0.4.1-linux_x64.tar.gz

ADD zulu17.36.17-ca-jdk17.0.4.1-linux_x64.tar.gz /opt/apache/ ENV JAVA_HOME=/opt/apache/zulu17.36.17-ca-jdk17.0.4.1-linux_x64 ENV PATH=$JAVA_HOME/bin:$PATH

trino

ADD trino-server-398.tar.gz /opt/apache/ ENV TRINO_HOME=/opt/apache/trino-server-398 ENV PATH=$TRINO_HOME/bin:$PATH

RUN chown -R admin:admin /opt/apache

WORKDIR $TRINO_HOME

ENTRYPOINT $TRINO_HOME/bin/launcher run --verbose ```

【溫馨提示】這裡jdk只能使用jdk17,其它版本暫時是不支援的。

在這裡插入圖片描述

開始構建映象 ```bash docker build -t myharbor.com/bigdata/trino:398 . --no-cache

引數解釋

-t:指定映象名稱

. :當前目錄Dockerfile

-f:指定Dockerfile路徑

--no-cache:不快取

推送harbor

docker push myharbor.com/bigdata/trino:398

刪除映象

crictl rmi myharbor.com/bigdata/trino:398 ```

3)修改配置

這裡只加了hive和mysql catalog,小夥伴可以自行新增其它catalog就行。 - trino/values.yaml

```bash ...

主要新增了catalog

additionalCatalogs: mysql: |- connector.name=mysql connection-url=jdbc:mysql://mysql-primary.mysql:3306 connection-user=root connection-password=WyfORdvwVm hive: |- connector.name=hive hive.metastore.uri=thrift://hadoop-ha-hadoop-hive-metastore.hadoop-ha:9083 ... ```

4)開始部署

```bash

安裝

helm install trino ./trino -n trino --create-namespace

更新

helm upgrade trino ./trino -n trino ``` NOTES

bash NAME: trino LAST DEPLOYED: Sun Oct 2 20:13:44 2022 NAMESPACE: trino STATUS: deployed REVISION: 1 TEST SUITE: None NOTES: Get the application URL by running these commands: export NODE_PORT=$(kubectl get --namespace trino -o jsonpath="{.spec.ports[0].nodePort}" services trino) export NODE_IP=$(kubectl get nodes --namespace trino -o jsonpath="{.items[0].status.addresses[0].address}") echo http://$NODE_IP:$NODE_PORT 在這裡插入圖片描述 檢視

bash kubectl get pods,svc -n trino -owide 在這裡插入圖片描述 web 地址:http://192.168.182.110:31080/ 使用者任意值 在這裡插入圖片描述 在這裡插入圖片描述

5)測試驗證

下載客戶端

```bash wget http://repo1.maven.org/maven2/io/trino/trino-cli/398/trino-cli-398-executable.jar chmod +x trino-cli-398-executable.jar

登入

./trino-cli-398-executable.jar --server http://192.168.182.110:31080 --user=admin show catalogs; ``` 在這裡插入圖片描述

1、mysql catalog 測試

```bash ./trino-cli-398-executable.jar --server http://192.168.182.110:31080 --user=admin --catalog=mysql

這裡的schema就是database

show schemas; create schema trino_test; create table trino_test.user(id int not null, username varchar(32) not null, password varchar(32) not null); insert into trino_test.user values(1,'user1','pwd1'); insert into trino_test.user values(2,'user2','pwd2'); insert into trino_test.user values(3,'user3','pwd2');

查詢

select * from trino_test.user; ``` 在這裡插入圖片描述

2、hive catalog 測試

在 Hive 中建立資料庫、資料表和資料

bash create schema test; show databases; CREATE TABLE test.users(id int, username string, password string) ROW FORMAT DELIMITED FIELDS TERMINATED BY ','; show tables from test; insert into table test.users values (1, 'user1', 'password1'), (2, 'user2', 'password2'), (3, 'user3', 'password3'); select * from test.users; 在presto中查詢 bash ./trino-cli-398-executable.jar --server http://192.168.182.110:31080 --user=admin --catalog=hive show schemas; show tables from test; select * from hive.test.users;

【溫馨提示】不建議在presto中建立庫表,一般presto只是作為查詢引擎。

6)解除安裝

```bash helm uninstall trino -n trino

kubectl delete pod -n trino kubectl get pod -n trino|awk 'NR>1{print $1}' --force kubectl patch ns trino -p '{"metadata":{"finalizers":null}}' kubectl delete ns trino --force ``` git下載地址:http://gitee.com/hadoop-bigdata/presto-on-k8s

Presto/Trino on k8s 環境部署就先到這裡,有不清楚的小夥伴,歡迎給我留言,後續會持續更新【雲原生+大資料】教程,請小夥伴耐心等待~