Detailed CentOS install Tomcat and deploy Java Web project _linux

Source: Internet
Author: User
Tags iptables java web tomcat server

1. Preparatory work

A. Download the Tomcat Linux package, address:, we download the version is 8.0, download the way as shown:

B. Because Tomcat installation relies on the Java JDK, we need to determine if the JDK is installed under the Linux system

B.1 Use (Xshell) to connect to the Linux system

B.2 input command: java-version, if the JDK version number is shown, the proof has been installed, if not shown, it is not installed, if not installed, please refer to the following address for installation: Http://, as shown in the figure:

C. Operating requirements of the software and the system as follows: Virtual machine (Vmware), virtual machine installed in the CentOS system, XSHELL,XFTP, Tomcat8.0,myeclipse development of the webdemo,apache-tomcat-8.0.29.tar.gz.

2. Install Tomcat8.0 under Linux

A. Through the preparation of the above, we now have the environment that can be installed and published, if not, please inquire the installation.

B. Then use the command in Xshell to jump to the local creator's own folder under Local: Kencery

B.1 CD usr/local/mkdir kencery CD kencery/

C. Then use XFTP to copy Tomcat to the Kencery folder, as shown in the following illustration:

D. Extract the uploaded Tomcat8.0 and rename it to Tomcat after decompression, as shown in the figure:

D.1 Tar-zxv-f apache-tomcat-8.0.29.tar.gz

D.2 MV apache-tomcat-8.0.29 Tomcat

D.3 CD Tomcat

E. When the resolution is complete, Tomcat can be started to check for successful installation, as shown in the following illustration:

The message appears as shown on the diagram, indicating that the startup was successful. At this time we can use http://ip:8080 access under Windows, such as the ability to display Tomcat's home page, means that no action is required, if not, you need to open the firewall in Linux 8080 ports.

F. Opening 8080 ports in a firewall under Linux uses the following commands:

F.1 Vim/etc/sysconfig/iptables

After the F.2 is opened, the key disk (i) enters the edit mode, writes the development 8080 port, as shown in the figure:

F.3 after writing we press the keyboard (ESC) button to exit, and then press (: WQ) to save and turn vim off.

G. Restart the firewall after the following command:

Service Iptables Restart 

H. Then enter http://ip:8080 again in the browser, if you see the Tomcat system interface, the installation is successful, you can proceed to the next step.

I. The command to stop Tomcat is:/usr/local/tomcat/bin/

Set up Tomcat server startup and shutdown in 3.Linux

A. As shown in 2, we have completed the installation of Tomcat to resolve to deploy the project, but there is a problem, that is, Linux system and reboot each time we need to pick up the path and execute the command, then we can set the form of horizontal service to achieve this function.

B. Execute command: vim/etc/rc.d/init.d/tomcat, create a script file, write the following code in the file, save and exit

C. Add permissions to the file so that the script file can be executed, the command is chmod 755/etc/rc.d/init.d/tomcat

D. Add it to the service, the command is Chkconfig--add/etc/rc.d/init.d/tomcat

E. Then add the following configuration file to the last face in the file in Tomcat, which is:

Export java_home=/usr/local/kencery/javajdk  #javajdk的安装路径, Use the Echo $JAVA _home command to read
export catalina_home=/usr/local/kencery/tomcat
export Catalina_base=/usr/local/ke Ncery/tomcat
Export Catalina_tmpdir=/usr/local/kencery/tomcat/temp

F. All of the above work smoothly and error, the configuration is completed, you can enter the command service Tomcat start and service Tomcat stop for verification (please test yourself).

Set up tomcat boot in 4.Linux

A. Through the third step we can easily set up Tomcat startup and shutdown, but there is a problem, that is, when the server shutdown restart, the service can not start with the computer startup, then we can set the Tomcat service to boot.

B. Open Linux settings to open startup files, write the following configuration file to the end of this file, command:

export java_home=/usr/local/kencery/javajdk
export classpath=.: $JAVA _home/jre/lib/ Rt.jar: $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar
export path= $PATH: $JAVA _home/bin
Export Catalina_ home=/usr/local/kencery/tomcat/

C.tomcat relies on the Java JDK, so setting up the JDK also synchronizes the imports.

D. After completing the above steps, we can restart the CentOS shutdown to check.

5. Set up username and password login for Tomcat

A. When the Tomcat installation is complete, visit http://ip:8080 to see the Web site Tomcat publishes, when it is necessary to manage our publishing site, we need to log on to Tomcat, then how to set the login name and password in CentOS.

B. Under the Tomcat installation package under the Conf file contains a Tomcat-user.xml file, modify this file, the command is: Vim Tomcat-users.xml

C. Save and exit after writing the following configuration file at the end of an open XML configuration file.

<role rolename= "Admin-gui"/> <role rolename= "Manager-gui"/> <user
"Tomcat" username= D= "Tomcat" roles= "Manager-gui,admin-gui"/>

D. There will be a problem, because the tomcat-users.xml inside the annotation of the user settings, uncomment, file with the user name and password to visit, there will be 403 errors, what reason? This is because we do not specify the permissions the user has, as we now want to access the graphical management application in Tomcat, the manager App, you need to specify Manager-gui permissions if you want to access the host The manager must specify Admin-gui permissions, so the configuration shown in C.

E. After you configure your username password, you need to restart Tomcat, as follows:

Service Tomcat Stop
       service Tomcat start

F. After restarting the service, detects if the login is successful and if the login enters the system, the login is successful.

6. Use MyEclipse to package Java Web projects

A. After all of the above work is done, we need a simple project to package the release, so how to package the project in the MyEclipse?

B. Create a Javaweb project casually, as shown in the figure:

C. Right-click on the project select export-Select Java EE folder-Select War file (MyEclipse), click Next> as shown, select the address of the packaging program, click Finish, that is, to achieve packaging, After you have finished, you can go to the place where you packed to see if the package is successful.

d.myeclipse10.7 When you choose War File (MyEclipse), click Next> to resolve the IDE crash when you package the program.

D.1 This error may be not cracked at the time of the very clean, so you need to perform the following steps

D.2 download file Com.genuitec.eclipse.export.wizard_9.0.0.me201211011550.jar, download address for

D.3 find the address of the MyEclipse installation environment, my installation of the bad is: D:\Program files\myeclipse\common\plugins, the downloaded file is resolved to replace the file with the same name in the plugins (after replacement, It is a good idea to change the jar file to a. txt file, and then restart Myeclipse10, then close, and then change the jar back to the. Jar is the extended state, after reboot.

D.4 has been tested, no problem, the perfect implementation, if you encounter, then according to this kind of thinking to solve.

7. Publish the Java Web Project under Tomcat8.0 and access the presentation

A. After all of the above work is done, we can release the packaged Javaweb program to Tomcat.

B.tomcat The default directory for publishing Web projects is: WebApps

C. Upload the exported War pack directly to the WebApps root directory using XFTP, and the war package can be resolved automatically as Tomcat starts.

D. Then call the path query to see if the installation was successful, as shown in the figure: the installation was successful

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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: 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.