1、安装influxdb-0.13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
[root@imzcy ~]# rpm -ivh influxdb-0.13.0.x86_64.rpm 准备中... ################################# [100%] 正在升级/安装... 1:influxdb-0.13.0-1 ################################# [100%] Created symlink from /etc/systemd/system/influxd.service to /usr/lib/systemd/system/influxdb.service. Created symlink from /etc/systemd/system/multi-user.target.wants/influxdb.service to /usr/lib/systemd/system/influxdb.service. [root@imzcy ~]# //安装过程会在系统中创建influxdb用户;并且它会把自己添加到系统服务里面,设置为开机自动启动。 [root@imzcy ~]# tail -n 1 /etc/passwd influxdb:x:989:984::/var/lib/influxdb:/bin/false [root@imzcy ~]# [root@imzcy ~]# systemctl list-unit-files |grep influxdb influxdb.service enabled [root@imzcy ~]# |
2、直接使用systemctl启动即可,启动后influxdb默认会开启监听以下三个端口
1 2 3 4 5 6 7 |
[root@imzcy ~]# systemctl start influxdb [root@imzcy ~]# ss -tnl |grep 80 LISTEN 0 128 :::8083 :::* LISTEN 0 128 :::8086 :::* LISTEN 0 128 :::8088 :::* [root@imzcy ~]# |
3、直接输入命令influx即可进入CLI配置界面
1 2 3 4 5 |
[root@imzcy ~]# influx Visit https://enterprise.influxdata.com to register for updates, InfluxDB server management, and monitoring. Connected to http://localhost:8086 version 0.13.0 InfluxDB shell version: 0.13.0 > |
4、常用命令介绍
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
4.1、查询当前有哪些数据库 > SHOW DATABASES name: databases --------------- name _internal > 4.2、切换到_internal数据库 > USE _internal Using database _internal > 4.3、查询数据库中有哪些表 > SHOW MEASUREMENTS name: measurements ------------------ name database httpd queryExecutor runtime shard subscriber tsm1_cache tsm1_wal write > 4.4、创建数据库 > CREATE DATABASE zcydb > 4.5、创建一个表 > USE zcydb Using database zcydb > INSERT cpu,host=serverA,region=us_west value=0.64 4.6、查询表内容(time为数据插入时的时间戳,可以在启动CLI时指定时间戳显示格式,详见5) > SELECT * FROM cpu name: cpu --------- time host region value 1534068503522425989 serverA us_west 0.64 > 4.7、退出 > exit [root@imzcy ~]# |
5、指定influxdb时间戳显示格式
使用-precision参数指定任何返回的时间戳的格式/精度。在下面的示例中,rfc3339告诉InfluxDB以RFC3339格式(YYYY-MM-DDTHH:MM:SS.nnnnnnnnnZ)返回时间戳。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
[root@imzcy ~]# influx -precision rfc3339 Visit https://enterprise.influxdata.com to register for updates, InfluxDB server management, and monitoring. Connected to http://imzcy:8086 version 0.13.0 InfluxDB shell version: 0.13.0 > > USE zcydb Using database zcydb > > SELECT * FROM cpu name: cpu --------- time host region value 2018-08-12T10:08:23.522425989Z serverA us_west 0.64 2018-08-13T07:08:10.821181699Z serverA us_west 0.89 > > exit [root@imzcy ~]# |