(二)Prometheus 安装部署

通过上一篇prometheus 监控系统 的学习,我们已经对 prometheus 有了一个全面的了解,本篇详细部署安装 prometheus 监控系统。
准备环境

# 个人环境:centos 7
[root@test2 ~]# hostname -I
192.168.31.201 172.17.0.1 

# 关闭防火墙
[root@test2 ~]# systemctl stop firewalld.service

#修改 selinux 为警告模式
[root@test2 ~]# setenforce 0
setenforce: SELinux is disabled

创建用户

# 创建 prometheus 的组和用户
[root@test2 ~]# groupadd prometheus
[root@test2 ~]# useradd -M -s /sbin/nologin prometheus -g prometheus

上传安装包,解压:

# 没有本地安装包,也可以进行下载
[root@test2 ~]# cd /opt/ ; mkdir prometheus ; cd prometheus
[root@test2 prometheus]# pwd
/opt/prometheus
[root@test2 prometheus]# wget https://github.com/prometheus/prometheus/releases/download/v2.16.0/prometheus-2.16.0.linux-amd64.tar.gz
[root@test2 prometheus]# ll
总用量 58212
-rw-r--r-- 1 root root 59608515 2月  14 09:57 prometheus-2.16.0.linux-amd64.tar.gz

# 解压
[root@test2 prometheus]# tar xf prometheus-2.16.0.linux-amd64.tar.gz
[root@test2 prometheus]# ls
prometheus-2.16.0.linux-amd64  prometheus-2.16.0.linux-amd64.tar.gz

更改文件夹位置

[root@fp-21 prometheus]# mv prometheus-2.16.0.linux-amd64 /usr/local/prometheus

# 创建所需目录
[root@test2 prometheus]# cd /usr/local/prometheus/
[root@test2 prometheus]# pwd
/usr/local/prometheus
[root@test2 prometheus]# mkdir conf relus data

# 修改配置文件路径
[root@test2 prometheus]# ll
总用量 140984
drwxr-xr-x 2 root root        6 6月  16 19:27 conf
drwxr-xr-x 2 3434 3434       38 2月  14 09:52 console_libraries
drwxr-xr-x 2 3434 3434      173 2月  14 09:52 consoles
drwxr-xr-x 2 root root        6 6月  16 19:27 data
-rw-r--r-- 1 3434 3434    11357 2月  14 09:52 LICENSE
-rw-r--r-- 1 3434 3434     3184 2月  14 09:52 NOTICE
-rwxr-xr-x 1 3434 3434 82329106 2月  14 07:52 prometheus
-rw-r--r-- 1 3434 3434      926 2月  14 09:52 prometheus.yml
-rwxr-xr-x 1 3434 3434 48417809 2月  14 07:54 promtool
drwxr-xr-x 2 root root        6 6月  16 19:27 relus
-rwxr-xr-x 1 3434 3434 13595766 2月  14 07:54 tsdb
[root@test2 prometheus]# mv prometheus.yml conf/

# 复制可执行文件至 /usr/local/bin
[root@test2 prometheus]# cp prometheus promtool tsdb /usr/local/bin/

# 授权
[root@test2 prometheus]# chown -R prometheus:prometheus /usr/local/prometheus

修改配置文件

[root@fp-21 prometheus]# cd conf
[root@fp-21 conf]# cp prometheus.yml prometheus.yml.bak
[root@fp-21 conf]# vim prometheus.yml
  - job_name: 'prometheus'

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

    static_configs:
    - targets: ['192.168.31.201:9090']

添加为系统服务

[root@test2 conf]# vim /usr/lib/systemd/system/prometheus.service
[root@test2 conf]# cat /usr/lib/systemd/system/prometheus.service
[Unit]
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@test2 conf]# systemctl daemon-reload

# 添加至开机自启
[root@test2 conf]# systemctl enable prometheus.service
Created symlink from /etc/systemd/system/multi-user.target.wants/prometheus.service to /usr/lib/systemd/system/prometheus.service.

# 启动服务
[root@test2 conf]# systemctl start prometheus.service

# 查看端口
[root@test2 conf]# ss -lntp |grep prometheus
LISTEN     0      128         :::9090                    :::*                   users:(("prometheus",pid=11625,fd=5))

# 查看进程
[root@test2 conf]# ps -ef |grep prometheus
root      11625      1 13 19:35 ?        00:00:02 /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
root      11642   1391  0 19:36 pts/0    00:00:00 grep --color=auto prometheus

访问 IP 进行查看 prometheus
(二)Prometheus 安装部署_第1张图片查看监控任务的状态
(二)Prometheus 安装部署_第2张图片查看 prometheus 的配置信息
(二)Prometheus 安装部署_第3张图片查看 prometheus 运行状态
(二)Prometheus 安装部署_第4张图片

你可能感兴趣的:(Docker)