influxdb 2.0.3 tar.gz的安装与配置

下载地址:https://dl.influxdata.com/influxdb/releases/influxdb2-2.0.3_linux_amd64.tar.gz

安装influxdb

### 解压
[root@jyzbdb2 soft]# tar -zxf influxdb2-2.0.3_linux_amd64.tar.gz

### 设置环境变量
[root@jyzbdb2 influxdb2-2.0.3_linux_amd64]# vim /etc/profile
...
export PATH=$PATH:/app/soft/influxdb2-2.0.3_linux_amd64
...

### 使环境变量生效
[root@jyzbdb2 influxdb2-2.0.3_linux_amd64]# source /etc/profile

启动

方式一:直接在终端中启动(该方式启动后,退出终端进程也随之终止,原因不明)

[root@jyzbdb2 influxdb2-2.0.3_linux_amd64]# nohup influxd >> /app/soft/influxdb2-2.0.3_linux_amd64/influx.log 2>&1 &

方式二:设置成服务启动

### 添加 influxdb 用户,用于启动 influxdb 服务
[root@jyzbdb2 influxdb2-2.0.3_linux_amd64]# groupadd influxdb
[root@jyzbdb2 influxdb2-2.0.3_linux_amd64]# useradd -g influxdb -s /bin/false influxdb

### 新增 influxdb 配置文件(这个文件主要用于 influxdb 的优化;如果没有性能问题,也可以不用配置)
[root@jyzbdb2 influxdb2-2.0.3_linux_amd64]# vim config.yml
storage-cache-max-memory-size: 4294967296

### 修改文件的权限
[root@jyzbdb2 influxdb2-2.0.3_linux_amd64]# chown -R influxdb:influxdb /app/soft/influxdb2-2.0.3_linux_amd64

### 新增系统服务的启动文件
### ExecStart后面的参数可以不加,也可以根据实际更改。具体参考:https://docs.influxdata.com/influxdb/v2.0/reference/config-options
[root@jyzbdb2 influxdb2-2.0.3_linux_amd64]# vim /usr/lib/systemd/system/influxdb.service
[Unit]
Description=InfluxDB is an open-source, distributed, time series database
Documentation=https://docs.influxdata.com/influxdb/
After=network-online.target

[Service]
User=influxdb
Group=influxdb
LimitNOFILE=65536
ExecStart=/app/soft/influxdb2-2.0.3_linux_amd64/influxd --storage-cache-max-memory-size=4294967296 --bolt-path=/data/influxdb-data/influxd.bolt --engine-path=/data/influxdb-data/engine
KillMode=control-group
Restart=on-failure

[Install]
WantedBy=multi-user.target

### 启动服务
[root@jyzbdb2 influxdb2-2.0.3_linux_amd64]# systemctl start influxdb

### 查看服务状态
[root@jyzbdb2 influxdb2-2.0.3_linux_amd64]# systemctl status influxdb

### 设置为开机启动
[root@jyzbdb2 influxdb2-2.0.3_linux_amd64]# systemctl enable influxdb

配置

### 初始化
[root@jyzbdb2 influxdb2-2.0.3_linux_amd64]# influx setup
Welcome to InfluxDB 2.0!
Please type your primary username: jygz

Please type your password: 

Please type your password again: 

Please type your primary organization name: copote

Please type your primary bucket name: gps

Please type your retention period in hours.
Or press ENTER for infinite.: 


You have entered:
  Username:          jygz
  Organization:      copote
  Bucket:            gps
  Retention Period:  infinite
Confirm? (y/n): y

Config default has been stored in /root/.influxdbv2/configs.
User	Organization	Bucket
jygz	copote		gps

### 查看 token(客户端一般通过token进行操作)
[root@jyzbdb2 influxdb2-2.0.3_linux_amd64]# cat /root/.influxdbv2/configs
[default]
  url = "http://localhost:8086"
  token = "qPhb-sP__WM3w0U_nhJIYIcfDB0Q1yJ26PqiqwE9_8wL0LrAXoTjm4cT1j0hC4wGWUJsu4BSN-5bev_nS4GRmA=="
  org = "copote"
  active = true

关于防火墙

8086 端口:使用该端口与influxdb客户端进行数据交互。

# 开放端口
firewall-cmd --zone=public --add-port=8086/tcp --permanent
# 配置立即生效
firewall-cmd --reload
# 查看防火墙所有开放的端口
firewall-cmd --zone=public --list-ports

