-
cd /etc/init.d/
进入目录 - 创建文件canal,把下面内容粘贴进去,修改java路径和canal安装路径。
#!/bin/bash
#
#chkconfig: 345 63 37
#description: canal
#processname: canal
export JAVA_HOME=/usr/local/jdk1.8.0_271
export PATH=$JAVA_HOME/bin:$PATH
CANAL_HOME=/usr/local/canal
case $1 in
start)
sh $CANAL_HOME/bin/startup.sh
echo "canal is started"
;;
stop)
sh $CANAL_HOME/bin/stop.sh
echo "canal is stop"
;;
restart)
sh $CANAL_HOME/bin/stop.sh
sh $CANAL_HOME/bin/startup.sh
echo "canal is started"
;;
*)
echo "start|stop|restart"
;;
esac
exit 0
- 给脚本添加权限
chmod 755 canal
- 添加服务到开机项
chkconfig --add canal
- 设置为开机启动
chkconfig canal on
- 测试
service canal start
发现一个有意思的事情,canal 如果不正常退出服务,比如虚拟机强制重启等,canal开机就无法正常启动,报错如下
found canal.pid , Please run stop.sh first ,then startup.sh canal is started
;
说的就是找到了canal.pid 请先运行stop.sh,实际上canal服务已经停止了.
这个时候就简单点;