InfluxDB安装及使用

1 安装

1.1 Tar包安装

  (1)获取tar包

wget https://dl.influxdata.com/influxdb/releases/influxdb-1.8.0_linux_amd64.tar.gz

  (2)解压tar包
  tar xvfz influxdb-1.8.0_linux_amd64.tar.gz

$ su - tigk
$ tar xvfz /opt/package/influxdb-1.8.0_linux_amd64.tar.gz -C /home/tigk/.local/
$ cd /home/tigk/.local
$ mv influxdb-1.8.0-1/ influxdb

  (3)修改配置文件

  可执行文件路径为:{influxdb目录}/usr/bin
  安装InfluxDB之后,在/usr/bin下会有如下几个文件:

influxd          influxdb服务器
influx           influxdb命令行客户端
influx_inspect   查看工具
influx_stress    压力测试工具
influx_tsm       数据库转换工具(将数据库从b1或bz1格式转换为tsm1格式)

  默认配置文件所在路径:{influxdb目录}/etc/influxdb/influxdb.conf

[tigk@fbi-local-02 .local]$ mkdir /data/tigk/influxdb/conf
[tigk@fbi-local-02 .local]$ cp /home/tigk/.local/influxdb/etc/influxdb/influxdb.conf  /data/tigk/influxdb/conf/
[tigk@fbi-local-02 .local]$ cd /data/tigk/influxdb/conf/influxdb.conf
[tigk@fbi-local-02 influxdb]$ mkdir meta
[tigk@fbi-local-02 influxdb]$ mkdir data
[tigk@fbi-local-02 influxdb]$ mkdir wal

  然后进行修改配置文件

   (4)配置文件说明

# reporting-disabled = false	# 该选项用于上报influxdb的使用信息给InfluxData公司,默认值为false
# bind-address = "127.0.0.1:8088"	# 备份恢复时使用,默认值为8088
### [meta]
[meta]
  dir = "/data/tigk/influxdb/meta"  # meta数据存放目录
  # retention-autocreate = true  # 用于控制默认存储策略,数据库创建时,会自动生成autogen的存储策略,默认值:true
  # logging-enabled = true  # 是否开启meta日志,默认值:true
### [data]
[data]
  dir = "/data/tigk/influxdb/data"  # 最终数据(TSM文件)存储目录
  wal-dir = "/data/tigk/influxdb/wal"  # 预写日志存储目录
  # wal-fsync-delay = "0s" #在同步写入之前等待的总时间,默认0s
  # index-version = "inmem" #用于新碎片的切分索引的类型。
  # trace-logging-enabled = false #跟踪日志记录在tsm引擎周围提供了更详细的输出
  # query-log-enabled = true  # 是否开启tsm引擎查询日志,默认值: true
  # Valid size suffixes are k, m, or g (case insensitive, 1024 = 1k).
  # cache-max-memory-size = "1g"  # 用于限定shard最大值,大于该值时会拒绝写入,默认值:1000MB,单位:byte
  # Valid size suffixes are k, m, or g (case insensitive, 1024 = 1k).
  # cache-snapshot-memory-size = "25m"  # 用于设置快照大小,大于该值时数据会刷新到tsm文件,默认值:25MB,单位:byte
  # cache-snapshot-write-cold-duration = "10m"  # tsm引擎 snapshot写盘延迟,默认值:10Minute
  # compact-full-write-cold-duration = "4h"  # tsm文件在压缩前可以存储的最大时间,默认值:4Hour
  # max-concurrent-compactions = 0 #压缩并发的最大数量,默认设置为0表示runtime.GOMAXPROCS(0)*50% ,否则以设置的非零值为准
  # Valid size suffixes are k, m, or g (case insensitive, 1024 = 1k).
  # max-index-log-file-size = "1m" #限制索引日志文件大小
  # max-series-per-database = 1000000  # 限制数据库的级数,该值为0时取消限制,默认值:1000000
  # max-values-per-tag = 100000  # 一个tag最大的value数,0取消限制,默认值:100000
  # tsm-use-madv-willneed = false #如果为true,mmap的建议值MADV_WILLNEED会被提供给内核
