Ubuntu 安装 prometheus

官网下载链接
这里选择下载最新版

wget https://github.com/prometheus/prometheus/releases/download/v2.40.4/prometheus-2.40.4.linux-amd64.tar.gz
tar -xf prometheus-2.40.4.linux-amd64.tar.gz
cd prometheus-2.40.4.linux-amd64

将可执行命令转移到/usr/bin

mv prometheus promtool /usr/bin/

将配置文件转移

mkdir /etc/prometheus/
cp -r console_libraries consoles /etc/prometheus/

添加prometheus用户

useradd -M -r -s /bin/false prometheus

创建所需路径并赋予权限

mkdir /etc/prometheus /var/lib/prometheus/metrics2 /var/run/prometheus /var/log/prometheus
chown -R prometheus:prometheus /var/lib/prometheus/ /etc/prometheus/ /var/run/prometheus /var/log/prometheus

创建prometheus服务启动配置文件

cd /etc/init.d/
vim prometheus

配置文件参考内容

#!/bin/sh
# kFreeBSD do not accept scripts as interpreters, using #!/bin/sh and sourcing.
if [ true != "$INIT_D_SCRIPT_SOURCED" ] ; then
    set "$0" "$@"; INIT_D_SCRIPT_SOURCED=true . /lib/init/init-d-script
fi
### BEGIN INIT INFO
# Provides:          prometheus
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Monitoring system and time series database
# Description:       Prometheus is a systems and services monitoring system. It
#                    collects metrics from configured targets at given
#                    intervals, evaluates rule expressions, displays the
#                    results, and can trigger alerts if some condition is
#                    observed to be true.
### END INIT INFO

# Author: Martín Ferrari <tincho@debian.org>

DESC="monitoring system and time series database"
DAEMON=/usr/bin/prometheus
NAME=prometheus
USER=prometheus
PIDFILE=/var/run/prometheus/prometheus.pid
LOGFILE=/var/log/prometheus/prometheus.log
CFGFILE=/etc/prometheus/prometheus.yml

HELPER=/usr/bin/daemon
HELPER_ARGS="--name=$NAME --output=$LOGFILE --pidfile=$PIDFILE --user=$USER"

ARGS="--config.file=/etc/prometheus/prometheus.yml \
      --web.console.templates=/etc/prometheus/consoles \
      --web.console.libraries=/etc/prometheus/console_libraries \
      --storage.tsdb.path=/var/lib/prometheus/metrics2/ \
      --storage.tsdb.retention.time=180d \
      --query.max-samples=200000000 \
      --web.enable-admin-api \
      --storage.tsdb.wal-compression \
      --web.enable-lifecycle"

config_check()
{
    retcode=0
    errors="$(/usr/bin/promtool check config $CFGFILE 2>&1)" || retcode=$?
    if [ $retcode -ne 0 ]; then
        log_failure_msg
        echo "Configuration test failed. Output of config test was:" >&2
        echo "$errors" >&2
        return $retcode
    fi
}

do_start_prepare()
{
    mkdir -p `dirname $PIDFILE` || true
    chown -R $USER: /var/lib/prometheus/metrics2
    chown -R $USER: `dirname $LOGFILE`
    chown -R $USER: `dirname $PIDFILE`
}

do_start_cmd()
{
    # Return
    #   0 if daemon has been started
    #   1 if daemon was already running
    #   2 if daemon could not be started
    $HELPER $HELPER_ARGS --running && return 1
    config_check || return 2
    $HELPER $HELPER_ARGS -- $DAEMON $ARGS || return 2
    return 0
}

do_stop_cmd()
{
    # Return
    #   0 if daemon has been stopped
    #   1 if daemon was already stopped
    #   2 if daemon could not be stopped
    #   other if a failure occurred
    $HELPER $HELPER_ARGS --running || return 1
    $HELPER $HELPER_ARGS --stop || return 2
    # wait for the process to really terminate
    for n in 1 2 3 4 5; do
        sleep $n
        $HELPER $HELPER_ARGS --running || break
    done
    $HELPER $HELPER_ARGS --running || return 0
    return 2
}

do_reload()
{
    log_daemon_msg "Reloading $DESC configuration files" "$NAME"
    $HELPER $HELPER_ARGS --running || return 1
    config_check || return 2
    helper_pid=$(cat $PIDFILE)
    if [ -z "$helper_pid" ]; then
        log_failure_msg "Unable to find PID"
        return 1
    fi
    start-stop-daemon --stop --signal 1 --quiet \
        --ppid "$helper_pid" --exec "$DAEMON"
    log_end_msg $?
}

服务的启 停 重启

chmod +x /etc/init.d/prometheus
/etc/init.d/prometheus start/stop/restart

proemtheus配置文件重新加载(前提是开启了–web.enable-admin-api选项)

curl -X POST http://localhost:9090/-/reload
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Ubuntu安装Prometheus,可以按照以下步骤进行操作: 1. 首先,使用wget命令下载Prometheus安装包。可以从官方GitHub仓库中获取最新版本的下载链接。例如,可以使用以下命令下载v2.40.4版本的安装包: ``` wget https://github.com/prometheus/prometheus/releases/download/v2.40.4/prometheus-2.40.4.linux-amd64.tar.gz ``` 2. 下载完成后,使用tar命令解压缩安装包: ``` tar -xf prometheus-2.40.4.linux-amd64.tar.gz ``` 3. 进入解压后的目录: ``` cd prometheus-2.40.4.linux-amd64 ``` 4. 在该目录下,可以找到prometheus.yml文件,该文件用于配置Prometheus的监控目标。可以根据需要进行相应的配置。 5. 最后,使用Docker运行Prometheus容器。可以使用以下命令: ``` docker run -d -p 9090:9090 --volume /root/prometheus.yml:/etc/prometheus/prometheus.yml --name prometheus prom/prometheus ``` 这将在后台运行一个名为"prometheus"的容器,并将主机的9090端口映射到容器的9090端口。同时,通过--volume选项将主机上的prometheus.yml文件挂载到容器内的/etc/prometheus/prometheus.yml路径下。 这样,Prometheus就成功安装Ubuntu上了。可以通过访问http://localhost:9090来访问Prometheus的Web界面。 #### 引用[.reference_title] - *1* [普罗米修斯!Ubuntuprometheus监控软件安装使用](https://blog.csdn.net/weixin_54281717/article/details/120134247)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Ubuntu 安装 prometheus](https://blog.csdn.net/weixin_45066823/article/details/128119509)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [ubuntu环境部署prometheus监控](https://blog.csdn.net/weixin_53053517/article/details/131641812)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值