Centos下部署prometheus+grafana并监控业务主机和数据库

首先准备环境。

由于prometheus是由go语言开发,所以需要先准备一个go语言环境。

下载地址:https://storage.googleapis.com/golang/go1.8.3.linux-amd64.tar.gz

再准备一个prometheus的tar包

下载地址:https://prometheus.io/download/

 

开始部署

1.首先将go的tar包解压至/usr/local目录下

[root@localhost ~]# tar -zxvf go1.8.3.linux-amd64.tar.gz -C /usr/local/

2.编辑环境变量配置文件,将export PATH=$PATH:/usr/local/go/bin加入至最后一行,然后source保存

[root@localhost ~]# vim /etc/profile
[root@localhost ~]# source /etc/profile

3.go version查看安装情况,出现结果说明安装成功

[root@localhost ~]# go version
go version go1.8.3 linux/amd64

4.解压prometheus tar包至/usr/local目录下

[root@localhost ~]# tar -zxvf prometheus-2.27.1.linux-amd64.tar.gz -C /usr/local/

5.编辑prometheus.yml配置文件,写入以下文本,注意缩进

[root@localhost prometheus-2.27.1.linux-amd64]# vim prometheus.yml
[root@localhost prometheus-2.27.1.linux-amd64]# cat prometheus.yml
  scrape_configs:

# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.

- job_name: ‘prometheus‘

# metrics_path defaults to ‘/metrics‘
# scheme defaults to ‘http‘.

static_configs:
- targets: [‘localhost:9090‘]

- job_name: ‘db-1‘
static_configs:
- targets: [‘192.168.66.20:9104‘]
labels:
instance: ‘db-1‘

- job_name: ‘node-1‘
static_configs:
- targets: [‘192.168.66.20:9100‘]
labels:
instance: ‘node-1‘

#红色字体部分为加入配置

6.在被监控主机上安装go语言环境,安装exporter,tar包下载地址:https://prometheus.io/download/

Centos下部署prometheus+grafana并监控业务主机和数据库

 

 

 Centos下部署prometheus+grafana并监控业务主机和数据库

 

 

 安装步骤还是跟上边一样解压,需要注意的是监控mysql需要创建一个用户并授权,命令如下

mysql> GRANT REPLICATION CLIENT,PROCESS ON *.* TO mysql_monitor@localhost identified by mysql_monitor;
mysql> GRANT SELECT ON *.* TO mysql_monitor@localhost;

7.随后在/usr/local/mysql_exporter目录下创建.my.cnf文件,将刚创建的用户名及密码写入,监控node则忽略这两步

[root@zabbix_server ~]# cat /usr/local/mysqld_exporter-0.13.0-rc.0.linux-amd64/.my.cnf 
[client] 
user=mysql_monitor
password=mysql_monitor

8.prometheus主机开9090端口,mysql的默认监听端口是9104,node端口默认是9100,在被监控主机开启这两个端口,然后在两台主机启动

prometheus主机:

[root@localhost ~]# /usr/local/prometheus-2.27.1.linux-amd64/prometheus --config.file="/usr/local/prometheus-2.27.1.linux-amd64/prometheus.yml" &

被监控主机(mysql和node):

[root@zabbix_server ~]# nohup /usr/local/node_exporter-1.1.2.linux-amd64/node_exporter &   ##启动node

[root@zabbix_server ~]# nohup /usr/local/mysqld_exporter-0.13.0-rc.0.linux-amd64/mysqld_exporter --config.my-cnf="/usr/local/mysqld_exporter-0.13.0-rc.0.linux-amd64/.my.cnf" & ##启动mysql

 

9.浏览器访问prometheus主机ip:9090/targets

Centos下部署prometheus+grafana并监控业务主机和数据库

 

 

 至此prometheus部署完成,接下来安装garfana进行可视化监控

10.下载并安装garfana

[root@zabbix_server ~]# wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.2.3-1.x86_64.rpm

 [root@zabbix_server ~]# yum localinstall grafana-5.2.3-1.x86_64.rpm

 

11.加入系统服务并启动

[root@zabbix_server ~]# sudo /sbin/chkconfig --add grafana-server
[root@zabbix_server ~]# sudo service grafana-server start
Starting grafana-server (via systemctl):                   [  确定  ]

12.防火墙开3000端口,浏览器访问,用户名密码默认admin/admin,第一次登陆会要求改密码

Centos下部署prometheus+grafana并监控业务主机和数据库

 

 13.配置prometheusCentos下部署prometheus+grafana并监控业务主机和数据库

 

 14.完成

Centos下部署prometheus+grafana并监控业务主机和数据库

 

Centos下部署prometheus+grafana并监控业务主机和数据库

上一篇:8、GET基于报错的SQL注入


下一篇:数据库设计