Actual combat of projects on the cloud: How to move Java projects to cloud servers?

1. How should small and medium-sized enterprises operate after the project development is completed?

Recently, in private messages in the background, many small partners asked bloggers whether to run directly on the PC after the development of the small and medium-sized enterprise project is completed. The answer is no. Professional software development companies will choose Linux servers as their operating environment. There are two types of enterprise servers: one is a physical computer room, and the other is a cloud server.

2. How to choose between traditional computer room and cloud server

Today, the proportion of companies using cloud servers has greatly exceeded that of traditional computer rooms. The reasons are as follows:

  1. The cost of the computer room is too high. A few days ago, the blogger company built a computer room for a local government agency, which cost nearly one million yuan. It is difficult for ordinary enterprises to accept the cost.
  2. The construction is difficult, and excellent network talents are needed to do personalized design to meet various needs of customers.
  3. The post-maintenance cost is high. If the effect completed by the network engineer is as follows, you can think about how to maintain it later.insert image description here
  4. The premise of software operation is network security, and using security software and hiring software security personnel is a big expense.
  5. The disaster recovery capability is poor. If data is lost due to natural or man-made disasters, the consequences cannot be estimated.
    Under the current environment, only a few extremely confidential projects such as governments and banks need to use traditional computer rooms.

3. How to choose a cloud server

Among the cloud server products of major manufacturers, the blogger recommends Huawei cloud server, which has the following characteristics compared with other cloud servers:

3.1 Safe, reliable and good service

The security level of Huawei Cloud's computer room has reached Tier 4, and the special R&D on security accounts for 5% of the total R&D investment. It has passed the global 100+ compliance certification and provides full protection for user data security. At the same time, Huawei promises not to illegally obtain customer data through technical means, and not to force customers to exchange data. Moreover, HUAWEI CLOUD has local teams in 300+ cities, providing 7*24 hours of consultation and in-depth customization of solutions. During the use of cloud servers, HUAWEI CLOUD provides a series of monitoring and operation and maintenance functions, making operation and monitoring more convenient.

3.2 Leading technical strength, better understanding of enterprise customers

Inheriting Huawei's 30+ years of experience in enterprise services, HUAWEI CLOUD understands enterprise needs better, fully covers enterprise business scenarios, and provides corresponding solutions and best practices. At the same time, HUAWEI CLOUD can easily cope with business challenges such as enterprise business security, high concurrency, and rapid innovation through continuous high investment in R&D and mastering the root technology of cloud computing. In addition, HUAWEI CLOUD can provide dedicated resources to meet the physical isolation requirements of data in specific industries. The resources are exclusive and there is no need to worry about resource preemption. The minimum 0.5ms is stable and low-latency, and 99.9999% of the business is highly available.

3.3 Low operation and maintenance costs

Enterprises can pay on demand according to usage needs, without investment in fixed assets. The cloud server is flexible and elastic, and the resources can be utilized according to the peak construction, reducing the waste of traffic and resources. Moreover, the latest technology can be used on the cloud at any time, on demand, and the implementation cycle is greatly shortened.

3.4 Superior performance

Next, we will conduct a comparative evaluation by selecting cloud server products for small and medium-sized enterprises on the market: Huawei Cloud HECS (Yunyao Cloud Server) and Alibaba Cloud Shared Standard S6 instances (hereinafter referred to as "ALS6"). Let us see See how it actually performs.
During the test, the computer rooms of HECS and ALS6 located in Beijing were selected, and the test configurations were both 4C8G. The specific configuration is as follows:
insert image description here

3.4.1 Processor and Memory Performance

In terms of processor performance, after five consecutive running points, we take the average of the four running points of single-core integer, single-core floating point, multi-core integer, and multi-core floating point to evaluate the processor performance of HECS and ALS6. For comparison, the results are as follows:
insert image description here
Through testing, we can see that HECS memory performance is much better than ALS6, with higher stability and reliability, and better memory performance.

3.4.2 Network performance

Here a test machine and a sparring machine are used as the test basis for testing. Firstly, the ping delay test is carried out, and the specific test results are as follows:
insert image description here
Through the test, it is found that the ping test delay of HECS is lower, at about 0.1 milliseconds, and HECS has an advantage in the delay between the intranet and the server.

3.4.3 Storage performance

