Setting Up Tomcat-based Java Web Environment (Huawei Cloud EulerOS 2.0)
Introduction
Apache Tomcat (or simply Tomcat) is an open source web server and servlet container developed by the Apache Software Foundation. This section describes how to deploy Tomcat in HCE 2.0.
Preparations
- Prepare an ECS and assign a public IP address or EIP to the ECS.
- Ensure that inbound security group rules allow traffic to flow to the ECS over port 8080.
Prerequisites
A yum repository has been configured. For details about how to configure a yum repository accessed over the Internet, see Configuring Repositories and Installing Software for HCE.
Procedure
- Install Tomcat.
- Run the following command to install Java:
dnf install java-1.8.0-openjdk
- Run the following command to check whether the installation is successful:
java -version
- Run the following command to install Tomcat:
dnf install tomcat
The Tomcat is installed in the /usr/share/tomcat directory.
- Run the following command to install Java:
- Configure Tomcat.
- Find the Java path in the /usr/lib/jvm/ directory. If the java-1.8.0-openjdk-1.8.0.432.b06-0.hce2.x86_64 file exists in the directory, the JRE path of Java is /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.432.b06-0.hce2.x86_64/jre.
- Edit the /etc/profile file to configure environment variables. Add the following content to the file (JAVA_HOME is the JRE path obtained in 2.a):
JAVA_HOME={JRE path} PATH=$PATH:$JAVA_HOME/bin CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export JAVA_HOME CLASSPATH PATH
- Run the following command to activate the preceding environment variables:
source /etc/profile
- Clear the /usr/share/tomcat/conf/server.xml file and paste the following content:
<?xml version="1.0" encoding="UTF-8"?> <Server port="8006" shutdown="SHUTDOWN"> <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/> <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/> <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/> <Listener className="org.apache.catalina.core.AprLifecycleListener"/> <GlobalNamingResources> <Resource name="UserDatabase" auth="Container" type="org.apache.catalina.UserDatabase" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" pathname="conf/tomcat-users.xml"/> </GlobalNamingResources> <Service name="Catalina"> <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" maxThreads="1000" minSpareThreads="20" acceptCount="1000" maxHttpHeaderSize="65536" debug="0" disableUploadTimeout="true" useBodyEncodingForURI="true" enableLookups="false" URIEncoding="UTF-8"/> <Engine name="Catalina" defaultHost="localhost"> <Realm className="org.apache.catalina.realm.LockOutRealm"> <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> </Realm> <Host name="localhost" appBase="/data/wwwroot/default" unpackWARs="true" autoDeploy="true"> <Context path="" docBase="/data/wwwroot/default" debug="0" reloadable="false" crossContext="true"/> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="%h %l %u %t %s %b" /> </Host> </Engine> </Service> </Server>
Save the settings and exit. You can customize the preceding configuration as required.
- Run the following command to create the directory specified by appbase and docbase in the preceding configuration:
mkdir -p /data/wwwroot/default
- Run the following command to set tomcat as the owner of the preceding directory:
chown -R tomcat.tomcat /data/wwwroot/
- Create the /usr/share/tomcat/bin/setenv.sh file and enter the following information to set JVM memory parameters:
JAVA_OPTS='-Djava.security.egd=file:/dev/./urandom -server -Xms256m -Xmx496m -Dfile.encoding=UTF-8'
- Run the following command to start Tomcat:
systemctl start tomcat
- Run the following command to check the Tomcat status:
systemctl status tomcat
If active (running) is displayed, Tomcat is started.
- Check whether Tomcat is installed.
- Run the following command to create a test page:
echo Tomcat test > /data/wwwroot/default/index.jsp
- Enter http://<Public IP address of the Tomcat service>:8080 in the address box of the browser. If the following page is displayed, the installation is successful.
Figure 1 Successful installation
- Run the following command to create a test page:

The preceding configuration is used only for tests. Exercise caution when using the configuration in the service environment.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot