SpringBoot complete project deployment process (software installation - front-end and back-end deployment)

SpringBoot complete project deployment process

Install Jdk

Use the XTFP tool to upload the jdk binary release package to Linux

Insert image description here

Unzip the installation package

tar -zxvf jdk-8u171-linux-x64.tar.gz -C /usr/local

Unzipping completed

Insert image description here

Configure environment variables, use the vim command to modify /etc/profilethe file, and add the following configuration at the end of the file

JAVA_HOME=/usr/local/jdk1.8.0_171
PATH=$JAVA_HOME/bin:$PATH

Reload the profile file to make the changed configuration take effect immediately. The command is

source /etc/profile

To check whether the installation is successful, the command is

java -version

Insert image description here

Install Tomcat

Use the XTFP tool to upload the tomcat binary release package to Linux

Insert image description here

To unzip the installation package, the command is

tar -zxvf apache-tomcat-7.0.57.tar.gz -C /usr/local

Decompression completed

Insert image description here

Enter the Tomcat bindirectory to start the service, command

Insert image description here

sh startup.sh

or

./startup.sh

Insert image description here

Verify whether Tomcat starts successfully

  • View startup log
more /usr/local/apache-tomcat-7.0.57/logs/catalina.out 

Insert image description here

tail -50 /usr/local/apache-tomcat-7.0.57/logs/catalina.out 

Insert image description here

  • View progress
ps -ef | grep tomcat

Insert image description here

Firewall operation

  • View firewall operations
firewall-cmd --state

or

systemctl status firewalld

Insert image description here

  • Temporarily turn off the firewall
systemctl stop firewalld
  • Turn off firewall permanently
systemctl disable firewalld
  • Turn on firewall
systemctl start firewalld
  • View all open ports
netstat -anp
  • Check whether the specified port is open
firewall-cmd --query-port=666/tcp
  • Open specified port
firewall-cmd --zone=public --add-port=80/tcp --permanent
  • Remove specified port
firewall-cmd --zone=public --remove-port=80/tcp --permanent
  • Effective immediately
firewall-cmd --reload
  • View open ports
firewall-cmd --zone=public --list-ports

Open port 8080 and access

Insert image description here

Insert image description here

Redis installation

Redis installation (only consider Linux environment)

Download address: Redis

1. Download and install the latest version of gcc compiler

Install the C language compilation environment

yum install centos-release-scl scl-utils-build

yum install -y devtoolset-8-toolchain

scl enable devtoolset-8 bash

Test gcc version

gcc --version

2. Download redis-6.2.1.tar.gz and put it in the /opt/soft directory

unzip

tar -zxvf redis-6.2.1.tar.gz

Enter the directory and execute the make command

cd redis-6.2.1

make

If the C language compilation environment is not prepared, make will report an error—Jemalloc/jemalloc.h: There is no such file.

Execute command to solve

make distclean

Execute the make command again in the redis-6.2.1 directory (just compile it)

Skip make test and continue execution: make install

Installation directory/usr/local/bin

View the default installation directory:

redis-benchmark: a performance testing tool that can be run in your own notebook to see how your notebook performs.

redis-check-aof: Repair problematic AOF files, rdb and aof will be discussed later

redis-check-dump: fix problematic dump.rdb file

redis-sentinel: used by Redis cluster

redis-server: Redis server startup command

redis-cli: client, operation entrance

3. Start in the foreground (not recommended)

When the foreground is started, the command line window cannot be closed, otherwise the server will stop.

4. Background startup (recommended)

Back up redis.conf

Copy a copy of redis.conf to another directory

cp  /opt/redis-3.2.5/redis.conf  /myredis

Change the background startup setting daemonize no to yes

Modify the redis.conf (line 128) file and daemonize nochange it yesto allow the service to start in the background

Start Redis

redis-server/myredis/redis.conf

Access with client: redis-cli

Redis is closed

Single instance shutdown

redis-cli shutdown

If you want to connect remotely, modify the configuration file

Change yes to no
Insert image description here
Visual tool connection
Modify configuration file
Comment out bind 127.0.0.1
Insert image description here
Restart service
Test connection
Insert image description here
Success!

Install Mysql

Detects that the MySQL database is currently installed on the system

Check all software currently installed on the system

rpm -qa

Query software with mysql name in the current system

rpm -qa | grep mysql

Query the software named mariadb installed in the current system

rpm -qa | grep mariadb

Insert image description here

Uninstall conflicting software that has been installed

rpm -e --nodeps mariadb-libs-5.5.35-3.el7.x86_64

Upload the MySQL installation package to Linux and extract it to the specified directory

mkdir /usr/local/mysql

tar -zxvf mysql-5.7.25-1.el7.x86_64.rpm-bundle.tar.gz -C /usr/local/mysql

Insert image description here

Enter the mysql directory to prepare for installation

Upgrade first

yum update

Execute the following commands in sequence

rpm -ivh mysql-community-common-5.7.25-1.el7.x86_64.rpm

rpm -ivh mysql-community-libs-5.7.25-1.el7.x86_64.rpm

rpm -ivh mysql-community-devel-5.7.25-1.el7.x86_64.rpm

rpm -ivh mysql-community-libs-compat-5.7.25-1.el7.x86_64.rpm

rpm -ivh mysql-community-client-5.7.25-1.el7.x86_64.rpm

yum install net-tools

rpm -ivh mysql-community-server-5.7.25-1.el7.x86_64.rpm

Start mysql

View mysql service status

systemctl status mysqld

Start mysql service status

systemctl start mysqld

boot

systemctl enable mysqld

View started services

