Prometheus deployment and use
1. Deploy in binary mode
1.1. Install prometheus
1.下载软件包
[root@prometheus-server ~]# wget https://github.com/prometheus/prometheus/releases/download/v2.23.0/prometheus-2.23.0.linux-amd64.tar.gz
2.安装
[root@prometheus-server ~]# mkdir /data/ -p
[root@prometheus-server ~]# tar xf prometheus-2.23.0.linux-amd64.tar.gz -C /data/
[root@prometheus-server ~]# mv /data/prometheus-2.23.0.linux-amd64 /data/prometheus
3.将可执行程序移动到/usr/bin
[root@prometheus-server ~]# lscd /data/prometheus
[root@prometheus-server prometheus]# cp prom* /usr/bin/
[root@prometheus-server prometheus]# prometheus --version
prometheus, version 2.23.0 (branch: HEAD, revision: 26d89b4b0776fe4cd5a3656dfa520f119a375273)
build user: root@37609b3a0a21
build date: 20201126-10:56:17
go version: go1.15.5
platform: linux/amd64
1.2. Start prometheus
Common startup parameters
-config.file="/data/prometheus/prometheus.yml" //Specify the configuration file path--Web.enable-lifecycle //Enable web hot reload configuration
--Storage.tsdb.path= //Specify the tsdb database path, the default is in data/
--Storage.tsdb.retention.time= //Specify the length of time tsdb retains data, the default is 15d
启动prometheus
[root@prometheus-server ~]# prometheus --config.file="/data/prometheus/prometheus.yml" --web.enable-lifecycle &
1.3. Use systemctl to start prometheus
Write the systemctl file, specify the path of tsdb when writing the startup command
1.编写文件
[root@prometheus-server system]# cd /usr/lib/systemd/system
[root@prometheus-server system]# vim prometheus.service
[Unit]
Description=https://prometheus.io
[Service]
Restart=on-failure
ExecStart=/data/prometheus/prometheus --config.file=/data/prometheus/prometheus.yml --web.enable-lifecycle --storage.tsdb.path=/data/prometheus/data
[Install]
WantedBy=multi-user.target
2.加载system配置以及启动服务
[root@prometheus-server system]# systemctl daemon-reload
[root@prometheus-server system]# systemctl start prometheus.service
[root@prometheus-server system]# systemctl enable prometheus.service
3.查看进程
[root@prometheus-server system]# ps aux | grep prome
1.4. Access prometheus
Visit: http://loclahost:9090
View the monitoring host page
status—>targets
1.5. Modify the prometheus address of the monitoring host page to the real ip address
1.修改配置,找到targets一行,将localhost修改为真实地址即可
[root@prometheus-server ~]# vim /data/prometheus/prometheus.yml
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['192.168.81.210:9090']
2.加载配置
由于启动增加了--web.enable-lifecycle,因此可以使用配置加载功能
[root@prometheus-server ~]# curl -XPOST 192.168.81.210:9090/-/reload
Click the link below the endpoint to see the metris metric
2. Docker deploy prometheus
2.1. Install docker
1.获取镜像源
[root@prometheus-server ~]# wget -O /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo
[root@prometheus-server ~]# sed -i 's#download.docker.com#mirrors.tuna.tsinghua.edu.cn/docker-ce#' /etc/yum.repos.d/docker-ce.repo
[root@prometheus-server ~]# yum makecache fast
2.安装docker
[root@prometheus-server ~]# yum -y install docker-ce
3.配置镜像加速器
[root@prometheus-server ~]# tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://zggyaen3.mirror.aliyuncs.com"]
}
EOF
4.启动docker
[root@prometheus-server ~]# systemctl restart docker
2.2. Run prometheus container
We mount the newly installed prometheus configuration file to the container and map it to port 7090
[root@prometheus-server ~]# docker run -d -p7090:9090 -v /data/prom/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus:latest
517523d6da1d4135bbd5d6bb2714576f20b7da832b6d75ce7dc88f1844c1d5f4
[root@prometheus-server ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
517523d6da1d prom/prometheus:latest "/bin/prometheus --c…" 16 seconds ago Up 10 seconds 0.0.0.0:7090->9090/tcp hopeful_tharp