操作系統 : CentOS7.3.1611_x64 go語言版本:1.8.3 linux/amd64 InfluxDB版本:1.1.0 安裝InfluxDB之後,在/usr/bin下會有如下幾個文件: 下麵簡單介紹下各個工具的使用。 influxd使用方法介紹 該可執行文件為InfluxDB伺服器程 ...
操作系統 : CentOS7.3.1611_x64
go語言版本:1.8.3 linux/amd64
InfluxDB版本:1.1.0
安裝InfluxDB之後,在/usr/bin下會有如下幾個文件:
influxd influxdb伺服器
influx influxdb命令行客戶端
influx_inspect 查看工具
influx_stress 壓力測試工具
influx_tsm 資料庫轉換工具(將資料庫從b1或bz1格式轉換為tsm1格式)
下麵簡單介紹下各個工具的使用。
influxd使用方法介紹
該可執行文件為InfluxDB伺服器程式,參數說明如下:
[root@localhost ~]# influxd --help Configure and start an InfluxDB server. Usage: influxd [[command] [arguments]] The commands are: backup downloads a snapshot of a data node and saves it to disk config display the default configuration help display this help message restore uses a snapshot of a data node to rebuild a cluster run run node with existing configuration version displays the InfluxDB version "run" is the default command. Use "influxd [command] -help" for more information about a command.
- backup參數
數據備份功能,參數如下:
[root@localhost ~]# influxd backup --help Downloads a snapshot of a data node and saves it to disk. Usage: influxd backup [flags] PATH -host <host:port> The host to connect to snapshot. Defaults to 127.0.0.1:8088. -database <name> The database to backup. -retention <name> Optional. The retention policy to backup. -shard <id> Optional. The shard id to backup. If specified, retention is required. -since <2015-12-24T08:12:23Z> Optional. Do an incremental backup since the passed in RFC3339 formatted time. backup: flag: help requested
- config參數
顯示InfluxDB預設參數,使用示例 :
influxd backup -host 127.0.0.1:8088 -database mydb -since 2015-12-24T08:12:23Z back1
其中,mydb為資料庫名稱,back1為備份文件夾。
- help參數
顯示幫助信息,使用示例 :influxd help
- restore參數
數據恢復功能,使用該功能時,InfluxDB應當關閉。參數如下:
[root@localhost ~]# influxd restore --help Uses backups from the PATH to restore the metastore, databases, retention policies, or specific shards. The InfluxDB process must not be running during a restore. Usage: influxd restore [flags] PATH -metadir <path> Optional. If set the metastore will be recovered to the given path. -datadir <path> Optional. If set the restore process will recover the specified database, retention policy or shard to the given directory. -database <name> Optional. Required if no metadir given. Will restore the database TSM files. -retention <name> Optional. If given, database is required. Will restore the retention policy's TSM files. -shard <id> Optional. If given, database and retention are required. Will restore the shard's TSM files. restore: flag: help requested
使用示例:
influxd restore -database mydb -metadir /var/lib/influxdb/meta -datadir /var/lib/influxdb/data/ back1
其中,mydb為資料庫名稱,back1為之前備份數據的文件夾,/var/lib/influxdb/meta為InfluxDB的meta文件夾,/var/lib/influxdb/data/為InfluxDB的data文件夾。
- run參數
run為預設參數,在控制台直接輸入 influxd 命令,實際上執行的是: influxd run
預設配置為INFLUXDB_CONFIG_PATH環境變數設置的的路徑,或者~/.influxdb/influxdb.conf,或者 /etc/influxdb/influxdb.conf
參數說明如下:
[root@localhost tsdbBin]# influxd run --help Runs the InfluxDB server. Usage: influxd run [flags] -config <path> Set the path to the configuration file. This defaults to the environment variable INFLUXDB_CONFIG_PATH, ~/.influxdb/influxdb.conf, or /etc/influxdb/influxdb.conf if a file is present at any of these locations. Disable the automatic loading of a configuration file using the null device (such as /dev/null). -pidfile <path> Write process ID to a file. -cpuprofile <path> Write CPU profiling information to a file. -memprofile <path> Write memory usage information to a file. run: flag: help requested
使用示例 :
influxd run -config default.conf : 使用default.conf中的配置啟動InfluxDB
influxd run -pidfile /tmp/test1.pid : 啟動InfluxDB併在/tmp/test1.pid文件中寫入pid
cpuprofile和memprofile用於InfluxDB性能分析時使用
- version參數
顯示版本信息,使用示例:influxd version
influx使用方法介紹
該可執行文件為InfluxDB命令行客戶端,參數如下:
[root@localhost ~]# influx --help Usage of influx: -version Display the version and exit. -host 'host name' Host to connect to. -port 'port #' Port 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. -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' [root@localhost ~]#
使用示例:
influx :直接連接本機的8086埠
influx -version :顯示版本信息並退出
influx -database 'mydb' -execute 'select * from cpu_load' : 執行單條指令並退出
influx_inspect使用方法介紹
該可執行文件為InfluxDB查看工具,參數如下:
[root@localhost ~]# influx_inspect help Usage: influx_inspect [[command] [arguments]] The commands are: dumptsm dumps low-level details about tsm1 files. export exports raw data from a shard to line protocol help display this help message report displays a shard level report "help" is the default command. Use "influx_inspect [command] -help" for more information about a command. [root@localhost ~]#
- dumptsm參數
解析tsm文件,參數如下:
[root@localhost ~]# influx_inspect dumptsm --help Dumps low-level details about tsm1 files. Usage: influx_inspect dumptsm [flags] <path -index Dump raw index data -blocks Dump raw block data -all Dump all data. Caution: This may print a lot of information -filter-key <name> Only display index and block data match this key substring [root@localhost ~]#
使用示例:
[root@localhost ~]# influx_inspect dumptsm -all /var/lib/influxdb/data/mydb/autogen/12/000000004-000000003.tsm Summary: File: /var/lib/influxdb/data/mydb/autogen/12/000000004-000000003.tsm Time Range: 2017-05-23T09:10:10.202006046Z - 2017-05-23T11:10:27.319302712Z Duration: 2h0m17.117296666s Series: 1 File Size: 325 Index: Pos Min Time Max Time Ofs Size Key Field 1 2017-05-23T09:10:10.202006046Z 2017-05-23T09:14:50.532248441Z 5 41 cpu_load,host=server_1,region=us-west value 2 2017-05-23T09:26:34.541091603Z 2017-05-23T09:26:34.541091603Z 46 34 cpu_load,host=server_1,region=us-west value 3 2017-05-23T10:59:10.72052295Z 2017-05-23T10:59:10.72052295Z 80 34 cpu_load,host=server_1,region=us-west value 4 2017-05-23T11:10:02.987617654Z 2017-05-23T11:10:27.319302712Z 114 40 cpu_load,host=server_1,region=us-west value Blocks: Blk Chk Ofs Len Type Min Time Points Enc [T/V] Len [T/V] 0 1091651936 5 37 float64 2017-05-23T09:10:10.202006046Z 2 rle/gor 16/19 1 1782732741 46 30 float64 2017-05-23T09:26:34.541091603Z 1 s8b/gor 9/19 2 2962666225 121 30 float64 2017-05-23T10:59:10.72052295Z 1 s8b/gor 9/19 3 1165672455 230 36 float64 2017-05-23T11:10:02.987617654Z 2 rle/gor 15/19 Statistics Blocks: Total: 4 Size: 149 Min: 30 Max: 37 Avg: 37 Index: Total: 4 Size: 163 Points: Total: 6 Encoding: Timestamp: none: 0 (0%) s8b: 2 (50%) rle: 2 (50%) Float: none: 0 (0%) gor: 4 (100%) Compression: Per block: 24.83 bytes/point Total: 54.17 bytes/point [root@localhost ~]#
- export參數
使用示例:
[root@localhost ~]# influx_inspect export -database mydb -datadir /var/lib/influxdb/data/ -waldir /var/lib/influxdb/wal/ -out /tmp/export writing out tsm file data for mydb/autogen...complete. writing out wal file data for mydb/autogen...complete. [root@localhost ~]# cat /tmp/export # INFLUXDB EXPORT: 1677-09-21T08:12:43+08:00 - 2262-04-12T07:47:16+08:00 # DDL CREATE DATABASE mydb WITH NAME autogen # DML # CONTEXT-DATABASE:mydb # CONTEXT-RETENTION-POLICY:autogen # writing tsm data cpu_load,host=server_1,region=us-west value=0.2 1495530610202006046 cpu_load,host=server_1,region=us-west value=0.2 1495530890532248441 cpu_load,host=server_1,region=us-west value=0.2 1495531594541091603 cpu_load,host=server_1,region=us-west value=0.2 1495537150720522950 cpu_load,host=server_1,region=us-west value=0.2 1495537802987617654 cpu_load,host=server_1,region=us-west value=0.2 1495537827319302712 # writing wal data [root@localhost ~]#
- help
顯示幫助信息。
- report
顯示shard信息,示例如下:
[root@localhost ~]# influx_inspect report /var/lib/influxdb/data/mydb/autogen/12/ File Series Load Time 000000004-000000003.tsm 1 51.104µs Statistics Series: Total (est): 1 Completed in 269.807µs [root@localhost ~]#
influx_stress使用方法介紹
該可執行文件為InfluxDB壓力測試工具,參數如下:
[root@localhost ~]# influx_stress --help Usage of influx_stress: -addr string IP address and port of database where response times will persist (e.g., localhost:8086) (default "http://localhost:8086") -config string The stress test file -cpuprofile filename Write the cpu profile to filename -database string name of database where the response times will persist (default "stress") -db string target database within test system for write and query load -retention-policy string name of the retention policy where the response times will persist -tags value A comma seperated list of tags -v2 Use version 2 of stress tool [root@localhost ~]#
直接執行influx_stress命令即可啟動壓力測試,會在本地InfluxDB自動創建名叫stress的資料庫,並向裡面寫數據。
influx_tsm使用方法介紹
該可執行文件為InfluxDB資料庫轉換工具(將資料庫從b1或bz1格式轉換為tsm1格式,其中b1 和 bz1 為InfluxDB 0.9版中使用過的存儲引擎格式),屬於InfluxDB版本相容系列的內容。
使用該工具時,InfluxDB應該處於關閉狀態。
參數如下:
[root@localhost ~]# influx_tsm --help Usage: influx_tsm [options] <data-path> Convert a database from b1 or bz1 format to tsm1 format. This tool will backup the directories before conversion (if not disabled). The backed-up files must be removed manually, generally after starting up the node again to make sure all of data has been converted correctly. To restore a backup: Shut down the node, remove the converted directory, and copy the backed-up directory to the original location. Options: -backup string The location to backup up the current databases. Must not be within the data directory. -dbs string Comma-delimited list of databases to convert. Default is to convert all databases. -debug string If set, http debugging endpoints will be enabled on the given address -interval duration How often status updates are printed. (default 5s) -nobackup Disable database backups. Not recommended. -parallel Perform parallel conversion. (up to GOMAXPROCS shards at once) -profile string CPU Profile location -sz uint Maximum size of individual TSM files. (default 2147483648) -y Don't ask, just convert [root@localhost ~]#
好,就這些了,希望對你有幫助。
本文github地址:
https://github.com/mike-zhang/mikeBlogEssays/blob/master/2017/20171229_InfluxDB使用說明.rst
歡迎補充