准备工作
1、创建用户和配置环境参数
(1)、创建用户和创建所需目录
[root@centos ~]# groupadd prometheus
[root@centos ~]# useradd -d /home/prometheus -g prometheus -m prometheus
[root@centos ~]# chmod 755 /home/prometheus
[root@centos ~]# mkdir -p /home/prometheus/software
[root@centos ~]# mkdir -p /home/prometheus/yunwei
[root@centos ~]# chown -R prometheus:prometheus /home/prometheus
[root@centos ~]# mkdir -p /data/prometheus
[root@centos ~]# chown -R prometheus:prometheus /data/prometheus
(2)、下载
https://github.com/prometheus/pushgateway/releases/download/v1.5.1/pushgateway-1.5.1.linux-amd64.tar.gz
部署方案
1、部署
(1)、关闭防火墙
[root@centos ~]# systemctl stop firewalld
[root@centos ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@centos ~]# setenforce 0
[root@centos ~]# getenforce
Permissive
[root@centos ~]# vi /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
(2)、解压安装包并备份配置文件
[prometheus@centos ~]$ tar -zxf $HOME/software/pushgateway-1.5.1.linux-amd64.tar.gz -C $HOME
[prometheus@centos ~]$ mv pushgateway-1.5.1.linux-amd64 pushgateway-1.5.1
(3)、创建日志路径
[prometheus@centos ~]$ mkdir /data/prometheus/pushgateway-1.5.1/logs -p
[prometheus@centos ~]$ touch /data/prometheus/pushgateway-1.5.1/logs/pushgateway-1.5.1.log
2、添加配置
(1)、pushgetway相关参数
[prometheus@centos ~]$ $HOME/pushgateway-1.5.1/pushgateway --help
usage: pushgateway []
The Pushgateway
Flags:
-h, --help Show context-sensitive help (also try --help-long and --help-man).
--web.systemd-socket Use systemd socket activation listeners instead of port listeners (Linux only).
--web.listen-address=:9091 ...
Addresses on which to expose metrics and web interface. Repeatable for multiple addresses.
--web.config.file="" [EXPERIMENTAL] Path to configuration file that can enable TLS or authentication.
--web.telemetry-path="/metrics"
Path under which to expose metrics.
--web.external-url= The URL under which the Pushgateway is externally reachable.
--web.route-prefix="" Prefix for the internal routes of web endpoints. Defaults to the path of --web.external-url.
--web.enable-lifecycle Enable shutdown via HTTP request.
--web.enable-admin-api Enable API endpoints for admin control actions.
--persistence.file="" File to persist metrics. If empty, metrics are only kept in memory.
--persistence.interval=5m The minimum interval at which to write out the persistence file.
--push.disable-consistency-check
Do not check consistency of pushed metrics. DANGEROUS.
--log.level=info Only log messages with the given severity or above. One of: [debug, info, warn, error]
--log.format=logfmt Output format of log messages. One of: [logfmt, json]
--version Show application version.
(2)、配置prometheus配置
[prometheus@centos ~]$ vi $HOME/prometheus/prometheus.yml
# 新增
- job_name: "pushgetway"
static_config:
- targets: ["192.168.19.149:9091"]
# 记得改完配置重启prometheus服务
3、启停服务与创建脚本
(1)、启动脚本配置
[prometheus@centos ~]$ vi yunwei/pushgateway-1.5.1_start.sh
#!/bin/bash
#
cd $HOME/pushgateway-1.5.1
./pushgateway --web.listen-address=:9091 >> /data/prometheus/pushgateway-1.5.1/logs/pushgateway-1.5.1.log &
(2)、停止脚本配置
[prometheus@centos ~]$ vi yunwei/pushgateway-1.5.1_stop.sh
#!/bin/bash
#
pgw_id=`ps -ef|grep pushgateway|grep -v grep|awk '{print $2}'`
kill -9 $pgw_id
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net