### [coordinator]
[coordinator]
  # write-timeout = "10s"  # 写操作超时时间,默认值: 10s
  # max-concurrent-queries = 0  # 最大并发查询数,0无限制,默认值: 0
  # query-timeout = "0s"  # 查询操作超时时间,0无限制,默认值:0s
  # log-queries-after = "0s"  # 慢查询超时时间,0无限制,默认值:0s
  # max-select-point = 0  # SELECT语句可以处理的最大点数(points),0无限制,默认值:0
  # max-select-series = 0  # SELECT语句可以处理的最大级数(series),0无限制,默认值:0
  # max-select-buckets = 0  # SELECT语句可以处理的最大"GROUP BY time()"的时间周期,0无限制,默认值:0
### [retention]
[retention]
  # enabled = true  # 是否启用该模块,默认值 : true
  # check-interval = "30m" # 检查时间间隔,默认值 :"30m"
### [shard-precreation]
[shard-precreation]
  # enabled = true # 是否启用该模块,默认值 : true
  # check-interval = "10m"  # 检查时间间隔,默认值 :"10m"
  # advance-period = "30m"  # 预创建分区的最大提前时间,默认值 :"30m"
[monitor]
  # store-enabled = true # 是否启用该模块,默认值 :true
  # store-database = "_internal" # 默认数据库:"_internal"
  # store-interval = "10s" # 统计间隔,默认值:"10s"
### [http]
[http]
  # enabled = true # 是否启用该模块,默认值 :true
  # bind-address = ":8086" # 绑定地址,默认值 :":8086"
  # auth-enabled = false # 是否开启认证,默认值:false
  # realm = "InfluxDB" # 配置JWT realm,默认值: "InfluxDB"
  # log-enabled = true  # 是否开启日志,默认值:true
  # suppress-write-log = false #在启用日志时是否抑制HTTP写请求日志
  # access-log-path = "" #当启用HTTP请求日志时,该选项指定了路径。如influxd不能访问指定的路径,它将记录一个错误并将请求日志写入stderr
  # write-tracing = false  # 是否开启写操作日志,如果置成true,每一次写操作都会打日志,默认值:false
  # pprof-enabled = true  # 是否开启pprof,默认值:true
  # debug-pprof-enabled = false  # 是否开启pprof,默认值:true
  # https-enabled = false # 是否开启https ,默认值 :false
  # https-certificate = "/etc/ssl/influxdb.pem" # 设置https证书路径,默认值:"/etc/ssl/influxdb.pem"
  # https-private-key = ""# 设置https私钥,无默认值
  # shared-secret = "" # 用于JWT签名的共享密钥,无默认值
  # max-row-limit = 0 # 配置查询返回最大行数,0无限制,默认值:0
  # max-connection-limit = 0  # 配置最大连接数,0无限制,默认值:0
  # unix-socket-enabled = false  # 是否使用unix-socket,默认值:false
  # bind-socket = "/var/run/influxdb.sock" # unix-socket路径,默认值:"/var/run/influxdb.sock"
  # max-body-size = 25000000 #客户端请求主体的最大值,以字节为单位。0无限制,默认值0
  # max-concurrent-write-limit = 0 #并发处理的最大写入次数,0无限制,默认值0
  # max-enqueued-write-limit = 0 #排队等待处理的最大数量,0无限制,默认值0
  # enqueued-write-timeout = 0 #在队列中等待处理的最长时间,0或者setting max-concurrent-write-limit=0无限制,默认值0
### [ifql]
[ifql]
  # enabled = true# 是否启用该模块,默认值 :true
  # log-enabled = true# 是否开启日志,默认值:true
  # bind-address = ":8082" #ifql RPC服务使用的绑定地址默认是8082
### [logging]
[logging]
  # format = "auto" #日志格式,默认是自动
  # level = "info" #日志级别默认info
  # suppress-logo = false #当程序启动时,会抑制打印出来的logo输出
### [subscriber]
[subscriber]
  # enabled = true	# 是否启用该模块,默认值 :true
  # http-timeout = "30s"	# http超时时间,默认值:"30s"
  # insecure-skip-verify = false	# 是否允许不安全的证书
  # ca-certs = ""	# 设置CA证书
  # write-concurrency = 40	#设置并发数目,默认值:40
  # write-buffer-size = 1000 	# 设置buffer大小,默认值:1000
