Article directory
I recently wrote a new entry-level project - a blog system. If you want others to access the website I wrote, the most convenient way is to buy a cloud server. The cloud server has a unique external network IP. Next Let's introduce in detail how to deploy the program to the cloud server
Step 1. Install JDK
Installed through the yum
package manager, yum is equivalent to the one on the phone应用商店
The main operations of yum:
yum list | grep [软件包关键字]
Function: View package listyum install [软件包名字]
Function: Install packages (requires administrator privileges)yum remove [软件包名字]
Function: uninstall package (requires administrator privileges)
Specific steps:
(1) First enter the command to
yum list | grep jdk
view various jdk versionsThis time we want to download
java-1.8.0-openjdk-devel.x86_64
devel which means software development kit, x86_64 means for 64-bit system(2) Input command
(3) Then wait for the download, and finally enter
y
, indicating download and installation(4) Use the
javac
command to verify that the installation is successful (as shown in the figure below, the download is successful)
Step 2. Install Tomcat
The version of Tomcat we need this time is 8 (in order to match the version of Servlet), but when viewing the software list with yum, it is found that the version is too old
In this article, there is an introduction to the download of Tomcat on Windows, and it is introduced that Tomcat is a cross-platform server. Therefore, downloading Tomcat on Linux can also be used directly by decompressing the compressed package.
Specific steps:
(1) First install a software package that supports the drag and drop function
yum install lrzsz
. This drag and drop operation can only be performed on a single file, and cannot be dragged and dropped from a directory(2) Create a file to put Tomcat related files, and then directly drag the Tomcat compressed package downloaded from the official website to the created directory
(3) Install a package that supports decompression
yum install unzip
(4) Use the
unzip apache-tomcat-8.5.72.zip
command to decompress the Tomcat compressed package. After unzip is the name of the decompressed Tomcat compressed package. The names of different minor versions will be different (red is the compressed package, and blue is the decompressed file directory. )
Start Tomcat:
(1) Enter the
bin
directory(2) To use
startup.sh
to need tochmod +x *.sh
give .sh executable permissions through the command (the .sh files all turn green at this time)(3)
sh startup.sh
Command to start Tomcat(4) Use the
netstat -anp | grep 8080
command to check whether port 8080 is occupied (whether Tomcat is successfully started)
Configure the security group/firewall behind the cloud server:
For the sake of security, cloud server manufacturers block the ports of the machine by default, so which port we need to be external, we need to configure it
My cloud server is from Alibaba Cloud (other configuration methods are similar), take this as an example
(1) Console -> Instance
(2) More -> Network and Security Group -> Security Group Configuration
(3) Configuration rules
(4) Configure port 8080
(5) Restart the server and then start Tomcat
(6) By entering 106.14.177.238:8080 in the browser, you can see the Tomcat welcome interface (in front of: 8080 is the external network IP of your cloud server), indicating that you have successfully accessed Tomcat
Step 3. Install MySQL
In order to simplify the steps, we choose to install the brother of MySQLMariaDB
The following operations need to be performed by the root
user
Specific steps:
(1) Installation
- Install mariadb service:
yum install -y mariadb-server
- Install the mariadb command line client:
yum install -y mariadb
- Install the mariadb C library:
yum install -y mariadb-libs
- Install the mariadb development package:
yum install -y mariadb-devel
(2) Change the configuration (edit through , remember
vim
to:wq
save after editing)
change
/etc/my.cnf.d/client.cnf
fileAdd a line of configuration under [client]
default-character-set=utf8
Effect:
change
/etc/my.cnf.d/mysql-clients.cnf
file[mysql] Add a line to configure
default-character-set=utf8
Effect:
change
/etc/my.cnf.d/server.cnf
configuration[mysqld] Add configuration under
collation-server = utf8_general_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
sql-mode = TRADITIONAL
Effect:
(3) Start
- Start the service:
systemctl start mariadb
- Set the service to start automatically:
systemctl enable mariadb
- Check service status:
systemctl status mariadb
Notice that the Active state is
active (running)
(4) Test the connection:
- Attempt to connect using the command line client:
mysql -uroot -p
(password defaults to空字符串
)
- Check the mariadb version number:
select version();
- View character set configuration:
show variables like '%char%';
The above installation of MariaDB operation reference article [link] ( CentOS 7 installs MariaDB through yum - Knowing (zhihu.com) )
After completing these operations, you need to open port 3306 on the cloud server security group/firewall
Step 4. Deploy the program
构造好数据库
(1) First need the table in MariaDB on the cloud server(2) Our password was not set before, and the default is an empty string, so the code in the code
PASSWORD
needs to be modified to""
(3) Repackaging
Specify the name and type of the packaged package in pom.xml (here I specify the packaged package as war package and the package name as BlogSystem)
Then click Maven -> Lifecycle -> double-click the package in the upper right corner (after packaging, you can see the ready war package in the list on the left)
(4) Deployment
Drag the BlogSystem.war just generated to the webapps directory in Tomcat, and the war package will be automatically decompressed and deployed in a short while
(5) VerificationBlog System
(http://106.14.177.238:8080/BlogSystem/blog_login.html)(use Zhang San for the username and 123 for the password)
106.14.177.238 is my external IP
BlogSystem is the name of the typed war package (Content Path)
Finish!