prometheus2.25安装和使用流程

prometheus2.25+grafana7.4安装和使用流程

作者:蓝眼泪

本人亲自试验,并成功安装,看了别人写的,都没讲到重点,自己花时间研究,并写出。原创不易,且行且珍惜。如有不足之处,请大佬指点!一起交流,共同进步。免费分享给大家。

实验环境:xshell7,xftp7,centos7.9,win7旗舰版,vm15.
资料准备齐全
在这里插入图片描述

第一 关闭防火墙和selinux

systemctl stop firewalld 
systemctl disable firewalld 
iptables -F
setenforce=0

用xftp上传以上资料到centos系统中。文件放置路径为/usr/local

第二 安装go软件

解压go软件

tar -C /usr/local/ -xvf go1.16.linux-amd64.tar.gz

配置环境变量

vim /etc/profile
export PATH=$PATH:/usr/local/go/bin
source /etc/profile

查看go版本

go version

第三 安装prometheus软件

解压prometheus软件

tar -C /usr/local/ -xvf prometheus-2.25.0.linux-amd64.tar.gz
ln -sv /usr/local/prometheus-2.25.0.linux-amd64/ /usr/local/Prometheus

启动prometheus软件

/usr/local/Prometheus/prometheus --config.file=/usr/local/Prometheus/prometheus.yml &

访问prometheus网页
http://localhost:9090
在这里插入图片描述

第四 安装grafana软件

普罗米修斯默认的页面比较简单,安装grafana可以使监控看起来更直观
安装命令:

rpm -ivh --nodeps grafana-7.4.3-1.x86_64.rpm
wget https://dl.grafana.com/oss/release/grafana-7.4.3-1.x86_64.rpm
sudo yum install grafana-7.4.3-1.x86_64.rpm

启动grafana软件

sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable grafana-server.service
sudo /bin/systemctl start grafana-server.service

用浏览器访问localhost:3000,即可打开grafana页面,默认用户名密码都是admin,初次登录会要求修改默认的登录密码
确认端口

lsof -i:3000
ss -anltp | grep 9090

在这里插入图片描述

第五 设置grafana

添加数据源adddatabase,选择prometheus。截图如下:
在这里插入图片描述

Dashboards页面选择“Prometheus 2.0 Stats”
在这里插入图片描述

Settings页面填写普罗米修斯地址并保存
在这里插入图片描述

换到我们刚才添加的“Prometheus 2.0 Stats”即可看到整个监控页面
在这里插入图片描述

第六 常用监控项目

1.监控linux电脑

在Linux上安装node-exporter

tar -xvf node_exporter-0.17.0.linux-amd64.tar.gz -C /usr/local/

启动node-exporter

/usr/local/node_exporter-0.17.0.linux-amd64/node_exporter &

还可以使用node_exporter启动

nohup /usr/local/node_exporter/node_exporter & 

普罗米修斯配置文件添加监控项

vim /usr/local/Prometheus/prometheus.yml
  - job_name: 'centos7.9'
    static_configs:
    - targets: ['192.168.1.130:9100']
      labels:
        instance: 192.168.1.130:9100

grafana导入画好的dashboard

如果提示缺少piechart文件,解决方法是
grafana的默认插件目录是/var/lib/grafana/plugins,将下载好的插件解压到这个目录,重启grafana即可

cd /var/lib/grafana/plugins
unzip grafana-piechart-panel-5f249d5.zip
service grafana-server restart
/usr/sbin/grafana-cli plugins ls  #查看已安装插件

重启prometheus服务

pkill prometheus 
ss -anltp | grep 9090
/usr/local/Prometheus/prometheus --config.file=/usr/local/Prometheus/prometheus.yml &

启动linux监控节点

/usr/local/node_exporter-0.17.0.linux-amd64/node_exporter &

编辑监控项目

vim /usr/local/Prometheus/prometheus.yml

2.监控mysql软件

安装mysql

rpm -qa | grep mysql
rpm -qa|grep -i mariadb
rpm -qa|grep mariadb|xargs rpm -e --nodeps
rpm -qa|grep -i mariadb
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum repolist all | grep mysql 
yum install mysql-server
rpm -qa | grep mysql
systemctl start mysqld.service #启动 mysql
systemctl restart mysqld.service #重启 mysql
systemctl stop mysqld.service #停止 mysql
systemctl enable mysqld.service #设置 mysql 开机启动

mysql常用文件路径:
/etc/my.cnf    #mysql的主配置文件
/var/lib/mysql   #mysql数据库的数据库文件存放位置
/var/logs/mysqld.log  #数据库的日志输出存放位置

mysql -u root
mysql> use mysql;
mysql> update user set password=PASSWORD("123456") where User='root';
mysql> flush privileges; 
mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "123456";
GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "123456";

