(openEuler21.03-x86)prometheus-2.16.0+grafana-7.2.0监控mysql8
【摘要】 (openEuler21.03-x86)prometheus-2.16.0+grafana-7.2.0监控mysql8
#关闭防火墙和 selinux 并重启
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
systemctl disable --now firewalld
#配源
vim /etc/yum.repos.d/openEuler.repo
[OS]
name=OS
baseurl=http://repo.openeuler.org/openEuler-21.03/OS/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://repo.openeuler.org/openEuler-21.03/OS/$basearch/RPM-GPG-KEY-openEuler
[everything]
name=everything
baseurl=http://repo.openeuler.org/openEuler-21.03/everything/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://repo.openeuler.org/openEuler-21.03/everything/$basearch/RPM-GPG-KEY-openEuler
[EPOL]
name=EPOL
baseurl=http://repo.openeuler.org/openEuler-21.03/EPOL/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://repo.openeuler.org/openEuler-21.03/OS/$basearch/RPM-GPG-KEY-openEuler
[debuginfo]
name=debuginfo
baseurl=http://repo.openeuler.org/openEuler-21.03/debuginfo/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://repo.openeuler.org/openEuler-21.03/debuginfo/$basearch/RPM-GPG-KEY-openEuler
[source]
name=source
baseurl=http://repo.openeuler.org/openEuler-21.03/source/
enabled=1
gpgcheck=1
gpgkey=http://repo.openeuler.org/openEuler-21.03/source/RPM-GPG-KEY-openEuler
[update]
name=update
baseurl=http://repo.openeuler.org/openEuler-21.03/update/$basearch/
enabled=0
gpgcheck=1
gpgkey=http://repo.openeuler.org/openEuler-21.03/OS/$basearch/RPM-GPG-KEY-openEuler
#更新yum源
yum makecache
1、安装prometheus-2.16.0
#prometheus官网
https://prometheus.io/download/
#通过wget下载prometheus
wget https://github.com/prometheus/prometheus/releases/download/v2.16.0/prometheus-2.16.0.linux-amd64.tar.gz
#同步时间
yum install -y ntpdate && ntpdate time.windows.com
#解压-安装
ll
#解压至/usr/local/
tar -zxvf prometheus-2.16.0.linux-amd64.tar.gz -C /usr/local/
#将prometheus-2.16.0.linux-amd64改名为prometheus
mv /usr/local/prometheus-2.16.0.linux-amd64/ /usr/local/prometheus
cd /usr/local/prometheus
ll
#启动Prometheus—使用默认配置文件启动
/usr/local/prometheus/prometheus --config.file="/usr/local/prometheus/prometheus.yml" &
#查看9090端口是否开启
ss -anlt | grep 9090
#通过浏览器进入页面
IP:9090
#数据展示
IP:9090/metrics
说明有数据
2、安装grafana-7.2.0
Grafana是一款用Go语言开发的开源数据可视化工具,可以做数据监控和数据统计,带有告警功能,支持Graphite、elasticsearch、zabbix、InfluxDB、Prometheus和OpenTSDB作为数据源。Grafana主要特性:灵活丰富的图形化选项;可以混合多种风格;支持白天和夜间模式;多个数据源
#安装go语言环境
yum -y install go
#下载grafana-7.2.0-1.x86_64.rpm
wget https://dl.grafana.com/oss/release/grafana-7.2.0-1.x86_64.rpm
#安装
yum -y install grafana-7.2.0-1.x86_64.rpm
#开机自启grafana-server
systemctl enable grafana-server
#开启grafana-server
systemctl start grafana-server
#浏览器输入IP:3000
账号密码默认admin/admin
设置新密码
或docker安装Grafana
#yum安装docker
yum -y install docker
#或一键用docker安装grafana
docker run -d --name=grafana -p 3000:3000 grafana/grafana-enterprise
#分解步骤
# 在docker库中查找grafana镜像
docker search grafana
# 从docker库拉取grafana镜像
docker pull grafana/grafana
# 查看docker镜像
docker images
#启动Grafana镜像
docker run -d -p 3000:3000 --name grafana grafana/grafana
-d: deamon, 后台启动
-p: port, 端口映射,宿主机端口:容器内端口, 3000为grafana的web界面端口
--name grafana: 启动的程序名,此处为grafana
grafana/grafana: 程序启动依赖的docker镜像
docker ps -a
3、安装mysql8.0数据库
#查看是否安装有数据库,避免mariadb和mysql数据库冲突
rpm -qa | grep -i mariadb
rpm -qa | grep -i mysql
yum -y remove mariadb-connector-c-3.0.6-7.oe1.x86_64
#查看可安装的mysql数据库
yum list mysql
yum clean all
yum makecache
#安装数据库,启动数据库,并开机自启
yum -y install mysql mysql-libs mysql-devel mysql-server
systemctl enable mysqld.service
systemctl start mysqld.service
#初始化 mariadb 并配置 root 密码
mysql_secure_installation
#直接回车,空
是否设置密码:y
输入设置密码:
再次输入密码:
是否移除anonymous用户:y
是否不允许root远程登录:n
是否移除test数据库:y
是否更新:y
4、配置prometheus-2.16.0+grafana-7.2.0
/etc/hosts文件(添加路由),配置完路由后,服务器相互ping通即可
vi /etc/hosts
#Prometheus可以查看到监控的数据
#Grafana主界面配置prometheus数据源,服务器收集到的数据作为数据源添加到Grafana,这样Grafana就能把Prometheus的数据进行可视化。
#上传安装mysqld_exporter组件,改名
tar xf mysqld_exporter-0.11.0.linux-amd64.tar.gz -C /usr/local/
mv /usr/local/mysqld_exporter-0.11.0.linux-amd64/ /usr/local/mysqld_exporter
ls /usr/local/mysqld_exporter
#进入数据库,授权
mysql -u root -p
mysql> grant select,replication client,process ON *.* to 'mysql_monitor'@'localhost' identified by '111111';
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
创建mysql配置文件
vi /usr/local/mysqld_exporter/.my.cnf
[client]
user=mysql_monitor
password=111111
#启动mysqld_exporter
nohup /usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/.my.cnf &
#确认端口
ss -anlt | grep 9104
#添加Prometheus服务器配置,在最后添加如下内容(配置格式要注意,不然开启prometheus服务会报错)
vi /usr/local/prometheus/prometheus.yml
- job_name: mysqld
static_configs:
- targets: ['IP:9104']
#重启prometheus服务
pkill prometheus
/usr/local/prometheus/prometheus --config.file="/usr/local/prometheus/prometheus.yml" &
#上传至/var/lib/grafana/
unzip grafana-dashboards-master.zip
cp -R /var/lib/grafana/grafana-dashboards-master/dashboards/ /var/lib/grafana/
#更改grafana配置文件
vi /etc/grafana/grafana.ini
[dashboards.json]
enabled = true
path = /var/lib/grafana/dashboards
#重启Grafana服务
systemctl restart grafana-server
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)