007-kafka基本保活

阅读量: zyh 2019-03-05 18:01:58
Categories: > Tags:

保活工具

monit

配置

check process zookeeper with pidfile /export/kafka/zookeeper.pid
  start program = "/bin/bash -c 'source /etc/profile && cd /export/kafka && ./zookeeper.start'"
    as uid "root" and gid "root"
  stop program = "/bin/bash -c 'source /etc/profile && cd /export/kafka && ./bin/zookeeper-server-stop.sh && rm -rf zookeeper.pid'"
    as uid "root" and gid "root"
if failed port 2181 then alert

check process kafka with pidfile /export/kafka/kafka.pid
  depends on zookeeper
  start program = "/bin/bash -c 'source /etc/profile && cd /export/kafka && ./kafka.start'"
    as uid "root" and gid "root"
  stop program = "/bin/bash -c 'source /etc/profile && cd /export/kafka && ./bin/kafka-server-stop.sh && rm -rf kafka.pid'"
    as uid "root" and gid "root"

脚本

/export/kafka/zookeeper.start

#!/bin/bash
set -eu
cd /export/kafka
[[ -d zk_data ]] && nohup bin/zookeeper-server-start.sh config/zookeeper.properties >> zookeeper.nohup &
sleep 1
ps aux | grep 'zookeeper.properties' | grep -v grep | awk '{print $2}' > zookeeper.pid

/export/kafka/kafka.start

#!/bin/bash
set -eu
cd /export/kafka
[[ -d data ]] && nohup bin/kafka-server-start.sh config/server.properties >> kafka.nohup &
sleep 1
ps aux | grep 'server.properties' | grep -v grep | awk '{print $2}' > kafka.pid