首页 > 其他分享 >Docker搭建FRP+OPENVPN+Prometheus+Grafana 实现内网穿透以及流量监控

Docker搭建FRP+OPENVPN+Prometheus+Grafana 实现内网穿透以及流量监控

时间:2024-06-17 16:28:24浏览次数:14  
标签:-- Grafana etc Prometheus FRP openvpn Docker root docker

Docker搭建FRP+OPENVPN+Prometheus+Grafana 实现内网穿透以及流量监控

文章目录

一、搭建Docker基础环境

​ 1. 安装依赖环境

[root@localhost ~]# yum -y install yum-utils device-mapper-persistent-datalvm2

​ 2. 设置Docker镜像源,使用国内阿里源

[root@localhost ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@localhost ~]# yum makecache fast

​ 3. 安装Docker,启动Docker服务,设置开机自动启动

[root@localhost ~]# yum install -y docker-ce docker-ce-cli containerd.io
[root@localhost ~]# systemctl enable --now docker
[root@localhost ~]# docker version      #查看Docker版本

测试
[root@localhost ~]# docker run hello-world
  Unable to find image 'hello-world:latest' locally
  latest: Pulling from library/hello-world
  1b930d010525: Pull complete 
  Digest: sha256:0e11c388b664df8a27a901dce21eb89f11d8292f7fca1b3e3c4321bf7897bffe
  Status: Downloaded newer image for hello-world:latest
  Hello from Docker!    <--- 出现以下代码,说明运行成功 --->

​ 4. 配置阿里云镜像加速,编辑daemon.json,如无则创建daemon.json

[root@localhost ~]# mkdir -p /etc/docker
[root@localhost ~]# cat /etc/docker/daemon.json
{
"registry-mirrors": ["https://78q111y9.mirror.aliyuncs.com"]
} 