mysql远程连接权限开通

 create user 'root'@'localhost' identified by '123456';
 GRANT REPLICATION CLIENT, PROCESS ON *.* TO 'root'@'localhost';
 GRANT SELECT ON performance_schema.* TO 'root'@'localhost';
 ALTER USER root@localhost IDENTIFIED WITH mysql_native_password BY '123456';
 flush privileges;

启动mysql监控

 export DATA_SOURCE_NAME='root:123456@(192.168.1.130:3306)/'
/usr/local/mysqld_exporter-0.11.0.linux-amd64/mysqld_exporter

配置文件通过–config.my-cnf参数指定:

cd /usr/local/mysqld_exporter-0.11.0.linux-amd64
./mysqld_exporter --config.my-cnf=".my.cnf"

配置文件的格式如下:

cat .my.cnf

[client]
host=localhost
port=3306
user=root
password=123456

/usr/local/mysqld_exporter-0.11.0.linux-amd64/mysqld_exporter --config.my-cnf="/usr/local/mysqld_exporter-0.11.0.linux-amd64/.my.cnf" &

3.监控redis软件

安装redis

 yum install -y gcc 
wget http://download.redis.io/releases/redis-5.0.3.tar.gz
tar -zxvf redis-5.0.3.tar.gz
cd redis-5.0.3
Make
make install PREFIX=/usr/local/redis
cd /usr/local/redis/bin/
./redis-server
cp /usr/local/redis-5.0.3/redis.conf /usr/local/redis/bin/

修改 redis.conf 文件,把 daemonize no 改为 daemonize yes

vi /usr/local/redis/bin/redis.conf

启动redis

/usr/local/redis_exporter redis//192.168.1.130:6379 & -web.listenaddress 192.168.1.130:9121
/usr/local/redis_exporter redis//192.168.60.124:6379 & -web.listenaddress 192.168.60.124:9121
./redis-server redis.conf
vi /etc/systemd/system/redis.service

代码段

[Unit]
Description=redis-server
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.target

设置开机启动

systemctl daemon-reload
systemctl start redis.service
systemctl enable redis.service

创建 redis 命令软链接

ln -s /usr/local/redis/bin/redis-cli /usr/bin/redis

测试 redis
在这里插入图片描述

redis服务操作命令

systemctl start redis.service   #启动redis服务
systemctl stop redis.service   #停止redis服务
systemctl restart redis.service   #重新启动服务
systemctl status redis.service   #查看服务当前状态
systemctl enable redis.service   #设置开机自启动
systemctl disable redis.service   #停止开机自启动

启动redis监控

./redis_exporter redis//192.168.1.130:6379 & -web.listenaddress 192.168.1.130:9121
./redis_exporter redis//192.168.60.124:6379 & -web.listenaddress 192.168.60.124:9121

4.监控windows电脑

在被监控windows电脑上安装wmi-exporter软件
网址:https://github.com/martinlindhe/wmi_exporter/releases
在这里插入图片描述

在这里插入图片描述

vim /usr/local/Prometheus/prometheus.yml
  - job_name: 'win7-64-001'
    static_configs:
    - targets: ['192.168.1.103:9182']

关于仪表盘json文件可以参考如下:
网址是https://grafana.com/grafana/dashboards/10467

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Prometheus 是一个开源的监控系统,它可以用来收集、存储和查询各种不同类型的指标数据。下面是一个简要的 Prometheus 安装使用教程: 1. 下载 Prometheus 你可以从 Prometheus 的官网下载最新版本的二进制文件:https://prometheus.io/download/ 2. 解压 Prometheus 将下载的 Prometheus 压缩文件解压到你想要安装的目录中: ``` tar xvfz prometheus-*.tar.gz cd prometheus-* ``` 3. 配置 Prometheus Prometheus 的配置文件是 `prometheus.yml`,你需要根据你的需要编辑它。这个文件包含了 Prometheus 的所有配置信息,包括要监控的目标、指标的抓取频率等等。 例如,以下是一个简单的 Prometheus 配置文件: ``` global: scrape_interval: 15s scrape_configs: - job_name: 'prometheus' static_configs: - targets: ['localhost:9090'] ``` 这个配置文件定义了一个名为 `prometheus` 的作业,它会每 15 秒抓取 localhost:9090 上的指标数据。 4. 启动 Prometheus 使用以下命令启动 Prometheus: ``` ./prometheus ``` 这将启动 Prometheus,并开始抓取指标数据。你可以在浏览器中访问 `http://localhost:9090`,查看 Prometheus 的 Web 界面。 5. 查询指标 在 Prometheus 的 Web 界面中,你可以使用 PromQL 查询语言查询指标数据。例如,以下查询会返回 Prometheus 目前存储的所有指标名称: ``` {__name__} ``` 这只是一个简单的例子,你可以在 Prometheus 的文档中找到更多的查询语言和示例。 这就是一个简单的 Prometheus 安装使用教程。希望能对你有所帮助!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值