Alibaba Cloud server deploys JavaWeb project

This article contains detailed steps to build the java environment of linux cloud server (jdk1.8, tomcat8, mysql) and deploy the javaweb project to the cloud server

1. Purchase Alibaba Cloud Server

Aliyun official website: https://www.aliyun.com/?utm_content=se_1007692031

2. Preparation

Three, install JDK and Tomcat

  • 3.1 download jdk1.8 and tomcat8

    Pay attention to select the file with the suffix .tar.gz

  • 3.2 Create a java directory and a tomcat directory under the /usr directory

    cd /usr
    mkdir java
    mkdir tomcat
    
  • 3.3 Use Xftp to upload jdk to java directory, and upload Tomcat to tomcat directory.

  • 3.4 Unzip the jdk (note that the names of the following jdk can be different, you can use ls to view your own jdk)

    tar -zvxf jdk-8u212-linux-x64.tar.gz
    

    Insert picture description hereimage-20201221172031954

  • 3.5 configure java environment variables

    vim /etc/profile
    

Insert the following content into /etc/profile (note: the path and version number of the JDK depends on your version)

#set java environment
export JAVA_HOME=/usr/java/jdk1.8.0_212
export JRE_HOME=/usr/java/jdk1.8.0_212/jre 
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH 
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$JAVA_HOME:$PATH

Make the configuration file effective

source /etc/profile

Check whether the configuration of the java environment has been changed to zero:

java -version

image-20201221172259992

  • 3.6 install tomcat

    Unzip tomcat

    tar -zvxf apache-tomcat-8.5.61.tar.gz
    

    image-20201221172737264

    Enter the bin folder of the unzipped file

    cd apache-tomcat-8.5.61/bin
    

    Modify the setclasspath.sh file

    vim setclasspath.sh
    

    Insert the following into the file

    #set java env
    export JAVA_HOME=/usr/java/jdk1.8.0_212
    export JRE_HOME=/usr/java/jdk1.8.0_212/jre
    

    Start the tomcat server (under the bin folder of the Tomcat installation):

    ./startup.sh
    

    image-20201221172821549

  • 3.7 Internet access

    Now you can access your own Alibaba Cloud server through http://public IP address:8080 on the external network

    If the following page is displayed, the configuration is successful:

    image-20201221202850590

​ If it cannot be displayed, it may be that port 8080 of the server is not open. Log in to the Alibaba Cloud console and modify the security group rules (see appendix).

Fourth, install Mysql database

  • 4.1 Create msyql file under /usr

    cd /usr
    mkdir mysql
    cd mysql
    
  • 4.2 Download the RPM installation source

    wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
    
  • 4.3 Install MySQL source files

     yum localinstall -y mysql57-community-release-el7-11.noarch.rpm
    
  • 4.4 Check whether the MySQL source is installed successfully

    yum repolist enabled | grep "mysql.*-community.*"
    

    The following is a successful installation:

    image-20201221173118909

  • 4.5 Install Mysql service

     yum install -y mysql-community-server
    
  • 4.6 Check whether the MySQL service is successfully installed

    systemctl status mysqld
    
  • 4.7 Start MySQL

    systemctl start mysqld
    
  • ​ 4.8 Get root password

    Due to the upgrade of Mysql security policy, the system will automatically set a random password after the installation is complete. Here we need to get this password first. Since the random password is more complicated, we will change the root password after we get the password and log in.

    grep 'temporary password' /var/log/mysqld.log
    

    image-20201221173419025

  • 4.9 Log in to MySQL

    mysql -u root -p
    
  • 4.10 Change password

    alter user 'root'@'localhost' identified by 'Root@2020';
    

    image-20201221174407082

  • 4.11 Turn off the MySQL password verification rules, so that you can set a simpler password

    Since Mysql requires high password complexity by default (it must contain uppercase and lowercase letters, numbers, and symbols), you can turn off the Mysql password verification rules to allow you to set a simpler password, which is not explained here. Refer to 4.11 in the blog .

  • 4.12 Configure remote user login

    grant all privileges on *.* to 'root'@'%' identified by 'Root@2020' with grant option;
    
  • 4.13 Set to automatically start MySQL when booting (here you need to exit MySQL)

     systemctl enable mysqld
     systemctl daemon-reload
    

    image-20201221174848618

  • 4.14 Open the 3306 port of MySQL in the security group of Alibaba Cloud

  • 4.15 Modify MySQL default character set encoding

    View the current character set encoding of mysql:

    image-20201221175144006

  • 4.16 Add the following content under [mysqld] in the /etc/my.cnf file

    character_set_server=utf8
    init_connect=’SET NAMES utf8’
    

    image-20201221175412746

  • 4.17 Restart MySQL for the configuration to take effect

    systemctl restart mysqld
    
  • 4.18 View the revised results:

    show variables like '%character%';
    

    image-20201221175738664

At this point, mysql has been installed and configured, and users can write data to MySQL

Five, upload war package and database file

I need to package the local Java Web project into a war, and export the local database to a sql file and upload it to the server.

  • 5.1 Upload the war package to the linux server

    Put the war package of the javaweb project into the /usr/tomcat/webapps directory. After tomcat runs, it will be automatically decompressed, and then you can use the path to access it.

    image-20201221194711119

    Start tomcat (the startup file startup.sh is under tomcat/apache-tomcat-8.5.61/bin)

    ./bin/startup.sh
    

    image-20201221195004289

  • 5.2 Upload the database script to the cloud server

    Convert the local database to a sql file and upload it to the server via XFTP

    image-20201221192319657

  • 5.3 execute sql

    Enter mysql to execute the sql file through the following statement

    source /root/shopping.sql
    

    image-20201221192638837

    View current data sheet

    show databases;
    

    image-20201221192750093

    The database is already in the server database

    image-20201221193155906

At this point, the deployment of the entire project is complete

http://ip地址:8080/war包名Access through the address bar

Guess you like

Origin blog.csdn.net/Supreme7/article/details/111498378