天天看點

部署Prometheus+Grafana

192.168.210.85  k8s-master1   Prometheus

192.168.210.177 k8s-node1     node_exporter

192.168.210.195 k8s-node2     grafana

一、安裝部署Prometheus

[root@k8s-master1 data]# cd

[root@k8s-master1 ~]# tar -zxvf prometheus-2.23.0.linux-amd64.tar.gz  -C /data

部署Prometheus+Grafana

[root@k8s-master1 data]# mv prometheus-2.23.0.linux-amd64 /data/prometheus

[root@k8s-master1 data]# chown prometheus:prometheus -R /data/prometheus

[root@k8s-master1 ~]# more /etc/systemd/system/prometheus.service

[Unit]

Description=Prometheus

After=network.target

[Service]

ExecStart=/data/prometheus/prometheus --config.file=/data/prometheus/prometheus.yml --storage.tsdb.path=/data/prometheus/data

User=prometheus

[Install]

WantedBy=multi-user.target

部署Prometheus+Grafana

[root@k8s-master1 data]# systemctl enable prometheus

[root@k8s-master1 data]# systemctl start prometheus

[root@k8s-master1 data]# netstat -nltp|grep prometheus

tcp6 0  0 :::9090   :::*  LISTEN   6957/prometheus   

部署Prometheus+Grafana
部署Prometheus+Grafana
部署Prometheus+Grafana

[root@k8s-master1 ~]#tar -zxvf node_exporter-1.0.1.linux-amd64.tar.gz -C /usr/local/

部署Prometheus+Grafana

[root@k8s-master1~]#mv/usr/local/node_exporter-1.0.1.linux-amd64/ /usr/local/node_exporter

[root@k8s-master1 ~]# nohup /usr/local/node_exporter/node_exporter &

部署Prometheus+Grafana

修改k8s-master1 伺服器prometheus.yml的配置

部署Prometheus+Grafana

static_configs:

    - targets: ['192.168.210.85:9090']

  - job_name: 'k8s-node1'

    static_configs:

    - targets: ['192.168.210.177:9100']

  - job_name: 'k8s-master1'

    - targets: ['192.168.210.85:9100']

[root@k8s-master1 ~]# pkill prometheus

[root@k8s-master1 ~]# netstat -nltp

[root@k8s-master1 ~]# systemctl restart prometheus

二、192.168.210.177 k8s-node1 安裝node_exporter 

[root@k8s-node1~]# tar -zxvf node_exporter-1.0.1.linux-amd64.tar.gz -C /usr/local/

node_exporter-1.0.1.linux-amd64/

node_exporter-1.0.1.linux-amd64/NOTICE

node_exporter-1.0.1.linux-amd64/node_exporter

node_exporter-1.0.1.linux-amd64/LICENSE

[root@k8s-node1~]#mv/usr/local/node_exporter-1.0.1.linux-amd64/ /usr/local/node_exporter

[root@k8s-node1 ~]# nohup /usr/local/node_exporter/node_exporter &

[1] 12524

檢視

http://192.168.210.85:9090/targets

部署Prometheus+Grafana

三、192.168.210.195 K8s-node2安裝grafana

 wget https://dl.grafana.com/oss/release/grafana-7.3.5.linux-amd64.tar.gz

[root@k8s-node2 ~]#tar -zxvf grafana-7.3.5.linux-amd64.tar.gz

[root@k8s-node2 ~]# mv grafana-7.3.5 /usr/local/

[root@k8s-node2 ~]# ln -s /usr/local/grafana-7.3.5/ /usr/local/grafana

[root@k8s-node2 ~]# useradd -s /sbin/nologin -M grafana

[root@k8s-node2 ~]# mkdir /data/grafana -pv

mkdir: 已建立目錄 "/data"

mkdir: 已建立目錄 "/data/grafana"

[root@k8s-node2 ~]# chown -R grafana:grafana /usr/local/grafana

grafana/       grafana-7.3.5/

[root@k8s-node2 ~]# chown -R grafana:grafana /usr/local/grafana/

[root@k8s-node2 ~]# chown -R grafana:grafana /data/grafana/

[root@k8s-node2 ~]# cd /usr/local/grafana

[root@k8s-node2 grafana]# ls

bin  conf  LICENSE  NOTICE.md  plugins-bundled  public  README.md  scripts  VERSION

[root@k8s-node2 grafana]# cd conf/

[root@k8s-node2 conf]# ls

defaults.ini  ldap_multiple.toml  ldap.toml  provisioning  sample.ini

[root@k8s-node2 conf]# cp defaults.ini defaults.ini.bak

[root@k8s-node2 conf]# vim defaults.ini

data = /data/grafana/data

logs = /data/grafana/log

plugins = /data/grafana/plugins

provisioning = /data/grafana/conf/provisioning

grafana-server添加到systemd中

vim /etc/systemd/system/grafana-server.service

Description=Grafana

After=network.target 

User=grafana

Group=grafana

Type=notify

ExecStart=/usr/local/grafana/bin/grafana-server -homepath /usr/local/grafana

Restart=on-failure

[root@k8s-node2 ~]# systemctl start grafana-server

[root@k8s-node2 ~]# systemctl status grafana-server

[root@k8s-node2 ~]# netstat -nltp|grep grafana

tcp6       0      0 :::3000                 :::*                    LISTEN      7107/grafana-server 

部署Prometheus+Grafana

浏覽器登入密碼admin

部署Prometheus+Grafana
部署Prometheus+Grafana
部署Prometheus+Grafana
部署Prometheus+Grafana
部署Prometheus+Grafana
部署Prometheus+Grafana
部署Prometheus+Grafana

配置節點

部署Prometheus+Grafana
部署Prometheus+Grafana

四、檢視伺服器和節點的基礎監控

k8s-master1--192.168.210.85

部署Prometheus+Grafana

k8s-node1--192.168.210.177

部署Prometheus+Grafana