IP:192.168.47.158 centos8系统
//关闭防火墙和selinux
[root@prometheus ~]# systemctl disable --now firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@prometheus ~]# setenforce 0
[root@prometheus ~]# vi /etc/selinux/config
创建用户
[root@prometheus ~]# useradd -r -M -s /sbin/nologin prometheus
[root@prometheus ~]# id prometheus
uid=994(prometheus) gid=991(prometheus) 组=991(prometheus)
上传安装包,解压,下载点击这里
[root@prometheus ~]# wget https://github.com/prometheus/prometheus/releases/download/v2.32.0-beta.0/prometheus-2.32.0-beta.0.linux-amd64.tar.gz
[root@prometheus ~]# ls
anaconda-ks.cfg prometheus-2.32.0-beta.0.linux-amd64.tar.gz
//解压
[root@prometheus ~]# tar xf prometheus-2.32.0-beta.0.linux-amd64.tar.gz -C /usr/local/
[root@prometheus ~]# cd /usr/local/
[root@prometheus local]# ls
bin games lib libexec sbin src
etc include lib64 prometheus-2.32.0-beta.0.linux-amd64 share
//改名
[root@prometheus local]# mv prometheus-2.32.0-beta.0.linux-amd64/ prometheus
[root@prometheus local]# ls
bin etc games include lib lib64 libexec prometheus sbin share src
更改文件夹位置
# 创建所需目录
[root@prometheus local]# cd prometheus/
[root@prometheus prometheus]# ls
console_libraries consoles LICENSE NOTICE prometheus prometheus.yml promtool
[root@prometheus prometheus]# mkdir conf relus data
# 修改配置文件路径
[root@prometheus prometheus]# mv prometheus.yml conf
# 复制可执行文件至 /usr/local/bin
[root@prometheus prometheus]# cp prometheus promtool /usr/local/bin/
# 授权
[root@prometheus prometheus]# chown -R prometheus:prometheus /usr/local/prometheus
修改配置文件
[root@prometheus prometheus]# cd conf/
[root@prometheus conf]# cp prometheus.yml prometheus.yml.bak
[root@prometheus conf]# vim prometheus.yml
..........
this config.
23 - job_name: "prometheus"
24
25 # metrics_path defaults to '/metrics'
26 # scheme defaults to 'http'.
27
28 static_configs:
29 - targets: ["192.168.47.158:9090"] #修改IP
...........
添加为系统服务
[root@prometheus conf]# vim /usr/lib/systemd/system/prometheus.service
[root@prometheus conf]# cat /usr/lib/systemd/system/prometheus.service
t]
Description=prometheus-server
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=simple
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/conf/prometheus.yml --web.enable-lifecycle --storage.tsdb.path=/usr/local/prometheus/data --storage.tsdb.retention.time=7d --web.max-connections=512 --web.read-timeout=3m --query.max-concurrency=25 --query.timeout=2m
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
WantedBy=multi-user.target
添加开机自启,启动,查看
[root@prometheus conf]# systemctl start prometheus.service
[root@prometheus conf]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 128 *:9090 *:*
查看监控任务的状态
查看 prometheus 的配置信息
查看 prometheus 运行状态