一、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