安装 Presto
1. 下载 Presto Server 包
wget https://repo1.maven.org/maven2/com/facebook/presto/presto-server/0.267/presto-server-0.267.tar.gz
2. 解压缩
tar -zxvf presto-server-0.267.tar.gz
3. 配置 Presto Server
a. 进入 Presto Server 目录
cd presto-server-0.267
b. 创建配置文件
mkdir etc
cd etc
cp ../etc/node.properties .
cp ../etc/config.properties .
c. 修改配置文件
i. node.properties
```properties
node.environment=production
node.id=ffffffff-ffff-ffff-ffff-ffffffffffff
node.data-dir=/var/presto/data
```
其中 `node.id` 需要是一个全局唯一的 UUID。
ii. config.properties
```properties
coordinator=true
node-scheduler.include-coordinator=true
http-server.http.port=8080
query.max-memory=5GB
query.max-memory-per-node=1GB
discovery-server.enabled=true
discovery.uri=http://localhost:8080
```
其中 `http-server.http.port` 是 Presto Server 的监听端口。
4. 启动 Presto Server
bin/launcher start
5. 验证 Presto Server 是否启动成功
a. 打开 Presto Web UI
在浏览器中打开 http://localhost:8080/ui/
。
b. 执行查询
在 Presto Web UI 中,输入以下 SQL 查询语句:
SELECT * FROM system.runtime.nodes;
如果查询成功,说明 Presto Server 安装成功。
实现 Mysql 跨库数据查询
1. 安装 Presto Mysql Connector
a. 下载 Presto Mysql Connector 包
wget https://repo1.maven.org/maven2/com/facebook/presto/presto-jdbc/0.267/presto-jdbc-0.267.jar
b. 将 Presto Mysql Connector 包放入 Presto Server 的插件目录
cp presto-jdbc-0.267.jar presto-server-0.267/plugin/mysql/
2. 创建 Mysql 数据源配置文件
a. 进入 Presto Server 的配置目录
cd presto-server-0.267/etc/
b. 创建 Mysql 数据源配置文件
touch catalog/mysql.properties
c. 编辑 Mysql 数据源配置文件
connector.name=mysql
connection-url=jdbc:mysql://localhost:3306
connection-user=root
connection-password=123456
其中 connection-url
是 Mysql 数据库的连接 URL,connection-user
和 connection-password
是 Mysql 数据库的用户名和密码。
3. 创建 Mysql 表
在 Mysql 数据库中创建两个表,例如 database1.table1
和 database2.table2
。
4. 创建 Presto Schema
a. 进入 Presto Server 的插件目录
cd presto-server-0.267/plugin/mysql/
b. 创建 Presto Schema
mkdir mysql_schema
cd mysql_schema
touch etc/schema.ini
c. 编辑 Presto Schema
[database1]
connection-url=jdbc:mysql://localhost:3306/database1
connection-user=root
connection-password=123456
[database2]
connection-url=jdbc:mysql://localhost:3306/database2
connection-user=root
connection-password=123456
其中 [database1]
和 [database2]
是 Presto Schema 的名称,connection-url
、connection-user
和 connection-password
是连接 Mysql 数据库的参数。
5. 执行跨库查询
在 Presto Web UI 中,输入以下 SQL 查询语句:
SELECT *
FROM mysql.database1.table1 t1
JOIN mysql.database2.table2 t2 ON t1.id = t2.id;
如果查询成功,说明 Presto Mysql Connector 安装成功,并且可以实现 Mysql 跨库数据查询。