netstat -tunlp

netstat -tunlp | grep mysql

Check the mysql process

ps -ef |grep mysql

Insert image description here

Log in to the MySQL database and check the temporary password

View file contents

cat /var/log/mysqld.log

View passwordthe line information contained in the file content

cat /var/log/mysqld.log | grep password

Insert image description here


Log in to MySQL, change password, and open access permissions

mysql -u root -p 临时密码

change Password

set global validate_password_length=4;      #设置密码长度最低数
set global validate_password_policy=LOW;	   #设置密码安全等级低		
set password=password('root');			   #设置密码为root

grant all on *.* to 'root'@'%'identified by 'root'; #开启访问权限

flush privileges;

Insert image description here

Open ports
View open port numbers

firewall-cmd --list-all

Set open port number

firewall-cmd --add-service=http --permanent

firewall-cmd --add-port=3306/tcp --permanent

Restart firewall

firewall-cmd --reload

Change the wildcard character to %

use mysql;

select Host,User from user;

update user set host = '%' where user ='root';

Remote connection test

Insert image description here

Install Irzsz

yum install lrzsz.x86_64

Insert image description here

enter

rz

Insert image description here

Install Git

yum list git

yum install git

Insert image description here

Insert image description here

Install Maven

tar -zxvf apache-maven-3.5.4-bin.tar.gz -C /usr/local

Modify the configuration file and add the following content

vim /etc/profile

# maven配置
export MAVEN_HOME=/usr/local/apache-maven-3.5.4
export PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$PAT

source /etc/profile

mvn -version

# 修改配置内容如下
vim /usr/local/apache-maven-3.5.4/conf/settings.xml

<localRepository>/usr/local/repo</localRepository>

Insert image description here

Insert image description here

Install nginx

Install dependency packages

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

Or wgetdownload the Nginx installation package

wget https://nginx.org/download/nginx-1.16.1.tar.gz

Unzip

tar -zxvf nginx-1.16.1.tar.gz

Install

cd nginx-1.16.1

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

make && make install

Execute ./configure and report an error

Insert image description here

Install dependency packages

yum -y install pcre-devel openssl openssl-devel

Successful installation

Insert image description here

make && make install

Check version

cd /usr/local/nginx/sbin/

./nginx -v

./nginx -t

If the following appears, it is correct

Insert image description here

Start Nginx

./nginx

Open port 80

firewall-cmd --zone=public --add-port=80/tcp --permanent

firewall-cmd --reload

Access successful

Insert image description here

Out of service

./nginx -s stop

View progress

ps -ef | grep nginx

Reset profile

./nginx -s reload

Configure global commands

Insert image description here

vim /etc/profile

source /etc/profile

Configuration successful

Insert image description here

Project packaging (manual deployment)

Insert image description here

Upload to the specified directory /usr/local/app directory

Insert image description here

Manual deployment project

Change to running in the background and output the log to the log file

nohup java -jar boot工程.jar &>hello.log &

Insert image description here

Browser input access item

Access successful

Insert image description here

Insert image description here

Automated execution scripts (automatic deployment)

#!/bin/sh
echo =================================
echo  自动化部署脚本启动
echo =================================

echo 停止原来运行中的工程
APP_NAME=helloworld

tpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
    echo 'Stop Process...'
    kill -15 $tpid
fi
sleep 2
tpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
    echo 'Kill Process!'
    kill -9 $tpid
else
    echo 'Stop Success!'
fi

echo 准备从Git仓库拉取最新代码
cd /usr/local/helloworld

echo 开始从Git仓库拉取最新代码
git pull
echo 代码拉取完成

echo 开始打包
output=`mvn clean package -Dmaven.test.skip=true`

cd target

echo 启动项目
nohup java -jar helloworld-1.0-SNAPSHOT.jar &> helloworld.log &
echo 项目启动完成

Automatically deploy projects through shell scripts

Set static IP

Modify files/etc/sysconfig/network-scripts/ifcfg-ens33

ifcfg-ens33 Everyone is different, generally it is ifcfg-ensxxxxxxxxxx

HWADDR=00:0C:29:8C:9F:BF
TYPE=Ethernet
BOOTPROTO=static  #使用静态IP地址,默认为dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777736
UUID=dfebdc59-a7da-4377-ac8e-e0346a8b71f6
ONBOOT=yes #开机是否使用
IPADDR=192.168.18.128 #设置的静态IP地址
NETMASK=255.255.255.0 #子网掩码
GATEWAY=192.168.18.2  #网关地址
DNS1=218.2.135.1 #DNS服务器

Notice

Insert image description here

Front-end deployment

Package the front-end project dist and upload it to the specified directory under the specified nginx

Insert image description here

Change nginx configuration file

cd /usr/local/nginx/conf/

vim nginx.conf
	 location / {
            root   html/dist;
            index  index.html index.htm;
        }

	location ^~ /api/ {
		rewrite ^/api/(.*) /$1 break;
		proxy_pass http://192.168.18.128:8080;
	
	}

Insert image description here

The following locationconfiguration is configured according to the project, each project is different

Backend deployment

Package the project and upload it to the specified directory

Insert image description here

Execute in this directory

java -jar boot工程.jar

Change to running in the background and logging

nohup java -jar boot工程.jar &>hello.log &

You can also flexibly specify external configuration files to start.

java -jar boot工程.jar --spring.config.location=classpath:application.yml

Insert image description here

Visit project

Insert image description here

Check the console for normal printing

Insert image description here

The project has been deployed successfully! ! !

Guess you like

Origin blog.csdn.net/qq_51495235/article/details/128509276