环境 win10 + docker
- (国内)更换镜像源
- 容器间通信:docker 启动容器时给容器命名,这个名字可以被 docker 识别,用来在容器间访问
- 容器与宿主机通信:
- win 下路径和 Linux 中的区别
- win 虚拟机 centos 联网问题(https://blog.csdn.net/IT_TIfarmer/article/details/85061373)
docker 时区问题
进容器修改:
docker exec -it container-name /bin/bashdate +%T -s "10:00:00"
进入容器后将主机(Linux)时区链接到容器
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
-
安装 node-exporter
#下载镜像docker pull prom/node-exporter#运行docker run -d -p 9100:9100 prom/node-exporter
安装 grafana
#下载镜像docker pull grafana/grafana#运行docker run -d --name=grafana -p 3000:3000 grafana/grafana
安装后通过 localhost:3000 访问,默认用户和密码均为:admin
首先添加数据源:(添加 Prometheus 数据源,地址为
修改 docker 端口可以通过环境变量 -e “GF_SERVER_HTTP_PORT=3030” (https://grafana.com/docs/grafana/latest/administration/configuration/ 文档中说明了环境变量如何得到)
常用面板: es:266(数据源同为 Prometheus,但有两种方式,一种是 es 自带的插件,一种是独立的 exporter,针对这两种有不同的面板,此处为支持 es 自带插件的面板)/ 6483(justwatch/es_exporter)
jvm / spring:4701 / 6756( 6756 面板需要修改环境变量 application 和 instance )
# applicationlabel_values(application)# instancelabel_values(jvm_memory_used_bytes{application="$application"}, instance)
Mysql:MySQL Overview 下载号:7362
- Node:Node Exporter for Prometheus Dashboard EN v20201010 下载号:11074
安装 Prometheus
prometheus 配置文件,docker 下对应路径:/etc/prometheus/prometheus.yml 增加配置:
容器内访问宿主机服务问题其中 host.docker.internal 是容器对本地 localhost 地址的映射,后为 spring 应用的端口号 PS:这种方式似乎只在 win 下有用,centos 服务器上无效
- job_name: 'spring-promethus'metrics_path: '/actuator/prometheus'static_configs:- targets:- host.docker.internal:4000
查看容器 docker 虚拟网卡的地址,用这个地址可以访问到宿主机
# 列出网卡信息> ifonfig# 或者直接查看网卡信息 此处 docker0 为网卡名> ip addr show docker0
安装启动:
#下载镜像docker pull prom/prometheus#运行# !!! 此处注意 -v 参数后的文件路径在 win 和 Linux 下的区别 /usr/local/src/file/prometheus.yml !!!sudo docker run -d -p 9090:9090 -v /D/dockerData/prometheus.yml:/usr/local/src/file/prometheus.yml prom/prometheus --config.file=D/dockerData/prometheus.yml
监控 MySQL
docker pull prom/mysqld-exporterdocker run -d -p 9104:9104 -e DATA_SOURCE_NAME="isp:Insteko_666@(host.docker.internal:3306)/" prom/mysqld-exporter
es
# installdocker pull docker.elastic.co/elasticsearch/elasticsearch:7.10.2# rundocker run -p 9200:9200 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.10.2
监控 es
es 的 exporter 选取 https://github.com/justwatchcom/elasticsearch_exporter
# 安装docker pull justwatch/elasticsearch_exporter:1.1.0# 运行docker run --rm -p 9114:9114 justwatch/elasticsearch_exporter:1.1.0
Prometheus 配置中增加
- job_name: 'elasticsearch'metrics_path: '/metrics'static_configs:- targets:- host.docker.internal:9114
利用 es 插件监控 es
https://github.com/vvanholl/elasticsearch-prometheus-exporter
插件依赖 es 自身版本,必须下载指定版本的插件
针对插件的 Prometheus 配置:
- job_name: 'elasticsearch'metrics_path: '/_prometheus/metrics'static_configs:- targets:- host.docker.internal:9220
安装 docker-compose
https://docs.docker.com/compose/install/
sudo curl -L "https://github.com/docker/compose/releases/download/1.28.2/docker-compose-$(uname -s)-$(uname -m)" -o /data/bytesforce/docker-compose chmod +x /data/bytesforce/docker-compose
