CentOS7安装配置JDK和tomcat
Centos7 JDK8安装配置
直接下载jdk到/usr/local/java,
解压后配置环境变量就完成了。
配置环境变量,编辑/etc/profile文件,在文件末尾添加:
export JAVA_HOME=/usr/local/java/jdk1.8.0_91
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命令重新加载/etc/profile文件,使修改的内容在当前shell窗口中生效。(永久生效,重启系统或注销用户)
测试是否安装成功:java -version
centos设置tomcat开机启动:
1、执行指令vi /etc/rc.d/init.d/tomcat生成脚本文件,内容如下
#!/bin/bash
#
# /etc/rc.d/init.d/tomcat
# init script for tomcat precesses
#
# processname: tomcat
# description: tomcat is a j2se server
# chkconfig: 2345 86 16
# description: Start up the Tomcat servlet engine.
if [ -f /etc/init.d/functions ]; then
. /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ]; then
. /etc/rc.d/init.d/functions
else
echo -e "\atomcat: unable to locate functions lib. Cannot continue."
exit -1
fi
RETVAL=$?
CATALINA_HOME="/usr/local/tomcat/apache-tomcat-9.0.0.M4" #tomcat安装目录
case "$1" in
start)
if [ -f $CATALINA_HOME/bin/startup.sh ];
then
echo $"Starting Tomcat"
$CATALINA_HOME/bin/startup.sh
fi
;;
stop)
if [ -f $CATALINA_HOME/bin/shutdown.sh ];
then
echo $"Stopping Tomcat"
$CATALINA_HOME/bin/shutdown.sh
fi
;;
*)
echo $"Usage: $0 {start|stop}"
exit 1
;;
esac
exit $RETVAL
2、添加权限chmod 755 /etc/rc.d/init.d/tomcat,使得脚本文件可执行
3、运行:chkconfig --add /etc/rc.d/init.d/tomcat #将其加到服务中
4、在vim /usr/local/tomcat7/bin/catalina.sh文件中加入以下语句:
#auto startup tomcat config
export JAVA_HOME=/usr/local/java/jdk1.8.0_91
export CATALINA_HOME=/usr/local/tomcat/apache-tomcat-9.0.0.M4
export CATALINA_BASE=/usr/local/tomcat/apache-tomcat-9.0.0.M4
export CATALINA_TMPDIR=/usr/local/tomcat/apache-tomcat-9.0.0.M4/temp
启动tomcat服务: service tomcat start
停止tomcat服务: service tomcat stop