### [[graphite]]
[[graphite]]
  # enabled = false# 是否启用该模块,默认值 :false
  # database = "graphite"# 数据库名称,默认值:"graphite"
  # retention-policy = "" # 存储策略,无默认值
  # bind-address = ":2003"# 绑定地址,默认值:":2003"
  # protocol = "tcp"# 协议,默认值:"tcp"
  # consistency-level = "one" # 一致性级别,默认值:"one
  # batch-size = 5000 # 批量size,默认值:5000
  # batch-pending = 10# 配置在内存中等待的batch数,默认值:10
  # batch-timeout = "1s" # 超时时间,默认值:"1s"
  # udp-read-buffer = 0# udp读取buffer的大小,0表示使用操作系统提供的值,如果超过操作系统的默认配置则会出错。 该配置的默认值:0
  # separator = "." # 多个measurement间的连接符,默认值: "."
  # tags = ["region=us-east", "zone=1c"] #将被添加到所有指标的默认标签。这些可以在模板级别上覆盖或者从指标中提取的标签
  # templates = [  
  #   "*.app env.service.resource.measurement",
  #   # Default template
  #   "server.*",
  # ]
### [collectd]
[[collectd]]
  # enabled = false# 是否启用该模块,默认值 :false
  # bind-address = ":25826"  # 绑定地址,默认值: ":25826"
  # database = "collectd"# 数据库名称,默认值:"collectd"
  # retention-policy = "" # 存储策略,无默认值
  # typesdb = "/usr/local/share/collectd" # 路径,默认值:"/usr/share/collectd/types.db"
  # security-level = "none" #安全级别
  # auth-file = "/etc/collectd/auth_file"
  # batch-size = 5000 #从缓存中批量获取数据的量,默认值:5000
  # batch-pending = 10 #可能在内存中等待的批次的数量,默认值:10
  # batch-timeout = "10s" #即使没有达到缓冲区的限制,至少要刷新一下,默认值:"10s"
  # read-buffer = 0 #udp读取buffer的大小,0表示使用操作系统提供的值,如果超过操作系统的默认配置则会出错。默认值:0
  # parse-multivalue-plugin = "split" #两种处理方式split和join,split会分到不同的表中,join会将记录作为一个单独的记录处理。默认是split
### [opentsdb]
[[opentsdb]]
  # enabled = false# 是否启用该模块,默认值 :false
  # bind-address = ":4242"# 绑定地址,默认值:":4242"
  # database = "opentsdb"  # 默认数据库:"opentsdb"
  # retention-policy = ""# 存储策略,无默认值
  # consistency-level = "one" # 一致性级别,默认值:"one"
  # tls-enabled = false # 是否开启tls,默认值:false
  # certificate= "/etc/ssl/influxdb.pem" # 证书路径,默认值:"/etc/ssl/influxdb.pem"
  # log-point-errors = true# 出错时是否记录日志,默认值:true
  # batch-size = 1000 #从缓存中批量获取数据的量,默认值:1000
  # batch-pending = 5 #可能在内存中等待的批次的数量,默认值:5
  # batch-timeout = "1s" #即使没有达到缓冲区的限制,至少要刷新一下,默认值:"1s"
### [[udp]]
[[udp]]
  # enabled = false# 是否启用该模块,默认值 :false
  # bind-address = ":8089" # 绑定地址,默认值:":8089"
  # database = "udp"# 数据库名称,默认值:"udp"
  # retention-policy = "" # 存储策略,无默认值
  # precision = "" #接收点的时间点的精度("" or "n", "u", "ms", "s", "m", "h")
  # batch-size = 5000#从缓存中批量获取数据的量,默认值:5000 
  # batch-pending = 10 #可能在内存中等待的批次的数量,默认值:10
  # batch-timeout = "1s" #即使没有达到缓冲区的限制,至少要刷新一下,默认值:"1s"
  # read-buffer = 0# udp读取buffer的大小,0表示使用操作系统提供的值,如果超过操作系统的默认配置则会出错。 该配置的默认值:0 
### [continuous_queries]
[continuous_queries]
  # enabled = true# 是否启用该模块,默认值 :true
  # log-enabled = true# 是否开启日志,默认值:true
  # query-stats-enabled = false #控制查询是否被记录到自我监控数据存储中
  # run-interval = "1s" # 时间间隔,默认值:"1s"
### [tls]
[tls]
  # ciphers = [
  #   "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305",
  #   "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
  # ]
  # min-version = "tls1.2"
  # max-version = "tls1.2"

  (5)启动

   cd {influxdb目录}

$ cd /home/tigk/.local/influxdb/usr/bin/
$ ./influxd -config /data/tigk/influxdb/conf/influxdb.conf 

  (6)启动失败

$ netstat -tunlp|grep 8086
(No info could be read for "-p": geteuid()=1005 but you should be root.)
tcp        0      0 10.0.165.2:8086         0.0.0.0:*               LISTEN      -

  修改端口 bind-address = “:8085”

  (7)后台启动服务

