这篇文章上次修改于 457 天前,可能其部分内容已经发生变化,如有疑问可询问作者。
安装环境
prometheus的二进制包下载地址
安装
cd /usr/local
wget https://github.com/prometheus/prometheus/releases/download/v2.48.0-rc.0/prometheus-2.48.0-rc.0.linux-amd64.tar.gz
tar -zxvf prometheus-2.48.0-rc.0.linux-amd64.tar.gz
mv prometheus-2.48.0-rc.0.linux-amd64 prometheus
#将prometheus 的数据放入data目录下面
cd /data
mkdir prometheus
cd prometheus
mv /usr/local/prometheus/data ./
编写service启动文件
- vi -b /etc/init.d/prometheus
- 内容如下
#!/bin/bash
#
# Comments to support chkconfig
# chkconfig: 2345 98 02
# description: prometheus service script
#
# Source function library.
. /etc/init.d/functions
### Default variables
prog_name="prometheus"
config_file="/usr/local/${prog_name}/${prog_name}.yml"
prog_path="/usr/local/${prog_name}/${prog_name}"
data_path="/data/${prog_name}/data"
pidfile="/var/run/${prog_name}.pid"
prog_logs="/var/log/${prog_name}.log"
#启动项,监听本地9090端口,支持配置热加载
options="--web.listen-address=localhost:9090 --config.file=${config_file} --web.enable-lifecycle --storage.tsdb.path=${data_path}"
DESC="Prometheus Server"
# Check if requirements are met
[ -x "${prog_path}" ] || exit 1
RETVAL=0
start(){
action $"Starting $DESC..." su -s /bin/sh -c "nohup $prog_path $options >> $prog_logs 2>&1 &" 2> /dev/null
RETVAL=$?
PID=$(pidof ${prog_path})
[ ! -z "${PID}" ] && echo ${PID} > ${pidfile}
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog_name
return $RETVAL
}
stop(){
echo -n $"Shutting down $prog_name: "
killproc -p ${pidfile}
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog_name
return $RETVAL
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status $prog_path
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
RETVAL=1
esac
exit $RETVAL
添加执行权限与加入开机启动
#添加可执行权限
chmod +x /etc/init.d/prometheus
#开机自启动
chkconfig prometheus on
启动prometheus
service prometheus start
访问
没有评论
博主关闭了评论...