同步时间
代码语言:javascript复制yum -y install ntpdate #同步时间 timedatectl set-timezone Asia/Shanghaintpdate ntp.aliyun.comhwclock -wsed -i 's%SYNC_HWCLOCK=no%SYNC_HWCLOCK=yes%' /etc/sysconfig/ntpdateecho "* 23 * * * root /usr/sbin/ntpdate ntp.aliyun.com" >> /etc/crontab && crontab /etc/crontab
下载安装文件
代码语言:javascript复制wget https://github.com/prometheus/prometheus/releases/download/v2.27.1/prometheus-2.27.1.linux-amd64.tar.gztar -xvf prometheus-2.27.1.linux-amd64.tar.gz -C /usr/local/cd /usr/local/mv prometheus-2.27.1.linux-amd64/ prometheus
创建用户和数据存储目录
代码语言:javascript复制useradd -M -s /sbin/nologin prometheusmkdir -pv /data/prometheuschown -R prometheus:prometheus /usr/local/prometheus/ /data/prometheus/
创建Systemd服务启动prometheus
代码语言:javascript复制cat >/usr/lib/systemd/system/prometheus.service <<EOF[Unit]Description=PrometheusAfter=network.target[Service]Type=simpleEnvironment="GOMAXPROCS=4"User=prometheusGroup=prometheusExecReload=/bin/kill -HUP $MAINPIDExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/data/prometheus --storage.tsdb.retention.time=30d --web.console.libraries=/usr/local/prometheus/console_libraries --web.console.templates=/usr/local/prometheus/consoles --web.listen-address=0.0.0.0:9090 --web.read-timeout=5m --web.max-connections=10 --query.max-concurrency=20 --query.timeout=2m --web.enable-lifecyclePrivateTmp=truePrivateDevices=trueProtectHome=trueNoNewPrivileges=trueLimitNOFILE=infinityReadWriteDirectories=/data/prometheusProtectSystem=fullSyslogIdentifier=prometheusRestart=always[Install]WantedBy=multi-user.targetEOF
启动
代码语言:javascript复制systemctl daemon-reloadsystemctl enable prometheussystemctl start prometheussystemctl status prometheus
放行防火墙
代码语言:javascript复制firewall-cmd --zone=public --add-port=9090/tcp --permanent firewall-cmd --reload# systemctl stop firewalld && systemctl disable firewalld
查看端口
代码语言:javascript复制[root@localhost ~]# netstat -tnpl | grep prometheustcp6 0 0 :::9090 :::* LISTEN 1745/prometheus
打开 prometheus 的 web 界面
http://ip:9090
更多内容, 豌豆日志 https://pealog.com/496.html