Install tomcat in Linux (Centos) and deploy a Java Web project, centostomcat

Source: Internet
Author: User

Install tomcat in Linux (Centos) and deploy a Java Web project, centostomcat
1. Preparations

A. Download the tomcat linux package at: http://tomcat.apache.org/download-80.cgi. the download method is 8.0.


B. because tomcat installation depends on Java jdk, we need to determine whether jdk B .1 is installed in linux and connect to the Linux system using (Xshell). Run the following command in B .2: java-version, if jdk version is displayed, it indicates that it has been installed. If not, it indicates that it is not installed. If not, see the following address for installation: http://www.cnblogs.com/hanyinglong/p/5025635.html,: c. the required software and system are as follows: Butler. 2. Install Tomcat8.0 in Linux

A. After the above preparations, we now have an environment for installation and release. If not, please check the installation on your own.

B. then run the command in Xshell to jump to the local folder of the Creator: kencery B .1 cd usr/local/mkdir kencery cd kencery/c. use Xftp to copy tomcat to the kencery Folder: d. decompress the uploaded tomcat 8.0, decompress it, and rename it tomcat: 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. after parsing, you can start Tomcat and check whether the installation is successful. The command is as follows:/usr/local/kencery/tomcat/bin/startup. sh indicates that the startup is successful. In this case, we can use http: // ip: 8080 for access in windows. If the home page of Tomcat is displayed, it means no operation is required. If it cannot be displayed, you need to open port 8080 of the firewall in Linux. F. to open port 8080 in the firewall under Linux, run the following command: f.1 vim/etc/sysconfig/iptables f.2, press the keyboard (I) to enter the editing mode, and write it to port 8080 of development ,: f.3 after writing, press the keyboard (ESC) button to exit, then press (: wq) to save and close Vim. G. restart the firewall. The command is as follows: service iptables restart h. enter http: // ip: 8080 in the browser again. If the tomcat System Interface is displayed, the installation is successful and you can proceed to the next step. I. Run the following command to stop Tomcat:/usr/local/tomcat/bin/shutdown. sh3.Linux to set tomcat server startup and shutdown.

A. as shown in figure 2, we have completed the installation of tomcat and can deploy the project through parsing, but there is a problem here, that is, we need to connect to the path and execute commands for Linux system and restart every time, so we can set the form of Horizontal service to implement this function.

B. Execute the command: vim/etc/rc. d/init. d/tomcat, create a script file, write the following code in the file, save and Exit 1 #! /Bin/bash 2 #/etc/rc. d/init. d/tomcat 3 # init script for tomcat precesses 4 # processname: tomcat 5 # description: tomcat is a j2se server 6 # chkconfig: 2345 86 16 7 # description: start up the Tomcat servlet engine. 8 9 if [-f/etc/init. d/functions]; then10. /etc/init. d/functions11 elif [-f/etc/rc. d/init. d/functions]; then12. /etc/rc. d/init. d/functions13 else14 echo-e "\ atomcat: unable t O locate functions lib. Cannot continue. "15 exit-116 fi17 RETVAL =$? 18 CATALINA_HOME = "/usr/local/kencery/tomcat" # tomcat installation directory, where you can copy the directory 19 case "$1" in20 start) 21 if [-f $ CATALINA_HOME/bin/startup. sh]; 22 then23 echo $ "Starting Tomcat" 24 $ CATALINA_HOME/bin/startup. sh25 fi26; 27 stop) 28 if [-f $ CATALINA_HOME/bin/shutdown. sh]; 29 then30 echo $ "Stopping Tomcat" 31 $ CATALINA_HOME/bin/shutdown. sh32 fi33; 34 *) 35 echo $ "Usage: $0 {start | stop}" 36 exit 137; 38 esac39 exit $ RETVALLinux 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 and run the command chkconfig -- add/etc/rc. d/init. d/tomcat e. then add the following configuration file to catalina in tomcat. command: vim/usr/local/kencery/tomcat/bin/catalina. sh export JAVA_HOME =/usr/local/kencery/javajdk # installation path of javajdk, use the echo $ JAVA_HOME command to read the export CATALINA_HOME =/usr/local/kencery/tomcat export CATALINA_BASE =/usr/local/kencery/tomcat export CATALIN A_TMPDIR =/usr/local/kencery/tomcat/temp f. if all of the above operations go smoothly and an error is reported, the configuration is complete. You can enter the Command service tomcat start and service tomcat stop for verification (Please experiment on your own ). 4. set tomcat startup in Linux.. through step 3, we can easily set tomcat startup and shutdown, but there is a problem here, that is, when the server is shut down and restarted, the service cannot be started with the startup of the computer, so we can set the tomcat service to start at startup. B. open the linux settings to enable the startup, and write the following configuration file to the end of the file. The command is vim/etc/rc. d/rc. local 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/# tomcat self-start/usr/local/kencery/tomcat/bin/startup. c. tomcat depends on the Java jdk, so the jdk is also imported synchronously when it is set. D. After completing the above steps, we can shut down centos and restart it for check. 5. set the username and password for tomcat to log on to. after tomcat is installed, visit http: // ip: 8080 to view the website published by tomcat. In this case, you need to manage our website and log on to tomcat, in centos, how do I set the login name and password. B. the conf file under the tomcat installation package contains a tomcat-user.xml file, modify this file, the command is: vim tomcat-users.xml c. write the following configuration file at the end of the xml configuration file to save the file and exit.

