influxdb安装和学习
安装
https://docs.docker.com/samples/library/influxdb/
- 先启动,创建admin用户
docker run -d --name influxdb -p 8086:8086 -p 8083:8083 -v /data/opt/monitor/influx/influxdb:/var/lib/influxdb influxdb
登录
docker exec -it influxdb /bin/bash
输入influx
创建admin用户
create user "admin" with password 'admin' with all privileges
- 创建配置文件:
docker run --rm influxdb influxd config > influxdb.conf
修改配置文件后,设置认证开启
[http]
enabled = true
bind-address = ":8086"
auth-enabled = true # ✨
- kill并重启,并指定我们的配置文件
docker kill influxdb
docker rm influxdb
docker run -d --name influxdb -p 8086:8086 -p 8083:8083 -v /data/opt/monitor/influx/influxdb.conf:/etc/influxdb/influxdb.conf:ro -v /data/opt/monitor/influx/influxdb:/var/lib/influxdb influxdb
再次登录
docker exec -it influxdb /bin/bash
输入influx
auth admin admin
show databases;
create database demo
备份
#!/bin/bash
# 0 0 * * * sh /data/opt/monitor/backup/influx/backup-influx.sh
source /etc/profile
LOG_DIR=/data/log/backup/influx
SOURCE_DIR=/data/opt/monitor/influx
BACKUP_DIR=/data/opt/monitor/backup/influx/data
REMOTE_IP=192.168.5.9
REMOTE_USER=root
REMOTE_DIR=/data/opt/backup/influx
function log()
{
echo "[ `date '+%Y-%m-%d %H:%M:%S'` ] $1"
}
# 备份
function main(){
d=`date "+%Y%m%d%H%M%S"`
fname=${BACKUP_DIR}/backup_${d}.tgz
log "开始备份 ${fname}"
tar -zcf ${fname} ${SOURCE_DIR}
scp ${fname} $REMOTE_USER@$REMOTE_IP:$REMOTE_DIR
log "备份到远程成功"
log "开始删除30天前的备份"
find ${BACKUP_DIR} -type f -atime +7 |xargs -t -i rm {}
log "删除完毕"
}
main >> 2>&1 ${LOG_DIR}/backup.log
概念
https://jasper-zhang1.gitbooks.io/influxdb/content/Concepts/crosswalk.html
基本操作
数据保存策略(Retention Policies)
influxdb提供了数据的报错策略 retention policies. 可以指定db的数据过期时间,然后定期删除过期数据。
查看retention
> create database demo
> use demo
Using database demo
> show retention policies on "demo"
name duration shardGroupDuration replicaN default
---- -------- ------------------ -------- -------
autogen 0s 168h0m0s 1 true
创建一个30天的过期策略
create retention policy "rp_30days" on "demo" duration 30d replication 1 default
- duration 单位 h(小时),d(天),w(星期);
修改retention
alter retention policy "rp_30days" on "demo" duration 30d default
删除retention
drop retention policy "rp_name" on "db_name"
关注我的公众号