CentOS7-安装Prometheus

环境

操作系统:CentOS7.4 内核:3.10

步骤

下载

1
2
$ cd /usr/local/
$ wget https://github.com/prometheus/prometheus/releases/download/v2.0.0/prometheus-2.0.0.linux-amd64.tar.gz

解压

1
2
3
$ tar -zxvf prometheus-2.0.0.linux-amd64.tar.gz
$ mv prometheus-2.0.0.linux-amd64 prometheus
$ cd prometheus

备份prometheus.yml

1
$ cp prometheus.yml prometheus.yml-bak

修改prometheus.yml

修改targets为当前主机的ip地址

1
2
3
4
5
6
7
8
from this config.
- job_name: 'prometheus'

# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.

static_configs:
- targets: ['当前主机的ip:9090']

启动

1
$ ./prometheus 或者./prometheus -config.file=prometheus.yml

验证

打开http://ip:9090,检查是否可以访问。

停止prometheus

ctrl+c先暂时停止prometheus。

配置prometheus为服务

创建服务文件

1
2
$ touch /lib/systemd/system/prometheus.service
$ vi /lib/systemd/system/prometheus.service

增加内容如下

1
2
3
4
5
6
7
8
9
10
11
12
13
[unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network.target

[Service]
Restart=on-failure
WorkingDirectory=/usr/local/prometheus/
ExecStart=/usr/local/prometheus/prometheus
-config.file=/usr/local/prometheus/prometheus.yml

[Install]
WantedBy=multi-user.target

设置权限

1
$ chown 644 /lib/systemd/system/prometheus.service

设置开机启动

设置prometheus开机启动

1
2
$ systelctl enable prometheus
$ reboot

检查

打开http://ip:9090,检查是否可以访问。

常用命令

启动prometheus

1
$ systemctl start prometueus

停止prometheus

1
$ systemctl stop prometueus

重启prometheus

1
$ systemctl stop prometueus

设置prometheus开机启动

1
$ systemctl enable prometueus

取消设置prometheus开机启动

1
$ systemctl disable prometueus
坚持原创技术分享,您的支持将鼓励我继续创作!
0%