How to deploy programs on cloud servers


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:

  1. yum list | grep [软件包关键字]Function: View package list
  2. yum install [软件包名字] Function: Install packages (requires administrator privileges)
  3. yum remove [软件包名字] Function: uninstall package (requires administrator privileges)

Specific steps:

(1) First enter the command to yum list | grep jdkview various jdk versions

insert image description here

This 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

insert image description here

(3) Then wait for the download, and finally enter y, indicating download and installation

insert image description here

(4) Use the javaccommand to verify that the installation is successful (as shown in the figure below, the download is successful)

insert image description here

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

insert image description here

Getting started with Tomcat

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 decompressionyum install unzip

(4) Use the unzip apache-tomcat-8.5.72.zipcommand 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. )

insert image description here

Start Tomcat:

(1) Enter the bindirectory

insert image description here

(2) To use startup.shto need to chmod +x *.shgive .sh executable permissions through the command (the .sh files all turn green at this time)

insert image description here

(3) sh startup.sh Command to start Tomcat

insert image description here

(4) Use the netstat -anp | grep 8080command to check whether port 8080 is occupied (whether Tomcat is successfully started)

insert image description here

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

insert image description here

(3) Configuration rules

insert image description here

(4) Configure port 8080

insert image description here

(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

insert image description here

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 rootuser

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.cnffile

    Add a line of configuration under [client] default-character-set=utf8

    Effect:

insert image description here

  • change /etc/my.cnf.d/mysql-clients.cnffile

    [mysql] Add a line to configuredefault-character-set=utf8

    Effect:

insert image description here

  • 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:

insert image description here

(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 isactive (running)

(4) Test the connection:

  • Attempt to connect using the command line client: mysql -uroot -p(password defaults to 空字符串)

insert image description here

  • Check the mariadb version number:select version();

insert image description here

  • View character set configuration:show variables like '%char%';

insert image description here

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 PASSWORDneeds 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)

insert image description here

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)

insert image description here

(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

insert image description here
(5) Verification

Blog 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!

Guess you like

Origin blog.csdn.net/weixin_46103589/article/details/123951464