promethus的安装
第一种安装方式二进制安装:
- 1.下载prometheus安装包:
wget https://github.com/prometheus/prometheus/releases/download/v2.53.4/prometheus-2.53.4.linux-amd64.tar.gz
2.解压prometheus安装包:
tar xf prometheus-2.53.4.linux-amd64.tar.gz - C /usr/local/
3.启动prometheus服务:
cd /usr/local/prometheus-2.53.4.linux-amd64
./prometheus
4.卸载promethus:
直接删除对应目录即可:rm -rf /usr/local/prometheus-2.53.4.linux-amd64
第二种安装方式:脚本安装
1.下载prometheus安装包:
wget https://github.com/prometheus/prometheus/releases/download/v2.53.4/prometheus-2.53.4.linux-amd64.tar.gz
2.编写安装脚本:
vim install-prometheus.sh
auther: violet
Description: PROMETHEUS SERVER INSTALL SCRIPTS
email:321588680@qq.com
office: www.vionletarchitect.top
VERSION=2.53.4 #这里要修改你下载的软件版本
ARCH=amd64
SOFTWARE=prometheus-${VERSION}.linux-${ARCH}.tar.gz
URL=https://github.com/prometheus/prometheus/releases/download/v${VERSION}/${SOFTWARE}
DOWNLOAD=./download
INSTALLDIR=/oldboyedu/softwares
BASEDIR=${INSTALLDIR}/prometheus-${VERSION}.linux-amd64
DATADIR=/oldboyedu/data/prometheus
LOGDIR=/oldboyedu/logs/prometheus
HOSTIP=0.0.0.0
PORT=9090
HOSTNAME=hostname
function prepare() {
# 判断目录是否存在,若不存在则创建
[ -d $INSTALLDIR ] || install -d ${INSTALLDIR}
[ -d $DOWNLOAD ] || install -d ${DOWNLOAD}
[ -d $DATADIR ] || install -d ${DATADIR}
[ -d $LOGDIR ] || install -d ${LOGDIR}
. /etc/os-release
if [ "$ID" == "centos" ];then
# 判断系统是否安装wget
[ -f /usr/bin/wget ] || yum -y install wget
fi
# 判断文件是否存在,若不存在则下载
[ -s ${DOWNLOAD}/${SOFTWARE} ] || wget $URL -O ${DOWNLOAD}/${SOFTWARE} #如果你没下载软件包,那么就会去github下载,时间比较慢,你可以代理翻墙下载好这里可以修改成mv ~/ 你的软件包名字${DOWNLOAD}/${SOFTWARE}
}
function deploy() {
# 检查环境
prepare
# 解压文件软件包
tar xf ${DOWNLOAD}/${SOFTWARE} -C ${INSTALLDIR}
# 生成启动脚本
cat > /etc/systemd/system/prometheus-server.service <<EOF
[Unit]
Description=Oldboyedu Linux Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network.target
[Service]
Restart=on-failure
ExecStart=/bin/bash -c "${BASEDIR}/prometheus \
--config.file=${BASEDIR}/prometheus.yml \
--web.enable-lifecycle \
--storage.tsdb.path=${DATADIR} \
--storage.tsdb.retention.time=60d \
--web.listen-address=${HOSTIP}:${PORT} \
--web.max-connections=65535 \
--storage.tsdb.retention.size=512MB \
--query.timeout=10s \
--query.max-concurrency=20 \
--log.level=info \
--log.format=json \
--web.read-timeout=5m &>> ${LOGDIR}/prometheus-server.log"
ExecReload=/bin/kill -HUP \$MAINPID
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target
EOF
# 将服务设置为开机自启动
systemctl daemon-reload
systemctl enable --now prometheus-server
systemctl status prometheus-server
sleep 0.3
ss -ntl | grep ${PORT}
}
function delete(){
systemctl disable --now prometheus-server.service
rm -rf /etc/systemd/system/node-exporter.service $BASEDIR $DATADIR $LOGDIR
}
function main() {
case $1 in
deploy|i)
deploy
echo "prometheus服务脚本: ${HOSTNAME} 的prometheus-server 已经部署成功![successfully]"
;;
delete|r)
delete
echo "prometheus服务脚本: ${HOSTNAME} 的prometheus-server 已经卸载成功,期待下次使用~"
;;
*)
echo "Usage: $0 deploy[i]|delete[r]"
;;
esac
}
main $1
3.给脚本执行权限:
chmod +x install-prometheus.sh
4.启动脚本:
./install-prometheus.sh i
5.检查端口是否启动:
ss -tlunp|grep 9090
6.访问Prometheus的webUI界面:
http://10.0.0.31:9090/targets

Categories: