参考:https://www.hellodemos.com/hello-influxdb/influxdb-hardware-sizing.html
MAC安装influxdb
brew update
brew install influxdb
ln -sfv /usr/local/opt/influxdb/*.plist ~/Library/LaunchAgents
#配置文件在/etc/influxdb/influxdb.conf ,如果没有就将/usr/local/etc/influxdb.conf 拷一个过去
配置缓存:cache-max-memory-size
#启动服务
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.influxdb.plist
#停止服务
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.influxdb.plist
#指定配置文件启动服务
influxd -config /usr/local/etc/influxdb.conf
遇到问题:端口被占用
解决方法: (1)执行launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.influxdb.plist停止服务
(2)修改配置文件并重新启动
查看influxdb运行配置
influxd config
linux安装influxDB(jmeter配置版本)
一、新建InfluxDB下载源
cat << EOF | tee /etc/yum.repos.d/influxdb.repo
[influxdb]
name = InfluxDB Repository - RHEL $releasever
baseurl = https://repos.influxdata.com/rhel/$releasever/$basearch/stable
enabled = 1
gpgcheck = 1
gpgkey = https://repos.influxdata.com/influxdb.key
EOF
二、使用yum下载InfluxDB
yum install -y influxdb
三、修改InfluxDB的配置,主要配置jmeter存储的数据库与端口号,还有需要将UI端口开放
[root@localhost ~]# vi /etc/influxdb/influxdb.conf
#找到graphite并且修改它的库与端口
[[graphite]]
enabled = true
database = “jmeter”
bind-address = “:2003”
protocol = “tcp”
consistency-level = “one”
#找到admin,将前面的#号去掉,开放它的UI端口
[admin]
Determines whether the admin service is enabled.
enabled = true
The default bind address used by the admin service.
bind-address = “:8083”
Whether the admin service should use HTTPS.
https-enabled = false
The SSL certificate used when HTTPS is enabled.
https-certificate = "/etc/ssl/influxdb.pem
四、启动InfluxDB
[root@localhost ~]# /etc/init.d/influxdb restart
Stopping influxdb…
influxdb process was stopped [ OK ]
Starting influxdb…
influxdb process was started [ OK ]
五、打开浏览器,访问虚拟机IP“http://192.168.245.131:8083”
如果启动成功应该会InfluxDB的web ui界面。查看有没有jmeter库,没有就新建一个。
六、在输入框中,输入如下,来新建库:
CREATE DATABASE “jmeter”
influxdb 基本概念
Database(绿色白框):数据库,可在这一层级做读写权限控制和数据保留时间(Retention policy)。
Measurement(紫色区域):表,包含tags,fields和time。
tag(蓝色区域):索引列,图中有n个tag。
sereis:由retention policy,Measurement、tag不同值的组合定位一个series。一个Series是多个时间序列的集合。
field(绿色区域):一个series会包含多个field,每一个field对应一个实际的时间序列。
point:红色的一行就是一个point,Series+time定位一个point。一个point是一个时间带多个field的名字和field的值。
数据库操作
influx进入命令行
influx带参数: influx -host 127.0.0.1 -port 9086
查询当前的所有数据库
show databases
1、创建数据库
create database mydb
2、删除数据库
drop database mydb
3、使用数据库
use mydb
4、插入数据库
insert mt,type=item,sensor=sensor01 value=3,is_delete=0
注意:第一次插入数据会确定数据类型,之后的插入不能换数据类型。
插入同一时间的数据会覆盖旧的,时间是主键。可以乱序插入。
5、查询
select * from jmeter
where 中对字符串的过滤必须用单引号,tag默认为字符串类型
显示所有表
show measurements
InfluxDB进行HTTP API查询
使用HTTP API在InfluxDB进行查询主要是发送 GET 请求到 InfluxDB的 /query 端,调用示例如下所示:
curl -GET ‘http://localhost:8086/query?pretty=true’ --data-urlencode “db=mydb”
–data-urlencode “q=SELECT value FROM mt WHERE name = ‘mengtao’”
参数db指定了需查询的数据库,q代表了需执行的查询语句。
我们可能需要用InfluxDB进行多条查询,HTTP API提供的多条查询的格式如下所示:
curl -G ‘http://localhost:8086/query?pretty=true’ --data-urlencode “db=mydb” --data-urlencode "q=SELECT value FROM mt WHERE name=‘mengtao’;
SELECT count(value) FROM mt WHERE name=‘mengtao’"
格式与单条查询相同,只是在多条语句之间要用分号“;”分隔。
返回值也是包含结果的json串。
influxdb数据保留策略
influxdb库的每个表默认只能存储100000条数据,表满之后新的数据便无法入库