Install Tomcat in Linux/centos

Source: Internet
Author: User
    • Software apache-tomcat-6.0.18.tar.gz:
    • Click to enter the download page: 3
    • Video:
    • Click to enter the Download Page: 1 | 2 | 3

JDK was installed in the last video. Now we will install the Tomcat server,

I would like to briefly introduce some Tomcat servers. It can run JSP files, and the servlet has no problems.

It is a good choice for some small JSP websites or individuals to learn JSP.

JSP server software JBoss, WebLogic, and so on ..

Next we will install Apache-Tomcat-5.3 on centos 6.0.18 Linux Server

Apache-tomcat-6.0.18.tar.gz files you can download on the http://www.apache.org,
In addition, there are multiple versions available. I have selected the latest version.

InArticleIn the end, I will provide you with my own upload link for download, so you do not need to go to apache.org to find it. Haha

Download the package and send it to the server.

Extract
Apache-tomcat-6.0.18.tar.gz] # tar zxvf
After decompression, you can move the extracted folder to/usr/local and rename it.
] # Mv APACHE-Tomcat-6.0.18/usr/local/tomcat

In this way, the installation is complete. It is because Tomcat can be directly decompressed without installation.

========================================================== =
Set tomcat-related environment variables below
] # Vi ~ /. Add bash_profile to Tomcat Environment Parameters

Tomcat_home =/usr/local/tomcat

Export path java_home classpath tomcat_home

Save and exit, and then execute source ~ /. Bash_profile for environment variables to take effect

] # Source ~ /. Bash_profile

Start the Tomcat server.

[Root @ localhost opt] #/usr/local/tomcat/bin/startup. Sh
Using catalina_base:/usr/local/tomcat
Using catalina_home:/usr/local/tomcat
Using catalina_tmpdir:/usr/local/tomcat/temp
Using jre_home:/usr/Java/jdk1.7.0

If there is no other information, it indicates that the service is started normally. You can also check whether the Tomcat port is enabled.

# Netstat-tnl check the port 8080 8009. If it is enabled, it indicates that Tomcat runs normally.

TCP 0 0: 8009: * listen
TCP 0 0: 8080: * listen

======================================

Perform the following tests:

You can access the Tomcat server you just created as a LAN in the XP system.

# Ifconfig view the Server IP address.

Inet ADDR: 192.168.138.128 bcast: 192.168.138.255 mask: 255.255.255.0

Therefore, in the LAN, the XP Access address is http: // 192.168.138.128: 8080.
Be sure to write port 8080.

The default Tomcat page cannot be opened because the default iptables firewall settings in centos 5.3 Operating System

Because port 8080 is not allowed

# The iptables-F command can clear the default firewall rules of iptables in centos5.3.

Access after clearing

If you're seeing this page via a web browser,
It means you 've setup Tomcat successfully. Congratulations!

It is displayed normally. For more information about the Linux built-in firewall iptables settings, see

Video on www.17rumen.com. You can see that iptables settings are demonstrated here.

========================================================== ==============

The following shows the memory size of the Tomcat runtime environment.

Compile a test. jsp file in the default Tomcat website path. The following is the webpage content.

/Usr/local/tomcat/webapps/root: This is the physical address of the website. Let's see my demonstration.

<%
Runtime lruntime = runtime. getruntime ();
Out. println ("*** begin memory statistics *** <br/> ");
Out. println ("free memory:" + lruntime. freememory ()/1024/1024 + "m <br/> ");
Out. println ("Max memory:" + lruntime. maxmemory ()/1024/1024 + "m <br/> ");
Out. println ("total memory:" + lruntime. totalmemory ()/1024/1024 + "m <br/> ");
Out. println ("available processors:" + lruntime. availableprocessors () + "<br/> ");
Out. println ("*** end memory statistics ***");
%>

Save the file and you will be able to access it. Http: // 192.168.138.128: 8080/test. jsp

You can also write other JSP files for learning.

A very simple JSP page.
<%
Out. println ("Hello, www.17rumen.com ");
%>

Further learning about JSP web page programming requires a certain Java language.
======================================
Set the size of Tomcat running memory in Linux
VI ~ /. Bash_profile

Add java_opts = "-xms256m-xmx512m"

Save and exit

# Source ~ /. Bash_profile is effective when environment variables are set

========================================================== ==================================

Finally, let the server automatically run Tomcat at startup.

The simplest method is to automatically start Tomcat through startup. SH and edit VI/etc/rc. d/rc. Local.

Add content at the end of the file (assume that the JDK directory is/usr/Java, and the Tomcat directory is/usr/local/tomcat)

Export jdk_home =/usr/Java/jdk1.7.0
Export java_home =/usr/Java/jdk1.7.0
/Usr/local/tomcat/bin/startup. Sh

Save and exit
======================

The last step is to restart the server to see if it is automatically started.
Shutdown-R now

Slow startup .. Check that port 8080 is automatically enabled. It indicates there is no problem.

Access using a browser and find that the access is inaccessible. It should be an iptables firewall problem,

I forgot to save and modified the iptables settings.

# Iptables-F

# Service iptables save

Saving firewall rules to/etc/sysconfig/iptables: [OK]

The two commands can be executed together, so that they will be saved to the configuration file, and the JSP webpage can be accessed directly at the next boot.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.