1. 程式人生 > 實用技巧 >InfluxDB:叢集版使用指南

InfluxDB:叢集版使用指南

Influx-proxy的使用指南

Influx Proxy 是一個基於高可用、一致性雜湊的 InfluxDB 叢集代理服務,實現了 InfluxDB 高可用叢集的部署方案,具有動態擴/縮容、故障恢復、資料同步等能力。

相關文件:https://github.com/chengshiwen/influx-proxy
下載地址:https://golang.org/dl/

1.安裝

安裝依賴

Influx-proxy編譯時需要go語言環境。

伺服器

系統:centos 7.x
網路:支援訪問公網
伺服器:兩臺

架構

        ┌──────────────────┐
        │ writes & queries │
        └──────────────────┘
                 │
                 ▼
        ┌──────────────────┐
        │                  │
        │  InfluxDB Proxy  │
        │   (only http)    │
        │                  │
        └──────────────────┘
                 │
                 ▼
        ┌──────────────────┐
        │  db,measurement  │
        │ consistent hash  │
        └──────────────────┘
          |              |
        ┌─┼──────────────┘
        │ └────────────────┐
        ▼                  ▼
     Circle 1          Circle 2
  ┌────────────┐    ┌────────────┐
  │            │    │            │
  │ InfluxDB 1 │    │ InfluxDB 3 │
  │ InfluxDB 2 │    │ InfluxDB 4 │
  │            │    │            │
  └────────────┘    └────────────┘

配置示例

# 配置檔案
/opt/influx-proxy/proxy.json
{
    "circles": [
        {
            "name": "circle-1",
            "backends": [
                {
                    "name": "influxdb-1-1",
                    "url": "http://192.168.1.11:8086",
                    "username": "root",
                    "password": "123456",
                    "auth_secure": false
                },
                {
                    "name": "influxdb-1-2",
                    "url": "http://192.168.1.11:8087",
                    "username": "root",
                    "password": "123456",
                    "auth_secure": false
                }
            ]
        },
        {
            "name": "circle-2",
            "backends": [
                {
                    "name": "influxdb-2-1",
                    "url": "http://192.168.1.12:8086",
                    "username": "root",
                    "password": "123456",
                    "auth_secure": false
                },
                {
                    "name": "influxdb-2-2",
                    "url": "http://192.168.1.12:8087",
                    "username": "root",
                    "password": "123456",
                    "auth_secure": false
                }
            ]
        }
    ],
    "listen_addr": ":7076",
    "db_list": [],
    "data_dir": "/mnt/data/influx-pr/data",
    "tlog_dir": "/mnt/data/influx-pr/log",
    "hash_key": "idx",
    "flush_size": 10000,
    "flush_time": 1,
    "check_interval": 1,
    "rewrite_interval": 10,
    "conn_pool_size": 20,
    "write_timeout": 10,
    "idle_timeout": 10,
    "username": "root",
    "password": "123456",
    "auth_secure": false,
    "write_tracing": false,
    "query_tracing": false,
    "https_enabled": false,
    "https_cert": "",
    "https_key": ""
}
# 配置檔案
/etc/influxdb/influxdb.conf.1

reporting-disabled = true         # 禁用報告,預設為 false
bind-address = ":8088"
[meta]
dir = "/mnt/data/influxdb/meta"    # 元資訊目錄
[data]
dir = "/mnt/data/influxdb/data"    # 資料目錄
wal-dir = "/mnt/data/influxdb/wal" # 預寫目錄
wal-fsync-delay = "10ms"          # SSD 設定為 0s,非 SSD 推薦設定為 0ms-100ms
index-version = "tsi1"            # tsi1 磁碟索引,inmem 記憶體索引需要大量記憶體
query-log-enabled = true          # 查詢的日誌,預設是 true
[coordinator]
write-timeout = "20s"             # 寫入請求超時時間,預設為 10s
[http]
enabled = true
bind-address = ":8086"
auth-enabled = true
log-enabled = true                 # http 請求日誌,預設是 true
[logging]
level = "info"                    # 日誌等級,error、warn、info(預設)、debug
# 配置檔案
/etc/influxdb/influxdb.conf.2

