{"id":1095,"date":"2023-03-12T11:33:44","date_gmt":"2023-03-12T03:33:44","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1095"},"modified":"2023-04-29T11:26:30","modified_gmt":"2023-04-29T03:26:30","slug":"getting-started-with-influxdb","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/12\/getting-started-with-influxdb\/","title":{"rendered":"InfluxDB\u5165\u95e8"},"content":{"rendered":"<h2>InfluxDB \u7b80\u4ecb<\/h2>\n<p>InfluxDB \u662f\u91c7\u7528Golang\u7f16\u5199\u7684\u4e00\u6b3e\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u5e93\uff0c\u8d1f\u8d23\u9ad8\u6548\u5904\u7406\u5b9e\u65f6\u6570\u636e\u3002\u76ee\u524d\u5e02\u9762\u4e0a\u6bd4\u8f83\u6d41\u884c\u7684\u65f6\u5e8f\u6570\u636e\u5e93\u8fd8\u6709Open TSDB\uff08Hbase\uff09\u3001Prometheus\u7b49\u3002\u5404\u65f6\u5e8f\u6570\u636e\u5e93\u90fd\u6709\u81ea\u5df1\u7684\u9002\u7528\u573a\u666f\uff0c\u5728\u505a\u6280\u672f\u9009\u578b\u7684\u65f6\u5019\u9700\u8981\u7ed3\u5408\u4e1a\u52a1\u9700\u6c42\u8fdb\u884c\u9009\u62e9\u3002<\/p>\n<p><!-- more --><\/p>\n<p>\u5b98\u7f51\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/www.influxdata.com\/\">https:\/\/www.influxdata.com\/<\/a><br \/>\n\u4e0b\u8f7d\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/portal.influxdata.com\/downloads\/\">https:\/\/portal.influxdata.com\/downloads\/<\/a><\/p>\n<p>\u76ee\u524d\u5b98\u65b9InfluxData\u514d\u8d39\u63d0\u4f9b\u5355\u673a\u7248\uff0c\u4f46\u662f\u5bf9\u4e8e\u96c6\u7fa4\u7248\u9700\u8981\u6536\u8d39\uff0c\u96c6\u7fa4\u7248\u4f1a\u63d0\u4f9b\u8d1f\u8f7d\u5747\u8861\u3001\u6570\u636e\u540c\u6b65\u7b49\u96c6\u7fa4\u9ad8\u53ef\u7528\u7684\u529f\u80fd\u3002\u7ebf\u4e0a\u751f\u4ea7\u73af\u5883\u5982\u9700\u5927\u89c4\u6a21\u4f7f\u7528\uff0c\u8fd8\u662f\u6bd4\u8f83\u63a8\u8350\u4f7f\u7528\u96c6\u7fa4\u7248\u6765\u4fdd\u8bc1\u9ad8\u53ef\u7528\u7684\u3002<\/p>\n<h3>\u7279\u8272\u529f\u80fd<\/h3>\n<ul>\n<li>\u57fa\u4e8e\u65f6\u95f4\u5e8f\u5217\uff0c\u652f\u6301\u4e0e\u65f6\u95f4\u6709\u5173\u7684\u76f8\u5173\u51fd\u6570<\/li>\n<li>\u53ef\u5ea6\u91cf\u6027\uff1a\u5b9e\u65f6\u5bf9\u5927\u91cf\u6570\u636e\u8fdb\u884c\u8ba1\u7b97<\/li>\n<li>\u57fa\u4e8e\u4e8b\u4ef6\uff1a\u652f\u6301\u4efb\u610f\u7684\u4e8b\u4ef6\u6570\u636e<\/li>\n<\/ul>\n<h3>\u4e3b\u8981\u7279\u70b9<\/h3>\n<ul>\n<li>\u65e0\u7ed3\u6784\uff08\u65e0\u6a21\u5f0f\uff09\uff1a\u53ef\u4ee5\u662f\u4efb\u610f\u6570\u91cf\u7684\u5217<\/li>\n<li>\u652f\u6301min, max, sum, count, mean, median \u7b49\u4e00\u7cfb\u5217\u51fd\u6570\uff0c\u65b9\u4fbf\u7edf\u8ba1<\/li>\n<li>\u539f\u751f\u7684HTTP\u652f\u6301\uff0c\u5185\u7f6eHTTP API<\/li>\n<li>\u5f3a\u5927\u7684\u7c7bSQL\u8bed\u6cd5<\/li>\n<li>\u81ea\u5e26\u7ba1\u7406\u754c\u9762\uff0c\u4e5f\u65b9\u4fbf\u4e0eGrafana\u7b49\u6574\u5408\u8fdb\u884c\u56fe\u8868\u5c55\u793a<\/li>\n<\/ul>\n<h2>influxDB\u5b89\u88c5<\/h2>\n<h3>\u5b89\u88c5\u65b9\u5f0f<\/h3>\n<p>\uff081\uff09OS X<\/p>\n<pre><code>brew update\nbrew install influxdb<\/code><\/pre>\n<p>\uff082\uff09Docker Image<\/p>\n<pre><code>docker pull influxdb<\/code><\/pre>\n<p>\uff083\uff09Ubuntu &amp; Debian<\/p>\n<pre><code>wget https:\/\/dl.influxdata.com\/influxdb\/releases\/influxdb_1.7.7_amd64.deb\nsudo dpkg -i influxdb_1.7.7_amd64.deb<\/code><\/pre>\n<p>\uff084\uff09RedHat &amp; CentOS<\/p>\n<pre><code>wget https:\/\/dl.influxdata.com\/influxdb\/releases\/influxdb-1.7.7.x86_64.rpm\nsudo yum localinstall influxdb-1.7.7.x86_64.rpm<\/code><\/pre>\n<p>\uff085\uff09Standalone Windows Binaries (64-bit)<\/p>\n<pre><code>wget https:\/\/dl.influxdata.com\/influxdb\/releases\/influxdb-1.7.7_windows_amd64.zip\nunzip influxdb-1.7.7_windows_amd64.zip<\/code><\/pre>\n<p>\uff086\uff09Standalone Linux Binaries (64-bit)<\/p>\n<pre><code>wget https:\/\/dl.influxdata.com\/influxdb\/releases\/influxdb-1.7.7_linux_amd64.tar.gz\ntar -zxf influxdb-1.7.7_linux_amd64.tar.gz -C \/usr\/local\/\nmv \/usr\/local\/influxdb-1.7.7-1 \/usr\/local\/influxdb<\/code><\/pre>\n<p>\uff087\uff09Standalone Linux Binaries (32-bit)<\/p>\n<pre><code>wget https:\/\/dl.influxdata.com\/influxdb\/releases\/influxdb-1.7.7_linux_i386.tar.gz\ntar -zxf influxdb-1.7.7_linux_amd64.tar.gz -C \/usr\/local\/\nmv \/usr\/local\/influxdb-1.7.7-1 \/usr\/local\/influxdb<\/code><\/pre>\n<p>\uff088\uff09Standalone Linux Binaries (ARM)<\/p>\n<pre><code>wget https:\/\/dl.influxdata.com\/influxdb\/releases\/influxdb-1.7.7_linux_armhf.tar.gz\ntar -zxf influxdb-1.7.7_linux_amd64.tar.gz -C \/usr\/local\/\nmv \/usr\/local\/influxdb-1.7.7-1 \/usr\/local\/influxdb<\/code><\/pre>\n<h3>\u914d\u7f6e\u6587\u4ef6<\/h3>\n<p>\u914d\u7f6e\u6587\u4ef6\u4f4d\u7f6e\uff1a<\/p>\n<pre><code>\/etc\/influxdb\/influxdb.conf  \/\/rpm\u5b89\u88c5\n\/usr\/local\/influxdb\/etc\/influxdb\/influxdb.conf  \/\/bin\u5b89\u88c5<\/code><\/pre>\n<p>\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u53ef\u4ee5\u4fee\u6539InfluxDB\u7684\u7f13\u5b58\u5927\u5c0f\u7b49\u53c2\u6570\u3002<\/p>\n<h2>InfluxDB\u542f\u52a8<\/h2>\n<h3>\u670d\u52a1\u7aef\u542f\u52a8<\/h3>\n<p>\u5982\u679c\u662f\u901a\u8fc7\u5305\u5b89\u88c5\u7684\uff0c\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u8bed\u53e5\u542f\u52a8\uff1a<\/p>\n<pre><code>sudo service influxdb start<\/code><\/pre>\n<p>\u5982\u679c\u76f4\u63a5\u4e0b\u8f7d\u7684\u4e8c\u8fdb\u5236\u5305\uff0c\u5219\u901a\u8fc7\u5982\u4e0b\u65b9\u5f0f\u542f\u52a8<\/p>\n<p>\u7f16\u5199\u5982\u4e0b\u811a\u672c<code>influxdb_start.sh<\/code><\/p>\n<pre><code>#!\/bin\/bash\n\/usr\/local\/influxdb\/usr\/bin\/influxd -config \/usr\/local\/influxdb\/etc\/influxdb\/influxdb.conf &amp;<\/code><\/pre>\n<p>\u8fd0\u884c\u4e0a\u8ff0\u811a\u672c\uff1a<\/p>\n<pre><code>chmod +x influxdb_start.sh\nsh influxdb_start.sh<\/code><\/pre>\n<p>\u5373\u53ef\u4ee5\u540e\u53f0\u8fd0\u884c\u7684\u65b9\u5f0f\u542f\u52a8influxdb\u7684\u670d\u52a1\u7aef<\/p>\n<h3>\u5ba2\u6237\u7aef\u542f\u52a8<\/h3>\n<p>\u521b\u5efa\u8f6f\u94fe\u63a5\u5e76\u6267\u884cinflux\u5373\u53ef\u767b\u5165Influx\u670d\u52a1\u5668<\/p>\n<pre><code># ln -s \/usr\/local\/influxdb\/usr\/bin\/influx \/usr\/bin\/\n# influx \nConnected to http:\/\/localhost:8086 version 1.7.7\nInfluxDB shell version: 1.7.7\n> <\/code><\/pre>\n<p>\u65b0\u7248\u672c\u5df2\u7ecf\u5220\u9664web\u7ba1\u7406\u754c\u9762\uff0c\u8bbf\u95ee\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"http:\/\/ip\/8086\">http:\/\/ip\/8086<\/a> \u663e\u793a404\u5373\u4ee3\u8868\u5b89\u88c5\u6210\u529f<\/p>\n<h2>\u719f\u6089\u57fa\u672c\u64cd\u4f5c<\/h2>\n<pre><code># influx \nConnected to http:\/\/localhost:8086 version 1.7.7\nInfluxDB shell version: 1.7.7\n> show databases;\nname: databases\nname\n----\n_internal\n> create database test;\n> create retention policy &quot;default_policy&quot; on &quot;test&quot; duration 90d replication 2 default;\n> use test;\nUsing database test\n> show retention policies;\nname           duration  shardGroupDuration replicaN default\n----           --------  ------------------ -------- -------\nautogen        0s        168h0m0s           1        false\ndefault_policy 2160h0m0s 24h0m0s            2        true\n> insert cpu,uuid=123456,projectId=10086d usr=1,idle=12\n> select * from cpu;\nname: cpu\ntime                idle projectId usr uuid\n----                ---- --------- --- ----\n1563845542369889051 12   10086d    1   123456\n> insert cpu,uuid=123456,projectId=2s2d usr=12,idle=27,sys=13\n> select mean(idle) from cpu group by projectId;\nname: cpu\ntags: projectId=10086d\ntime mean\n---- ----\n0    12\n\nname: cpu\ntags: projectId=2s2d\ntime mean\n---- ----\n0    27\n> precision rfc3339\n> select mean(idle) from cpu group by projectId;\nname: cpu\ntags: projectId=10086d\ntime                 mean\n----                 ----\n1970-01-01T00:00:00Z 12\n\nname: cpu\ntags: projectId=2s2d\ntime                 mean\n----                 ----\n1970-01-01T00:00:00Z 27\n> drop database test\n> <\/code><\/pre>\n<h2>\u5ba2\u6237\u7aef\u5de5\u5177<\/h2>\n<p>\u63a8\u8350Windows\u5e73\u53f0\u4e0b\u7684\u5f00\u6e90\u6570\u636e\u5e93\u7ba1\u7406\u5de5\u5177<code>InfluxDBStudio<\/code>\uff0c\u7b80\u5316\u67e5\u8be2\u6570\u636e\u5e93\u7684\u6b65\u9aa4\uff0c\u63d0\u9ad8\u5de5\u4f5c\u6548\u7387\u3002<\/p>\n<p>\u8f6f\u4ef6\u4e0b\u8f7d\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/github.com\/CymaticLabs\/InfluxDBStudio\/releases\">https:\/\/github.com\/CymaticLabs\/InfluxDBStudio\/releases<\/a><\/p>\n<h3>\u8f6f\u4ef6\u4f7f\u7528<\/h3>\n<p>\uff081\uff09\u521b\u5efa\u8fde\u63a5<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.yezhou.me\/AppBlog\/images\/\u6570\u636e\u5e93\/InfluxDB\u521b\u5efa\u8fde\u63a5.jpg\" alt=\"APP\u5f00\u53d1\u6280\u672f\u535a\u5ba2\" \/><\/p>\n<p>\uff082\uff09\u67e5\u8be2\u6570\u636e<\/p>\n<p>![APP\u5f00\u53d1\u6280\u672f\u535a\u5ba2](<a target=\"_blank\" rel=\"noopener\" href=\"http:\/\/www.yezhou.me\/AppBlog\/images\/\u6570\u636e\u5e93\/InfluxDB\">http:\/\/www.yezhou.me\/AppBlog\/images\/\u6570\u636e\u5e93\/InfluxDB<\/a> Query.jpg)<\/p>\n<h3>\u4f7f\u7528\u611f\u53d7<\/h3>\n<p><code>InfluxDBStudio<\/code>\u652f\u6301\u5220\u9664\u6570\u636e\u5e93\uff0c\u5220\u9664\u8868\uff0c\u5bfc\u51fa\u6570\u636e\u7b49\u529f\u80fd\uff0c\u76ee\u524d\u8be5\u5de5\u5177\u8fd8\u5728\u5f00\u53d1\u4e2d\uff0c\u53ef\u80fd\u8ddf\u6210\u719f\u7684Oracle\u5de5\u5177<code>PLSQL<\/code>\u6216Mysql\u7684<code>Navicat<\/code>\u7b49\u5de5\u5177\u8fd8\u6709\u4e00\u4e9b\u5dee\u8ddd\uff0c\u4f46\u53ef\u4ee5\u6ee1\u8db3\u5728Windows\u73af\u5883\u4e0a\u5bf9InfluxDB\u7684\u5e38\u89c4\u64cd\u4f5c\uff0c\u521a\u63a5\u89e6InfluxDB\u7684\u5f00\u53d1\u8005\uff0c\u53ef\u4ee5\u7528\u6b64\u4f53\u9a8c\u3002<\/p>\n<p>\u76ee\u524d\u4f7f\u7528\u770b\u6765\uff0c\u8fd8\u7b97\u6d41\u7545\uff0c\u53ea\u5728\u67e5\u8be2\u5168\u8868\u5343\u4e07\u6761\u6570\u636e\u7684\u65f6\u5019\uff0c\u6ca1\u6709\u5206\u9875\u529f\u80fd\uff0c\u4f1a\u5bfc\u81f4\u5361\u987f\uff0c\u6240\u4ee5\u5927\u8868\u67e5\u8be2\uff0c\u63a8\u8350\u7528<code>limit 1000<\/code>\u8bed\u53e5\u52a0\u4ee5\u9650\u5236\uff0c\u9632\u6b62\u5361\u6b7b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>InfluxDB \u7b80\u4ecb InfluxDB \u662f\u91c7\u7528Golang\u7f16\u5199\u7684\u4e00\u6b3e\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u5e93\uff0c\u8d1f\u8d23\u9ad8\u6548\u5904\u7406\u5b9e\u65f6\u6570\u636e\u3002\u76ee [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[302],"class_list":["post-1095","post","type-post","status-publish","format-standard","hentry","category-database","tag-influxdb"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1095","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1095"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1095\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1095"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1095"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1095"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}