本文主要是介绍CentOS7设置开机启动(+ZooKeeper3.4.6+Tomcat7),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
https://blog.csdn.net/pucao_cug/article/details/71240246
https://blog.csdn.net/oaim_zh/article/details/78316254
一、设置zookeeper开机启动
1、进入到/etc/rc.d/init.d目录下,命令是:
cd /etc/rc.d/init.d
另一种开机启动 vim /etc/rc.local
2、新建一个名为zookeeper的文件,命令是:
touch zookeeper
3、编写zookeeper内容
#!/bin/bash
#chkconfig: 2345 10 90
#description: service zookeeper
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-0.el7_5.x86_64
export ZOO_LOG_DIR=/usr/local/zookeeper-3.4.6/log
ZOOKEEPER_HOME=/usr/local/zookeeper-3.4.6
su root ${ZOOKEEPER_HOME}/bin/zkServer.sh "$1"
4、为新建的/etc/rc.d/init.d/zookeeper文件添加可执行权限,命令是:
chmod +x /etc/rc.d/init.d/zookeeper
5、把zookeeper这个脚本添加到开机启动项里面,命令是:
chkconfig --add zookeeper
6、 如果想看看是否添加成功,命令是:
chkconfig --list
7、使用命令重启机器,命令是:
reboot
8、查看zookeeper的状态
重启机器,然后不手动启动zookeeper的情况下,执行命令:
service zookeeper status
二、设置Tomcat开机启动
1、在/etc/init.d/目录下创建tomcat7服务脚本文件。
编辑脚本:
vim /etc/init.d/tomcat7
#!/bin/bash
# tomcat startup script for the Tomcat server
# chkconfig: 345 80 20
# description: start the tomcat deamon
# Source function library
. /etc/rc.d/init.d/functions
prog=tomcat8
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-0.el7_5.x86_64 # 根据自己的路径改写JAVA_HOME
export JAVA_HOME
CATALANA_HOME=/usr/local/apache-tomcat-7.0.47 # 根据自己的路径改写CATALANA_HOME
export CATALINA_HOME
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: $prog {start|stop|restart}"
;;
esac
exit 0
2、修改脚本权限:
chmod 755 tomcat7
3、启动、停止、重启脚本
service tomcat7 start
service tomcat7 stop
service tomcat7 restart
4、执行脚本:
chkconfig tomcat7 on #服务脚本加入到系统启动队列
chkconfig --list #检查服务是否已经生效
这篇关于CentOS7设置开机启动(+ZooKeeper3.4.6+Tomcat7)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!