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
[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
[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
[root@k8s-master1 ~]#tar -zxvf node_exporter-1.0.1.linux-amd64.tar.gz -C /usr/local/
[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 &
修改k8s-master1 服务器prometheus.yml的配置
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
三、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
浏览器登录密码admin
配置节点
四、查看服务器和节点的基础监控
k8s-master1--192.168.210.85
k8s-node1--192.168.210.177