In the selection of storage specifications, 1000G HUAWEI CLOUD ultra-high IO cloud hard disk and Alibaba Cloud SSD hard disk were selected, mounted on HECS and ALS6 respectively as system disks, and their performance was tested using fio. The test results are as follows:
insert image description here
From the test data, it can be seen that the HUAWEI CLOUD ultra-high IO cloud hard disk can reach its declared specifications after being mounted to HECS, and its performance is better than that of Alibaba Cloud SSD hard disk, and it is also better in terms of stability.

3.5 There are a lot of discounts on the double 11 cloud

Coinciding with Double 11, HUAWEI CLOUD has also launched a series of combined discounts for website and enterprise application cloud scenarios. From now to November 30, all scenarios will be discounted at up to 10% off, and you can also receive a 5,000 yuan gift certificate. Corporate users can also receive new coupons for 3 years, while supplies last. There are also benefits such as ten-thousand-dollar gift packs, roulette lottery draws, service support, value-added purchases, and free orders for a limited time.
insert image description here

4. Teach you to use the cloud server to publish Java projects

After purchasing the cloud server, you need to master the linux syntax for deployment. The following summarizes the blogger's deployment process on the Huawei cloud server.
This deployment process adopts the most basic release method, the full-text fool-style tutorial, just follow the command input, and you can find docker, k8s and other deployment methods by yourself when you upgrade.
The project requires traditional dependencies such as jdk, mysql, and redis, and the project can be run after installation.
Note: It is recommended to use the network disk address for the software installation package, and the official address is too slow.

4.1 install jdk

4.1.1 Download jdk8

Direct online disk link: https://pan.baidu.com/s/1Ip6ILZ5eU90aqNryUqwFgw
Extraction code: 8por

4.1.2 Import into linux

The software is installed in usr/local and can be imported directly using the ssh tool.

4.1.3 Decompression

cd /usr/local
tar -zxvf jdk-8u231-linux-x64.tar.gz

insert image description here

4.1.4 Environment variable configuration

vi /etc/profile

Press the i key to switch to edit mode. Find the end of the content, press the picture to enter the following paragraph. Type in front of unset i.

export JAVA_HOME=/usr/local/jdk1.8.0_231
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
(!!!注意:JAVA_HOME的路径是你实际解压后的JDK的路径,千万别写错了)

insert image description here
Press Esc to exit edit mode, enter :wq to save and exit.

4.1.5 Environment variables take effect

source /etc/profile

4.1.6 Verification

java -version

insert image description here
If the version number is displayed, the installation is successful.

4.1.7 Other commands related to jdk

查看JDK版本:java -version
查看java执行路径:which java
查看JAVA_HOME路径:echo $JAVA_HOME
插看PATH内容:echo $PATH

4.2 Install mysql database

4.2.1 Download

Direct online disk link: https://pan.baidu.com/s/1FNijjVILpp_96nbZrFQ-iQ
Extraction code: s59l

4.2.2 Decompression

Create a new folder and enter it to extract it.

tar -xvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz

insert image description here

4.2.3 Move and rename

mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql

insert image description here

4.2.4 Create mysql user groups and users and modify permissions

cd /usr/local/mysql
groupadd mysql
useradd -r -g mysql mysql
mkdir -p  /data/mysql              #创建目录
chown mysql:mysql -R /data/mysql   #赋予权限

insert image description here

4.2.5 Configure my.cnf

vim /etc/my.cnf

The configuration is as follows.

