Prometheus + Grafana安装部署指南
创作时间:
作者:
@小白创作中心
Prometheus + Grafana安装部署指南
引用
CSDN
1.
https://blog.csdn.net/zfgylbcc/article/details/137177631
Prometheus和Grafana是常用的监控和可视化工具,它们可以收集和展示各种系统指标,帮助运维人员及时发现和解决问题。本文将详细介绍Prometheus和Grafana的安装部署过程,包括Prometheus的安装、配置和服务启动,Node Exporter的部署和Prometheus对接,以及Grafana的安装和登录。
Prometheus安装部署
1.1 下载
1.2 解压
tar -xvf prometheus-2.40.4.linux-amd64.tar.gz
1.3 安装
- 进入目录
cd prometheus-2.40.4.linux-amd64
- 将可执行命令转移到/usr/bin
mv prometheus promtool /usr/bin/
- 将配置文件转移
mkdir /etc/prometheus/
cp -r console_libraries consoles prometheus.yml /etc/prometheus/
- 添加prometheus用户
useradd -M -r -s /bin/false prometheus
- 创建所需路径并赋予权限
mkdir -p /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服务启动配置文件
编辑/etc/init.d/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
1.4 打开web页面
Prometheus安装成功后,打开http://localhost:9090会出现如下页面,即表示安装成功
Node Exporter部署和Prometheus对接
2.1 下载
2.2 解压
tar xvf node_exporter-1.7.0.linux-amd64.tar.gz
2.3 运行
./node_exporter --web.listen-address="192.168.10.131:9100" --log.level=warn
2.4 测试验证
curl -g -X GET http://192.168.10.131:9100/metrics?collect[]=cpu
注意这里一定要保证listen-address和url的ip端口一致,最好都用同网段ip,不要用localhost和127.0.0.1
2.5 Prometheus配置
修改Prometheus配置/etc/prometheus/prometheus.yml文件
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["192.168.10.131:9100"]
将Node Exporter监控地址后,重启Prometheus
systemctl restart prometheus
2.6 查看验证
通过Prometheus自带的UI界面,可以看到新的监控节点已经接入。点击进去,能够看到监控的内容选项。
Grafana安装部署
3.1 下载
下载地址:https://dl.grafana.com/enterprise/release/grafana-enterprise_10.4.1_amd64.deb
3.2 安装
因为我使用的是离线安装,因此需要很多离线包,这里我统一下载放到云盘,需要自取
链接:https://pan.baidu.com/s/1k-6lmtGgAOCJug9btWW6SQ
提取码:20zs
注意,这里的离线包参考的是Ubuntu 20.04的版本,其他版本的系统请自我调整
安装指令:
dpkg -i *.deb
查看版本号
grafana-cli -version
3.3 启动Grafana
启动:
systemctl start grafana-server
停止:
systemctl stop grafana-server
重启:
systemctl restart grafana-server
查看状态:
systemctl status grafana-server
3.4 登录Web页
Web页地址:http://localhost:3000
用户名:admin
第一次登录,会让设置密码。
热门推荐
马拉松长跑跑步技巧大全及教程?如何有效提高长跑表现?
跑步后必学!5个有效拉伸小腿的动作及正确方法
如何为我的服装品牌挑选一个吸引人的注册商标名称?
如何给创新团队起名字
直播软件录屏黑屏问题的七个解决办法-哪种方法最有效
初级消控证工资多少钱一个月
和银行谈判信用卡债务重组全攻略及案例分析
VR技术重现中华文明的辉煌,穿越千年探索古迹之美
考古发掘50年 秦兵马俑持续揭示中华文明密码
内娱有自己的“答案之书”
举报所需的证据及注意事项
塔罗牌解读工作运势占卜方法 塔罗带您了解职场运势
全球固态电池之争,谁更胜一筹?
如何进行公积金贷款提前还贷
康熙大帝:一位皇帝的治国智慧与历史传奇
中国历代帝王排名前十:谁是最具影响力的千古一帝?
云服务器的性能如何评估?
点阵激光对疤痕有用吗?有副作用吗?
北京首次招生的新增普高学校介绍,你了解多少?含中考录取分数线
裴松之:东晋至刘宋时期官员、史学家,他担任过哪些职位?
星光下的誓言:明星恋情官宣文案的艺术与技巧
全面保湿指南:如何为不同肤质选择最佳保湿产品
医保门诊慢特病跨省直接结算服务指南
脾胃湿热的治疗方法
2024:这些科技“明星”闪耀中国
白起为什么叫杀神?白起共杀了多少人?
工业HMI界面设计:与移动UI的差异及应用场景
生石灰安全存储与使用全攻略:从基础到应急处理
博物馆展柜灯光设计:文物保护与展示效果的完美平衡
李嘉诚千亿抛售背后深意:巴拿马对他不重要,但190亿美元很重要