下载地址:https://dl.influxdata.com/influxdb/releases/influxdb2-2.0.3_linux_amd64.tar.gz
安装influxdb
### 解压
[root@jyzbdb2 soft]# tar -zxf influxdb2-2.0.3_linux_amd64.tar.gz
### 设置环境变量
[root@jyzbdb2 influxdb2-2.0.3_linux_amd64]# vim /etc/profile
...
export PATH=$PATH:/app/soft/influxdb2-2.0.3_linux_amd64
...
### 使环境变量生效
[root@jyzbdb2 influxdb2-2.0.3_linux_amd64]# source /etc/profile
启动
方式一:直接在终端中启动(该方式启动后,退出终端进程也随之终止,原因不明)
[root@jyzbdb2 influxdb2-2.0.3_linux_amd64]# nohup influxd >> /app/soft/influxdb2-2.0.3_linux_amd64/influx.log 2>&1 &
方式二:设置成服务启动
### 添加 influxdb 用户,用于启动 influxdb 服务
[root@jyzbdb2 influxdb2-2.0.3_linux_amd64]# groupadd influxdb
[root@jyzbdb2 influxdb2-2.0.3_linux_amd64]# useradd -g influxdb -s /bin/false influxdb
### 新增 influxdb 配置文件(这个文件主要用于 influxdb 的优化;如果没有性能问题,也可以不用配置)
[root@jyzbdb2 influxdb2-2.0.3_linux_amd64]# vim config.yml
storage-cache-max-memory-size: 4294967296
### 修改文件的权限
[root@jyzbdb2 influxdb2-2.0.3_linux_amd64]# chown -R influxdb:influxdb /app/soft/influxdb2-2.0.3_linux_amd64
### 新增系统服务的启动文件
### ExecStart后面的参数可以不加,也可以根据实际更改。具体参考:https://docs.influxdata.com/influxdb/v2.0/reference/config-options
[root@jyzbdb2 influxdb2-2.0.3_linux_amd64]# vim /usr/lib/systemd/system/influxdb.service
[Unit]
Description=InfluxDB is an open-source, distributed, time series database
Documentation=https://docs.influxdata.com/influxdb/
After=network-online.target
[Service]
User=influxdb
Group=influxdb
LimitNOFILE=65536
ExecStart=/app/soft/influxdb2-2.0.3_linux_amd64/influxd --storage-cache-max-memory-size=4294967296 --bolt-path=/data/influxdb-data/influxd.bolt --engine-path=/data/influxdb-data/engine
KillMode=control-group
Restart=on-failure
[Install]
WantedBy=multi-user.target
### 启动服务
[root@jyzbdb2 influxdb2-2.0.3_linux_amd64]# systemctl start influxdb
### 查看服务状态
[root@jyzbdb2 influxdb2-2.0.3_linux_amd64]# systemctl status influxdb
### 设置为开机启动
[root@jyzbdb2 influxdb2-2.0.3_linux_amd64]# systemctl enable influxdb
配置
### 初始化
[root@jyzbdb2 influxdb2-2.0.3_linux_amd64]# influx setup
Welcome to InfluxDB 2.0!
Please type your primary username: jygz
Please type your password:
Please type your password again:
Please type your primary organization name: copote
Please type your primary bucket name: gps
Please type your retention period in hours.
Or press ENTER for infinite.:
You have entered:
Username: jygz
Organization: copote
Bucket: gps
Retention Period: infinite
Confirm? (y/n): y
Config default has been stored in /root/.influxdbv2/configs.
User Organization Bucket
jygz copote gps
### 查看 token(客户端一般通过token进行操作)
[root@jyzbdb2 influxdb2-2.0.3_linux_amd64]# cat /root/.influxdbv2/configs
[default]
url = "http://localhost:8086"
token = "qPhb-sP__WM3w0U_nhJIYIcfDB0Q1yJ26PqiqwE9_8wL0LrAXoTjm4cT1j0hC4wGWUJsu4BSN-5bev_nS4GRmA=="
org = "copote"
active = true
关于防火墙
8086 端口:使用该端口与influxdb客户端进行数据交互。
# 开放端口
firewall-cmd --zone=public --add-port=8086/tcp --permanent
# 配置立即生效
firewall-cmd --reload
# 查看防火墙所有开放的端口
firewall-cmd --zone=public --list-ports
使用 influxdb api的方式进行操作
### 添加数据(多条):
curl --request POST 'http://200.200.200.71:8086/api/v2/write?org=copote&bucket=gps&precision=ms' \
--header 'Authorization: Token N6M048DSeVq6s93aZRkjX5bqqCAQKaPCbf56NjjjuO28J3EZdywx0_df7RNlGy925AYRi2NS_rRwxsfsUVaVEA==' \
--data '
test,id=1 username="tom" 1609299009330
test,id=1 age=12 1609299009330
'
### 添加数据(单条):
curl --request POST 'http://200.200.200.71:8086/api/v2/write?org=copote&bucket=gps&precision=ms' </span>
--header 'Authorization: Token N6M048DSeVq6s93aZRkjX5bqqCAQKaPCbf56NjjjuO28J3EZdywx0_df7RNlGy925AYRi2NS_rRwxsfsUVaVEA==' </span>
--data 'test,id=1 realname="汤姆" 1609299009330'
### 查询数据:
curl --request POST 'http://200.200.200.71:8086/api/v2/query?org=copote' </span>
--header 'Authorization: Token N6M048DSeVq6s93aZRkjX5bqqCAQKaPCbf56NjjjuO28J3EZdywx0_df7RNlGy925AYRi2NS_rRwxsfsUVaVEA==' </span>
--header 'Accept: application/csv' </span>
--header 'Content-type: application/vnd.flux' </span>
--data 'import "experimental/geo"
from(bucket:"gps")
|> range(start: -12h)
|> filter(fn: (r) => r._measurement == "test")
|> geo.toRows()'
### 删除数据:
curl --request POST 'http://200.200.200.71:8086/api/v2/delete?org=copote&bucket=gps' </span>
--header 'Authorization: Token N6M048DSeVq6s93aZRkjX5bqqCAQKaPCbf56NjjjuO28J3EZdywx0_df7RNlGy925AYRi2NS_rRwxsfsUVaVEA==' </span>
--header 'Content-Type: application/json' </span>
--data '{
"start": "2020-12-30T00:00:00Z",
"stop": "2020-12-31T00:00:00Z",
"predicate": "_measurement="test" and id="1""
}'
使用 influxdb 客户端命令的方式进行操作
### 删除数据:
influx delete --bucket gps --org copote \
--host 'http://200.200.200.71:8086' \
--token 'N6M048DSeVq6s93aZRkjX5bqqCAQKaPCbf56NjjjuO28J3EZdywx0_df7RNlGy925AYRi2NS_rRwxsfsUVaVEA==' \
--start '2020-12-30T00:00:00Z' \
--stop '2020-12-31T00:00:00Z' \
--predicate '_measurement="test" and id="1"'