创建网络
- 查看现有网络:
docker network ls
[root@zhulang home]# docker network ls
NETWORK ID NAME DRIVER SCOPE
874979f64b45 bridge bridge local
3eaf2e5dea55 host host local
962e1d6cfa34 none null local
- 创建网络:
docker network create mynet
,mynet为网络名
[root@zhulang home]# docker network create mynet
f73d04c62fd7ecd4313d6702a4f4bb2293c652bafecb12c7cabd8f441a876e5c
- 查看创建的网络:
docker network inspect mynet
[root@zhulang home]# docker network inspect mynet
[
{
"Name": "mynet",
"Id": "f73d04c62fd7ecd4313d6702a4f4bb2293c652bafecb12c7cabd8f441a876e5c",
"Created": "2021-01-17T14:43:15.085120773+08:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "172.21.0.0/16",
"Gateway": "172.21.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {},
"Options": {},
"Labels": {}
}
]
Docker部署influxdb
- 获取镜像:
docker pull influxdb
[root@zhulang home]# docker pull influxdb
Using default tag: latest
latest: Pulling from library/influxdb
2587235a7635: Pull complete
953fe5c215cb: Pull complete
d4d3f270c7de: Pull complete
d81696497404: Pull complete
febe82b40114: Pull complete
9a89692c7853: Pull complete
5b833af9a4dc: Pull complete
69d297038fc8: Pull complete
Digest: sha256:fe53382e9fa49dd1ac079143ac5b26bfb4fb0ba32ac9b4b61c859a16943b1bff
Status: Downloaded newer image for influxdb:latest
docker.io/library/influxdb:latest
- 启动influxdb容器并命名为jmeterdb:
docker run -d -p 8086:8086 --name jmeterdb --net mynet influxdb
[root@zhulang home]# docker run -d -p 8086:8086 --name jmeterdb --net mynet influxdb
2771fd54e2ae8576b67a52ecbfe20423e3cfab374c558161d2698926f6ae448d
- 进入该容器:
docker exec -it jmeterdb /bin/bash
[root@zhulang home]# docker exec -it jmeterdb /bin/bash
root@2771fd54e2ae:/#
- 进入建数据库:
influx
root@2771fd54e2ae:/# influx
Connected to http://localhost:8086 version 1.8.3
InfluxDB shell version: 1.8.3
- 创建数据库并查看是否创建成功
create database jmeterdb;
show databases;
name: databases
name
_internal
jmeterdb
-
通过jmeter测试influxdb数据库是否创建成功
设置jmeter参数,启动jmeter
进入容器内的数据库查看是否有数据,有数据代表启动成功
Docker部署grafana
- 获取镜像:
docker pull gafana/grafana
[root@zhulang home]# docker pull grafana/grafana
Using default tag: latest
latest: Pulling from grafana/grafana
801bfaa63ef2: Pull complete
efdb3434c59e: Pull complete
8cbdb3f56d34: Pull complete
34f82d4bd2ec: Pull complete
af445b3382af: Pull complete
4f4fb700ef54: Pull complete
8aab09bbec8e: Pull complete
9e81c23e3db5: Pull complete
Digest: sha256:5f19b6c385e8bfb8e5c9ecc7cdd123a453af3cf01e7c20d20059e770f656286d
Status: Downloaded newer image for grafana/grafana:latest
docker.io/grafana/grafana:latest
- 在创建的网络下启动grafana:
docker run -d -p 3000:3000 --name mygrafana --net mynet grafana/grafana
[root@zhulang home]# docker run -d -p 3000:3000 --name mygrafana --net mynet grafana/grafana
b924a47732ebcb3801def47a72cffeacd5119ace28e2e4bae25df009166029e3
- 打开浏览器查看是否启动成功,用户名和密码均为admin
grafana中设置influxdb
添加数据源
- 导入模板,模板选择id是4026或者5496即可
Docker部署prometheus
- 拉取镜像:
docker pull prom/prometheus
[root@zhulang home]# docker pull prom/prometheus
Using default tag: latest
latest: Pulling from prom/prometheus
ea97eb0eb3ec: Pull complete
ec0e9aba71a6: Pull complete
2c56484238c4: Pull complete
e04e22d751fb: Pull complete
725acffe426c: Pull complete
1aa9fa0253f1: Pull complete
d7fc56cae204: Pull complete
0697b0ac3503: Pull complete
1b03755e0f17: Pull complete
2c3149ca37ae: Pull complete
27dc64abca70: Pull complete
7ed50cc292d7: Pull complete
Digest: sha256:943c7c57115a449353e0158dcba4eaab2e56de07b7d552b5145cb6c0d1cbab19
Status: Downloaded newer image for prom/prometheus:latest
docker.io/prom/prometheus:latest
- 新建目录,生成prometheus.yaml
[root@zhulang home]# mkdir /home/prometheus
[root@zhulang home]# cd prometheus
[root@zhulang prometheus]#vim prometheus.yml
global:
scrape_interval: 60s
evaluation_interval: 60sscrape_configs:
job_name: prometheus
static_configs:
- targets: ['localhost:9090']
labels:
instance: prometheusjob_name: linux
static_configs:
- targets: ['47.106.86.188:9100']
labels:
instance: localhost~
- 启动prometheus
[root@zhulang prometheus]# docker run -d -p 9090:9090 -v /home/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml --net mynet prom/prometheus
4556160bec678aba8b6ebeaca4e34ea534d7306d2cbbec85a091ac95522cbd65
- 访问prometheus
- 安装node-exporter,拉取镜像,启动服务
[root@zhulang prometheus]# docker pull prom/node-exporter
Using default tag: latest
latest: Pulling from prom/node-exporter
86fa074c6765: Pull complete
ed1cd1c6cd7a: Pull complete
ff1bb132ce7b: Pull complete
Digest: sha256:cf66a6bbd573fd819ea09c72e21b528e9252d58d01ae13564a29749de1e48e0f
Status: Downloaded newer image for prom/node-exporter:latest
docker.io/prom/node-exporter:latest
[root@zhulang prometheus]# docker run -d -p 9100:9100 --name mynode-exporter --net mynet prom/node-exporter
994c5c645ed32479eb86bf18256869b011b82487dff40860c02d11d66431e94d
访问如下,表示安装成功
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-xG8ja1hC-1612768905675)(C:\Users\fsy\AppData\Roaming\Typora\typora-user-images\image-20210117213544432.png)]
- 在grafana中安装监控主机的看板,id:9276,如图配置成功