前面把apache和git服务器配置好了,今天把tomcat的安装和配置记录一下。
第一步先安装java。
1.源里没有jdk8,直接下载编译好的jdk8 for linux.
wget http://download.Oracle.com/otn-pub/java/jdk/8u60-b27/jdk-8u60-linux-x64.tar.gz
tar xf jdk-8u60-linux-x64.tar.gz -C /usr/local/
cd /usr/local/
ln -sv jdk1.8.0_60 jdk
2.配置环境变量:
vim /etc/profile.d/jdk.sh
--------------------------------------------------->
JAVA_HOME=/usr/local/jdk
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME PATH
<---------------------------------------------------
. /etc/profile.d/jdk.sh //重读此文件,让变量生效
3.查看JAVA是否安装成功:
java -version
第二步安装Tomcat。
1.下载tomcat8.5 for linux
wget http://mirrors.cnnic.cn/apache/tomcat/tomcat-8/v8.0.24/bin/apache-tomcat-8.0.24.tar.gz
tar xf apache-tomcat-8.0.24.tar.gz -C /usr/local/
cd /usr/local/
ln -sv apache-tomcat-8.0.24 tomcat
2.配置环境变量:
vim /etc/profile.d/tomcat.sh
--------------------------------------------------->
CATALINA_BASE=/usr/local/tomcat
PATH=$CATALINA_BASE/bin:$PATH
export PATH CATALINA_BASE
<---------------------------------------------------
. /etc/profile.d/tomcat.sh
3.查看tomcat版本状态:
catalina.sh version
第三部配置tomcat。
1.配置server.xml:
vim /usr/local/tomcat/conf/server.xml
---------------------------------------------------------->
<Connector port="8080" protocol="HTTP/1.1" //默认端口为8080
connectionTimeout="20000"
redirectPort="8443" />
2.tomcat有manager-gui的管理页面,后面jenkins配置要用管理用户,配置tomcat-users.xml:
vim /usr/local/tomcat/conf/tomcat-users.xml
------------------------------------------------------------------------------->
<role rolename="manager-gui"/> //指定用户可以使用的接口为manager-gui
<user username="tomcat" password="tomcat" roles="manager-gui"/> //用户名和密码为tomcat,在manager-gui接口使用
3.创建测试页面:
mkdir -pv /usr/local/tomcat/webapps/test/WEB-INF/{classes,lib}
vim /usr/local/tomcat/webapps/test/index.jsp
--------------------------------------------------------------->
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<html>
<head>
<title>test</title>
</head>
<body>
<%
out.println("Hello World!"); //嵌入java语言
%>
</body>
</html>
4.启动测试:
catalina.sh start
用浏览器打开http://域名:8080/test/index.jsp,正常显示Hello World!。
用浏览器打开http://域名:8080,可以打开Manager App管理页面,用之前配置的用户名和密码进入
5.配置tomcat自启动
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/tomcat8" #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
添加权限,使得脚本文件可执行
chmod 755 /etc/rc.d/init.d/tomcat
#将其加到服务中
chkconfig --add /etc/rc.d/init.d/tomcat
启动tomcat服务: service tomcat start
停止tomcat服务: service tomcat stop
把开发的小程序后台程序打好的包放到/usr/local/tomcat8/webapps/里面,用Postman测试一下,正常运行,tomcat配置结束。