Prepare the apache + tomcat environment in linux

Source: Internet
Author: User
Tags ftp file ftp file transfer
Because our technology now uses Struts2 + Hibernate3 + Spring3, so the general javaWeb container can be used. if we want to use something like EJB in the future, we can change it to JBOSS or weblogic. in the previous section, JDK and TOMCAT: 8080 containers can be installed to run...

Because our technology now uses Struts2 + Hibernate3 + Spring3, so the common java Web container can be used. if we want to use something like EJB in the future, we can change it to JBOSS or weblogic.
 
The previous section mainly installed JDK and TOMCAT: 8080 containers, which can be run, followed by the http service of apache: 80.
 
Step 1
 
Download the SSH remote connection tool. I use Secure Shell and install it.
 
Step 2
 
1. download jdk. the version I use is jdk-6u26-linux-x64-rpm.bin Web site to download to http://www.oracle.com
Then, upload the bind file to the linux server by using the FTP file transfer tool provided by the ssh tool. Put it in this file (/usr/local /);
2. then run the following command on ssh: (note: "#" indicates the leftmost side of the command. for example, "#" in ssh does not need to be entered. the command is followed by the command we need to enter .)
 
# Cd/usr/local
 
Modify the permission so that it has the execution permission a + x indicates that all users have the execution permission =,-[u, g, o] indicates users, groups, and others respectively.
 
# Chmod a + x jdk-6u26-linux-x64-rpm.bin

#./Jdk-6u26-linux-x64-rpm.bin
 
 
 
* *** The installer is running ****
 
 
 
Wait and the installation is complete. I personally feel that jdk is faster to install in linux than in windows.
 
Then run ln-s command ln (link)-s (symbolic). if-s is added, the file is mapped to the image, if-s is not added, the same file is generated and saved to the corresponding directory, but the file name is followed by @. note: No matter whether-s is added, the file is synchronized. The same applies to other files in the master file. the format is ln-s [source] [target].
 
Ln-s/usr/local/jdk1.6.0 _ 03 1 space/usr/local/jdk
 
Ln-s/usr/local/jdk1.6.0 _ 03/jre 1 space/usr/local/jre
 
 
# Cd/usr
# Ls
Enter the above command and you will find the successfully installed java file (/usr/java). now we have installed jdk. It's easier than you think.

2. configure environment variables
The installation of java in windows requires environment variables, and linux does not. In linux, the environment variables are stored in the next file (bashrc) in the root directory. to modify the environment variables, you only need to modify the file.
# Cd ~
# Vim. bashrc
Enter the preceding command to enter the environment variable Editing File. note ". bashrc can have fewer vertices or be written ". /bashrc ". add the following lines of code to the file, save and exit (the vim command is ": wq"), so that our java environment variables are set, you can use the above java folder as jdk, or use the jre path. here I use/usr/local as the file path. the following describes how to set the java environment variables. the "export" command can be understood as the "set" command in windows.
 
Export JAVA_HOME =/usr/local/jdk
Export CLASSPATH =.: $ JAVA_HOME/lib/dt. jar: $ JAVA_HOME/lib/tools. jar
Export PATH = $ PATH: $ JAVA_HOME/bin
Export CATALINA_HOME =/usr/local/tomcat

3. deploy Tomcat
1. download the Tomcat installation file. I use the free installation version of apache-tomcat.zip. Then, use the ssh File Transfer Tool to upload it to the linux server. I will put it under this file (/usr/local ).
2. run the following command to decompress the package.
# Cd/usr/local
# Unzip apache-tomcat-5.5.26.zip
* ****** Unzip the package ******
Decompress the package, and set the tomcat environment variables by referring to step 2. If the path has already been set, check whether the path is correct (/usr/local/apache-tomcat-5.5.26 ).
Enter the following command to start tomcat
# Cd, usr, local, apache, tomcat, 5.5.26, and bin
#./Sartup. sh
* *** Start Tomcat ****
3. enter the IP address url of your server in the windows browser, for example, http: // IP address: 8080.
The home page of tomcat indicates that tomcat is successfully installed.

IV. problems encountered during installation and solutions
If the above url access fails, that is, tomcat startup fails, please try the following methods
(1) permission issues, whether the user permissions and files have executable permissions.
A. general user permissions are generally insufficient. please use Google commands to add permissions to users. I installed them as a root user, so this problem was not encountered.
B. The file has insufficient permissions. In most cases, the file has no executable permissions. After the installation fails, I grant the executable permission to all the files in the following (/usr/local/apache-tomcat-5.5.26/bin) folder. The following commands are available.
# Cd/usr/local/apache-tomcat = 5.5.26/bin
# Chmod 777 "file name" (e.g.: # chmod 777 startup. sh)