[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
#character config
character_set_server=utf8mb4
symbolic-links=0
explicit_defaults_for_timestamp=true
lower_case_table_names=1

4.2.6 Initialize the database

cd /usr/local/mysql/bin/
./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql --initialize

insert image description here
Note: Be sure to match the version of the system, 32-bit installation package under 32-bit, otherwise an error will be reported. mysqld: mysqld: cannot execute binary file.

4.2.7 View password

cat /data/mysql/mysql.err

insert image description here
Note: Including the last one. And if the mysql input password has no cursor, you can also copy and paste it directly.

4.2.8 Start mysql and change root password

First place mysql.server in /etc/init.d/mysql.

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

Start the service.

service mysql start
ps -ef|grep mysql

Out of service.

service mysql stop

insert image description here

4.2.9 Modify the password below

Log in to the initial password first, and copy the string you checked out above.

./mysql -u root -p 

insert image description here
Landed successfully.

4.2.10 Change Password

SET PASSWORD = PASSWORD('123456');
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
FLUSH PRIVILEGES;       

4.2.11 Change the configuration and use navicat to connect

use mysql                                            #访问mysql库
update user set host = '%' where user = 'root';      #使root能再任何host访问
FLUSH PRIVILEGES;   

If you don't want to use the mysql command in the bin directory every time, execute the following command.

ln -s  /usr/local/mysql/bin/mysql    /usr/bin

4.3 install redis

4.3.1 Download

Visit the official website and download it. It is relatively small. For the redis address, please visit: Redis official website.
Note: The c/c++ environment must be installed first! ! !

yum -y install gcc gcc-c++ autoconf pcre pcre-devel make automake

insert image description here

4.3.2 Decompression

Unzip the installation package, and a folder will be generated under the directory.

tar zxvf redis-5.0.0.tar.gz

insert image description here

4.3.3 Compile

Then enter the unzipped folder to compile.

make

insert image description here

4.3.4 Modify the configuration file redis.conf

There are mainly three parts to modify here. The following configuration needs to be commented/modified.

bind 0.0.0.0        #将该行注释
daemonize yes       #将后台运行设为yes
protected-mode yes   #将安全模式设为yes
requirepass 123456  #设置密码

insert image description here

4.3.5 Running

cd src
./redis-server  ../redis.conf

insert image description here

4.3.6 Verification

Check to see if it is started.

ps axu | grep redis

insert image description here

4.3.7 Stop

./redis-cli shutdown

4.4 Start the jar package

Execute mvn clean install in the idea, and transfer the packaged jar package to the server through ssh, and execute nohup java-jar package name.
insert image description here

4.5 How to publish the front-end project

4.5.1 Install nginx

4.5.1.1 Installation dependencies

yum -y install gcc pcre-devel zlib-devel openssl openssl-devel

insert image description here

4.5.1.2 Download

The nginx download address is as follows: just download it directly. Please select a newer version.

4.5.1.3 Copy into linux

Download nginx-1.14.2.tar.gz and move it to /usr/local/. You can use the ssh tool to copy directly.

4.5.1.4 Decompression

tar -zxvf nginx-1.14.2.tar.gz

insert image description here

4.5.1.5 Compile

##Enter the nginx directory

cd nginx-1.14.2

configuration.

./configure --prefix=/usr/local/nginx-1.21.4

Compile and install.

make
make install

insert image description here

4.5.1.6 Verification

Test whether the installation is successful

./sbin/nginx -t

Abnormal
insert image description here
cause analysis: There is no logs folder in the nginx/ directory.
Solution:

mkdir logs
chmod 777 logs

Successful installation.

4.5.1.7 Start nginx

cd /usr/local/nginx/sbin
./nginx //启动nginx

Successful
insert image description here
startup Configure nginx to start automatically at boot

vim /etc/rc.d/rc.local

4.5.2 Packaging

Package to generate dist file.

yarn run build

Create a new jeecg-boot folder in nginx and put the generated dist folder into it.
insert image description here

4.5.3 Modify configuration file

Modify the nginx configuration file as follows, file location: /usr/local/nginx-1.14.2/conf/nginx.conf

server {
    
    
                listen       80;
                server_name  你的域名;

                #后台服务配置,配置了这个location便可以通过http://域名/jeecg-boot/xxxx 访问                
                location ^~ /jeecg-boot {
    
    
                        proxy_pass              http://127.0.0.1:8080/jeecg-boot/;
                        proxy_set_header        Host 127.0.0.1;
                        proxy_set_header        X-Real-IP $remote_addr;
                        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
                }
                #解决Router(mode: 'history')模式下,刷新路由地址不能找到页面的问题
                location / {
    
    
                        root   html;
                        index  index.html index.htm;
                        if (!-e $request_filename) {
    
    
                                rewrite ^(.*)$ /index.html?s=$1 last;
                                break;
                        }
                }
        }

4.5.4 Verification

Just visit http://domain name/jeecg-boot It can
insert image description here
be seen that the project has been released successfully.

5. Summary

Enterprise cloud is already a development trend in the software industry. For example, large enterprises such as Neusoft have completed the transformation from computer rooms to cloud servers. Small and medium-sized enterprises should also follow the trend, replace traditional methods, and embrace cloud servers in an all-round way to reduce development costs. Improve customer experience. For us, using cloud servers to deploy private activities and personal sites is also a good choice. The price, quality, and after-sales service of Huawei Cloud servers are all excellent. Let's take advantage of the Double 11 discount to start practicing.

Guess you like

Origin blog.csdn.net/qq_20143059/article/details/127997497