Centos7安装jdk8+zookeeper+tomcat9开机自启详细教程

搭建zookeeper

安装jdk

卸载系统自带的OpenJDK以及相关的java文件

java -version

rpm -qa | grep java

rpm -e --nodeps java-1.7.0-openjdk-1.7.0.111-2.6.7.8.el7.x86_64

解压jdk

tar xvf jdk-8u201-linux-x64.tar.gz 

rm -rf jdk-8u201-linux-x64.tar.gz 

复制到存放文件夹

mkdir /usr/java
mv jdk1.8.0_201/ /usr/java/

配置JDK环境变量

vi /etc/profile
#java environment
export JAVA_HOME=/usr/java/jdk1.8.0_201
export CLASSPATH=.:${JAVA_HOME}/jre/lib/rt.jar:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar
export PATH=$PATH:${JAVA_HOME}/bin

配置生效

source /etc/profile

java -version

安装zookeeper

tar vxf zookeeper-3.4.13.tar.gz 

rm -rf zookeeper-3.4.13.tar.gz

mv zookeeper-3.4.13/ /usr/

复制一份zoo.cfg

tar -xvf zookeeper-3.4.13.tar.gz 

cp zoo_sample.cfg zoo.cfg
# 创建一个文件夹,存放数据
[root@localhost zookeeper-3.4.13]# mkdir data

/usr/zookeeper-3.4.13/data

启动zookeepr

[root@localhost bin]# ./zkServer.sh start

[root@localhost bin]# ./zkServer.sh status

将zookeeper修改成为开机启动

cd 

vi /etc/rc.d/init.d/zookeeper
#!/bin/bash  
#chkconfig: 2345 10 90  
#description: service zookeeper  
export  JAVA_HOME=/usr/java/jdk1.8.0_201 
export  ZOO_LOG_DIR=/usr/zookeeper-3.4.13/logs 
ZOOKEEPER_HOME=/usr/zookeeper-3.4.13  
su    root    ${ZOOKEEPER_HOME}/bin/zkServer.sh      "$1" 
chmod  +x  /etc/rc.d/init.d/zookeeper

chkconfig  --add  zookeeper

安装tomcat

tar xvf apache-tomcat-9.0.16.tar.gz 

rm -rf apache-tomcat-9.0.16.tar.gz

mv apache-tomcat-9.0.16/ /usr

设置开机自启

vi /etc/init.d/tomcat

chmod +x /etc/init.d/tomcat
chkconfig --add tomcat
#!/bin/bash
   # description: Tomcat Start Stop Restart
   # processname: tomcat
   # chkconfig: 2345 20 80
   JAVA_HOME=/usr/java/jdk1.8.0_201/
   export JAVA_HOME
   PATH=$JAVA_HOME/bin:$PATH
   export PATH
   CATALINA_HOME=/usr/tomcat-9.0.16/

   case $1 in
   start)
     sh $CATALINA_HOME/bin/startup.sh
   ;;
   stop)
     sh $CATALINA_HOME/bin/shutdown.sh
   ;;
   restart)
     sh $CATALINA_HOME/bin/shutdown.sh
     sh $CATALINA_HOME/bin/startup.sh
   ;;
   esac
   exit 0

   #chmod 755 tomcat
   #chkconfig --add tomcat
   #chkconfig --level 2345 tomcat on
   #chkconfig --list tomcat

你可能感兴趣的:(Centos7安装jdk8+zookeeper+tomcat9开机自启详细教程)