香港服务器香港服务器租用

如何在Ubuntu 20.04 LTS Focal Fossa上安装Prometheus

步骤1.首先,通过apt在终端中运行以下以下命令,确保所有系统软件包都是最新的。
sudo apt update
sudo apt upgrade
第2步。安装Nginx Web服务器。
Nginx在默认的Ubuntu存储库中可用。要安装它,请运行以下命令:
sudo apt install nginx
安装完成后,运行以下命令以使Nginx在服务器启动时自动启动:
sudo systemctl stop nginx.service
sudo systemctl start nginx.service
sudo systemctl enable nginx.service
步骤3.创建Prometheus用户。
我们必须创建名为prometheus的用户和组,以及名为Prometheus的目录:
sudo useradd -s /sbin/nologin --system -g prometheus prometheus
sudo mkdir /var/lib/prometheus
for i in rules rules.d files_sd; do sudo mkdir -p /etc/prometheus/${i}; done
步骤4.在Ubuntu 20.04上安装Prometheus。
使用以下wget命令下载Prometheus的最新稳定版本:
mkdir -p /tmp/prometheus && cd /tmp/prometheus
curl -s https://api.github.com/repos/prometheus/prometheus/releases/latest | grep browser_download_url | grep linux-amd64 | cut -d '"' -f 4 | wget -qi -
tar xvf prometheus*.tar.gz
一旦文件提取完成,然后将提取的Prometheus归档文件夹下的prometheus和promtool二进制文件移动到/usr/local/bin目录:
sudo mv prometheus promtool /usr/local/bin/
步骤5.配置Prometheus。
我们将在/etc/prometheus目录中创建名为prometheus.yml的配置文件:
sudo mv prometheus.yml /etc/prometheus/prometheus.yml
sudo mv consoles/ console_libraries/ /etc/prometheus/
sudo nano /etc/prometheus/prometheus.yml
prometheus.yml的内容如下:

my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
Alertmanager configuration
alerting:
alertmanagers:
static_configs: targets:
# - alertmanager:9093
Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
A scrape configuration containing exactly one endpoint to scrape:
Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label job= to any timeseries scraped from this config.
job_name: 'prometheus'
metrics_path defaults to '/metrics'
scheme defaults to 'http'.
static_configs:
targets: ['localhost:9090']
步骤6.创建Prometheus Systemd服务。
现在,我们将为systemd服务创建一个文件:
sudo nano /etc/systemd/system/prometheus.service
添加以下文件:

[Unit]
Description=Prometheus
Documentation=https://prometheus.io/docs/introduction/overview/
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=prometheus
Group=prometheus
ExecReload=/bin/kill -HUP \$MAINPID
ExecStart=/usr/local/bin/prometheus \
--config.file=/etc/prometheus/prometheus.yml \
--storage.tsdb.path=/var/lib/prometheus \
--web.console.templates=/etc/prometheus/consoles \
--web.console.libraries=/etc/prometheus/console_libraries \
--web.listen-address=0.0.0.0:9090 \
--web.external-url=

SyslogIdentifier=prometheus
Restart=always

[Install]
WantedBy=multi-user.target
然后,将以下目录的所有权更改为Prometheus用户和组:
for i in rules rules.d files_sd; do sudo chown -R prometheus:prometheus /etc/prometheus/${i}; done
for i in rules rules.d files_sd; do sudo chmod -R 775 /etc/prometheus/${i}; done
sudo chown -R prometheus:prometheus /var/lib/prometheus/
完成上述配置后,请使用以下命令重新加载systemd:
sudo systemctl daemon-relaod
sudo systemctl start prometheus
sudo systemctl enable prometheus
步骤7.配置防火墙。
同时,您需要确保将防火墙配置为允许HTTP(80),HTTPS(443)和9090端口上的流量。Nginx通过以下方式将自己注册为服务ufw:
sudo ufw allow in "Nginx Full"
sudo ufw allow 9090/tcp
步骤8.访问Prometheus Web界面。
默认情况下,Prometheus将在HTTP端口9090上可用。打开您喜欢的浏览器,然后浏览至http://your-domain.com:9090或http://server-ip-addreess:9090完成所需的步骤以完成安装。


至此,您就已经成功安装了Prometheus。A5互联https://www.a5idc.net/

posted @ 2020-10-06 09:00  A5互联  阅读(387)  评论(0编辑  收藏  举报
江苏镇江高防服务器BGP云服务器