prometheus安装部署

Prometheus环境搭建

1 安装prometheus

1.1将prometheus安装包上传到服务器的/usr/local目录下,进行解压

[root@prometheus-1 local]# ls

bin  etc  games  include  lib  lib64  libexec  prometheus  sbin  share  src

[root@prometheus-1 local]# pwd

/usr/local

1.2进行环境验证

[root@prometheus-1 prometheus]# ./prometheus --version

prometheus, version 2.6.0 (branch: HEAD, revision: dbd1d58c894775c0788470944b818cc724f550fb)

  build user:       root@bf5760470f13

  build date:       20181217-15:14:46

  go version:       go1.11.3

1.3修改配置文件prometheus.yml

修改以后内容如下所示

global:

 

alerting:

  alertmanagers:

  - static_configs:

    - targets:

 

rule_files:

 

scrape_configs:

  - job_name: 'prometheus'

    static_configs:

    - targets: ['192.168.101.21:9090', '192.168.101.37:9090', '192.168.101.32:9090']

 

  - job_name: 'node-1'

    static_configs:

    - targets: ['192.168.101.33:9100']

      labels:

        instance: server1

  

  - job_name: 'node-2'

    static_configs:

    - targets: ['192.168.101.39:9100']

      labels:

        instance: server2

1.4 设置用户

添加用户,后期使用此账号启动服务

groupadd prometheus

useradd -g prometheus -s /sbin/nologin prometheus

赋权

chown -R prometheus:prometheus /usr/local/prometheus/

创建prometheus运行数据目录

mkdir -p /var/lib/prometheus

chown -R prometheus:prometheus /var/lib/prometheus/

设置开机启动

touch /usr/lib/systemd/system/prometheus.service

chown prometheus:prometheus /usr/lib/systemd/system/prometheus.service

修改新创建的prometheus.service文件

[root@prometheus-1 prometheus]# cat /usr/lib/systemd/system/prometheus.service

[Unit]

Description=Prometheus

Documentation=https://prometheus.io/

After=network.target

 

[Service]

# Type设置为notify时,服务会不断重启

Type=simple

User=prometheus

# --storage.tsdb.path是可选项,默认数据目录在运行目录的./dada目录中

ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus

Restart=on-failure

 

[Install]

WantedBy=multi-user.target

开启服务

systemctl start prometheus

systemctl status prometheus

systemctl enable prometheus

2 安装node_exporter

添加用户,后期使用此账号启动服务

groupadd prometheus

useradd -g prometheus -s /sbin/nologin prometheus

赋权

chown -R prometheus:prometheus /usr/local/node_exporter/

修改配置文件/usr/lib/systemd/system/node_exporter.service

修改后内容如下所示

[root@nodeexport-1 ~]# cat /usr/lib/systemd/system/node_exporter.service

[Unit]

Description=node_exporter

Documentation=https://prometheus.io/

After=network.target

 

[Service]

Type=simple

User=prometheus

ExecStart=/usr/local/node_exporter/node_exporter

Restart=on-failure

 

[Install]

WantedBy=multi-user.target

开启服务

systemctl start node_exporter

systemctl status node_exporter

systemctl enable node_exporter

 

3 安装grafana

[root@prometheus-1 ~]# rpm -ivh grafana-5.4.1-1.x86_64.rpm --nodeps

warning: grafana-5.4.1-1.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID 24098cb6: NOKEY

Preparing...                          ################################# [100%]

Updating / installing...

   1:grafana-5.4.1-1                  ################################# [100%]

登录http://192.168.101.45:3000,进入grafana首界面

Grafana导入dashboard.json文件

文件下载地址:

http://blog.csdn.net/ywd1992/article/details/85989259

prometheus节点

在安装mysqld-exporter过程中,需要注意在prometheus节点安装mysql相应的客户端

安装如下所示

mysql-community-client-5.7.24-1.el7.x86_64.rpm

mysql-community-common-5.7.24-1.el7.x86_64.rpm

mysql-community-libs-5.7.24-1.el7.x86_64.rpm

在安装mysql相应安装包的过程中需要卸载redhat自带的包,如下所示

rpm -e mariadb-libs-5.5.60-1.el7_5.x86_64 –nodeps

mysql节点

在/usr/local/mysqld_exporter-0.11.0.linux-amd64目录下配置配置文件.my.conf

内容如下所示:

[client]

user=root

password=admin123

安装好mysql以后可以通过在/etc/my.cnf配置文件中添加如下内容从而实现可以不通过密码登录数据库

在[mysqld]下添加如下内容

skip-grant-tables

登录到数据库以后可以通过如下命令设置数据库密码

update  mysql.user set authentication_string=password(‘admin123’) where user=’root’;

flush privileges;使修改密码指令立即生效

此刻可以修改去掉在my.cnf配置文件中添加的内容,重启数据库,此刻可以通过设置的密码进行登录。

设置prometheus远程登录mysql节点的权限

GRANT  ALL  PRIVILEGES  ON  *.* TO  ‘root’@ ’IP’  IDENTIFIED BY  ‘admin123’  WITH GRANT OPTION.

如果启动mysql_exporter过程中报错数据库登录密码过期,可以采用如下方法解决:

alter user ‘root’@’localhost’ identified by ‘admin123’;

flush privileges;

猜你喜欢

转载自blog.csdn.net/wzf862187413/article/details/87867797