Linux目录/etc/init.d下存放的是服务service信息,启动时会扫描该目录
1.进入该目录/etc/init.d
cd /etc/init.d
2.使用vim命令创建并编辑脚本
- 创建tomcat自启动
vim ./dubbo-admin
按inset或i进入编辑模式,输入
#!/bin/bash
#chkconfig:2345 20 90
#description:dubbo-admin
#processname:dubbo-admin
CATALANA_HOME=/opt/tomcat4dubbo
export JAVA_HOME=/opt/jdk1.8.0_152
case $1 in
start)
echo "Starting Tomcat..."
$CATALANA_HOME/bin/startup.sh
;;
stop)
echo "Stopping Tomcat..."
$CATALANA_HOME/bin/shutdown.sh
;;
restart)
echo "Stopping Tomcat..."
$CATALANA_HOME/bin/shutdown.sh
sleep 2
echo
echo "Starting Tomcat..."
$CATALANA_HOME/bin/startup.sh
;;
*)
echo "Usage: tomcat {start|stop|restart}"
;; esac
error:
CATALANA_HOME=/opt/tomcat4dubbo 这个目录得改为自己的tomcat目录
export JAVA_HOME=/opt/jdk1.8.0_152 这个目录得改为自己的JDK目录
题外话:tomcat的webapp下放dubbo或者修改tomcat/conf/server.xml
在末尾</host>前添加
<Context path="/dubbo" docBase="/opt/dubbo" debug="0" privileged="true"/>
就可以tomcat启动即加载这个项目
- 创建zookeeper自启动
vim ./zookeeper
#!/bin/bash
#chkconfig:2345 20 90
#description:zookeeper
#processname:zookeeper
ZK_PATH=/opt/zookeeper
export JAVA_HOME=/opt/jdk1.8.0_152
case $1 in
start) sh $ZK_PATH/bin/zkServer.sh start;;
stop) sh $ZK_PATH/bin/zkServer.sh stop;;
status) sh $ZK_PATH/bin/zkServer.sh status;;
restart) sh $ZK_PATH/bin/zkServer.sh restart;;
*) echo "require start|stop|status|restart" ;;
esac
error:
ZK_PATH=/opt/zookeeper 这个目录得改为自己的zookeeper目录
export JAVA_HOME=/opt/jdk1.8.0_152 这个目录得改为自己的JDK目录
3.最关键的一步不要忘记:把脚本注册为Service
- tomcat
chmod 777 dubbo-admin
chkconfig --add dubbo-admin
- zookeeper
chmod 777 zookeeper
chkconfig --add zookeeper
reboot命令重启就会发现都开机加载了