使用 influxdb api的方式进行操作

### 添加数据(多条):
curl --request POST 'http://200.200.200.71:8086/api/v2/write?org=copote&bucket=gps&precision=ms' \
  --header 'Authorization: Token N6M048DSeVq6s93aZRkjX5bqqCAQKaPCbf56NjjjuO28J3EZdywx0_df7RNlGy925AYRi2NS_rRwxsfsUVaVEA==' \
  --data '
test,id=1 username="tom" 1609299009330
test,id=1 age=12 1609299009330
'

### 添加数据(单条):
curl --request POST 'http://200.200.200.71:8086/api/v2/write?org=copote&bucket=gps&precision=ms' \
  --header 'Authorization: Token N6M048DSeVq6s93aZRkjX5bqqCAQKaPCbf56NjjjuO28J3EZdywx0_df7RNlGy925AYRi2NS_rRwxsfsUVaVEA==' \
  --data 'test,id=1 realname="汤姆" 1609299009330'


### 查询数据:
curl --request POST 'http://200.200.200.71:8086/api/v2/query?org=copote' \
  --header 'Authorization: Token N6M048DSeVq6s93aZRkjX5bqqCAQKaPCbf56NjjjuO28J3EZdywx0_df7RNlGy925AYRi2NS_rRwxsfsUVaVEA==' \
  --header 'Accept: application/csv' \
  --header 'Content-type: application/vnd.flux' \
  --data 'import "experimental/geo"
        from(bucket:"gps")
        |> range(start: -12h)
        |> filter(fn: (r) => r._measurement == "test")
        |> geo.toRows()'


### 删除数据:
curl --request POST 'http://200.200.200.71:8086/api/v2/delete?org=copote&bucket=gps' \
  --header 'Authorization: Token N6M048DSeVq6s93aZRkjX5bqqCAQKaPCbf56NjjjuO28J3EZdywx0_df7RNlGy925AYRi2NS_rRwxsfsUVaVEA==' \
  --header 'Content-Type: application/json' \
  --data '{
    "start": "2020-12-30T00:00:00Z",
    "stop": "2020-12-31T00:00:00Z",
    "predicate": "_measurement=\"test\" and id=\"1\""
  }'

使用 influxdb 客户端命令的方式进行操作

