helm安装配置mysql exporter

过程1波三折,实际上需要做的并不多
mysql exporter 使用helm安装,只需要将mysql的设定传入到chart下的values.yaml中
具体步骤如下:

#查看当前的helm repo
[root@master ~]# helm repo list
NAME    URL                          
stable  https://charts.helm.sh/stable

拉取相关的chart,不直接install的原因是将mysql 连接需要的值传入到values.yaml中

helm pull prometheus-mysql-exporter stable/prometheus-mysql-exporter 
cd $HOME/.cache/helm/repository/   #helm 文件下载的目录
tar zxvf prometheus-mysql-exporter-0.7.1.tgz   #解压mysql exporter 的文件
cd prometheus-mysql-exporter/
#修改values.yaml的值,主要是将连接数据库的用户名,host信息等传入进去,同时在建立容器的同时建立servicemonitor
...
serviceMonitor:
  enabled: true
...
mysql:
  db: ""
  host: "你的ip"
  param: ""
  pass: "你的密码"
  port: 3306
  protocol: ""
  user: "exporter"
  existingSecret: false
...

当然exporter在数据库中首先定义好相关的权限,以及密码,访问限制等

CREATE USER 'exporter'@'localhost' IDENTIFIED BY 'XXXXXXXX' WITH MAX_USER_CONNECTIONS 3;
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost';

操作完以上之后,需要重新打包helm文件

rm -f prometheus-mysql-exporter-0.7.1.tgz
tar zcvf prometheus-mysql-exporter-0.7.1.tgz prometheus-mysql-exporter
#之后执行helm install
helm install mysql  prometheus-mysql-exporter-0.7.1.tgz --namespace monitoring
#观察容器是否正常启动
kubectl -n monitoring get pods
NAME                                                     READY   STATUS    RESTARTS   AGE
alertmanager-prometheus-prometheus-oper-alertmanager-0   2/2     Running   0          69d
mysql-prometheus-mysql-exporter-bfc59c7b7-dnhhm          1/1     Running   0          4h54m
prometheus-grafana-5558455c66-52dsg                      2/2     Running   0          69d
prometheus-kube-state-metrics-6b46f67bf6-h5nhs           1/1     Running   0          46d
prometheus-prometheus-node-exporter-2jrvp                1/1     Running   0          69d
prometheus-prometheus-node-exporter-ct96h                1/1     Running   0          69d
prometheus-prometheus-node-exporter-lbsnm                1/1     Running   0          69d
prometheus-prometheus-node-exporter-m6jd6                1/1     Running   0          14d
prometheus-prometheus-node-exporter-nlfwt                1/1     Running   0          69d
prometheus-prometheus-oper-operator-7c75ff5864-g2lkq     2/2     Running   0          23h
prometheus-prometheus-prometheus-oper-prometheus-0       3/3     Running   2          45h
#测试与数据库的连通性
[root@master ~]# kubectl -n monitoring get svc
NAME                                      TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE
alertmanager-operated                     ClusterIP   None                     9093/TCP,9094/TCP,9094/UDP   69d
mysql-prometheus-mysql-exporter           ClusterIP   10.105.203.102           9104/TCP                     4h55m
prometheus-grafana                        NodePort    10.104.181.79            80:32669/TCP                 69d
prometheus-kube-state-metrics             ClusterIP   10.102.76.12             8080/TCP                     69d
prometheus-operated                       ClusterIP   None                     9090/TCP                     69d
prometheus-prometheus-node-exporter       ClusterIP   10.103.134.197           9100/TCP                     69d
prometheus-prometheus-oper-alertmanager   ClusterIP   10.103.19.123            9093/TCP                     69d
prometheus-prometheus-oper-operator       ClusterIP   10.97.236.198            8080/TCP,443/TCP             69d
prometheus-prometheus-oper-prometheus     NodePort    10.97.65.121             9090:30658/TCP               69d
curl 10.105.203.102:9104/metrics |grep mysql_up
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  347k  100  347k    0     0  2079k      0 --:--:-- --:--:-- --:--:-- 2081k
# HELP mysql_up Whether the MySQL server is up.
# TYPE mysql_up gauge
mysql_up 1

mysql_up是1 证明与数据库连接正常,接下来要看与prometheus 是否连接正常

#确认service monitor已创建
[root@master ~]# kubectl -n monitoring get servicemonitors.monitoring.coreos.com 
NAME                                                 AGE
mysql-prometheus-mysql-exporter                      5h4m

浏览器确认状态:


image.png

上图表明,prometheus已经成功加入了mysql exporter。
在这个过程中,我开始创建的mysql exporter 并未在网页端targets选项中找到,最后发现问题的所在是要


image.png

这里默认生成的release 是mysql ,但是需要指定为prometheus,修改完之后,需要等一段时间重新查看就能看到了

你可能感兴趣的:(helm安装配置mysql exporter)