前言:
一、前置环境说明
1、关闭firewall
systemctl stop firewalld.service
systemctl disable firewalld.service
2、关闭selinux
vim /etc/selinux/config
SELINUX=disabled
使配置立即生效,重启永久生效
setenforce 0
3、系统约定
软件源代码包存放位置:/opt
源码包编译安装位置:/usr/local/软件名字
数据存储位置:/data
二、部署Prometheus server
1、创建用户
useradd -d /data/prometheus -s /sbin/nologin prometheus
2、解压软件包
下载地址:https://prometheus.io/download/
tar xzvf prometheus-2.26.0.linux-amd64.tar.gz -C /usr/local/
授权属主属组
chown -R prometheus:prometheus prometheus/
ln -s /usr/local/prometheus-2.26.0.linux-amd64/ /usr/local/prometheus
已服务启动
cat >> /usr/lib/systemd/system/prometheus.service<<EOF
[Unit]
Description=Prometheus server Daemon
After=network.target
[Service]
Type=simple
User=root
Group=root
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/data/prometheus --storage.tsdb.retention=15d --web.enable-lifecycle
Restart = on-failure
[Install]
WantedBy=multi-user.target
EOF
3、启动服务
systemctl daemon-reload
systemctl enable prometheus --now
systemctl start prometheus
查看进程
netstat -tunlp | grep 9090
cd /usr/local/prometheus
./promtool check config prometheus.yml
三、部署node_exporter
centos 7安装
1、下载node_exporter
sudo wget https://github.com/prometheus/node_exporter/releases/download/v1.1.2/node_exporter-1.1.2.linux-amd64.tar.gz
2、解压软件
tar xf node_exporter-1.1.2.linux-amd64.tar.gz -C /usr/local/
cd /usr/local/ && mv node_exporter-1.1.2.linux-amd64/ node_exporter
3、创建用户
useradd -s /sbin/nologin prometheus
sudo chown -R prometheus:prometheus node_exporter/
4、已服务启动
cat >>/usr/lib/systemd/system/node-exporter.service<<EOF
[Unit]
Description=Prometheus server Daemon
After=network.target
[Service]
Type=simple
User=root
Group=root
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/data/prometheus --storage.tsdb.retention=15d --web.enable-lifecycle
Restart = on-failure
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable node-exporter --now
netstat -tunlp | grep 9100
脚本:
点击查看代码
#!/bin/bash
sudo wget https://github.com/prometheus/node_exporter/releases/download/v1.1.2/node_exporter-1.1.2.linux-amd64.tar.gz
tar xf node_exporter-1.1.2.linux-amd64.tar.gz -C /usr/local/ && cd /usr/local/ && mv node_exporter-1.1.2.linux-amd64/ node_exporter && useradd -s /sbin/nologin prometheus && chown -R prometheus:prometheus node_exporter/
cd /usr/lib/systemd/system/
cat << EOF > node-exporter.service
[Unit]
Description=Prometheus node_exporter
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/node_exporter/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
如果系统开启防火墙,需要设置防火墙规则
systemctl status firwlalld
firewall-cmd --zone=public --add-port=9100/tcp --permanent (--permanent永久生效,没有此参数重启后失效)
重新载入
firewall-cmd --reload
centos6安装
nohup ./node_exporter --web.listen-address=":9100" >/dev/null 2>&1 &
如果系统开启防火墙,需要设置防火墙规则
iptables -A INPUT -p tcp --dport 9100 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 9100 -j ACCEPT
service iptables save
vim /etc/sysconfig/iptables
service iptables restart
待补充。。。
标签:node,exporter,部署,prometheus,centos7,--,Prometheus,usr,local From: https://www.cnblogs.com/windle/p/16932216.html