一、安装docker,用于运行exporter
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sudo yum makecache fast
sudo yum -y install docker-ce
systemctl restart docker
systemctl enable docker
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://res3lpuj.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
二、安装docker-compose,用于管理docker
sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
三、安装prometheus-server服务
安装rpm
yum -y install wget lrzsz net-tools vim
wget https://github.com/prometheus/prometheus/releases/download/v2.28.0/prometheus-2.28.0.linux-amd64.tar.gz
tar zxf prometheus-2.28.0.linux-amd64.tar.gz
mv prometheus-2.28.0.linux-amd64 /usr/local/prometheus
[root@prometheus-server157 ~]# ll /usr/local/prometheus/
total 181656
drwxr-xr-x 2 3434 3434 38 Jun 21 2021 console_libraries
drwxr-xr-x 2 3434 3434 173 Jun 21 2021 consoles
-rw-r--r-- 1 3434 3434 11357 Jun 21 2021 LICENSE
-rw-r--r-- 1 3434 3434 3646 Jun 21 2021 NOTICE
-rwxr-xr-x 1 3434 3434 98491188 Jun 21 2021 prometheus
-rw-r--r-- 1 3434 3434 926 Jun 21 2021 prometheus.yml
-rwxr-xr-x 1 3434 3434 87502544 Jun 21 2021 promtool
编辑systemd启动文件
[root@prometheus-server-custom ~]# vim /usr/lib/systemd/system/prometheus.service
[Unit]
Description=Prometheus: the monitoring system
Documentation=http://prometheus.io/docs/
[Service]
ExecStart=/usr/local/prometheus/prometheus \
--config.file=/usr/local/prometheus/prometheus.yml \
--storage.tsdb.path=/var/lib/prometheus \
--storage.tsdb.retention.time=90d \
--storage.tsdb.retention.size=163840MB \
--web.console.templates=/usr/local/prometheus/consoles \
--web.console.libraries=/usr/local/prometheus/console_libraries \
--web.listen-address=0.0.0.0:9090 --web.external-url= \
--web.enable-lifecycle
Restart=always
StartLimitInterval=0
RestartSec=10
[Install]
WantedBy=multi-user.target
挂载数据盘
mkdir /var/lib/prometheus
mkfs.xfs /dev/sdb
mount /dev/sdb /var/lib/prometheus/
echo '/dev/sdb /var/lib/prometheus/ xfs defaults 0 0' >> /etc/fstab
mount -a
启动服务
systemctl daemon-reload
systemctl enable prometheus
systemctl restart prometheus
systemctl status prometheus
四、示例:监控es
下载esporter镜像
docker pull quay.io/prometheuscommunity/elasticsearch-exporter:latest
[root@yw-mon opt]# cat elasticsearch-exporter/docker-compose.yaml
version: '2'
services:
prometheus-es1:
container_name: elasticsearch-exporter-es
image: quay.io/prometheuscommunity/elasticsearch-exporter:v202210
restart: always
command:
--es.uri='http://elastic:密码@11.11.11.11:9200'
--es.indices
--es.cluster_settings
--es.indices_settings
--es.shards
--es.snapshots
--es.timeout=30s
--web.listen-address=":9114"
--es.all
ports:
- 127.0.0.1:9114:9114
networks:
- pronet
networks:
pronet:
external:
name: prometheus-monitoring
[root@yw-mon opt]#
检测是否成功可以
curl http://127.0.0.1:9114
编辑prometheus.yml文件
- job_name: 'elasticsearch_exporter_es'
scrape_interval: 15s
metrics_path: /metrics
static_configs:
- targets: ['127.0.0.1:9114']
labels:
server_exporter: elasticsearch_exporter'
重载
curl -X POST "http://127.0.0.1:9090/-/reload"