[Linux] Deploy web projects on Ubuntu (Ubuntu version is 16.04.7, jdk1.8, mysql5.7, tomcat9.0.48)

introduce

This is the journey of the editor's growth path, and also the editor's learning path. Hope to grow up with you guys!

Here are two of my favorite quotes:

To have the most simple life and the most distant dream, even if it will be cold tomorrow, the mountains will be high and the water will be far away, and the road will be far away.

Why should one work hard? The best answer I have ever seen is: because the things I like are expensive, the places I want to go are far away, and the person I love is perfect. Therefore, the editor would like to say: encourage each other!

This article is a small editor to record the systematic learning of Linux

Table of contents

1. Install jdk

Two, install mysql

3. Install tomcat

1) Download from the official website

2) Unzip

3) Configure the environment

4) Start the service (this place needs attention, it needs to be executed in the bin directory of tomcat)

5) Test whether the tomcat startup is successful

6) Close the tomcat service (it needs to be executed in the bin directory like starting)

Other configuration and knowledge

Ubuntu configures tomcat to start automatically at boot

4. Project construction

Step 1: Run the sql script

Step 2: Modify the database configuration

Step 3: Copy the project to linux (just drag the entire folder of the project into it)

Step 4: Run the ssm project (put it under webapps and access it directly in the browser in windows)


1. Install jdk

The steps to install jdk are in the following blog, if you are interested, you can check it out

[Linux] Download jdk and uninstall oraclejdk_lyn.R blog in Ubuntu - CSDN blog https://blog.csdn.net/weixin_60387745/article/details/130736955?spm=1001.2014.3001.5501

Two, install mysql

The same steps to install mysql are also in the following blog. If you are interested, you can go to [Linux] Uninstall and download mysql in Ubuntu and how to check whether mysql is successfully uninstalled_lyn.R's blog-CSDN bloghttps :// blog.csdn.net/weixin_60387745/article/details/130937831?spm=1001.2014.3001.5501


3. Install tomcat

1) Download from the official website

Apache Tomcat® - Welcome!

 Download the linux version, pay attention to the suffix of linux

2) Unzip

Put the apache compressed package under /usr/local (the moba tool I use here, if you need it, you can ask me for a link to this tool)

 Unzip, -C means to specify a directory for it

tar -xvf /usr/local/java/apache-tomcat-9.0.48.tar.gz -C  /usr/local

3) Configure the environment

cd /usr/local/apache-tomcat-9.0.48/bin

 Open the startup.sh configuration and add the following environment configuration at the last position 

vim startup.sh
#set java environment

export JAVA_HOME=/usr/local/jdk1.8.0_371

export JRE_HOME=${JAVA_HOME}/jre

export CLASSPATH=.:%{JAVA_HOME}/lib:%{JRE_HOME}/lib

export PATH=${JAVA_HOME}/bin:$PATH

#tomcat

export TOMCAT=/usr/local/apache-tomcat-9.0.48

exec "$PRGDIR"/"$EXECUTABLE" start "$@"

 

4) Start the service (this place needs attention, it needs to be executed in the bin directory of tomcat)

 ./startup.sh

5) Test whether the tomcat startup is successful

wget http://localhost:8080

Note: Instead of using localhost to access in the windows browser, use the ip address of the linux operating system to access

# 查看ip地址
ifconfig  

Access through the browser, the following interface appears to indicate that the installation is successful: (If the interface does not appear, you can restart the virtual machine, and then start tomcat to see if there is an icon as shown below)

# 查看tomcat动态日志
tail -f catalina.out 

 

Tomcat log file description:

1. catalina.out : This file records the console output of Tomcat, including Tomcat startup and shutdown information, and other debugging information;

2. catalina*.log : This file records all exceptions and errors that occur during Tomcat operation;

3. access_log.* : This file records the detailed information of accessing the Web application in Tomcat, including the detailed information of each request, such as the requested address, request time, processing time, response code, request size, etc.;

4. localhost.* : This file records the exception and error information of Tomcat on the local computer;

5. host-manager.* : This file records the exception and error information of Tomcat's management web application;

6. manager.* : This file records the exceptions and error messages that appear in Tomcat’s web application management interface;

7. localhost_access_log.* : This file records the detailed information of the remote client accessing the Tomcat web application, including the requested address, request time, processing time, response code, request size, etc.

So in general, by viewing Tomcat's log files, you can locate and eliminate exceptions and errors during Tomcat's running process, and understand the access status of Web applications, thereby optimizing performance and improving reliability .

6) Close the tomcat service (it needs to be executed in the bin directory like starting)

./shutdown.sh

Other configuration and knowledge

Ubuntu configures tomcat to start automatically at boot

1. Copy catalina.sh in /bin under the tomcat directory to /etc/init.d, and rename it to tomcat

The command is as follows:

cp /usr/local/tomcat/bin/catalina.sh /etc/init.d/ 
mv /etc/init.d/catalina.sh /etc/init.d/tomcat

2. Configure environment variables

vim /etc/init.d/tomcat 


Add the following at the beginning of the file:

CATALINA_HOME=/usr/local/tomcat

JAVA_HOME=/usr/lib/java/jdk1.8.0_371

3. Add to boot automatic service: 

update-rc.d –f tomcat defaults 


4. Use the following command to check whether the setting is successful: 

sysv-rc-conf --list tomcat 


5. Restart the computer to verify

4. Project construction

Step 1: Run the sql script

Operate in windows, use the IP address of linux to connect, and run the sql of the project in the mysql connected to the ip address

Step 2: Modify the database configuration

In the configuration file in the project, change the localhost of the database to the ip address under linux

 <!--配置连接池-->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="com.mysql.jdbc.Driver"/>
		<property name="jdbcUrl" value="jdbc:mysql://linux下的IP地址:3306/ssmdb?serverTimezone=UTC&amp;useSSL=false&amp;allowPublicKeyRetrieval=true"/>
        <property name="user" value="root"/>
        <property name="password" value="123456"/>
    </bean>

Step 3: Copy the project to linux (just drag the entire folder of the project into it)

Can be copied to the webapps in the tomcat directory

 Note: If it cannot run in the webapp , you can put it in the root directory and run it

Step 4: Run the ssm project (put it under webapps and access it directly in the browser in windows)

 The above is the content of the editor's practice, I hope it can help everyone, thank you for watching! ! !

Supongo que te gusta

Origin blog.csdn.net/weixin_60387745/article/details/130929711
Recomendado
Clasificación