(2) Check whether tomcat 8080 is enabled for firewall and port problems
First, check whether it is a firewall problem. run the following command to disable the firewall service and then access it to check whether it is normal. If it is normal, it indicates a Firewall problem. I encountered this problem during the installation process. later I found that the firewall problem was solved by using the following method.
Disable the firewall service command of the server
# Service iptables stop
Enable server firewall service commands
# Service iptables start
Edit and enable corresponding firewall Port commands
# Vim/ect/sysconfig/iptables
Check whether the port is in use and view the PORT command
# Netstat-pan | gerp 8080
View all process commands
# Ps-ef
Kill a process Command
# Kill process id (note: It feels much simpler than windows, kill you, hehe)
View all initial system service commands
# Cd/etc/rc. d/init. d
# Ls
Mount the service and delete the service. you can view the service list by running the following command:
# Chkconfig-h

 
 
 
If not, disable the firewall "service iptables stop" first"
"./Shutdown. sh" ends the Tomcat service
You can also use "kill PID" to kill the Tomcat process.

Add Tomcat to the self-starting directory and modify the/etc/rc. local file.
Add the following content.
JAVA_HOME =/usr/java/jdk1.6.0 _ 16
Export JAVA_HOME
/Tomcat5/bin/startup. sh

Run the following command:
Ps-aux | grep tomcat
Tomcat process with no port 8080 is found.
Run netstat-apn
View all processes and port usage. The following process list is found. The last column is PID/Program name.
 
Port 8080 is occupied by Java processes with a PID of 9658.
Run the following command: ps-aux | grep java, or run the command: ps-aux | grep pid.
 
You can clearly know which program occupies port 8080! Then determine whether to use the KILL command to KILL it!


Method 2: directly use netstat-anp | grep portno
That is, netstat-apn | grep 8080
 
 
Decompress the file with "gzip-d apache-tomcat-5.5.28.tar.gz" and extract a folder named "apache-tomcat-5.5.28.tar"
Decompress the file with the tar-xvf apache-tomcat-5.5.28.tar, and the unzipping information is displayed.
Use "ls-l" to display the TomCat folder "apache-tomcat-5.5.28"
Use "mv apache-tomcat-5.5.28/usr/" to move the folder to its usr directory.
Use "mv apache-tomcat-5.5.28 tomcat5" to change the directory name to "tomcat5"
Go to the Tomcat 5/bin directory, and start Tomcat in the "startup. sh" and "catalina. sh" files.
Use "./startup. sh" to start the service. The package is incorrect as follows:
"[Root @ localhost bin] #./startup. sh
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program"
This is because the JAVA_HOME variable is not set,
Use "JAVA_HOME =/usr/java/jdk1.6.0 _ 16" and "export JAVA_HOME" to set variables
Run "./startup. sh" to display the following information:
"Using CATALINA_BASE:/usr/tomcat5
Using CATALINA_HOME:/usr/tomcat5
Using CATALINA_TMPDIR:/usr/tomcat5/temp
Using JRE_HOME:/usr/java/jdk1.6.0 _ 16
Using CLASSPATH:/usr/tomcat5/bin/bootstrap. jar"
You can use "ps-ef | grep tomcat" to display that tomcat has been started.
Use "wget
Http: // localhost: 8080 "test local access
 
The following describes how to enable the system to automatically start tomcat as a service.
 
1. create a tomcat startup script under/etc/init. d.
2. chkconfig -- add tomcat
3. service tomcat start
In this case, env:/etc/init. d/tomcat: No such file or directory appears.
The tomcat service cannot be started. do you still need other configurations? Let's take a look.
Script:
#! /Bin/sh
# Chkconfig: 345 99 10
# Description: Auto-starts tomcat
#/Etc/init. d/tomcatd
# Tomcat auto-start
# Source function library.
./Etc/init. d/functions
# Source networking configuration.
./Etc/sysconfig/network
RETVAL = 0

Export JAVA_HOME =/usr/local/jdk
Export CATALINA_HOME =/usr/local/tomcat7
Export CATALINA_BASE =/usr/local/tomcat7
Export CATALINA_TMPDIR =/usr/tomcat7/temp
TOMCATUSER = tomcat
Start ()
{
If [-f $ CATALINA_HOME/bin/startup. sh];
Then
Echo $ "Starting Tomcat"
/Bin/su $ TOMCATUSER-c $ CATALINA_HOME/bin/startup. sh
RETVAL =$?
Echo "OK"
Return $ RETVAL
Fi
}
Stop ()
{
If [-f $ CATALINA_HOME/bin/shutdown. sh];
Then
Echo $ "Stopping Tomcat"
/Bin/su $ TOMCATUSER-c $ CATALINA_HOME/bin/shutdown. sh
RETVAL =$?
Sleep 1
Ps-fwwu tomcat | grep apache-tomcat | grep-v grep | grep-v PID | awk '{print $2}' | xargs kill-9
Echo "OK"
# [$ RETVAL-eq 0] & rm-f/var/lock /...
Return $ RETVAL
Fi
}

Case "$1" in
Start)
Start
;;
Stop)
Stop
;;

Restart)
Echo $ "Restaring Tomcat"
$0 stop
Sleep 1
$0 start
;;
*)
Echo $ "Usage: $0 {start | stop | restart }"
Exit 1
;;
Esac
Exit $ RETVAL

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.