### 删除数据:
influx delete --bucket gps --org copote \
--host 'http://200.200.200.71:8086' \
--token 'N6M048DSeVq6s93aZRkjX5bqqCAQKaPCbf56NjjjuO28J3EZdywx0_df7RNlGy925AYRi2NS_rRwxsfsUVaVEA==' \
--start '2020-12-30T00:00:00Z' \
--stop '2020-12-31T00:00:00Z' \
--predicate '_measurement="test" and id="1"'
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
SQLite,是一款轻型的数据库,是遵守ACID的关联式数据库管理系统,它的设计目标是嵌入式的,而且目前已经在很多嵌入式产品中使用了它,它占用资源非常的低,在嵌入式设备中,可能只需要几百K的内存就够了。它能够支持Windows/Linux/Unix等等主流的操作系统,同时能够跟很多程序语言相结合,比如 Tcl、C#、PHP、Java等,还有ODBC接口,同样比起Mysql、PostgreSQL这两款开源世界著名的数据库管理系统来讲,它的处理速度比他们都快。SQLite第一个Alpha版本诞生于2000年5月. 至今已经有10个年头,SQLite也迎来了一个版本 SQLite 3已经发布。 SQLite功能   SQLite虽然很小巧,但是支持的SQL语句不会逊色于其他开源数据库,它支持的SQL包括:   ATTACH DATABASE   BEGIN TRANSACTION   comment   COMMIT TRANSACTION   COPY   CREATE INDEX   CREATE TABLE   CREATE TRIGGER   CREATE VIEW   DELETE   DETACH DATABASE   DROP INDEX   DROP TABLE   DROP TRIGGER   DROP VIEW   END TRANSACTION   EXPLAIN   expression   INSERT   ON CONFLICT clause   PRAGMA   REPLACE   ROLLBACK TRANSACTION   SELECT   UPDATE   同时它还支持事务处理功能等等。也有人说它象Microsoft的Access,有时候真的觉得有点象,但是事实上它们区别很大。比如SQLite 支持跨平台,操作简单,能够使用很多语言直接创建数据库,而不象Access一样需要Office的支持。如果你是个很小型的应用,或者你想做嵌入式开发,没有合适的数据库系统,那么现在你可以考虑使用SQLite。目前它的最新版本是 3.7.8 。它的官方网站是:http://www.sqlite. org或者http://www.sqlite .com .cn,能在上面获得源代码和文档。同时因为数据库结构简单,系统源代码也不是很多,也适合想研究数据库系统开发的专业人士 SQLite特性 下面是访问SQLite官方网站: http://www.sqlite. org/ 时第一眼看到关于SQLite的特性.   1. ACID事务   2. 零配置 – 无需安装和管理配置   3. 储存在单一磁盘文件中的一个完整的数据库   4. 数据库文件可以在不同字节顺序的机器间自由的共享   5. 支持数据库大小至2TB   6. 足够小, 大致3万行C代码, 250K   7. 比一些流行的数据库在大部分普通数据库操作要快   8. 简单, 轻松的API   9. 包含TCL绑定, 同时通过Wrapper支持其他语言的绑定   10. 良好注释的源代码, 并且有着90%以上的测试覆盖率   11. 独立: 没有额外依赖   12. Source完全的Open, 你可以用于任何用途, 包括出售它   13. 支持多种开发语言,C, PHP, Perl, Java, C#,Python SQLite类型 SQLite的数据类型   首先你会接触到一个让你惊讶的名词: Typelessness(无类型). 对! SQLite是无类型的. 这意味着你可以保存任何类型的数据到你所想要保存的任何表的任何列中, 无论这列声明的数据类型是什么(只有在一种情况下不是, 稍后解释). 对于SQLite来说对字段不指定类型是完全有效的. 如:   Create Table ex1(a, b, c);   诚然SQLite允许忽略数据类型, 但是仍然建议在你的Create Table语句中指定数据类型. 因为数据类型对于你和其他的程序员交流, 或者你准备换掉你的数据库引擎. SQLite支持常见的数据类型, 如:   CREATE TABLE ex2(   a VARCHAR(10),   b NVARCHAR(15),   c TEXT,   d INTEGER,   e FLOAT,   f BOOLEAN,   g CLOB,   h BLOB,   i TIMESTAMP,   j NUMERIC(10,5)   k VARYING CHARACTER (24),   l NATIONAL VARYING CHARACTER(16)   );   前面提到在某种情况下, SQLite的字段并不是无类型的. 即在字段类型为”Integer Primary Key”时. 使用.NET操作SQLLITE   先下载ADO.NET2.0 Provider for SQLite。下载binaries zip版就可以了。下载完后解压缩,可以在bin目录下找到System.Data.SQLite.DLL。在vs2008中用Add Refrence功能把System.Data.SQLite.DLL加到工程里就可以了。运行下面代码试试:   string datasource = "e:/tmp/test.db";   System.Data.SQLite.SQLiteConnection.CreateFile(datasource);   //连接数据库   System.Data.SQLite.SQLiteConnection conn = new System.Data.SQLite.SQLiteConnection();   System.Data.SQLite.SQLiteConnectionStringBuilder connstr = new System.Data.SQLite.SQLiteConnectionStringBuilder();   connstr.DataSource = datasource;   connstr.Password = "admin";//设置密码,SQLite ADO.NET实现了数据库密码保护   conn.ConnectionString = connstr.ToString();   conn.Open();   //创建表   System.Data.SQLite.SQLiteCommand cmd = new System.Data.SQLite.SQLiteCommand();   string sql = "CREATE TABLE test(username varchar(20),password varchar(20))";   cmd.CommandText = sql;   cmd.Connection = conn;   cmd.ExecuteNonQuery();   //插入数据   sql = "INSERT INTO test VALUES('a','b')";   cmd.CommandText = sql;   cmd.ExecuteNonQuery();   //取出数据   sql = "SELECT * FROM test";   cmd.CommandText = sql;   System.Data.SQLite.SQLiteDataReader reader = cmd.ExecuteReader();   StringBuilder sb = new StringBuilder();   while (reader.Read())   {   sb.Append("username:").Append(reader.GetString(0)).Append("\n")   .Append("password:").Append(reader.GetString(1));   }   MessageBox.Show(sb.ToString());

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值