Prometheus 监控

Prometheus 监控

1.Prometheus服务端安装

# 关闭机器防火墙
systemctl stop firewalld
systemctl disable firewalld
# 安装GO语言环境
yum -y install golang
# 查看位置 
find / -name golang 
# 在环境变量文件中添加go语音环境
vim /etc/profile
export GOROOT=/usr/lib/golang
export GOPATH=/root/Work/programmer/go/gopath/
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
# 加载配置文件
source /etc/profile
tee /etc/systemd/system/prometheus.service <<EOF
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/
After=network.target

[Service]
Type=simple
ExecStart=/opt/prometheus/prometheus \
  --config.file=/opt/prometheus/prometheus.yml \
  --web.listen-address=:9090
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF
vim /etc/systemd/system/node_exporter.service
[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
ExecStart=/opt/node_exporter/node_exporter

[Install]
WantedBy=default.target
 vim /opt/prometheus/prometheus.yml   
   - job_name: 'node_exporter'
     static_configs:
       - targets: ['localhost:9100']
# 安装插件
grafana-cli plugins install devopsprodigy-kubegraf-app
grafana-cli plugins install grafana-kubernetes-app

# 插件依赖环境:(Grafana之KubeGraf插件展示kubernetes集群性能)
1、需先部署好kubernetes集群,因为我们要监控的目标就是kubernetes。
2、需先部署好prometheus、node_exporter、kube-state-metrics、cAdvisor等,因为我们要依赖prometheus作为数据源来监控kubernetes,而prometheus需依赖node_exporter、kube-state-metrics、cAdvisor等来采集数据。
3、需先安装好Grafana-piechart-panel,因为KubeGraf中的Dashboard中有用到piechart-panel。

# 获取文件
wget  https://github.com/kubernetes/kube-state-metrics/tree/master/examples/standard
for file in cluster-role-binding.yaml cluster-role.yaml service-account.yaml service.yaml deployment.yaml  ; do wget https://raw.githubusercontent.com/kubernetes/kube-state-metrics/master/examples/standard/$file ;done 

# 修改对应名称空间(namespace)
for i in cluster-role-binding.yaml deployment.yaml service-account.yaml service.yaml; do sed -i '/namespace/s/kube-system/ns-monitor/' $i ; done 
# 增加参数
vim service.yaml
修改service.yaml
[root@master kube-state-metrics]# vim service.yaml 
apiVersion: v1
kind: Service
metadata:
  labels:
    app.kubernetes.io/name: kube-state-metrics
    app.kubernetes.io/version: v1.8.0
  name: kube-state-metrics
  namespace: ns-monitor
  annotations:
   prometheus.io/scrape: "true"       ##添加此参数,允许prometheus自动发现
spec:
  clusterIP: None
  ports:
  - name: http-metrics
    port: 8080
    targetPort: http-metrics
  - name: telemetry
    port: 8081
    targetPort: telemetry
  selector:
    app.kubernetes.io/name: kube-state-metrics

留下评论