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/influxd-cluster@.service
[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/influxd-cluster@.service
# 設置權限(服務器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