官方文档:https://docs.influxdata.com/influxdb/v2/
1.下载
需要下载两样东西:influxd.exe和influx.exe
influxd:influx数据库的服务端。下载地址:https://dl.influxdata.com/influxdb/releases/influxdb2-2.7.5-windows.zip
influx:连接influx数据库用的cli工具。下载地址:https://dl.influxdata.com/influxdb/releases/influxdb2-client-2.7.3-windows-amd64.zip
下载后解压,都放到一个文件夹里:
2.启动
2.1 默认配置启动
在该目录下打开命令窗口,输入influxd.exe
即可启动 :
打开网址:http://localhost:8086
点击GET STARTED,然后输入一些基本信息,点击Continue
上面那个token需要记录下来,连接数据库的时候会使用到
2.2 自定义配置启动
可以直接从默认配置直接复制文件到自定义配置文件夹,然后更改配置文件路径
使用influx
(cli)连接默认配置的influxd
step1:设置influx的连接,打开Power shell,输入如下命令
.\influx config create --config-name test `
--host-url "http://localhost:8086" `
--org "manager" `
--token "TH5iC0E9q8KeUcBHipEf4yGh83lapZRKst-PjxMHLcEySFa-sIbM9V_edGrSR2tKeMqgAQ9ST1HwTbc95cUznw==" `
--active
step2:导出数据库服务端的运行配置
.\influx server-config > config.json
可以看到在目录下生成了一个config.json
的文件
可以看到在目录下生成了一个config.json
的文件
step3:编辑配置文件
{ "assets-path": "", "bolt-path": "D:\\Tools\\influxdb2-2.7.5-windows\\influxdbv2\\influxd.bolt", "e2e-testing": false, "engine-path": "D:\\Tools\\influxdb2-2.7.5-windows\\influxdbv2\\engine", "feature-flags": null, "flux-log-enabled": false, "hardening-enabled": false, "http-bind-address": ":8086", "http-idle-timeout": 180000000000, "http-read-header-timeout": 10000000000, "http-read-timeout": 0, "http-write-timeout": 0, "influxql-max-select-buckets": 0, "influxql-max-select-point": 0, "influxql-max-select-series": 0, "instance-id": "", "log-level": "info", "metrics-disabled": false, "nats-max-payload-bytes": 0, "nats-port": 0, "no-tasks": false, "pprof-disabled": false, "query-concurrency": 1024, "query-initial-memory-bytes": 0, "query-max-memory-bytes": 0, "query-memory-bytes": 0, "query-queue-size": 1024, "reporting-disabled": false, "secret-store": "bolt", "session-length": 60, "session-renew-disabled": false, "sqlite-path": "D:\\Tools\\influxdb2-2.7.5-windows\\influxdbv2\\influxd.sqlite", "storage-cache-max-memory-size": 1073741824, "storage-cache-snapshot-memory-size": 26214400, "storage-cache-snapshot-write-cold-duration": "10m0s", "storage-compact-full-write-cold-duration": "4h0m0s", "storage-compact-throughput-burst": 50331648, "storage-max-concurrent-compactions": 0, "storage-max-index-log-file-size": 1048576, "storage-no-validate-field-size": false, "storage-retention-check-interval": "30m0s", "storage-series-file-max-concurrent-snapshot-compactions": 0, "storage-series-id-set-cache-size": 0, "storage-shard-precreator-advance-period": "30m0s", "storage-shard-precreator-check-interval": "10m0s", "storage-tsm-use-madv-willneed": false, "storage-validate-keys": false, "storage-wal-fsync-delay": "0s", "storage-wal-max-concurrent-writes": 0, "storage-wal-max-write-delay": 600000000000, "storage-write-timeout": 10000000000, "store": "disk", "testing-always-allow-setup": false, "tls-cert": "", "tls-key": "", "tls-min-version": "1.2", "tls-strict-ciphers": false, "tracing-type": "", "ui-disabled": false, "vault-addr": "", "vault-cacert": "", "vault-capath": "", "vault-client-cert": "", "vault-client-key": "", "vault-client-timeout": 0, "vault-max-retries": 0, "vault-skip-verify": false, "vault-tls-server-name": "", "vault-token": "" }
配置说明
# 绑定IP端口 http-bind-address: ip:port #存储engine engine-path: /data/soft/influxdb2.7.4/data # 用户数据和元数据存储地址(元数据不单独配置则使用此项) bolt-path: /data/soft/influxdb2.7.4/influx.bolt #证书地址 vault-capath: /data/soft/influxdb2.7.4/certs #http相关配置 http-idle-timeout: 3m0s http-read-header-timeout: 90s http-read-timeout: 90s http-write-timeout: 180s #最大桶数 influxql-max-select-buckets: 0 #最大数据数量 influxql-max-select-point: 0 #最大字段数 influxql-max-select-series: 0 #日志相关 log-level: info # 无需评测数据 pprof-disabled: true #查询并发数 query-concurrency: 512 # 查询最大内存数 5G query-max-memory-bytes: 5368709120 # 查询队列 query-queue-size: 1024 #会话超时 min session-length: 60 #多大内存写一次,内存大则可开大些 storage-cache-snapshot-memory-size: 26214400 #写文件的最大线程数 高写操作,建议限制为机器的总核数 storage-max-concurrent-compactions: 4 #过期检查频率 storage-retention-check-interval: 1d0h0m0s #写并发数 storage-wal-max-concurrent-writes: 0
step4:重新启动influxd.exe
出现这个错误表示编码格式不正确,通过vs进行UTF-8 编码格式保存
3.注册服务
step1:新增环境变量
step2:创建服务
@echo.服务启动...... @echo off @sc create influxd binpath="D:\Tools\influxdb2-2.7.5-windows\influxd.exe" @net start influxd @sc config influxd start= AUTO @echo.influxd start is OK......success @pause
4.数据库操作
4.1 查询数据
4.2 编程代码
using InfluxDB.Client; using InfluxDB.Client.Api.Domain; using InfluxDB.Client.Writes; using System.Diagnostics; Console.WriteLine("Hello, World!"); var familyNames = new List<string>{ "赵", "钱", "孙", "李", "周", "吴", "郑", "王", "冯", "陈", "褚", "卫", "蒋", "沈", "韩", "杨", "朱", "秦", "尤", "许", "何", "吕", "施", "张", "孔", "曹", "严", "华", "金", "魏", "陶", "姜", "戚", "谢", "邹", "喻", "柏", "水", "窦", "章", "云", "苏", "潘", "葛", "奚", "范", "彭", "郎", "鲁", "韦", "昌", "马", "苗", "凤", "花", "方", "俞", "任", "袁", "柳", "酆", "鲍", "史", "唐", "费", "廉", "岑", "薛", "雷", "贺", "倪", "汤", "滕", "殷", "罗", "毕", "郝", "邬", "安", "常", "乐", "于", "时", "傅", "皮", "卞", "齐", "康", "伍", "余", "元", "卜", "顾", "孟", "平", "黄", "和", "穆", "萧", "尹" }; var givenNames = new List<string>{ "子璇", "淼", "国栋", "夫子", "瑞堂", "甜", "敏", "尚", "国贤", "贺祥", "晨涛", "昊轩", "易轩", "益辰", "益帆", "益冉", "瑾春", "瑾昆", "春齐", "杨", "文昊", "东东", "雄霖", "浩晨", "熙涵", "溶溶", "冰枫", "欣欣", "宜豪", "欣慧", "建政", "美欣", "淑慧", "文轩", "文杰", "欣源", "忠林", "榕润", "欣汝", "慧嘉", "新建", "建林", "亦菲", "林", "冰洁", "佳欣", "涵涵", "禹辰", "淳美", "泽惠", "伟洋", "涵越", "润丽", "翔", "淑华", "晶莹", "凌晶", "苒溪", "雨涵", "嘉怡", "佳毅", "子辰", "佳琪", "紫轩", "瑞辰", "昕蕊", "萌", "明远", "欣宜", "泽远", "欣怡", "佳怡", "佳惠", "晨茜", "晨璐", "运昊", "汝鑫", "淑君", "晶滢", "润莎", "榕汕", "佳钰", "佳玉", "晓庆", "一鸣", "语晨", "添池", "添昊", "雨泽", "雅晗", "雅涵", "清妍", "诗悦", "嘉乐", "晨涵", "天赫", "傲", "佳昊", "天昊", "萌萌", "若萌" }; const string token = "MSGEFXnKGhrb6EPxDmlCoeGMeU1yKTI0S66tokl3Z9AcC9vM6RLJV8H5DCfP-7NoXh8A14ntOIuCalO8QKANBA=="; // influxdb生成的token const string url = "http://localhost:8086"; const string org = "manager";//用户组 const string bucket = "test";//数据实例 const string measurement = "mem";//表 var stopwatch = Stopwatch.StartNew(); using var client = new InfluxDBClient("http://localhost:8086", token); //const string data = "mem,host=host1 used_percent=23.43234543"; //using (var writeApi = client.GetWriteApi()) //{ // writeApi.WriteRecord(data,WritePrecision.Ns, bucket,org); //} //1.增加 using (var writeApi = client.GetWriteApi()) { for (int i = 0; i <= 1000; i++) { var point = PointData.Measurement(measurement) .Tag("host", "local") .Field("Name", $"{familyNames[new Random().Next(0, familyNames.Count - 1)]}{givenNames[new Random().Next(0, givenNames.Count - 1)]}") .Field("Age", new Random().Next(0, 100)) .Timestamp(DateTime.UtcNow, WritePrecision.Ns); writeApi.WritePoint(point, bucket, org); Thread.Sleep(10); } } //2.删除数据 //var delete = client.GetDeleteApi(); //await delete.Delete(DateTime.UtcNow.AddHours(-12), DateTime.UtcNow, "", bucket, org); //3.查询数据 Console.WriteLine("*** Query Points ***"); const string start = "-3600s"; const string stop = "-1h"; var query = @$" from(bucket: ""{bucket}"") |> range(start:{start}) |> filter(fn: (r) => r[""_measurement""] == ""{measurement}"") |> filter(fn: (r) => r[""_field""] == ""Name"" or r[""_field""] == ""Age"" ) |> pivot(rowKey: [""_time""], columnKey: [""_field""], valueColumn: ""_value"")"; var tables = await client.GetQueryApi().QueryAsync(query, "manager"); tables.ForEach(table => { for (int j = 0; j < table.Records.Count; j++) { var record = table.Records[j]; Console.WriteLine($"序号{j}:{record.GetTime()} {record.GetMeasurement()}: {record.Values["Name"]} {record.Values["Age"]}"); } }); stopwatch.Stop(); // 输出方法运行时间 Console.WriteLine("方法运行时间:{0}", stopwatch.Elapsed); //Console.WriteLine("Hello, World 2 !"); //Console.ReadLine();View Code 标签:http,windows,max,influxd,storage,时序,vault,false,influx2.7 From: https://www.cnblogs.com/xm123/p/18663411