1、先修改内核参数
在启动doris的be时,需要将 Linux 操作系统的内核参数设置为2000000,这里是Doris官方要求的。
# 此代码无需运行,只是提示
sh-4.2# /opt/apache-doris-1.2.4.1-bin-x86_64/be/bin/start_be.sh --daemon
Please set vm.max_map_count to be 2000000 under root using 'sysctl -w vm.max_map_count=2000000'.
Linux系统修改内核参数
直接在Docker宿主机中设置即可
sudo sysctl -w vm.max_map_count=2000000
sysctl vm.max_map_count
MacOS 系统修改内核参数
无需停止doris容器,直接执行创建以下容器:
docker run -it --privileged --pid=host --name=change_count debian nsenter -t 1 -m -u -n -i sh
容器创建成功执行以下命令:
sysctl -w vm.max_map_count=2000000
然后再执行be启动命令即可。
2、下载Doris的运行环境镜像
这里面安装了doris启动需要的环境,不用自己再提前准备环境了,如jdk等。
docker pull apache/doris:build-env-ldb-toolchain-latest
3、下载安装包
# doris程序包
https://apache-doris-releases.oss-accelerate.aliyuncs.com/apache-doris-1.2.4.1-bin-x86_64.tar.xz
# mysql连接客户端
https://doris-build-hk.oss-cn-hongkong.aliyuncs.com/mysql-client/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
4、启动镜像环境
docker run -d -it --name=doris \
-p 9030:9030 -p 8030:8030 \
apache/doris:build-env-ldb-toolchain-latest \
/bin/bash
复制安装包到doris容器中
# 根据实际路径拷贝
docker cp D:/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz doris:/opt
docker cp D:/apache-doris-1.2.4.1-bin-x86_64.tar.xz doris:/opt
进入到容器中
# 进入容器
docker exec -it doris bash
# 解压文件
cd /opt/
tar -xvf apache-doris-1.2.4.1-bin-x86_64.tar.xz
tar -xzvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
# 获取本机容器内网ip地址,需修改到配置文件中。
hostname -i
5、配置fe
cd /opt/apache-doris-1.2.4.1-bin-x86_64/fe
vi conf/fe.conf
打开 priority_networks注释 将刚刚 【hostname -i】 打印出来的内网ip替换到
priority_networks = 172.17.0.2/24
接着启动fe
# 启动
./bin/start_fe.sh --daemon
# 查看java启动进程
jps
# 测试是否正常
curl http://127.0.0.1:8030/api/bootstrap
如下图所示表示启动成功
浏览器地址访问 http://localhost:8030/login,账号root,密码为空
接着在mysql中连接fe,默认无密码
/opt/mysql-5.7.22-linux-glibc2.12-x86_64/bin/mysql -uroot -P9030 -h127.0.0.1 --skip-ssl
show frontends\G;
看到像我这样IsMaster、Join 和 Alive 三列均为true,则表示节点正常
6、配置be
#退出mysql
exit;
#修改配置文件
cd /opt/apache-doris-1.2.4.1-bin-x86_64/be
vi conf/be.conf
和上面一样,替换内网ip
priority_networks = 172.17.0.2/24
然后在启动脚本中设置jdk的路径,我们这里下载的镜像的jdk的默认路径为 /usr/lib/jvm/java-1.8.0
可以先ehco确认一下,因为使用的是最新镜像,路径可能随时版本的变更而改变
echo $JAVA_HOME
vi bin/start_be.sh
export JAVA_HOME=/usr/lib/jvm/java-1.8.0
启动be,通过mysql客户端工具连接be,即在Doris中添加已经后端节点
# 启动be
./bin/start_be.sh --daemon
# 进入mysql
/opt/mysql-5.7.22-linux-glibc2.12-x86_64/bin/mysql -uroot -P9030 -h127.0.0.1 --skip-ssl
# 将BE节点加入到集群中
ALTER SYSTEM ADD BACKEND "172.17.0.2:9050";
# 显示doris后端详情
SHOW BACKENDS\G
Alive : true表示节点运行正常(如果为false,可以尝试等待一会再重新查看,第一次启动会慢一点;或有其他问题在/opt/apache-doris-1.2.4.1-bin-x86_64/be/log/be.out 里面查看日志)
正常启动的进程是这样的,会有一个空名字的进程,正常,就是be
7、建表测试
第一次接触doris的同学可能会疑惑,怎么语法与MySQL差不多,其实这里建表语句就提现出来了,下面的DDL,在MySQL是无法运行的
这里使用MySQL仅作为远程连接工具,在实际使用中仅需启动fe与be即可,Doris自动启动和管理内部的 MySQL 实例,用于存储和管理元数据
进入mysql命令:
/opt/mysql-5.7.22-linux-glibc2.12-x86_64/bin/mysql -uroot -P9030 -h127.0.0.1 --skip-ssl
执行如下SQL语句:
create database demo;
use demo;
CREATE TABLE IF NOT EXISTS demo.example_tbl
(
`user_id` LARGEINT NOT NULL COMMENT "user id",
`date` DATE NOT NULL COMMENT "",
`city` VARCHAR(20) COMMENT "",
`age` SMALLINT COMMENT "",
`sex` TINYINT COMMENT "",
`last_visit_date` DATETIME REPLACE DEFAULT "1970-01-01 00:00:00" COMMENT "",
`cost` BIGINT SUM DEFAULT "0" COMMENT "",
`max_dwell_time` INT MAX DEFAULT "0" COMMENT "",
`min_dwell_time` INT MIN DEFAULT "99999" COMMENT ""
)
AGGREGATE KEY(`user_id`, `date`, `city`, `age`, `sex`)
DISTRIBUTED BY HASH(`user_id`) BUCKETS 1
PROPERTIES (
"replication_allocation" = "tag.location.default: 1"
);
exit;
新建一个数据文件
cd ~
vi test.csv
test.csv 内容
10000,2017-10-01,beijing,20,0,2017-10-01 06:00:00,20,10,10
10006,2017-10-01,beijing,20,0,2017-10-01 07:00:00,15,2,2
10001,2017-10-01,beijing,30,1,2017-10-01 17:05:45,2,22,22
10002,2017-10-02,shanghai,20,1,2017-10-02 12:59:12,200,5,5
10003,2017-10-02,guangzhou,32,0,2017-10-02 11:20:00,30,11,11
10004,2017-10-01,shenzhen,35,0,2017-10-01 10:00:15,100,3,3
10004,2017-10-03,shenzhen,35,0,2017-10-03 10:20:22,11,6,6
导入数据
curl --location-trusted -u root: -T test.csv -H "column_separator:," http://127.0.0.1:8030/api/demo/example_tbl/_stream_load
执行详情:
查询数据
# mysql客户端连接be
/opt/mysql-5.7.22-linux-glibc2.12-x86_64/bin/mysql -uroot -P9030 -h127.0.0.1 --skip-ssl
mysql> use demo;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from example_tbl;
+---------+------------+-----------+------+------+---------------------+------+----------------+----------------+
| user_id | date | city | age | sex | last_visit_date | cost | max_dwell_time | min_dwell_time |
+---------+------------+-----------+------+------+---------------------+------+----------------+----------------+
| 10000 | 2017-10-01 | beijing | 20 | 0 | 2017-10-01 06:00:00 | 20 | 10 | 10 |
| 10001 | 2017-10-01 | beijing | 30 | 1 | 2017-10-01 17:05:45 | 2 | 22 | 22 |
| 10002 | 2017-10-02 | shanghai | 20 | 1 | 2017-10-02 12:59:12 | 200 | 5 | 5 |
| 10003 | 2017-10-02 | guangzhou | 32 | 0 | 2017-10-02 11:20:00 | 30 | 11 | 11 |
| 10004 | 2017-10-01 | shenzhen | 35 | 0 | 2017-10-01 10:00:15 | 100 | 3 | 3 |
| 10004 | 2017-10-03 | shenzhen | 35 | 0 | 2017-10-03 10:20:22 | 11 | 6 | 6 |
| 10006 | 2017-10-01 | beijing | 20 | 0 | 2017-10-01 07:00:00 | 15 | 2 | 2 |
+---------+------------+-----------+------+------+---------------------+------+----------------+----------------+
7 rows in set (0.05 sec)
mysql> select * from example_tbl where city='beijing';
+---------+------------+---------+------+------+---------------------+------+----------------+----------------+
| user_id | date | city | age | sex | last_visit_date | cost | max_dwell_time | min_dwell_time |
+---------+------------+---------+------+------+---------------------+------+----------------+----------------+
| 10000 | 2017-10-01 | beijing | 20 | 0 | 2017-10-01 06:00:00 | 20 | 10 | 10 |
| 10001 | 2017-10-01 | beijing | 30 | 1 | 2017-10-01 17:05:45 | 2 | 22 | 22 |
| 10006 | 2017-10-01 | beijing | 20 | 0 | 2017-10-01 07:00:00 | 15 | 2 | 2 |
+---------+------------+---------+------+------+---------------------+------+----------------+----------------+
3 rows in set (0.02 sec)
mysql> select city, sum(cost) as total_cost from example_tbl group by city;
+-----------+------------+
| city | total_cost |
+-----------+------------+
| beijing | 37 |
| shanghai | 200 |
| guangzhou | 30 |
| shenzhen | 111 |
+-----------+------------+
4 rows in set (0.03 sec)
8、远程连接
默认无密码
除了三方工具,还可以访问ui界面 Playground
至此安装完成。
启动命令
/opt/apache-doris-1.2.4.1-bin-x86_64/fe/bin/start_fe.sh --daemon
/opt/apache-doris-1.2.4.1-bin-x86_64/be/bin/start_be.sh --daemon
关闭命令
/opt/apache-doris-1.2.4.1-bin-x86_64/fe/bin/stop_fe.sh
/opt/apache-doris-1.2.4.1-bin-x86_64/be/bin/stop_be.sh
注意:
docker重启后ip会变,启动后先查看hostname -i是否跟之前的一致,不一致可以关掉有影响的docker容器重新按ip顺序启动,或者改成固定IP。