Going to do
This article is about deploying a Java Web project (mine is a Maven project for SSM) on a cloud server.
Preparation:
- A war file packaged as a project that can be run locally
- The balance of alipay is 10 yuan
Environment:
- Ali Cloud Server ECS System Linux (centOS 7.2)
- JDK 1.8
- Tomcat 9.0
- Mysql 5.7.27
buy
Ali cloud cloud wing students plan ($9.5) a month: promotion.aliyun.com/ntms/act/ca…
There are two models :(the second one I bought seems to have the same performance)
-
Lightweight application server: Suitable for beginners
-
Cloud server ECS
Get an instance after successful purchase: Login – console – Cloud server ECS- instance (buy without password to reset the password)
Remote connection use
-
The instance page has a remote connection, click and then follow the operation to enter, account password is root and you set the secret
-
Use XShell (jailbroken blog.csdn.net/qq_31362105…
-
The new session
-
Name: Name yourself
-
Protocol: indicates the default SSH
-
Host: public IP address of Ali Cloud service (see the ECS instance list page)
-
Port: the default is 22
-
-
When you click connect, you will be asked to enter your password (root and your secret).
Success will be displayed as follows
File transfer tool
The file transfer tool is a tool for the interaction between the local machine and the server files. Just now, the JDK download was directly downloaded from the Linux server by command, and the tomcat installation will use the file transfer method, that is, after downloading on the local machine (I am Windows 10), it will be transferred to the server through this tool. Later our project (WAR package, SQL file, etc.) will also need to be used when it is passed to the server.
I have used XFTP (after the trial charge, cracked version did not find), and then changed to FileZilla(open source free, Baidu official website download)
FileZilla is used here. After installation, open it to connect
Install the JDK
I have installed all these environments in /home/money/. Money is my own folder. Therefore, it is best to enter all commands in this directory
-
Download:
The cloud: pan.baidu.com/s/1_Slgq1Jx… Extraction code: H57L
Download the.tar.gz suffix JDK and pass it in using the file transfer tool
-
Unzip: I am all put in home/money
tar xzf jdk-8u212-linux-x64.tar.gz -C /home/money Copy the code
-
Configure Java environment variables:
vim /etc/profile Copy the code
-
At the bottom of the configuration file add:
Export JAVA_HOME = / home/money/jdk1.8.0 _144 export CLASSPATH = $JAVA_HOME/lib/tools. The jar: $JAVA_HOME/lib/dt. The jar: $JAVA_HOME/lib export PATH=$JAVA_HOME/bin:$PATHCopy the code
-
The configuration environment takes effect
source /etc/profile Copy the code
Install Tomcat9.0
-
Download tomcat.apache.org/download-90… Select the.tar.gz download
-
Upload the downloaded file to /home/money/
-
Install apache-tomcat-9.0.26.tar.gz is the file name downloaded
Tar xf apache-tomcat-9.0.26.tar.gz -c /home/moneyCopy the code
-
After the installation is successful, modify the environment variables of Tomcat (this step can be used even if it is not configured during the second installation, it seems not necessary)
[root@Tomcat ~]# vim /home/money/apache-tomcat-9.0.26/bin/startup [root@Tomcat ~]# vim /home/money/apache-tomcat-9.0.26/bin/shutdown Copy the code
Sh/startup.sh/shutdown.sh/startup.sh/shutdown.sh
exportJAVA_HOME = / home/money/jdk1.8.0 _212exportTOMCAT_HOME = / home/money/apache tomcat -- 9.0.26exportThe CATALINA_HOME = / home/money/apache tomcat -- 9.0.26export CLASS_PATH=$JAVA_HOME/bin/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tool.jar export PATH=$PATH: / home/money/jdk1.8.0 _212 / bin: / home/money/apache tomcat - 9.0.26 / binCopy the code
-
Change the host localhost in server. XML to your server’S IP address
-
On the ECS page of the cloud server, choose Network and Security > Security Groups > Configuration Rules > Add security Rules
-
open
Sh # Enable /home/money/apache-tomcat-9.0.26/bin/startup.sh # Enable /home/money/apache-tomcat-9.0.26/bin/shutdownCopy the code
-
access
Http://your exet IP :8080 Showing apache’s home page represents success
Mysql installation
Run the following command in the directory you want to install. This is where I go to /home/money/ and run the following command
-
download
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm Copy the code
-
Yum install
yum -y install mysql57-community-release-el7-10.noarch.rpm Copy the code
-
Installing the mysql Server
yum -y install mysql-community-server Copy the code
-
Start the service
service mysqld start Copy the code
-
Change the password
For the first installation, root is given a random password. Run the grep “password” /var/log/mysqld.log command
Enter the password of the database mysql -uroot -p
Default password tape'('Deng did not enter the solution: https://blog.csdn.net/qq_42910468/article/details/99692105Copy the code
ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘; (To include case and symbol, difficult to set)
-
Mysql > modify mysql
First log in to mysql again and type status:
The language is not UTF8, so we need to change it by exiting (type exit)
vi /etc/my.cnf Copy the code
Add four lines of code
Mysql > restart the mysql server, log in to the mysql server, and change the status to UTf8
service mysqld restart Copy the code
Operation command:
Start the mysql service service service mysqld restart Check the mysql service status service mysqld statusCopy the code
Deploying a JAVA Web project (WAR package)
First shut down Tomcat, I need to package the local Java Web project into WAR, and export the database to SQL file and upload it to the server. Put the project’s WAR package into tomcat’s webapps directory and start Tomcat. After tomcat runs, it will automatically unpack it and you can use the path to access it.
(For database import, you need to create a database with the same name under mysql command, and then run source data.sql.)
Matters needing attention
- Mysql/mysql.mysql/mysql.mysql/mysql.mysql/mysql.mysql/mysql.mysql/mysql.mysql/mysql.mysql
- About a file upload, Linux without \ operator and drive, such as Windows, path directly is/on behalf of the root directory, file upload is like me in/home/money/tonynews/uploads, The file upload path is writing/home/money/tonynews/uploads/filename
I set the base path
Second context: map file path
Tomcat virtual path mapping do not know to baidu, here is to provide some ideas.