Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to deploy Tomcat and configure virtual hosts

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

1. Tomcat introduces that Tomcat server is a free and open source Web application server, which is a lightweight application server. It is widely used in small and medium-sized systems and not many concurrent access users. It is the first choice for developing and debugging JSP programs. For a beginner, it can be thought that when an Apache server is configured on a machine, it can be used to respond to requests for access to HTML (an application under the standard general markup language) pages. Tomcat is actually an extension of the Apache server, but at run time it runs independently, so when you run tomcat, it actually runs as a separate process from Apache. Tomcat core component Tomcat is composed of a series of components, of which there are three core components: Web container: complete the function of Web server. Servlet container: the name is catalina and is used to process Servlet code. JSP container: used to translate JSP dynamic web pages into Servlet code. 1.2.The Tomcat directory structure bin: stores the script files for starting and shutting down Tomcat. The more commonly used files are catalina.sh, startup.sh and shutdown.sh. Conf: stores various configuration files of the Tomcat server, and the more commonly used files are server.xml, context.xml, and tomcat-users. Xm1, web.xml four files. Lib: store the jar package of the Tomcat server, generally without any changes, unless you connect to a third-party service, such as redis, then you need to add the corresponding jar package logs: store the Tomcat log temp: store the files generated when Tomcat is running webapps: store the work:Tomcat working log of the project resources. Generally, the deployment step 1 of Tomcat will be used to clear the Tomcat cache. Download and install jdk2. Install and start Tomcat2.1, install JDK you must install jdk before deploying Tomcat, because jdk is a necessary environment for Tomcat to run. The installation of jdk is also relatively simple, there are many versions, here we can choose the rpm version. Download the installation package locally, create a shared folder, and share it with a virtual machine centos7. 1. Install the installation package first, install jdkmkdir / abcmount.cifs / / 192.168.56.1/lamp7 / abc # # lamp7 is my local shared file rpm-ivh jdk-8u201-linux-x64.rpm 2, and set the JDK environment variable And make it effective vim / etc/profile# add export JAVA_HOME=/usr/java/jdk1.8.0_201-amd64export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jarexport PATN=$JAVA_HOME/bin:$PATH# environment variable effective source / etc/profile# View java version java-version

Install Tomcat1, extract the installation package to / usr/local, and execute the following command to download the stable version of apache-tomcat-9.0.16.tar.gz from the Tomcat official website. Upload the installation package apache-tomcat-9.0.16.tar.gz to the / root directory # # move the installation package tomcat to the directory / usr/local tar zxvf apache-tomecat-9.0.16.tar.gz-C / usr/loaclcd / usr/localmv apache-tomcat-9.0.16 / tomcat2, optimize the path Start tomcat## start tomcat## # Open ln-s / usr/local/tomcat/bin/startup.sh / usr/bin/ input: startup.sh# close ln-s / usr/loacl/tomcat/bin/shutdown.sh / usr/bin/ input: shutdown.sh3, enter http://192.168.111.145:8080 in the browser

)

Optimize the startup speed of Tomcat the first time you check the log, you will find that Tomcat starts very slowly, which takes dozens of seconds by default. You can modify the jdk parameter to improve it and open the / usr/java/jdk1.8.0_201-amd64/jre/lib/security/java.security file. Cd / usr/java//jdk1.8.0_201-amd64/jre/lib/cd securityvim java.security # # query randomsecurerandom.source=flie:/dev/random # # change to securerandom.source=flie:/dev/urandom

Then, restart Tomcat and you will find that the startup time is much shorter. Note: in the actual working environment, the effect is significant, we only simulate in the virtual machine here, the effect is not very obvious. Third, the configuration of virtual hosts 3.1, the requirements of virtual hosts sometimes companies have multiple projects to run, so it is certainly impossible to run multiple Tomcat services on one server, which will consume too many system resources. At this point, you need to use the Tomcat virtual host. Add two new domain names, www.kgc.com and www.accp.com, to access different project content through the two domain names. Step 1. Create kgc and accp project directories and files 2. Modify the Tomcat main configuration file 3. Restart the Tomcat service 4. Test 3.2. configuration process 1. DNS configuration provides the resolution of two domain names. Yum install bind-yvim / etc/named.conf

Vim / etc/named.rfc1912.zones

Cd / var/namedcp-p named.localhost kgc.com.zone vim kgc.com.zone cp-p kgc.zom.zone accp.zom.zone

Start the service and turn off the firewall. # # start the service and disable the firewall. Systemctl start namedsystemctl stop firewalldsetenforce 0 create these two project directories and files # # create kgc and accp project directories and files cd / usr/local/tomcat/webapps/mkdir / usr/local/tomcat/webapps/kgcecho "this is kgc page\!" > / usr/local/tomcat/webapps/kgc/index.jspmkdir / usr/local/tomcat/webapps/accpecho "this is accp page\!" > / usr/local/tomcat/webapps/accp/index.jsp

2. Modify the Tomcat main configuration file vim / usr/local/tomcat/conf/server.xml to restart the Tomcat service and verify the success of http://www.kgc.com:8080/ and http://www.accp.com:8080/ in the browser.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report