Centos7下Prometheus+Grafana部署 redis 以及 mysql 监控
要在CentOS 7上部署Prometheus和Grafana监控Redis和MySQL,你需要先安装Prometheus和Grafana,然后配置它们以收集Redis和MySQL的指标。
以下是简化的步骤和示例配置:
- 安装Prometheus和Grafana:
# 安装Prometheus
sudo yum install -y prometheus
# 启动并使Prometheus服务开机自启
sudo systemctl start prometheus
sudo systemctl enable prometheus
# 安装Grafana
sudo yum install -y epel-release
sudo yum install -y grafana
# 启动并使Grafana服务开机自启
sudo systemctl start grafana-server
sudo systemctl enable grafana-server
- 配置Prometheus来监控Redis和MySQL:
首先,你需要为Redis和MySQL编写适当的exporter,例如redis_exporter
和mysqld_exporter
。
# 下载并安装Redis Exporter
wget https://github.com/oliver006/redis_exporter/releases/download/v0.27.0/redis_exporter-v0.27.0.linux-amd64.tar.gz
tar xvzf redis_exporter-v0.27.0.linux-amd64.tar.gz
sudo mv redis_exporter-v0.27.0.linux-amd64/redis_exporter /usr/local/bin/
# 下载并安装MySQL Exporter
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz
tar xvzf mysqld_exporter-0.12.1.linux-amd64.tar.gz
sudo mv mysqld_exporter-0.12.1.linux-amd64/mysqld_exporter /usr/local/bin/
# 运行Redis Exporter
redis_exporter -redis.addr=localhost:6379
# 运行MySQL Exporter
mysqld_exporter -config.my-cnf="/path/to/your/my.cnf"
然后,在Prometheus配置文件中添加以下内容:
# 在 /etc/prometheus/prometheus.yml 中
scrape_configs:
- job_name: 'redis'
static_configs:
- targets: ['localhost:9121']
- job_name: 'mysql'
static_configs:
- targets: ['localhost:9104']
- 配置Grafana以显示Redis和MySQL的监控仪表盘:
你需要在Grafana上导入Redis和MySQL的监控仪表盘。可以从以下地址找到预先准备的仪表盘:
- Redis: https://grafana.com/grafana/dashboards/13954-redis-monitoring-dashboard
- MySQL: https://grafana.com/grafana/dashboards/8919-mysql-overview
导入仪表盘的命令如下:
# 导入Redis仪表盘
grafana-cli plugins install redis-datasource
sudo systemctl restart grafana-server
grafana-cli dashboard import /path/to/redis-monitoring-dashboard.json
# 导入MySQL仪表盘
grafana-cli dashboard import /path/to/mysql-overview-dashboard.json
在Grafana界面中,你可以创建新的视图并选择相应的仪表盘来查看Redis和MySQL的监控数据。
确保你的Redis和MySQL服务器配置允许从运行Prometheus和Grafana的机
评论已关闭