$ nohup ./influxd -config /data/tigk/influxdb/conf/influxdb.conf &

  (8)启动influxdb控制台,第一次启动会较慢,耐心等待

$ ./influx -port 8085
Connected to http://localhost:8085 version 1.8.0
InfluxDB shell version: 1.8.0
>

  (9)创建一个tigk用户,作为管理用户

> create user "tigk" with password 'tigk' with all privileges
> show users
user admin
---- -----
tigk true

2 使用

2.1 常用命令

  (1)命令展示influx –help

$ ./influx –help
unknown arguments: –help
Usage of influx:
  -version
			Display the version and exit.
  -path-prefix 'url path'
			Path that follows the host and port
  -host 'host name'
			Host to connect to.
  -port 'port #'
			Port to connect to.
  -socket 'unix domain socket'
			Unix socket to connect to.
  -database 'database name'
			Database to connect to the server.
  -password 'password'
			Password to connect to the server.  Leaving blank will prompt for password (--password '').
  -username 'username'
			Username to connect to the server.
  -ssl
			Use https for requests.
  -unsafeSsl
			Set this when connecting to the cluster using https and not use SSL verification.
  -execute 'command'
			Execute command and quit.
  -type 'influxql|flux'
			Type specifies the query language for executing commands or when invoking the REPL.
  -format 'json|csv|column'
			Format specifies the format of the server responses:  json, csv, or column.
  -precision 'rfc3339|h|m|s|ms|u|ns'
			Precision specifies the format of the timestamp:  rfc3339, h, m, s, ms, u or ns.
  -consistency 'any|one|quorum|all'
			Set write consistency level: any, one, quorum, or all
  -pretty
			Turns on pretty print for the json format.
  -import
			Import a previous database export from file
  -pps
			How many points per second the import will allow.  By default it is zero and will not throttle importing.
  -path
			Path to file to import
  -compressed
			Set to true if the import file is compressed

Examples:

    # Use influx in a non-interactive mode to query the database "metrics" and pretty print json:
    $ influx -database 'metrics' -execute 'select * from cpu' -format 'json' -pretty

    # Connect to a specific database on startup and set database context:
    $ influx -database 'metrics' -host 'localhost' -port '8086'

  (2)Influx命令使用
  Influx是连接influxdb的一个CLI程序,在本地成功安装influxdb后,influxdb启动,influx命令就可以直接使用。Influxdb默认在8086端口运行。Influx cli默认使用localhost:8086连接。可以使用-host和-port选项,连接到其他机器或者端口。

$ ./influx -port 8085
Connected to http://localhost:8085 version 1.8.0
InfluxDB shell version: 1.8.0
>

  (3)Influx-sql使用举例
  Influx命令连接数据库后,可以使用类sql语句查询数据

命令解释
CREATE DATABASE database_name建立数据库
SHOW DATABASES查询所有数据库
USE database_name使用database_name 库
INSERT cpu,host=host_name,region=cn value=66插数据入cpu measurement,标签host=host_name,region=cn, field是value=66
SELECT “host”, “region”, “value” FROM “cpu”从cpu measurement查询数据
SELECT * FROM “cpu”从cpu measurement查询所有数据

  (4)Influxdb的数据格式
  Influxdb是一个时序数据库,其保存metric的在某一系列时间点的状态。这些点状态包含时间戳,一个所谓的“measurement”名称,至少一个称为filed的键值对,以及0到多个标签(如 host=bigdata01)。
  在influxdb中可以把measurement看为关系数据库中的table,tag和field是其中的列。其中Tag都加了索引、field不加。和关系数据库不同的是,不用预先定义schema,没有value的点不会被保存。其格式如下:

<measurement>[,<tag-key>=<tag-value>...] <field-key>=<field-value>[,<field2-key>=<field2-value>...] [unix-nano-timestamp]

  举例:

cpu,host=bigdata01,region=cn value=66

payment,device=mobile,product=Notepad,method=credit billed=88,licenses=2i 1434067469156329323