<Role rolename = "admin-gui"/>
<Role rolename = "manager-gui"/>
<User username = "tomcat" password = "tomcat" roles = "manager-gui, admin-gui"/>

D. there will be a problem here, because there is a comment in the tomcat-users.xml of the user settings information, cancel the comment, with the user name and password provided by the file to access, there will be a 403 error, why? This is because we do not specify the user's permissions. For example, if we want to access the graphical management application function in tomcat, that is, the Manager App, We need to specify the manager-gui permissions, to access the host manager, you must specify the admin-gui permission, as shown in c.

E. after configuring the username and password, you need to restart tomcat. The command is as follows: service tomcat stop service tomcat start f. after the service is restarted, check whether the logon is successful. If you log on to the system, the logon is successful. 6. Use MyEclipse to package Java Web projects

A. After all the above work is completed, we need a simple project to package and release. How can we package the project in MyEclipse?

B. create a Java Web project: c. right-click the project, select Export, select the JavaEE folder, select WAR file (MyEclipse), click Next>, select the address for storing the package, and click Finish to complete packaging, after packaging, you can check whether the package is successful. D. How to Solve IDE crash when selecting WAR File (MyEclipse) and clicking Next> In MyEclipse10.7 package. D.1 this error may be caused by the fact that the attack was not completely cracked. Therefore, you need to perform the following steps to download the file com. genuitec. eclipse. export. wizard_9.0.0.me201211011550.jar, find the address of MyEclipse installation environment for: http://files.cnblogs.com/files/hanyinglong/java.zip d.3, my installation environment is: D: \ Program Files \ MyEclipse \ Common \ Program file end, then restart myeclipse10, then close, change jar back. jar is in the extension state, and you can restart it ). D.4 has been tested, and there are no problems, so it can be implemented perfectly. If you encounter it, you can solve it in this way. 7. Publish the Java Web project to Tomcat8.0 and access the display

A. After all the above work is completed, we can release the packaged JavaWeb program to tomcat.

B. the default directory for tomcat web project publishing is webapps c. upload the exported war package directly to the webapps root directory using Xftp. As tomcat starts, the war package can be automatically parsed. D. then, call the path to check whether the installation is successful. This indicates that the installation is successful and all the configurations are complete. In the implementation of the configuration, I also encountered many problems, it has been written in the article. If you encounter it, you can refer to the solution. You are welcome to give your comments. If any errors are found in this article, please point them out. Thank you.

  

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.