部署tomcat+apache+java环境

我的安装环境及所需要的软件:

RHEL7.0     

httpd-2.2.29.tar.gz         

apache-tomcat-7.0.57.tar.gz 

jdk-8u25-linux-i586.tar.gz 

mod_jk-1.2.28-httpd-2.2.X.so

安装过程:

[root@localhost Desktop]# ll

-rw-r--r--.  1 root root  8900571 Nov  1 08:35 apache-tomcat-7.0.57.tar.gz

drwxr-xr-x. 12  500  500      4096 Nov  1 19:21 httpd-2.2.29

-rw-r--r--.  1 root root  7537230 Nov  1 08:36 httpd-2.2.29.tar.gz

-rw-r--r--.  1 root root 162406866 Nov  1 08:36 jdk-8u25-linux-i586.tar.gz

-rw-r--r--.  1 root root    930293 Nov  1 08:34 mod_jk-1.2.28-httpd-2.2.X.so

(1)安装httpd

[root@localhost Desktop]# yum -y install gcc gcc-c++

[root@localhost Desktop]# tar xf httpd-2.2.29.tar.gz

[root@localhost Desktop]# cd httpd-2.2.29/

[root@localhost Desktop]# ./configure --prefix=/usr/local/apache2 --enable-rewrite --enable-so

[root@localhost Desktop]# make && make install

防火墙开放http协议、https协议和开启8080端口

[root@localhost Desktop]# firewall-cmd --add-service=http

[root@localhost Desktop]# firewall-cmd --add-service=https

[root@localhost Desktop]# firewall-cmd --zone=public --add-port=80/tcp --permanent

启动apache

[root@localhost Desktop]# /usr/local/apache2/bin/apachectl start

测试apache是否安装成功

[root@localhost Desktop]# echo "apache is successfully." /usr/local/apache2/htdocs/index.html

打开浏览器输入http://主机ip地址

(2)安装dk-8u25-linux-i586.tar.gz

[root@localhost Desktop]# tar xf jdk-8u25-linux-i586.tar.g

z[root@localhost Desktop]# mkdir /usr/lib/jvmnew

[root@localhost Desktop]# mv jdk1.8.0_25/ /usr/lib/jvmnew/

[root@localhost Desktop]# cat >> ~/.bash_profile < #set jdk env

> export JAVA_HOME=/usr/lib/jvmnew/jdk1.8.0_25

> export JRE_HOME=/usr/lib/jvmnew/jdk1.8.0_25/jre

> export CLASSPATH=.:\$JAVA_HOME/lib/dt.jar:\$JAVA_HOME/lib/tools.jar:\$JAVA_HOME/lib:\$JRE_HOME/lib:\$CLASSPATH

> export PATH=\$JAVA_HOME/bin:\$PATH

> end

[root@localhost Desktop]# source ~/.bash_profile

[root@localhost Desktop]# yum install glibc.i686 -y

[root@localhost Desktop]# java -version //这里可以看到新版的jdk

因为系统本身就安装了jdk所以要更新一下配置

[root@localhost Desktop]# update-alternatives --install /usr/bin/java java /usr/lib/jvmnew/jdk1.8.0_25/bin/java 300

[root@localhost Desktop]# update-alternatives --install /usr/bin/javac javac /usr/lib/jvmnew/jdk1.8.0_25/bin/javac 300

下面两条命令需要我们去选择使用哪个版本(需要清楚我们要使用哪个版本以便我们去选择)

[root@localhost Desktop]# update-alternatives --config java

[root@localhost Desktop]# update-alternatives --config javac

可用下命令检查是否成功

[root@localhost Desktop]# ls -lA /etc/alternatives/


(3)安装apache-tomcat-7.0.57.tar.gz

[root@localhost Desktop]# mkdir /usr/tomcat7

[root@localhost Desktop]# tar xf  apache-tomcat-7.0.57.tar.gz  -C /usr/tomcat7/

#启动

[root@localhost Desktop]# /usr/tomcat7/apache-tomcat-7.0.57/bin/startup.sh

#关闭

[root@localhost Desktop]# /usr/tomcat7/apache-tomcat-7.0.57/bin/shutdown.sh

查看tomcat启动

[root@localhost Desktop]# ps -ef |grep tomcat

将之前~/.bash_profile改掉如下内容重新加载

[root@localhost Desktop]# vim ~/.bash_profile

#set jdk env

export JAVA_HOME=/usr/lib/jvmnew/jdk1.8.0_25

export JRE_HOME=/usr/lib/jvmnew/jdk1.8.0_25/jre

export CATALINA_HOME=/usr/tomcat7/apache-tomcat-7.0.57

export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH:$CATALINA_HOME/lib/servlet-api.jar

export PATH=$JAVA_HOME/bin:$PATH

#set jdk env

重新加载

source ~/.bash_profile

测试:

在浏览器输入http://ip地址:8080,查看是否有弹出tomcat的网页

给tomcat加密码[root@localhost Desktop]# vim /usr/tomcat7/apache-tomcat-7.0.57/conf/tomcat-users.xml 在这个文件,在中间插入如下行保存 添加完后重新加载使配置生效

[root@localhost Desktop]# /usr/tomcat7/apache-tomcat-7.0.57/bin/shutdown.sh

[root@localhost Desktop]# /usr/tomcat7/apache-tomcat-7.0.57/bin/startup.sh

测试:

在浏览器输入http://ip地址:8080,查看是否有弹出让你输入用户名和密码的网页

(4)将tomcat 服务与apache服务进行连接

[root@localhost Desktop]# cp mod_jk-1.2.28-httpd-2.2.X.so /usr/local/apache2/modules/

修改apache配置文件如下,如果有就改,没有就加上

[root@localhost Desktop]# vim /usr/local/apache2/conf/httpd.conf

#######

servername www.jiajia.com

DocumentRoot "/usr/local/apache2/htdocs"

######

Loadmodule jk_module modules/mod_jk-1.2.28-httpd-2.2.X.so

JkWorkersFile conf/workers.properties

JkLogFile logs/mod_jk.log

JkShmFile logs/mod_jk.shm

JkLogLevel notice

JkMount /*/*.jsp jiajia

JkMountCopy All

AddType application/x-jsp .jsp

保存退出

[root@localhost Desktop]# cat >> /usr/local/apache2/conf/workers.properties <

>worker.list=jiajia

>worker.jiajia.port=8009

>worker.jiajia.host=localhost

>worker.jiajia.type=ajp13

>worker.jiajia.lbfactor=1

>end

[root@localhost Desktop]# cd /usr/tomcat7/apache-tomcat-7.0.57

[root@localhost apache-tomcat-7.0.57]#  mv webapps webapps.bak

[root@localhost apache-tomcat-7.0.57]# ln -sf /usr/local/apache2/htdocs webapps

[root@localhost Desktop]# /usr/local/apache2/bin/apachectl stop

[root@localhost Desktop]# /usr/local/apache2/bin/apachectl start

[root@localhost Desktop]# /usr/tomcat7/apache-tomcat-7.0.57/bin/shutdown.sh

[root@localhost Desktop]# /usr/tomcat7/apache-tomcat-7.0.57/bin/startup.sh

测试:

[root@localhost Desktop]# mkdir /usr/local/apache2/htdocs/apps

[root@localhost Desktop]# vim /usr/local/apache2/htdocs/apps/showtime.jsp

<%@page language="java" import="java.util.*" %>

now,thetimeis : <%out.println(new Date());%>

http://主机ip地址/apps/showtime.jsp

你可能感兴趣的:(部署tomcat+apache+java环境)