prometheus&zookeeper的自定义启动

一、prometheus的自启动
prometheus添加到系统服务中

[root@localhost ~]# vim /etc/systemd/system/prometheus.service

进入编辑输入

[Unit]
Description=Prometheus Monitoring System
Documentation=Prometheus Monitoring System

[Service]
ExecStart=/usr/local/prometheus/prometheus  \
  --config.file=/usr/local/prometheus/prometheus.yml  \
  --web.listen-address=:9090

[Install]
WantedBy=multi-user.target

有看其他博客配置如下也可以

[Unit]
Description=Prometheus
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/usr/local/prometheus/data
Restart=on-failure
[Install]
WantedBy=multi-user.target

保存退出后
在这里插入图片描述

输入命令:

[root@localhost prometheus-2.9.2.linux-amd64]# systemctl daemon-reload
[root@localhost prometheus-2.9.2.linux-amd64]# systemctl enable prometheus
Created symlink from /etc/systemd/system/multi-user.target.wants/prometheus.service to /etc/systemd/system/prometheus.service.
[root@localhost prometheus-2.9.2.linux-amd64]# systemctl start prometheus
Failed to start prometheus.service: Unit is not loaded properly: Invalid argument.
See system logs and 'systemctl status prometheus.service' for details.

报错1:Failed to start prometheus.service: Unit is not loaded properly: Invalid argument.
See system logs and ‘systemctl status prometheus.service’ for details.
原因:自启动命令写错,没有大写开头
重新编辑后保存退出,再起启动,输入上述命令后,成功
去查看是否启动成功

[root@localhost prometheus-2.9.2.linux-amd64]# ps -ef |grep prometheus
root       2188   1694  0 15:25 pts/0    00:00:00 grep --color=auto prometheus

错误2:为何没启动成功
分析:网络问题,配置错误问题;防火墙问题

查看防火墙状态[root@localhost ~]# firewall-cmd --state
running
关闭防火墙[root@localhost ~]# systemctl stop firewalld.service
再次启动,还是失败

错误3:[root@localhost prometheus]# systemctl start prometheus
Warning: prometheus.service changed on disk. Run ‘systemctl daemon-reload’ to reload units.

去启动关闭prometheus服务

[root@localhost prometheus-2.9.2.linux-amd64]# service prometheus stop
Redirecting to /bin/systemctl stop prometheus.service
[root@localhost prometheus-2.9.2.linux-amd64]# service prometheus start

二、zookeeper的命令启动
1.上传zookeeper
2.解压zookeeper
3.配置zoo.cfg

[root@localhost zookeeper-3.4.14]# cd conf/
[root@localhost conf]# cp zoo_sample.cfg zoo.cfg
[root@localhost conf]# vim zoo.cfg

在这里插入图片描述
4.配置环境变量

[root@localhost conf]# vim /etc/profile
[root@localhost conf]# source /etc/profile

在这里插入图片描述5.配置节点
连续创建

[root@localhost conf]# mkdir -p /export/servers/onekey/zk
[root@localhost conf]# vim  /export/servers/onekey/zk/slave

创建节点,输入配置刚才配置的IP节点,无需输入端口,有几个IP就输入几个
在这里插入图片描述
wq保存退出后
6.创建启动文件

[root@localhost zookeeper-3.4.14]# vim startzk.sh

输入:

cat /export/servers/onekey/zk/slave | while read line
do
{
 echo "开始启动zk服务-->"$line
 ssh $line "source /etc/profile;nobup sh zkServer.sh start >/dev/null 2>&1 &"
}&
wait 
done
echo "zk服务启动完成"

保存退出后

赋予权限[root@localhost zookeeper-3.4.14]# chmod 775 startzk.sh
启动服务[root@localhost zookeeper-3.4.14]# ./startzk.sh
查看服务状态
[root@localhost zookeeper-3.4.14]# ps -ef |grep zookeeper
root       3199   2790  0 16:38 pts/1    00:00:00 grep --color=auto zookeeper

7.创建关闭文件
创建关闭文件

[root@localhost zookeeper-3.4.14]# vim stopzk.sh

输入编辑

cat /export/servers/onekey/zk/slave | while read line
do
{
 echo "开始停止zk服务-->"$line
 ssh $line "source /etc/profile;nobup sh zkServer.sh stop  >/dev/null 2>&1 &"
}&
wait 
done
echo "zk服务停止完成"

保存退出后

[root@localhost zookeeper-3.4.14]# chmod 775 stopzk.sh
[root@localhost zookeeper-3.4.14]# ./stopzk.sh

8.命令解释
/dev/null 2>&1 的含义 > 代表重定向到哪里
1表示std标准输入,系统默认1
2表示stdder标准错误
&:表示等同于错误

首先表示标准输入重定向到空设备文件,也就是不输出任何信息到设备

9.启动zookeeper_exporter
提前下载好zookeeper_exporter到 /usr/local/bin 下

[root@localhost local]# cd bin
[root@localhost bin]# /usr/local/bin/zookeeper_exporter

打开:http://192.168.102.130:9090/targets
查看服务是否启动

[root@localhost zookeeper-3.4.14]# ps -ef |grep zookeeper
[root@localhost zookeeper-3.4.14]# netstat -anp |grep 2181

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

米雪唲2

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值