reporting-disabled = true         # 禁用報告,預設為 false
bind-address = ":8089"
[meta]
dir = "/mnt/data/influxdb/meta"    # 元資訊目錄
[data]
dir = "/mnt/data/influxdb/data"    # 資料目錄
wal-dir = "/mnt/data/influxdb/wal" # 預寫目錄
wal-fsync-delay = "10ms"          # SSD 設定為 0s,非 SSD 推薦設定為 0ms-100ms
index-version = "tsi1"            # tsi1 磁碟索引,inmem 記憶體索引需要大量記憶體
query-log-enabled = true          # 查詢的日誌,預設是 true
[coordinator]
write-timeout = "20s"             # 寫入請求超時時間,預設為 10s
[http]
enabled = true
bind-address = ":8087"
auth-enabled = true
log-enabled = true                 # http 請求日誌,預設是 true
[logging]
level = "info"                    # 日誌等級,error、warn、info(預設)、debug
# 系統服務檔案
/etc/systemd/system/[email protected]

[Unit]
Description=influx-cluster
After=network.target

[Service]
Type=simple
ExecStart=/usr/bin/influxd -config /etc/influxdb/influxdb.conf.%i
Restart=on-failure

[Install]
WantedBy=multi-user.target
# 系統服務檔案
/etc/systemd/system/influx-proxy.service

[Unit]
Description=influx-proxy
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/influx-proxy -config /opt/influx-proxy/proxy.json
KillSignal=SIGTERM

[Install]
WantedBy=multi-user.target

Influx-proxy 版本安裝

伺服器1:Circle 1 、influx-proxy
伺服器2:Circle 2 
# 下載influx-proxy(伺服器1)
cd /opt
git clone https://github.com/chengshiwen/influx-proxy.git
# 安裝go環境(伺服器1)
tar -zxvf go1.15.linux-amd64.tar.gz -C /usr/local
echo "export PATH=\$PATH:/usr/local/go/bin" >> /etc/profile
echo "export GOPROXY=https://goproxy.io" >> /etc/profile
source /etc/profile
# 編譯influx-proxy(伺服器1)
cd influx-proxy
make

cp /opt/influx-proxy/bin/influx-proxy /usr/local/bin/
# 配置influx-proxy(伺服器1)
vim /opt/influx-proxy/proxy.json
vim /etc/systemd/system/influx-proxy.service
# 安裝influxdb(多例項)(伺服器1)(伺服器2)
wget https://dl.influxdata.com/influxdb/releases/influxdb-1.8.2.x86_64.rpm
yum -y localinstall influxdb-1.8.2.x86_64.rpm
vim /etc/influxdb/influxdb.conf.1
vim /etc/influxdb/influxdb.conf.2
vim /etc/systemd/system/[email protected]
# 設定許可權(伺服器1)(伺服器2)
mkdir -p /mnt/data/influxdb
chown influxdb:influxdb /mnt/data/influxdb

mkdir -p /mnt/data/influx-pr
chown influxdb:influxdb /mnt/data/influx-pr
# 啟動influxDB、influx-proxy(伺服器1)(伺服器2)
systemctl start influxd-cluster@1
systemctl start influxd-cluster@2
systemctl start influx-proxy
# 設定使用者、密碼(兩臺伺服器4個例項都需要設定)(伺服器1)(伺服器2)
influx -port 8086
create user 'username' with password 'password' with all privileges
exit

influx -port 8087
create user 'username' with password 'password' with all privileges
exit

2.使用

基本命令

# 啟動叢集(三種都可以)
① influx-proxy -config /opt/influx-proxy/proxy.json
② systemctl start influx-proxy
③ nohup influx-proxy -config /opt/influx-proxy/proxy.json > /dev/null 2>&1 &
# 檢視版本
influx-proxy -version

# 檢視叢集狀態
curl http://127.0.0.1:7076/health -u root:123456