influxdb数据迁移

之前公司用的influxdb是直接买的influxdb实例,最近厂商产品下线,不得不迁移到自己的机器,以下是迁移过程。

考虑生产有现成的k8s集群,influxdb官网文档也有k8s部署说明,便直接将influxdb部署到k8s中。(版本1.8.x)

部署新的influxdb

部署的yaml文件如下:

# 单独弄个ns influxdb
apiVersion: v1
kind: Namespace
metadata:
    name: influxdb
---
# 配置文件弄个ConfigMap,便于修改
apiVersion: v1
kind: ConfigMap
metadata:
  name: influxdb-config
  namespace: influxdb
data:
  influxdb.conf: >-
    [meta]
      dir = "/var/lib/influxdb/meta"

    [coordinator]
      log-queries-after = "60s"
      max-select-series = 10000
      write-timeout = "30s"
    [data]
      dir = "/var/lib/influxdb/data"
      engine = "tsm1"
      wal-dir = "/var/lib/influxdb/wal"
      cache-max-memory-size = "0"
      cache-snapshot-memory-size = "256m"
      index-version = "tsi1"
      max-index-log-file-size = "64k"
      max-series-per-database = 3000000
      max-values-per-tag = 100000

---
## 挂个PersistentVolumeClaim
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: influxdb-data
  namespace: influxdb
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: csi-xxx # 自行配置
  resources:
    requests:
      storage: 8Gi # 按需配置,存储数据较多可适当放大
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
    labels:
        app: influxdb
    name: influxdb
    namespace: influxdb
spec:
    replicas: 1
    selector:
        matchLabels:
            app: influxdb
    serviceName: influxdb
    template:
        metadata:
            labels:
                app: influxdb
        spec:
            containers:
              - image: uhub.service.ucloud.cn/tv1234pub/influxdb:1.8.10
                name: influxdb
                ports:
                  - containerPort: 8086
                    name: influxdb
                volumeMounts:
                  - mountPath: /var/lib/influxdb
                    name: data
                  - name: influxdb-config
                    mountPath: /etc/influxdb/influxdb.conf
                    readOnly: true
                    subPath: influxdb.conf
            volumes:
              - name: data
                persistentVolumeClaim:
                  claimName: influxdb-data
              - name: timezone-config
                hostPath:
                  path: /usr/share/zoneinfo/Asia/Shanghai
              - name: influxdb-config
                configMap:
                  defaultMode: 0600
                  name: influxdb-config
---
apiVersion: v1
kind: Service
metadata:
    name: influxdb
    namespace: influxdb
spec:
    ports:
      - name: influxdb
        port: 8086
        targetPort: 8086
    selector:
        app: influxdb
    type: ClusterIP

dump 历史数据

dump 需要开启 8088 端口

influxd backup -portable -host 172.16.xx.xxx:8088 sai-snapshot

恢复数据

上传

kubectl cp -r sai-snapshot influxdb/influxdb-0:/root/
influxd restore -portable ./sai-snapshot

验证

influx客户端查验数据即可。


influxdb数据迁移
https://blog.puresai.com/2022/03/07/391/
作者
puresai
许可协议