<think>好的,我需要帮助用户了解如何在不同操作系统上安装使用InfluxDB。根据用户提供的引用资料,我需要整理出Windows、Ubuntu和CentOS的安装步骤,以及基本使用方式。首先,我需要检查每个引用中的信息是否准确,并确保步骤清晰。 首先看引用[1],提到Windows安装是通过下载二进制安装包,用户需要下载并解压,然后运行influxd.exe。这部分需要详细步骤,包括下载、解压、运行和访问。接着引用[2]是关于Ubuntu的安装,涉及添加GPG密钥、添加仓库源、安装、启动服务,以及初始配置。需要注意的是命令的正确性,比如添加源时的发行版名称是否正确,是否需要根据Ubuntu版本调整。 然后引用[3]是关于CentOS的安装,提到下载tar包、解压、运行influxd,以及初始设置时的用户名和密码要求。这里需要确认解压路径是否正确,运行命令是否准确,以及访问方式是否包括正确的端口。此外,引用中提到的密码必须八位数,需要提醒用户注意。 接下来,使用方式部分需要涵盖Web界面访问、命令行工具的使用,以及基本命令示例。比如创建存储桶、生成令牌、写入和查询数据。要确保命令的准确性,例如influx setup的步骤是否正确,以及写入数据时如何指定存储桶和组织。 同时,需要注意引用标记的正确使用,在相关步骤后添加[^1]、[^2]、[^3]。还要生成相关问题,可能涉及不同系统的安装差异、配置文件位置、常见错误解决等。需要确保问题覆盖用户可能遇到的后续疑问。 最后,检查LaTeX格式是否正确,虽然InfluxDB安装可能不涉及数学公式,但如果有变量或路径需要特别强调,是否需要使用$...$格式。比如路径中的目录名或文件名是否需要特殊处理,但根据示例似乎不需要,因此可能可以忽略LaTeX部分,除非有变量需要强调。不过用户要求所有行内数学表达式必须使用$...$,但本问题可能不涉及数学内容,所以可能不需要,但需注意是否有变量需要处理。 综上所述,需要分步骤整理各个操作系统的安装方法,确保引用正确,命令无误,并补充使用方式。然后生成相关问题,帮助用户深入理解。</think>### InfluxDB安装使用指南 #### 一、不同操作系统安装方法 **1. Windows系统安装** - **步骤1**:访问[InfluxDB官网](https://www.influxdata.com/)下载Windows二进制安装包[^1]。 - **步骤2**:解压下载的压缩包到目标目录(如`C:\influxdb`)。 - **步骤3**:打开命令行工具,进入解压目录的`influxdb2-<版本号>`文件夹,运行以下命令启动服务: ```bash influxd.exe ``` - **步骤4**:访问`http://localhost:8086`,按提示完成初始配置(用户名需满足密码复杂度要求,如8位以上字符)[^3]。 --- **2. Ubuntu系统安装** - **步骤1**:添加GPG密钥并配置仓库源[^2]: ```bash curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add - echo "deb https://repos.influxdata.com/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/influxdb.list ``` - **步骤2**:更新仓库并安装: ```bash sudo apt update && sudo apt install influxdb ``` - **步骤3**:启动服务并设置开机自启: ```bash sudo systemctl start influxdb sudo systemctl enable influxdb ``` - **步骤4**:访问`http://localhost:8086`进行初始化。 --- **3. CentOS系统安装** - **步骤1**:下载并解压预编译包: ```bash wget https://dl.influxdata.com/influxdb/releases/influxdb2-2.7.5-linux-amd64.tar.gz tar -zxvf influxdb2-2.7.5-linux-amd64.tar.gz -C /usr/local/ ``` - **步骤2**:进入解压目录并启动服务: ```bash cd /usr/local/influxdb2-2.7.5 ./usr/bin/influxd ``` - **步骤3**:访问`http://<服务器IP>:8086`,按提示设置用户名(如`zhangyanfen`)和密码(需8位以上)。 --- #### 二、基本使用方式 1. **Web界面操作** - 登录后创建存储桶(Bucket)、生成API令牌,用于数据写入和查询。 - 通过“Data Explorer”可视化查询数据。 2. **命令行工具(CLI)** - 安装CLI: ```bash curl https://dl.influxdata.com/influxdb/releases/influxdb2-client-2.7.3-linux-amd64.tar.gz | tar xz sudo cp influx /usr/local/bin/ ``` - 配置连接: ```bash influx config create --name myconfig --url http://localhost:8086 --token <API令牌> --org <组织名> ``` 3. **数据写入与查询示例** ```bash # 写入数据 influx write --bucket <存储桶名> --precision s "measurement,tag=value field=123 $(date +%s)" # 查询数据 influx query 'from(bucket:"<存储桶名>") |> range(start:-1h)' ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值