# InfluxDB

官方文档 (opens new window)

# 安装

  1. 下载压缩包
wget https://dl.influxdata.com/influxdb/releases/influxdb2-2.5.0-linux-amd64.tar.gz
1
  1. 解压
tar -xzvf influxdb2-2.5.0-linux-amd64.tar.gz -C /opt/module/
1
  1. 启动
/opt/module/influxdb2_linux_amd64/influxd
1
  1. 访问web页面,初始化数据库
  • 访问页面 http://192.168.50.223:8086/
  • 点击get start
  • 初始化用户 Bucket相当于数据库概念,所有都填influxdb
  1. Telegraf 下载

官方地址:https://portal.influxdata.com/downloads/

wget https://dl.influxdata.com/telegraf/releases/telegraf-1.24.2_linux_amd64.tar.gz
tar -xzvf telegraf-1.24.2_linux_amd64.tar.gz -C /opt/module/
1
2

Telegraf 启停脚本

#!/bin/bash
is_exist() {
    pid=$(ps -ef | grep telegraf | grep -v grep | awk '{print $2}')
    # 如果不存在返回 1,存在返回 0
    if [ -z "${pid}" ]; then
        return 1
    else
        return 0
    fi
}

stop() {
    is_exist
    if [ $? -eq "0" ]; then
        kill ${pid}
        if [ $? -eq "0" ]; then
            echo "进程号:${pid},弄死你"
        else
            echo "进程号:${pid},没弄死"
        fi
    else
        echo "本来没有 telegraf 进程"
    fi
}

start() {
    is_exist
    if [ $? -eq "0" ]; then
        echo "跑着呢,pid 是${pid}"
    else
        export INFLUX_TOKEN=OnWjITC4VQiK1DKdSXMgzyeFheTECp7fOxc0onjSWIt_zL76A5QNX1jHicmlyXCV3RTvg7sBHDN_82613tKRQA==
        /opt/module/telegraf-1.24.2/usr/bin/telegraf --config http://192.168.50.223:8086/api/v2/telegrafs/0a3a1c0e414c9000
    fi
}

status() {
    is_exist
    if [ $? -eq "0" ]; then
        echo "telegraf 跑着呢"
    else
        echo "telegraf 没有跑"
    fi
}

usage() {
    echo "哦!请你 start 或 stop 或 status"
    exit 1
}

case "$1" in
"start")
    start
    ;;
"stop")
    stop
    ;;
"status")
    status
    ;;
*)
    usage
    ;;
esac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
  1. node_exporter

官方地址:https://prometheus.io/download/

wget https://github.com/prometheus/node_exporter/releases/download/v1.4.0/node_exporter-1.4.0.linux-amd64.tar.gz
tar -xzvf node_exporter-1.4.0.linux-amd64.tar.gz -C /opt/module/
/opt/module/node_exporter-1.4.0.linux-amd64/node_exporter
1
2
3

访问页面: http://192.168.50.223:9100/metrics

更新时间: 11/3/2022, 5:08:06 PM