InfluxDB安装(转)

本操作参照InfluxDB官网:InfuxDB

使用的Red Hat和CentOS用户可以安装InfluxDB最新的稳定版本 yum包管理器:

cat <<EOF | sudo tee /etc/yum.repos.d/influxdb.repo
[influxdb]
name = InfluxDB Repository - RHEL $releasever
baseurl = https://repos.influxdata.com/rhel/$releasever/$basearch/stable
enabled = 1
gpgcheck = 1
gpgkey = https://repos.influxdata.com/influxdb.key
EOF

一旦添加到存储库 yum配置,安装和启动InfluxDB服务通过运行:

sudo yum install influxdb
sudo service influxdb start

或者如果你的操作系统是使用systemd(CentOS 7 +,RHEL 7 +):

sudo yum install influxdb
sudo systemctl start influxdb

在2019/03/08实践成功

详细的配置可参照官网进行进一步调试,笔者没有进行特殊的配置已经正常使用。

influxdb是目前比较流行的时间序列数据库。时间序列也就是里面的每条数据都会有一个时间戳的字段,方便基于时间的统计,查询过滤等。内置很多常见的度量函数,还能类似Nosql一样的无结构话,可以直接插入数据,新建表,随时通过插入数据改变表结构等,非常方便好用,支持http api,可以通过http协议进行连接,操作。而且其语法也非常类似与常用的sql语句。
这里,本人是将其与grafana一同使用,作为grafana的数据源,进行监控图标的绘制。
下面就记录一下influxdb的安装与简单的操作。
一:安装
$  wget https://dl.influxdata.com/influxdb/releases/influxdb-1.2.2.x86_64.rpm  (下载包) 
$ yum localinstall influxdb-1.2.2.x86_64.rpm  (用yum进行本地安装)
$ vim /etc/influxdb/influxdb.conf (修改配置文件)
------------------------------------------------------------------------------------------
reporting-disabled = true ( 这个要设置真,关闭定时上传数据到influxdata.com)
#bind-address = ":8086"(这个需要自己手动添加,指定http的连接操作端口,默认为8086) 
[admin]
  # Determines whether the admin service is enabled.
  enabled = true (web管理界面,1.1版本以上默认关闭。需要的话,可以手动打开)


  # The default bind address used by the admin service.
  bind-address = ":8083"    (web服务界面的端口)
---------------------------------------------------------------------------------------------------------------


二,启动influxdb,并使用
## 本人并没有开启web界面,所以这里讲一下命令行的操作。就类似与常用数据库。
$ systemctl start influxdb (启动influxdb)
$ systemctl enable influxdb (设为开机启动)
$ influx ( 进入influxdb )
Connected to http://localhost:8086 version 1.2.2
InfluxDB shell version: 1.2.2
-----------------------------------------------influxdb 的基本操作 -----------------------------
>create database test_db (创建数据库test_db )
>show databases (列出所有数据库)
>drop database test_db (删除数据库)
>use test_db ( 转入test_db数据库下 )
>create measurement test_table ( 创建test_table表,measurements==table(关系型数据库中的) )
>show measurements  (列出所有表)
>drop measyrement test_table (删除表test_able)


>insert test_table,host=web1 cpu=22,memory=33 (插入数据,test_table为表名,host为除了tag是,也就是方便用于度量的分类标签,可以是字符串。cpu和memory是数值,不能是字符串,只能是数值,中间用空格隔开)格式如下:
insert table_name,tags=* values=values,values=values (分别为三段
>curl -i -X POST "http://127.0.0.1:8086/write?db=testDb【&u=username&p=password】" --data-binary "test_table,host=127.0.0.1 cpu=22,memory=33"
!!!!!!!!!!!!!!!!!!!!!利用http接口远程插入数据,最常用的功能,用密码时,通过u和P的参数进行认证,没有则去掉。也就是利用post提交,默认的连接操作的端口为8086.


> select * from test_table (查询语句,类似sql语句)
>select * from test_table where cpu = 22 ( where用法,类似sql)
>select * from test_table where host = 'web1' (同上)
>select * from test_table order by time [desc] (按时间排序,默认为顺序,加上desc为倒序)


>show users (查看用户)
>create user "username" with password 'password' (创建普通用户)
>create user "username" with password 'password' with all privileges (创建管理员用户)
>drop user "username" (删除用户)
>auth (用户认证,用于设置了密码后,登陆influxdb的认证)
username: username
password: password

原文地址:https://www.cnblogs.com/wangbin/p/13280334.html