本次部署服务器环境为Centos7(64位)
进入官网下载最新版本
https://prometheus.io/download/
wget https://github.com/prometheus/prometheus/releases/download/v2.19.2/prometheus-2.19.2.linux-amd64.tar.gz
tar xzf prometheus-2.19.2.linux-amd64.tar.gz
mv prometheus-2.19.2.linux-amd64 /usr/local/prometheus
添加低权限用户运行Promtheus
groupadd prometheus
useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus
添加开机启动项
cat /etc/systemd/system/prometheus.service
[Unit]
Description=prometheus
After=network.target
[Service]
Type=simple
User=prometheus
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 daemon-reload
systemctl start prometheus
systemctl status prometheus
安装node_exporter
wget https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz
tar -zxf node_exporter-1.0.1.linux-amd64.tar.gz
mv node_exporter-1.0.1.linux-amd64 /usr/local/node_exporter
添加开机启动项
cat /etc/systemd/system/node_exporter.service
[Unit]
Description=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
systemctl daemon-reload
systemctl start node_exporter
systemctl enable node_exporter
systemctl status node_exporter
添加Prometheus监控项
cat /usr/local/prometheus/prometheus.yml
global:
scrape_interval: 15s
evaluation_interval: 15s
alerting:
alertmanagers:
- static_configs:
- targets:
rule_files:
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'node'
static_configs:
- targets: ['localhost:9100']
添加完成后重启prometheus使服务生效
systemctl restart prometheus
安装Grafana
进入官网下载最新版https://grafana.com/grafana/download
wget https://dl.grafana.com/oss/release/grafana-7.0.6-1.x86_64.rpm
yum -y install grafana-7.0.6-1.x86_64.rpm
systemctl start grafana-server
systemctl enable grafana-server
systemctl status grafana-server
防火墙开放放端口
firewall-cmd --zone=public --add-port=9090/tcp --permanent
firewall-cmd --zone=public --add-port=3000/tcp --permanent
firewall-cmd --reload
\\删除命令
firewall-cmd --zone=public --remove-port=9090/tcp --permanent
附Centos6默认防火墙命令
/sbin/iptables -I INPUT -p tcp --dport 9090 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 3000 -j ACCEPT
更新时间,设置时区
yum -y install ntpdate
crontab -l > crontabtmp && echo "0 * * * * ntpdate cn.ntp.org.cn" >> crontabtmp && crontab crontabtmp && rm -f crontabtmp
timedatectl list-timezones
timedatectl set-timezone Asia/Shanghai
网友评论