本次部署服務(wù)器環(huán)境為Centos7(64位)
進(jìn)入官網(wǎng)下載最新版本
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
添加低權(quán)限用戶運(yùn)行Promtheus
groupadd prometheus
useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus
添加開機(jī)啟動(dòng)項(xiàng)
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
添加開機(jī)啟動(dòng)項(xiàng)
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監(jiān)控項(xiàng)
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使服務(wù)生效
systemctl restart prometheus
安裝Grafana
進(jìn)入官網(wǎng)下載最新版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默認(rèn)防火墻命令
/sbin/iptables -I INPUT -p tcp --dport 9090 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 3000 -j ACCEPT
更新時(shí)間忧换,設(shè)置時(shí)區(qū)
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