Influxdb双写服务influxdb-relay部署配置【离线】

Background

  • Influxdb社区版未提供集群方案,官方提供的集群模式为闭源收费版本,具体收费明细不太清楚哈,有知道的请留言告知哈。
  • 官方开源的influxdb-relay仅仅支持双写功能,并未支持负载均衡能力,仅仅解决了数据备份的问题,并未解决influxdb读写性能的问题。Github地址:https://github.com/influxdata/influxdb-relay
  • 饿了么开源的influx-proxy是一个基于高可用、一致性哈希的 InfluxDB 集群代理服务,实现了 InfluxDB 高可用集群的部署方案,具有动态扩 / 缩容、故障恢复、数据同步等能力,但是组件较多,学习成本高,后期不易维护。Github地址:https://github.com/shell909090/influx-proxy
  • 这里只介绍下influxdb-relay方案的部署配置。

1、首先安装配置Golang环境

  • go语言开发的,编译时需要go环境,当然,如果是编译好的那就不用了,这里我提供一个在Centos7上编译好可以直接运行的。
  • 下载地址:https://pan.baidu.com/s/1ti5HNJJ1jiuFLvOJWG1l7A,提取码:king
  • 里面包含所有所需,operate.sh是一个启动停止的脚本。

在这里插入图片描述

  • 下载

官方下载地址:https://golang.org/
镜像站下载地址:https://golang.google.cn/dl/

# 用yum安装
yum install golang
# 或 使用编译好的二进制包
wget https://golang.google.cn/dl/go1.15.8.linux-amd64.tar.gz
  • 安装
tar -zxf go1.15.8.linux-amd64.tar.gz -C /usr/local
  • 配置
tee -a /etc/profile <<-'EOF'
#golang config
export GOROOT=/usr/local/go 
export GOPATH=/local/gopath
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
EOF
mkdir /local/gopath
source /etc/profile
# 查看版本
go version

2、下载编译influxdb-relay

如果用我提供的这一步也不用了。

# 一键获取远程仓库代码、编译并安装到你配置的 $GOPATH/bin
go get -u github.com/influxdata/influxdb-relay

3、编辑配置文件relay.toml

其中IP 10.0.0.110.0.0.2需要修改成你自己的inflxudb服务所在的IP。

[[http]]
name = "influxdb-http"
bind-addr = "0.0.0.0:9096"
output = [
    { name="influxdb1", location="http://10.0.0.1:8086/write", timeout="10s", buffer-size-mb=1024 },
    { name="influxdb2", location="http://10.0.0.2:8086/write", timeout="10s", buffer-size-mb=1024 },
]

4、启动influxdb-relay服务

  • 启动命令
nohup ./influxdb-relay -config ./relay.toml > ./run.log 2>&1 &
  • operate.sh

直接使用operate.sh脚本启动就行。

#!/bin/bash  

:<<!
【脚本说明】
1、此脚本适用操作某个程序;
2、支持服务启动、停止、重启、查看状态、查看日志;
!

# 程序名称
app=influxdb-relay
# 运行目录
dir_home=$(cd $(dirname $0);pwd)
dir_log=$dir_home/logs/
log_file=$dir_log/$app.log
if [[ ! -d $dir_log ]]; then
    mkdir $dir_log
fi

# 服务基本信息
operate=$1
ps_1=$app
pid_1=`ps -ef | grep $ps_1 | grep -v grep | awk '{print $2}'`
# 提示信息
msg="Please input the param 【<run|kil|res|sta|log>】"

# 定制化shell输出
function custom_print(){
    
    
    echo -e "\033[5;34m ***** \033[0m"
    echo -e "\033[32m $@ ! \033[0m"
    echo -e "\033[5;34m ***** \033[0m"
}

# 启动命令
function run(){
    
    
    nohup $dir_home/influxdb-relay -config $dir_home/relay.toml > $log_file 2>&1 &
}

# 启动服务
if [[ $operate = "run" || $operate = "start" ]]; then
    if [[ ! $pid_1 ]]; then
        run
        msg='Start success'
        custom_print $msg
    else
        msg='The service is already running'
        custom_print $msg
    fi

# 停止服务
elif [[ $operate = "kil" || $operate = "stop" ]]; then
    if [[ $pid_1 ]]; then
        kill -9 $pid_1
        msg='Stopped success'
        custom_print $msg
    else
        # 服务早已停止或未启动
        msg='The service is already down'
        custom_print $msg
    fi

# 重启服务
elif [[ $operate = "res" || $operate = "restart" ]]; then
    if [[ $pid_1 ]]; then
        kill -9 $pid_1
    fi
    run
    msg='Restart success'
    custom_print $msg

# 查看服务运行状态
elif [[ $operate = "sta" || $operate = "status" ]]; then
    if [[ $pid_1 ]]; then
        # 黄底蓝字
        echo -e "\033[43;34m RUNNING \033[0m"
    else
        # 蓝底黑字
        echo -e "\033[44;30m STOPPED \033[0m"
    fi

# 查看服务运行日志
elif [[ $operate = "log" ]]; then
    if [[ -e $log_file ]]; then
        tail -f $log_file
    else
        msg="No logs have been generated so far"
        custom_print $msg
    fi

else
    custom_print $msg
fi

猜你喜欢

转载自blog.csdn.net/qq_42761569/article/details/128418980
今日推荐