「雲原生」Presto/Trino on k8s 環境部署

大數據老司機 發佈 2022-10-04T18:53:37.492199+00:00

Presto是Facebook開源的MPP架構的OLAP,完全基於內存的並⾏計算,可針對不同數據源,執行大容量數據集的一款分布式SQL交互式查詢引擎。

一、概述

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官方文檔:https://prestodb.io/docs/current/

Trino官方文檔:https://trino.io/docs/current/

了解更多也可以參考我這篇文章:大數據Hadoop之——基於內存型SQL查詢引擎Presto(Presto-Trino環境部署)

二、環境部署

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

1)添加源並下載編排部署包

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

2)構建鏡像

Dockerfile

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 https://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,其它版本暫時是不支持的。

開始構建鏡像

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
...
### 主要新增了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)開始部署

# 安裝
helm install trino ./trino -n trino --create-namespace
# 更新
helm upgrade trino ./trino -n trino

NOTES

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


查看

kubectl get pods,svc -n trino -owide


web 地址:http://192.168.182.110:31080/
用戶任意值


5)測試驗證

下載客戶端

wget https://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 測試

./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 中創建資料庫、數據表和數據

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中查詢

./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)卸載

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下載地址:https://gitee.com/hadoop-bigdata/presto-on-k8s

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

關鍵字: