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
-
Download remote control tool Xshell and file transfer tool Xftp
Xshell official website download address https://www.netsarang.com/zh/all-downloads/
Xftp official website download address: https://www.netsarang.com/zh/xftp/
-
Download the linux version installation package of jdk and tomcat
Link: https://pan.baidu.com/s/1EnOerP_uT_mm3JpnlAwU5g
Extraction code: zbfr -
Configure the security group of the cloud server
Enter the Alibaba Cloud console , find the security group configuration of this server, and open port 8080 and port 3306
-
Modify the jdbc database connection part of the java project
Change the connected local database to the Mysql database under port 3306 of the cloud server, for example:
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
-
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
-
3.6 install tomcat
Unzip tomcat
tar -zvxf apache-tomcat-8.5.61.tar.gz
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
-
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:
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:
-
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
-
4.9 Log in to MySQL
mysql -u root -p
-
4.10 Change password
alter user 'root'@'localhost' identified by 'Root@2020';
-
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
-
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:
-
4.16 Add the following content under [mysqld] in the /etc/my.cnf file
character_set_server=utf8 init_connect=’SET NAMES utf8’
-
4.17 Restart MySQL for the configuration to take effect
systemctl restart mysqld
-
4.18 View the revised results:
show variables like '%character%';
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.
Start tomcat (the startup file startup.sh is under tomcat/apache-tomcat-8.5.61/bin)
./bin/startup.sh
-
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
-
5.3 execute sql
Enter mysql to execute the sql file through the following statement
source /root/shopping.sql
View current data sheet
show databases;
The database is already in the server database
At this point, the deployment of the entire project is complete
http://ip地址:8080/war包名
Access through the address bar