[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker

二、配置FRP,实现端口映射

2.1 使用Docker部署FRP

​ 从0.52.0版本起弃用 INI ,改用 TOML、YAML、JSON 作为配置文件格式。

Frps服务端(拥有公网IP)

​ 编写:frps.toml

root@frps:~# mkdir -p /etc/frp/
root@frps:~# vim /etc/frp/frps.toml
#frps.toml
bindPort =  6000
#域名
subdomain_host = xxx.xxx.cn

auth.method = "token"
auth.token = "abcd123456"  ##frps与frpc需要一致

webServer.addr = "0.0.0.0"
webServer.port = 6001
webServer.user = "admin"
webServer.password = "000000"
webServer.pprofEnable = false

log.to = "/etc/frp/log/frps.log"
log.level = "info"
log.maxDays = 7
log.disablePrintColor = false

#监控
enable_prometheus = true       #是否提供 Prometheus 监控接口,需要启动Dashboard才会生效

通过浏览器访问http://<服务器ip>:6001/metrics来查看监控收集的数据

​ Docker开始构建 **/root/frps/frps.ini存放的frps.ini**的路径

root@frps:~# docker run --restart=always --network host -d -v /etc/frp/frps.toml:/etc/frp/frps.toml --name frps ghcr.io/snowdreamtech/frps

​ 放开防火墙开放端口: **6000,6001 **,本地映射到公网的端口

!云服务器,需在服务商管理控制台开放安全组 !
[root@frps ~]# firewall-cmd --zone=public --add-port=6000/udp --permanent
[root@frps ~]# firewall-cmd --zone=public --add-port=6001/udp --permanent

[root@frps ~]# systemctl restart firewalld && systemctl status firewalld
tip:端口的基本设置
1、开放端口
firewall-cmd --zone=public --add-port=<端口号>/tcp --permanent
2、重新载入
firewall-cmd --reload
3、查看对应端口
firewall-cmd --zone=public --query-port=<端口号>/tcp
4、删除端口
firewall-cmd --zone=public --remove-port=<端口号>/tcp --permanent
Frpc客户端(内网IP)

​ 编写:frpc.toml

root@controller:~# mkdir -p /etc/frp/
root@controller:~# vim /etc/frp/frpc.toml
#frpc.toml

serverAddr = "{frps的公网ip}"
serverPort = 6000

auth.method = "token"
auth.token = "abcd123456"   ##frps与frpc需要一致

webServer.addr = "0.0.0.0"
webServer.port = 6001
webServer.user = "admin"
webServer.password = "000000"
webServer.pprofEnable = false

log.to = "/etc/frp/log/frpc.log"
log.level = "info"
log.maxDays = 7
log.disablePrintColor = false

[[proxies]]
name = "openvpn"
type = "tcp"
localIP = "192.162.3.10"
localPort = 1194
remotePort =  21194

[root@frpc ~]#  docker run --restart=always --network host -d -v /etc/frp/frpc.toml:/etc/frp/frpc.toml --name frpc ghcr.io/snowdreamtech/frpc

​ 放开防火墙开放端口: **21194 **,要本地映射出去的端口

[root@frpc ~]# firewall-cmd --zone=public --add-port=21194/udp --permanent
[root@frpc ~]# systemctl restart firewalld && systemctl status firewalld

​ 访问Frps后台面板, Prometheus后台面板

Frps后台面板
http://<服务器ip>:6001/

查看监控收集的数据
http://<服务器ip>:6001/metrics

tip:如无法访问,则检查防火墙,确保开放了对应端口

在这里插入图片描述

三、搭建OPENVPN实现内网穿透

3.1 脚本搭建openVPN

内网服务器操作,这里直接使用一键搭建脚本

脚本地址:https://github.com/angristan/openvpn-install

[root@localhost ~]# curl -O https://raw.githubusercontent.com/angristan/openvpn-install/master/openvpn-install.sh
[root@localhost ~]# chmod +x openvpn-install.sh
[root@localhost ~]# sudo ./openvpn-install.sh

在这里插入图片描述
在这里插入图片描述

修改openvpn服务端配置文件 server.conf

[root@localhost ~]# vim /etc/openvpn/server.conf
management 0.0.0.0 5555
port 1194
proto tcp
dev tun
ca ca.crt
cert server.crt
key server.key
dh dh.pem
auth SHA512
tls-crypt tc.key
topology subnet
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
client-to-client
push "dhcp-option DNS 192.168.66.253"           # 推送内部dns服务器地址
;push "dhcp-option DOMAIN putianhui-local.com"  # 推送内部dns服务器后设置哪些内部域名走vpn的dns去解析
push "route 192.168.66.0 255.255.255.0"		# 内网段地址
keepalive 10 120
cipher AES-256-CBC
user nobody
group nobody
persist-key
persist-tun
status openvpn-status.log									# 状态记录日志
log-append openvpn.log										# 运行日志
verb 3
crl-verify crl.pem

启动 OpenVPN

[root@localhost ~]# systemctl enable --now [email protected]     # 开机自启
[root@localhost ~]# systemctl status openvpn.service    # 查看启动状态

在安装完成后,在/root/下会生成一个以刚刚命名好的**.ovpn**文件。

在这里插入图片描述

修改刚刚生成的 /root/test.ovpn 文件
port 1194 改成 21194
添加:
route-nopull
route 192.1.3.0 255.255.255.0 vpn_gateway  #指定代理的网段

四、搭建Prometheus+Grafana监控平台

4.1 Docker部署Prometheus

​ 1)安装Prometheus

[root@Docker ~]# docker pull prom/prometheus
[root@Docker ~]# docker run -itd --name=prometheus --restart=always -p 9090:9090 prom/prometheus
+++
通过浏览器访问http://<服务器ip>:9090

2)配置 Prometheus 监控Node节点, 修改Prometheus主配置文件

[root@Docker ~]# docker cp prometheus:/etc/prometheus/prometheus.yml $PWD
[root@Docker ~]# vim prometheus.yml
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
    - targets: ['localhost:9090']
      labels:
        instance: prometheus
        
