in the on the Linux platform is left on the site platform is LAMP or lnmp, in fact, there is a more extensive use of Java language written in the Web program JSP, The Java runtime requires the JDK(Java Development Kit) to be a product developed by Sun Microsystems. JSP program can use Tomcat, it is a project of the Apache Software Foundation, it is technologically advanced, stable performance, is a more popular Web application Server, in addition, There is also an open source resin can also parse the JSP program, it has a commercial version called Resinpro.
System Platform: CentOS Release 6.7 (Final)
Hostname:balichvm (192.168.171.51)
JDK version:jdk1.7.0_79
Tomcat version:apache-tomcat-7.0.64
1), download, configure JDK
[Email protected] ~]# cd/usr/local/src/
[Email protected] src]# wgethttp://download.oracle.com/otn-pub/java/jdk/7u79-b15/jdk-7u79-linux-x64.tar.gz # Download
[[Email protected] src]# tar zxvfjdk-7u79-linux-x64.tar.gz # Unzip
[[Email protected] src]# MV JDK1.7.0_79//USR/LOCAL/JDK # Move program and rename
2), configure the JDK environment variables, in the/etc/profile.d/ directory, edit a java.sh Java environment variable file, configured as follows
[Email protected] src]# vim/etc/profile.d/java.sh
Java_home=/usr/local/jdk
Java_bin=/usr/local/jdk/bin
Jre_home=/usr/local/jdk/jre
Path= $PATH:/usr/local/jdk/bin:/usr/local/jdk/jre/bin
Classpath=/usr/local/jdk/jre/lib:/usr/local/jdk/lib:/usr/local/jdk/jre/lib/charsets.jar
Save configuration file
[Email protected] src]# source/etc/profile.d/java.sh
[[email protected] src]# java–version # test environment variables are normal
Java Version "1.7.0_79"
Java (TM) SE Runtime Environment (BUILD1.7.0_79-B15)
Java HotSpot (TM) 64-bit Server VM (build24.79-b02, Mixed mode)
[Email protected] src]#
JDK installation Complete, the following installation Tomcat,Tomcat 's official website is http://tomcat.apache.org. ,Tomcat is a project under Apache.
3), download and install tomcat
[Email protected] src]# wgethttp://archive.apache.org/dist/tomcat/tomcat-7/v7.0.64/bin/apache-tomcat-7.0.64.tar.gz
[[Email protected] src]# tar zxvf apache-tomcat-7.0.64.tar.gz # Unzip
[Email protected] src]# Mvapache-tomcat-7.0.64/usr/local/tomcat
[Email protected] src]# cd/usr/local/tomact/
[[email protected] tomact]# Cp-pvbin/catalina.sh/etc/init.d/tomcat # copy Launch Script
"Bin/catalina.sh", "/etc/init.d/tomcat"
[[email protected] tomact]# Vim/etc/init.d/tomcat # Edit startup script, support chkconfig
#!/bin/sh
#chkconfig: 2345 Number of Panax Notoginseng # increased,2345 start Basic,the number of boot sequence,PNS shutdown sequence
#description: Tomcat Server init script
#Source Function Library
. /etc/init.d/functions # There's a space behind the dot
Java_home=/usr/local/jdk
Catalina_home=/usr/local/tomcat
Save the configuration file, and then add Tomcat to the System Services list
[Email protected] tomact]# chmod 755/etc/init.d/tomcat
[Email protected] tomact]# chkconfig--addtomcat
[[Email protected] tomcat]# service Tomcatstart
Using catalina_base:/usr/local/tomcat
Using Catalina_home:/usr/local/tomcat
Using catalina_tmpdir:/usr/local/tomcat/temp
Using Jre_home:/USR/LOCAL/JDK
Using CLASSPATH:/usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
[Email protected] tomcat]#
at this point,Tomcat has started, you can use PS and netstat to view the process and open ports,Tomcat default port is 8080, can be accessed by the browser (note firewall rules).
If there is a iptables rule, add the rule release:
-A input-m state--state new-m tcp-p tcp--dport 8080-j ACCEPT
4),tomcat configuration and optimization (combined with JSP)
The default listener port for Tomcat is 8080, which can be modified on the configuration file server.xml . The file is in the Conf directory under the Tomcat installation directory , here is :/usr/local/tomcat/conf/server.xml
To Configure a virtual host, in Tomcat , each virtual host is used with the <Host> </Host> pair to appear.
first need to build the directory of the site to /data/javaweb , the domain name is java.balichvm.org, configured as follows:
[[email protected] tomcat]# Mkdir/data/javaweb # Create a Site Directory
[Email protected] tomcat]# Vim/usr/local/tomcat/conf/server.xml
Find </Host> next line Insert new <Host> content as follows :
Unpackwars= "false" autodeploy= "true"
xmlvalidation= "Flase" xmlnamespaceaware= "Flase" >
<context path= "" docbase= "./" debug= "0" reloadable= "true" crosscontext= "true"/>
</Host>
Restart the Tomcat service because Tomcat does not support restart, stop first, and then start.
[Email protected] tomcat]#/etc/init.d/tomcatstop
Using catalina_base:/usr/local/tomcat
Using Catalina_home:/usr/local/tomcat
Using catalina_tmpdir:/usr/local/tomcat/temp
Using Jre_home:/USR/LOCAL/JDK
Using CLASSPATH:/usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
[Email protected] tomcat]#/etc/init.d/tomcatstart
Using catalina_base:/usr/local/tomcat
Using Catalina_home:/usr/local/tomcat
Using catalina_tmpdir:/usr/local/tomcat/temp
Using Jre_home:/USR/LOCAL/JDK
Using CLASSPATH:/usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
[Email protected] tomcat]#
in the/data/javaweb directory to write a jsp file, using a Java time function, if the normal display of the current time, it indicates that the JSP environment is basically OK.
[Email protected] tomcat]# vim/data/javaweb/timenow.jsp
<body>
<center> now time is <%=new java.util.Date ()%></center>
</body>
Save the file, test it.
[[Email protected] tomcat]# Date
year on month Saturday 23:35:59 CST
[Email protected] tomcat]# curl-xlocalhost:8080 java.balichvm.org/timenow.jsp
<body>
<center> now time is Sat, 23:36:48 CST </center>
</body>
[Email protected] tomcat]#
now it can be displayed, stating The JSP environment configuration is complete.
This is a JSP environment built using tomcat .
This article is from the "Balich" blog, make sure to keep this source http://balich.blog.51cto.com/6641781/1710973
CentOS 6.7 Configuration JSP running environment tomcat