之前安装的starRocks没有同步hdfs的数据,所以一直也没有安装Broker 服务,现记录一下部署broker 后将数据load进starRocks 表的过程,我目前部署的是 StarRocks-2.1.4 还没有升级,后续记录一次升级
1,部署Boker
参考地址 https://docs.starrocks.com/zh-cn/2.1/quick_start/Deploy
cd StarRocks-2.1.4/apache_hdfs_broker/conf
cp ../../hadoop-3.1.3/etc/hadoop/hdfs-site.xml ./
ll
总用量 16
-rw-rw-r-- 1 gadmin gadmin 925 7月 12 17:43 apache_hdfs_broker.conf
-rw-r--r-- 1 gadmin gadmin 1235 7月 12 17:45 hdfs-site.xml
-rw-rw-r-- 1 gadmin gadmin 1489 4月 7 20:05 hdfs-site.xml.bak
-rw-rw-r-- 1 gadmin gadmin 336 4月 7 20:05 log4j.properties
这样就算是配置好了broker 就可以访问hdfs了
启动broker 服务,可以看到多了一个 BrokerBootstrap 进程
[XXXX apache_hdfs_broker]$ bin/start_broker.sh --daemon
[XXXX apache_hdfs_broker]$ jps
3649 Jps
28856 StarRocksFE
17578 BrokerBootstrap
再在mysql cli中添加broker节点,集群安装在三个节点,就启动三个broker,命名为 broker1
MySQL> ALTER SYSTEM ADD BROKER broker1 "172.16.139.24:8000";
MySQL> ALTER SYSTEM ADD BROKER broker1 "172.16.139.25:8000";
MySQL> ALTER SYSTEM ADD BROKER broker1 "172.16.139.26:8000";
2,在starRocks cli 执行load
参照官网文档编写load
LOAD LABEL ods.label1
(
DATA INFILE("hdfs://xxxx:8020/user/hive/warehouse/ods.db/xxxx/dt=${dt}/*")
INTO TABLE ods_xxxx
COLUMNS TERMINATED BY "\\x02"
FORMAT AS parquet
(mandt ,cpudt ,budat ,bukrs ,conno ,konnr ,lifnr ,mblnr ,zeile ,matnr ,charg ,werks ,bwart ,ebeln ,ebelp ,knumv ,menge ,meins ,dmbtr ,zsl,waers ,abtnr ,prdha ,yewjx ,level4,level3,level2) -- 这里写的是hdfs中数据的列的命名,不是starrocks中的表字段
SET
(
dt='${dt}', -- 这里设置一些映射,key是starrocks表的字段,value可以取上面hdfs中定义的字段作为值
matnr=right(matnr,9)
)
)
WITH BROKER 'broker1' # 部署broker时定义的broker1为它的名称
(
"username" = "xxx",
"password\" = "xxx"
)
PROPERTIES
(
"timeout" = "3600"
);
在msyql cli执行后,查看数据是否同步成功
mysql > show load where label = 'label1'\G
将脚本写在shell脚本执行
[xxx xxx]$ more push_data_to_starrocks.sh
#!/bin/bash
if [ $# -eq 1 ];then
dt=$1
elif [ $# -eq 0 ];then
dt=`date -d "-1 days" +"%Y%m%d"`
else
echo "参数不正确"
exit 1
fi
echo ${dt}
source /etc/profile;
mysql -P9030 -h127.0.0.1 -uxxxx -p'xxx' -e "
LOAD LABEL ods.label_pall_${dt}
(
DATA INFILE(\"hdfs://xxx:8020/user/hive/warehouse/ods.db/xxx/dt=${dt}/*\")
INTO TABLE ods_xxxx
COLUMNS TERMINATED BY \"\\x02\"
FORMAT AS parquet
(mandt ,cpudt ,budat ,bukrs ,conno ,konnr ,lifnr ,mblnr ,zeile ,matnr ,charg ,werks ,bwart ,ebeln ,ebelp ,knumv ,menge ,meins ,dmbtr ,zsl,waers ,abtnr ,prdha ,yewjx ,leve
l4,level3,level2)
SET
(
dt='${dt}',
matnr=right(matnr,9)
)
)
WITH BROKER 'broker1'
(
\"username\" = \"xxx\",
\"password\" = \"xxx\"
)
PROPERTIES
(
\"timeout\" = \"3600\"
);
"
当前版本的starRocks不是最新版本2.3,后续记录一次升级过程,官网有很详细的文档,但是我还是喜欢将一些自己操作的过程记录一下