prometheus安裝(Server)
setenforce 0 && sed -i ‘s/^SELINUX=enforcing$/SELINUX=disabled/‘ /etc/selinux/config #關閉selinux
yum install -y epel-release #centos安裝epel擴充倉庫
wget https://github.com/prometheus/prometheus/releases/download/v2.43.0/prometheus-2.43.0.linux-amd64.tar.gz #下載官方#prometheus (官網)
useradd —no-create-home —shell /bin/false prometheus #創建prometheus使用者
mkdir /var/lib/prometheus #建立需要的文件夾
chown prometheus:prometheus /etc/prometheus #更換擁有者為prometheus
chown prometheus:prometheus /var/lib/prometheus #更換擁有者為prometheus
tar -xvzf prometheus-2.43.0.linux-amd64.tar.gz #解壓縮
mv prometheus-2.43.0.linux-amd64 prometheuspackage #重新命名
cp prometheuspackage/prometheus /usr/local/bin/ #複製二進制文件到/usr/local/bin/
cp prometheuspackage/promtool /usr/local/bin/ #複製二進制文件到/usr/local/bin/
chown prometheus:prometheus /usr/local/bin/prometheus #更換擁有者為prometheus
chown prometheus:prometheus /usr/local/bin/promtool #更換擁有者為prometheus
cp -r prometheuspackage/consoles /etc/prometheus #將文件複製到
cp -r prometheuspackage/console_libraries /etc/prometheus #將文件複製到
chown -R prometheus:prometheus /etc/prometheus/consoles #更換擁有者為prometheus
chown -R prometheus:prometheus /etc/prometheus/console_libraries #更換擁有者為prometheus
cp -r prometheuspackage/prometheus.yml /etc/prometheus #複製yaml 配置文件
chown -R prometheus:prometheus /etc/prometheus/prometheus.yml ##更換擁有者為prometheus
設定加入systemd
vi /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/usr/local/bin/prometheus \
--config.file /etc/prometheus/prometheus.yml \
--storage.tsdb.path /var/lib/prometheus/ \
--web.console.templates=/etc/prometheus/consoles \
--web.console.libraries=/etc/prometheus/console_libraries
[Install]
WantedBy=multi-user.target
- —config.file = prometheus.yml # 指定配置文件
- —web.listen-address = 0.0.0.0:9090 # 指定監聽地址和端口
- —log.level = info # 設置日誌級別
- —alertmanager.timeout = 10s # 設置與報警組件的超時時間
- —storage.tsdb.path = /data/ # 指定數據目錄
- —storage.tsdb.retention.time = 15d # 設置數據保存時間,默認 15 天
- —web.enable-lifecycle # 開啟熱加載功能
systemctl daemon-reload #重載配置文件
systemctl restart prometheus
systemctl enable prometheus
systemctl status prometheus
./promtool check config prometheus.yml #到/usr/local/bin 裡面執行,可以確認yaml文件配置是否正確
ntpd -u 171.22.195.110 #要校正時間,在瀏覽http://192.168.253.126:9090/
加入node_export端口
vi /etc/prometheus/prometheus.yml #普羅米修斯配置文件
請在配置文件底部新增或設定以下配置
----略過-----
- job_name: "Linux"
static_configs:
- targets: ["192.168.30.130:9100","192.168.30.131:9100","192.168.30.132:9100"]
systemctl restart prometheus
沒有留言:
張貼留言