卸载旧版的docker
sudo apt-get remove docker
sudo apt-get remove docker-engine
sudo apt-get remove docker.io
sudo apt-get remove containerd
sudo apt-get remove runc
安装docker
sudo apt-key list
sudo apt-get update
sudo apt-get install docker-ce
root@hjj1:~# docker --version
Docker version 20.10.7, build f0df350
拉去依赖包
docker pull prom/node-exporter
docker pull prom/prometheus
docker pull grafana/grafana
假如找不到
可用其他版本
拉去了 再卸载
docker简单操作
因为之前错误安装 有几个服务需要关闭 关闭服务的命令
启动服务:systemctl start vsftpd.service
关闭服务:systemctl stop vsftpd.service
重启服务:systemctl restart vsftpd.service
显示服务的状态:systemctl status vsftpd.service
在开机时启用服务:systemctl enable vsftpd.service
在开机时禁用服务:systemctl disable vsftpd.service
查看服务是否开机启动:systemctl is-enabled vsftpd.service
查看已启动的服务列表:systemctl list-unit-files|grep enabled
查看启动失败的服务列表:systemctl --failed
显示出所有docker的容器
docker container ls -a
docker ps
关闭docker容器
docker stop
启动docker容器
docker start
删除所有的docker容器
docker rm $(docker container ls -aq)
启动node-exporter
客户端也要启动
docker run -d -p 9100:9100 \
-v "/proc:/host/proc:ro" \
-v "/sys:/host/sys:ro" \
-v "/:/rootfs:ro" \
--net="host" \
prom/node-exporter
等待几秒钟,查看端口是否起来了
root@ubuntu:~# netstat -anpt
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp6 0 0 :::9100 :::* LISTEN 3070/node_exporter
访问url
http://192.168.1.108:9100/metrics
启动prometheus
新建目录prometheus,编辑配置文件prometheus.yml
mkdir /opt/prometheus
cd /opt/prometheus/
vim prometheus.yml
global:
scrape_interval: 60s
evaluation_interval: 60s
scrape_configs:
- job_name: prometheus
static_configs:
- targets: ['localhost:9090']
labels:
instance: prometheus
- job_name: linux
static_configs:
- targets: ['192.168.1.108:9100']
labels:
instance: localhost
启动prometheus
docker run -d \
-p 9090:9090 \
-v /opt/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \
prom/prometheus
等待几秒钟,查看端口状态
root@ubuntu:/opt/prometheus# netstat -anpt
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp6 0 0 :::9100 :::* LISTEN 3070/node_exporter
tcp6 0 0 :::9090 :::* LISTEN 3336/docker-proxy
访问url:
http://192.168.1.108:9090/graph
http://192.168.1.108:9090/graph 2个都是UP状态
启动grafana
新建空文件夹grafana-storage,用来存储数据
mkdir /opt/grafana-storage
设置权限
chmod 777 -R /opt/grafana-storage
启动grafana
docker run -d \
-p 3000:3000 \
--name=grafana \
-v /opt/grafana-storage:/var/lib/grafana \
grafana/grafana
等待几秒钟,查看端口状态
root@ubuntu:/opt/prometheus# netstat -anpt
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1147/sshd
tcp 0 36 192.168.91.132:22 192.168.91.1:63648 ESTABLISHED 2969/0
tcp 0 0 192.168.91.132:22 192.168.91.1:63340 ESTABLISHED 1321/1
tcp6 0 0 :::9100 :::* LISTEN 3070/node_exporter
tcp6 0 0 :::22 :::* LISTEN 1147/sshd
tcp6 0 0 :::3000 :::* LISTEN 3494/docker-proxy
tcp6 0 0 :::9090 :::* LISTEN 3336/docker-proxy
tcp6 0 0 192.168.91.132:9100 172.17.0.2:55108 ESTABLISHED 3070/node_exporter
访问url进行配置
http://192.168.91.132:3000/
安装插件 Prometheus
导入ID 1860
监控其他机器
启动node-exporter
客户端也要启动
docker run -d -p 9100:9100 \
-v "/proc:/host/proc:ro" \
-v "/sys:/host/sys:ro" \
-v "/:/rootfs:ro" \
--net="host" \
prom/node-exporter
等待几秒钟,查看端口是否起来了
root@ubuntu:~# netstat -anpt
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp6 0 0 :::9100 :::* LISTEN 3070/node_exporter
访问url
http://192.168.1.108:9100/metrics
修改被监控机配置文件
新建目录prometheus,编辑配置文件prometheus.yml
cd /opt/prometheus/
vim prometheus.yml
global:
scrape_interval: 60s
evaluation_interval: 60s
scrape_configs:
- job_name: prometheus
static_configs:
- targets: ['localhost:9090']
labels:
instance: prometheus
- job_name: linux
static_configs:
- targets: ['192.168.1.108:9100']
labels:
instance: localhost
- targets: ['192.168.1.107:9100']
labels:
instance: work1
- targets: ['192.168.1.105:9100']
labels:
instance: work1