## 在Prometheus配置文件按以下内容修改:        
## 如需要认证 ##
  - job_name: 'frp'
    static_configs:
      - targets: ['your_backend_address']    #被监控端的IP地址和端口号(有多个被监控端可用 逗号 隔开)
    basic_auth:
      username: 'your_username'   
      password: 'your_password'

[root@Docker ~]# docker cp $PWD/prometheus.yml prometheus:/etc/prometheus/prometheus.yml

3)重启Prometheus容器

[root@Docker ~]# docker restart prometheus

在这里插入图片描述

4.2 Docker部署Grafana

准备Grafana配置文件

#启动容器
[root@Docker ~]# docker run --restart=always --name grafana -d -p 3000:3000 grafana/grafana:10.0.1

#将容器中默认的配置文件拷贝到宿主机上
[root@Docker ~]# docker cp grafana:/etc/grafana/grafana.ini /root/grafana.ini

#修改配置文件(需要的话)
[root@Docker ~]# vim /root/grafana.ini
#配置为中文,将default_language = en-US改为 zh-Hans即可.
[server]
default_language = zh-Hans

[root@Docker ~]# docker cp $PWD/grafana.ini grafana:/etc/grafana/grafana.ini 
[root@Docker ~]# docker restart grafana
tip:Docker 修改文件
docker cp <容器id>:docker<容器中配置文件路径>  <主机路径>
docker cp grafana:/etc/grafana/grafana.ini /root/grafana.ini
 
//改完之后
docker cp 主机文件路径  <容器id>:docker容器中配置文件路径
docker cp $PWD/grafana.ini grafana:/etc/grafana/grafana.ini
通过浏览器访问http://<服务器ip>:3000
admin/admin
4.3 Promethues对接openVPN

修改openvpn的server.conf添加状态日志

[root@neutron-proxy ~]# find / -name server.conf
/etc/openvpn/server.conf
[root@neutron-proxy ~]# vim /etc/openvpn/server.conf
status openvpn-status.log
status /var/log/openvpn/status.log

查看生成的状态日志

[root@neutron-proxy ~]# cat /var/log/openvpn/status.log
TITLE,OpenVPN 2.4.12 x86_64-redhat-linux-gnu [Fedora EPEL patched] [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] [PKCS11] [MH/PKTINFO] [AEAD] built on Mar 17 2022
TIME,Mon Nov 13 22:40:31 2023,1699666431
HEADER,CLIENT_LIST,Common Name,Real Address,Virtual Address,Virtual IPv6 Address,Bytes Received,Bytes Sent,Connected Since,Connected Since (time_t),Username,Client ID,Peer ID
HEADER,ROUTING_TABLE,Virtual Address,Common Name,Real Address,Last Ref,Last Ref (time_t)
GLOBAL_STATS,Max bcast/mcast queue length,0
END
4.4 Docker部署openvpn_exporter
[root@neutron-proxy ~]# docker run -d --restart=always --name openvpn_exporter -p 9176:9176   -v /var/log/openvpn/status.log:/etc/openvpn_exporter/server.status   kumina/openvpn-exporter -openvpn.status_paths /etc/openvpn_exporter/server.status

通过浏览器访问http://<服务器ip>:9176/metrics

修改promethues.yml配置文件,Prometheus 添加openvpn的监控Job

[root@Docker ~]# vim prometheus.yml
在scrape_configs:加入以下内容
scrape_configs:
  - job_name: "openvpn_exporter"
    static_configs:
      - targets: ['<your_backend_address>:9176']

[root@Docker ~]# docker cp $PWD/prometheus.yml prometheus:/etc/prometheus/prometheus.yml
[root@Docker ~]# docker restart prometheus

在这里插入图片描述

Grafana导入仪表盘

ID: 10562

在这里插入图片描述

标签:--,Grafana,etc,Prometheus,FRP,openvpn,Docker,root,docker
From: https://blog.csdn.net/m0_64417755/article/details/139745798

