在安卓平台运行

从 v0.4.0 开始,GreptimeDB 支持在采用了 ARM64 CPU 和 Android API 23 版本以上的安卓平台运行。

安装终端模拟器

您可以从 GitHub release 页面 下载 Termux 终端模拟器 来运行 GreptimeDB.

下载 GreptimeDB 的二进制

请执行以下命令来下载安卓平台的 GreptimeDB 二进制:

  1. VERSION=$(curl -s -XGET "https://api.github.com/repos/GreptimeTeam/greptimedb/releases" | grep tag_name | grep -v nightly | cut -d: -f 2 | sed 's/.*"\(.*\)".*/\1/' | uniq | sort -r | head -n 1)
  2. curl -sOL "https://github.com/GreptimeTeam/greptimedb/releases/download/${VERSION}/greptime-android-arm64-${VERSION}.tar.gz"
  3. tar zxvf ./greptime-android-arm64-${VERSION}.tar.gz
  4. ./greptime -V

如果下载成功,以上命令将输出当前 GreptimeDB 的版本信息。

创建 GreptimeDB 的配置文件

您可以通过以下命令来创建一个最小化的配置文件以允许从局域网访问 GreptimeDB:

  1. DATA_DIR="$(pwd)/greptimedb-data"
  2. mkdir -p ${DATA_DIR}
  3. cat <<EOF > ./config.toml
  4. [http]
  5. addr = "0.0.0.0:4000"
  6. [grpc]
  7. addr = "0.0.0.0:4001"
  8. [mysql]
  9. addr = "0.0.0.0:4002"
  10. [storage]
  11. data_home = "${DATA_DIR}"
  12. type = "File"
  13. EOF

从命令行启动 GreptimeDB

  1. ./greptime --log-dir=$(pwd)/logs standalone start -c ./config.toml

从局域网连接运行在安卓设备上的 GreptimeDB

您可以通过ifconfig来获取您所使用的的安卓设备的网络地址。

在启动 GreptimeDB 后,您可以从局域网内安装了 MySQL 客户端的设备上通过 MySQL 协议访问 GreptimeDB。

  1. mysql -h <ANDROID_DEVICE_IP_ADDR> -P 4002

连接成功后,您可以像在任何其他平台一样使用运行在安卓设备上的 GreptimeDB!

  1. Welcome to the MySQL monitor. Commands end with ; or \g.
  2. Your MySQL connection id is 8
  3. Server version: 5.1.10-alpha-msql-proxy Greptime
  4. Copyright (c) 2000, 2023, Oracle and/or its affiliates.
  5. Oracle is a registered trademark of Oracle Corporation and/or its
  6. affiliates. Other names may be trademarks of their respective
  7. owners.
  8. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  9. mysql> CREATE TABLE monitor (env STRING, host STRING, ts TIMESTAMP, cpu DOUBLE DEFAULT 0, memory DOUBLE, TIME INDEX (ts), PRIMARY KEY(env,host));
  10. Query OK, 0 rows affected (0.14 sec)
  11. mysql> INSERT INTO monitor(ts, env, host, cpu, memory) VALUES
  12. -> (1655276557000,'prod', 'host1', 66.6, 1024),
  13. -> (1655276557000,'prod', 'host2', 66.6, 1024),
  14. -> (1655276557000,'prod', 'host3', 66.6, 1024),
  15. -> (1655276558000,'prod', 'host1', 77.7, 2048),
  16. -> (1655276558000,'prod', 'host2', 77.7, 2048),
  17. -> (1655276558000,'test', 'host3', 77.7, 2048),
  18. -> (1655276559000,'test', 'host1', 88.8, 4096),
  19. -> (1655276559000,'test', 'host2', 88.8, 4096),
  20. -> (1655276559000,'test', 'host3', 88.8, 4096);
  21. Query OK, 9 rows affected (0.14 sec)
  22. mysql>
  23. mysql> select * from monitor where env='test' and host='host3';
  24. +------+-------+---------------------+------+--------+
  25. | env | host | ts | cpu | memory |
  26. +------+-------+---------------------+------+--------+
  27. | test | host3 | 2022-06-15 15:02:38 | 77.7 | 2048 |
  28. | test | host3 | 2022-06-15 15:02:39 | 88.8 | 4096 |
  29. +------+-------+---------------------+------+--------+
  30. 2 rows in set (0.20 sec)