开启pulsar自动启动,开启broker与bookie自启与自检功能

1. Broker

添加文件:
vim /usr/lib/systemd/system/pulsar.broker.service

内容:
[Unit]
Description=Pulsar Broker
After=network.target

[Service]
ExecStart=/opt/apache-pulsar-2.3.0/bin/pulsar broker
WorkingDirectory=/opt/apache-pulsar-2.3.0
RestartSec=1s
Restart=on-failure
Type=simple

[Install]
WantedBy=multi-user.target

启动命令
systemctl start pulsar.broker.service
systemctl stop pulsar.broker.service

2. bookie(修改这个之前最好关闭自动拷贝功能,)


关闭
bookkeeper shell autorecovery -disable
开启
bin/bookkeeper shell autorecovery -enable

添加文件:
vim /usr/lib/systemd/system/bookkeeper.service

[Unit]
Description=BookKeeper
After=network.target

[Service]
ExecStart=/opt/apache-pulsar-2.3.0/bin/pulsar bookie
WorkingDirectory=/opt/apache-pulsar-2.3.0
RestartSec=1s
Restart=on-failure
Type=simple

[Install]
WantedBy=multi-user.target

启动命令
systemctl start bookkeeper.service
systemctl stop bookkeeper.service

3. 脚本控制broker自启动

broker
启动命令
nohup ./broker_self_start.sh > /tmp/pulsar_broker.log 2>&1 &

broker_self_start.sh
脚本文件
#!/bin/sh
while true
do
sh /etc/profile
time=$(date “+%Y-%m-%d %H:%M:%S”)
echo t i m e p s − e f ∣ g r e p " P u l s a r B r o k e r S t a r t e r " ∣ g r e p − v " g r e p " i f [ " time ps -ef | grep "PulsarBrokerStarter" |grep -v "grep" if [ " timepsefgrep"PulsarBrokerStarter"grepv"grep"if["?" -eq 1 ]
then
pulsar-daemon start broker
echo “process has been restarted!”
else
echo “process already started”
fi
sleep 60
done

bookie

启动命令
nohup ./bookie_self_start.sh > /tmp/pulsar_bookie.log 2>&1 &

bookie_self_start.sh
脚本文件
#!/bin/sh
while true
do
sh /etc/profile
time=$(date “+%Y-%m-%d %H:%M:%S”)
echo t i m e p s − e f ∣ g r e p " B o o k i e S e r v e r " ∣ g r e p − v " g r e p " i f [ " time ps -ef | grep "BookieServer" |grep -v "grep" if [ " timepsefgrep"BookieServer"grepv"grep"if["?" -eq 1 ]
then
pulsar-daemon start bookie
echo “process has been restarted!”
else
echo “process already started”
fi
sleep 60
done

4. 脚本每日清除log以及重启控制脚本

添加定时执行任务

crontab -e
#添加 每日00:30执行
30 0 * * * /opt/shellExecute/pulsar.sh

pulsar.sh

#!/bin/bash
sh /etc/profile
cd /opt/shellExecute
#broker 的每日启动
ps -ef | grep “pulsar_self_start.sh” |grep -v “grep”
if [ "KaTeX parse error: Expected 'EOF', got '&' at position 92: …r_broker.log 2>&̲1 & else proces…(ps x | grep $process | grep -v grep | awk ‘{print $1}’)
echo $pid
pkill -f pulsar_self_start.sh
rm -f /tmp/pulsar_broker.log
nohup ./pulsar_self_start.sh > /tmp/pulsar_broker.log 2>&1 &
fi

#bookie 的每日启动
ps -ef | grep “bookie_self_start.sh” |grep -v “grep”
if [ "KaTeX parse error: Expected 'EOF', got '&' at position 92: …r_bookie.log 2>&̲1 & else proces…(ps x | grep $process | grep -v grep | awk ‘{print $1}’)
echo $pid
pkill -f bookie_self_start.sh
rm -f /tmp/pulsar_bookie.log
nohup ./bookie_self_start.sh > /tmp/pulsar_bookie.log 2>&1 &
fi

你可能感兴趣的:(pulsar,linux)