相关文章

  • Prometheus+grafana部署
    分类出所需的监控项种类一般可分为︰业务级别监控/系统级别监控/网络监控/程序代码监控/日志监控/用户行为分析监控/其他种类监控大的分类还有更多的细小分类,这里给出几个例子,例如:业务监控可以包含用户访问QPS,DAU日活,访问状态,业务接口,产品转化率,充值额度,用户投诉等等这些很宏观......
  • prometheus的进程监控process-exporter
    1.下载二进制文件process-exporter项目地址:https://github.com/ncabatoff/process-exporter下载地址:https://github.com/ncabatoff/process-exporter/releases/download/2.启动#解压tar-zxvfprocess-exporter-0.8.2.linux-amd64.tar.gzmkdir/usr/local/node_exporter/......
  • K8S环境部署Prometheus
    K8S环境部署Prometheus记录在K8S1.18版本环境下部署Prometheus0.5版本。1.下载kube-prometheus仓库gitclonehttps://github.com/coreos/kube-prometheus.gitcdkube-prometheus笔者安装的K8S版本是1.18,prometheus选择配套的分支release-0.5:#切换到release-0.5gitc......
  • liunx下prometheus页面设置用户名密码登陆
    前言 前两天公司漏洞通报prometheus未设置鉴权,漏洞详情如下图所示。 操作前须知Prometheus于2.24版本(包括2.24)之后提供BasicAuth功能进行加密访问,在浏览器登录UI的时候需要输入用户密码,访问Prometheusapi的时候也需要加上用户密码1、安装依赖yum-yinstallepel-......
  • 【NAS】Docker Gitea+SakuraFrp+绿联DPX4800标 搭建私有代码托管平台
    本文主要分享Gitea的一些设置,和Https的实现。Gitea的一些设置映射网络HTTPS的实现先准备好一个域名,建议准备一个1Panel创建一个AC账户然后点击申请证书,手动解析。申请完毕后,点击详情,查看证书crt和私钥key自己创建一个txt文本,将证书crt粘贴进去,然后将名字改为xxx.crt......
  • 【30天精通Prometheus:一站式监控实战指南】第16天:snmp_exporter从入门到实战:安装、配
    亲爱的读者们......
  • 用 tiny-frpc 轻松搞定内网穿透
    你是否曾为内网穿透的复杂配置和庞大工具而头疼?好消息来了,tiny-frpc就是为你设计的!这是由gofrp团队开发的一款轻量级反向代理工具,不仅简单高效,还能大大减少依赖和配置的麻烦。tiny-frpc基于Go语言开发,体积极小,部署和运行极为快速。下载、配置、运行,一气呵成,你只需要几分钟......
  • 【NAS】绿联NAS UGOS PRO 使用natfrp(Sakura Frp)内网穿透访问Docker应用
    配置加速https://registry.cn-hongkong.aliyuncs.com下载镜像创建容器【容器】-【创建】-【手动创建】-选择你下载的镜像即可在日志中查看密码访问容器以HTTPS方式访问容器输入从日志中得到的密码。然后去官网查看访问密钥(不知道官网的就去看截图上的URL)将得到的密......
  • 基于prometheus实现SQL监控方案
    需求描述业务上经常会出现这样的问题:客户反馈某个业务今天查不到数据。怎么通过监控提前发现呢?我们的业务场景是这样:在mysql中,每小时、每天,会通过定时任务汇总统计车辆在道路上的作业情况(作业时间、里程、平均速度等)。经常出现,某一个客户某一类型数据没算(表中没有新增数据)。......
  • prometheus表达式常用公式
    1._over_time()下面的函数列表允许传入一个区间向量,它们会聚合每个时间序列的范围,并返回一个瞬时向量avg_over_time(range-vector):区间向量内每个度量指标的平均值。min_over_time(range-vector):区间向量内每个度量指标的最小值。max_over_time(range-vector):......