JAVA web环境搭建(使用Tomcat8整合httpd)
Posted meizy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JAVA web环境搭建(使用Tomcat8整合httpd)相关的知识,希望对你有一定的参考价值。
说明:这里是Linux服务综合搭建文章的一部分,本文可以作为单独搭建Tomcat并整合httpd的参考。
如果需要查看相关软件版本和主机配置要求,请根据目录自行查看。
Linux服务综合搭建的文章目录
8、rhel7 JAVA web环境搭建(使用Tomcat8整合httpd)
8.1 单独安装Tomcat(很简单)
8.1.1 准备httpd和网站目录
1 [[email protected] ~]# yum install httpd 2 3 [[email protected] ~]# systemctl enable httpd && systemctl restart httpd 4 5 [[email protected] ~]# firewall-cmd --permanent --add-service=http && firewall-cmd --reload
1 [[email protected] www]# echo ‘172.25.0.55:/nfsshare/web/ /var/www/html nfs defaults 0 0‘ >>/etc/fstab
挂载:
8.1.2 安装Tomcat
安装过程:下载--解压--做链接--启动
下载软件包
1 [[email protected] ~]#mkdir /usr/local/tomcat8 2 [[email protected] ~]# tar xvf apache-tomcat-8.5.38.tar -C /usr/local/tomcat8
1 [[email protected] bin]# ln -s /usr/local/tomcat8/apache-tomcat-8.5.38/bin/startup.sh /usr/sbin/start-tomcat8 2 [[email protected] bin]# ln -s /usr/local/tomcat8/apache-tomcat-8.5.38/bin/shutdown.sh /usr/sbin/shutdown-tomcat8
1 [[email protected] bin]# firewall-cmd --permanent --add-port=8080/tcp --add-port=8080/udp 2 [[email protected] bin]# firewall-cmd --reload
8.2 Tomcat整合httpd
注意:网站域名为tomcat.mei.com
8.2.1 在前面的基础上安装httpd-devel (开发包)和tomcat-connectors
Connector主要负责处理与客户端的通信。Connector的实例用于监听端口,接受来自客户端的请求并将请求转交给Engine处理。同时将来自Engine的答复返回给客户端
注意:这里我在foundation上已经准备好了tomcat-connectors-1.2.40-src.tar.gz的软件包
可以到官网下载或者我的网盘共享中下载或者其它第三方下载
建议不要官网https://tomcat.apache.org/download-connectors.cgi
官网下载很慢,可以到下面的网站搜索下载
8.2.2 安装httpd-devel
1 [[email protected] ~]# yum install httpd-devel
8.2.3 安装tomcat-connectors
1 [[email protected] ~]# wget http://pakg.mei.com/packages/tomcat-connectors-1.2.40-src.tar.gz 2 [[email protected] ~]# mv tomcat-connectors-1.2.40-src.tar.gz /usr/local/src/ 3 [[email protected] src]# tar xvf tomcat-connectors-1.2.40-src.tar.gz
1 [[email protected] src]# cd tomcat-connectors-1.2.40-src/native/ 2 [[email protected] native]# which apxs 3 /bin/apxs
注意:编译要依赖apxs还有JAVA环境
1 [[email protected] native]# ./configure --with-apxs=/bin/apxs 2 [[email protected] native]# make
8.2.4 配置Tomcat-connectors
1 [[email protected] apache-2.0]# cp mod_jk.so /etc/httpd/modules/
JkLogLevel info JkLogStampFormat "[%a %b %d %H:%M:%S %Y]" JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories JkRequestLogFormat "%w %V %T" JkMount /servlet/* worker1 JkMount /*.jsp worker1
worker.list=worker1 worker.worker1.type=ajp13 worker.worker1.host=localhost worker.worker1.port=8009 worker.worker1.lbfactor=50 worker.worker1.cachesize=10 worker.worker1.cache_timeout=600 worker.worker1.socket_keepalive=1 worker.worker1.socket_timeout=300
Include conf/mod_jk.conf LoadModule jk_module modules/mod_jk.so ServerName tomcat.mei.com:80
8.3 测试
8.3.1 添加测试页面
index.jsp中的内容
<%@page import="java.util.Date"%> <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Insert title here</title> </head> <body> 当前时间是: <% //out.print(new java.util.Date().toLocaleString());toLocaleString()方法早已经过时了, //由DateFormat.format(Date date)取代。 //out.print(new java.util.Date().toLocaleString()); out.print(new java.util.Date().toString()); out.print(new java.util.Date()); %> </body> </html>
8.3.2 启动Tomcat8
8.3.4 测试
[[email protected] ~]# curl http://tomcat.mei.com <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Insert title here</title> </head> <body> 当前时间是: Sun Jul 07 17:55:45 CST 2019Sun Jul 07 17:55:45 CST 2019 </body> </html> [[email protected] ~]#
最后希望大家提意见、转发、评论和交流!!!
以上是关于JAVA web环境搭建(使用Tomcat8整合httpd)的主要内容,如果未能解决你的问题,请参考以下文章