Detailed deployment steps of sprinboot+vue project
Article directory
The following are complete and detailed steps for actual project deployment, for reference only.
1. Prepare deployment files
First you need the following files:
- Backend package (required for related transactions: toplink-admin.jar background management package and toplink-rule-server.jar rule engine service package ) Maven->clean->package
- Backend configuration files, such as application.ym, etc., are used to extract the configuration files to the same path as the jar package for modification later.
- sql file
- For the front-end dist package, after modifying the IP, port, path, etc., use the npm run build command to package it.
- mysql-8.0.28-1.el7.x86_64.rpm-bundle.tar (If you have someone else’s mysql server, you don’t need this, just run the sql on someone else’s server)
- redis installation package
- nginx installation package
And two linux servers: one for database and the other for code, nginx, redis
2. Install mysql
Of course, general project deployment may directly connect to other people's databases, so there is no need to install the database yourself and run the sql file.
2.1. Configure mysql
First download the compressed package of mysql and upload it to the Linux server where mysql is stored, decompress it, and then follow the following steps:
MySQL的安装步骤:
1.先进入MySQL的安装包 cd mysql5.71/
2.检查依赖: rpm -ivh mysql-community-common-5.7.32-1.el7.x86_64.rpm
3.避免依赖: rpm -Uvh --force --nodeps *.rpm
4.配置MySQL: vi etc/my.cnf 在最后面添加lower_case_table_names=1
5.初始化:mysqld --initialize --user=mysql
6.启动MySQL: systemctl start mysqld
#查看mysql状态 停掉mmysql systemctl stop mysqld
#service mysqld status 或者ps -ef | grep mysql kill -9 PID可以关闭端口
7.查看防火墙状态: systemctl status firewalld systemctl stop firewalld 停止防火墙
禁用防火墙 systemctl disable firewalld.service
8.查看日志文件中密码:cat /var/log/mysqld.log | grep password root@localhost:这个后面的是密码 比如: @localhost: L*e8a5teI/_6
9.登陆MySQL: mysql -uroot -p
10.修改MySQL的密码: ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';
11.支持root用户允许远程连接mysql数据库
①show databases;
②use mysql;
③select user,host from user;
④update user set host = '%' where user = 'root';
⑤flush privileges;
12.刷新数据库: flush privileges;
13.建立一个用户
create user zmz identified by 'zmz';
grant all privileges on *.* to 'zmz'@'%';
flush privileges;
2.2. Use navicat to remotely connect to mysql to import data
View IP:
ifconfig
If you cannot connect to mysql:
ping linux的虚拟机ip
MySQL配置文件:检查MySQL服务器的配置文件(通常是/etc/mysql/my.cnf),确保bind-address参数的值设置为MySQL服务器的IP地址。如果该参数被设置为127.0.0.1,则只能本地访问MySQL,需要将其修改为服务器的IP地址。
bind-address = 服务器IP地址
还是连不上就查看防火墙关闭防火墙
systemctl status firewalld.service
systemctl stop firewalld.service
2.3. Import mysql data
Create database->execute sql file
3. Install jdk
Install jdk on the server where the project code and nginx and redis are located.
- I first created a directory /usr/local/jdk1.8 here, and directly used Xftp to upload the downloaded jdk1.8 to this path.
- Unzip:
tar zxvf jdk-8u333-linux-x64.tar.gz
Decompression completed:
- Next, it’s time to configure the environment variables. Enter the following commands to configure:
vim /etc/profile
- After inputting, press Enter and add the following information at the end of the file: Pay attention to your path and jdk package name (enter i to enter editing mode)
JAVA_HOME=/usr/local/jdk1.8/jdk1.8.0_333
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/tools.jar
export PATH JAVA_HOME CLASSPATH
- esc then:wq save and exit
- After editing, save and exit, then enter the following command to refresh the environment configuration to make it effective:
source /etc/profile
java -version
Check the version as follows, ok
4. Install nginx
Also first download the nginx compressed package and upload it to the Linux server using a visualization tool.
The installation steps are as follows:
Nginx的安装步骤:
cd usr/local/
mkdir nginx
使用可视化工具把nginx压缩包放进/nginx目录下
1.解压nginx tar -xf nginx-make-1.19.5.tar.gz 或者yum install -y unzip 然后unzip 文件名.zip
2.进入sbin chmod +x nginx
3.启动nginx ./nginx
4.查看进程 ps -ef |grep nginx
5.返回上一级,进入conf,查看,ls |grep nginx.conf
6.检查是否安装成功: 访问本机ip
5. Install redis
1.解压redis unzip redis.zip
2.进入bin文件
3.赋予权限 chmod 744 .........(文件)
4.启动:./start.sh
或者 nohup ./redis-server /usr/local/redis/bin/redis.conf
5.查看进程: ps -ef |grep redis
netstat -ano |grep 6379(端口号)
6. Create the corresponding directory level and start
- This is the level of toplink-admin background management of the project
6.1 Build startup script
The following is the startup script server.sh placed in the same directory as the jar package (since there are two services, I changed the two scripts)
There may be a problem with script line breaks here. The solution is as follows:
yum install dos2unix
dos2unix server.sh
chmod +x server.sh
#!/bin/bash
#下面分别改为你的服务名和jar名称
APP_NAME="toplink"
JAR_FILE="toplink-admin.jar"
JAVA_OPTS="-Xmx512m -Xms256m"
APP_ARGS=""
LOG_FILE="/var/log/${APP_NAME}.log"
start() {
echo "Starting $APP_NAME..."
nohup java $JAVA_OPTS -jar $JAR_FILE $APP_ARGS > $LOG_FILE 2>&1 &
echo "$APP_NAME started."
}
stop() {
echo "Stopping $APP_NAME..."
pkill -f $JAR_FILE
echo "$APP_NAME stopped."
}
status() {
pgrep -f $JAR_FILE > /dev/null && echo "$APP_NAME is running." || echo "$APP_NAME is not running."
}
case "$1" in
start) start ;;
stop) stop ;;
restart) stop; start ;;
status) status ;;
*) echo "Usage: $0 {start|stop|restart|status}"; exit 1 ;;
esac
exit 0
Usage
启动命令:sh server.sh start 或者 ./server.sh start
停止命令:sh server.sh stop 或者 ./server.sh stop
重启命令:sh server.sh restart 或者 ./server.sh restart
查看状态:sh server.sh status 或者 ./server.sh status
6.2. Modify the configuration files of the two background services and start them
Since the configuration file has been extracted to the same directory level as the jar, the configuration file at the same level will be read first instead of the configuration file at the lower level.
Mainly modify the database configuration and file path, etc.
After modification, use the script to start the toplink-admin service
sh server.sh start
The toplink-admin service started successfully!
Similarly: this is the directory level of my rule engine service
Execute the script to start the rule engine service.
#如果有字符报错先替换字符
dos2unix server.sh
chmod +x server.sh
sh server.sh start
6.3. Store the front-end directory
The dist file level created by the front end is as follows
7. Install and configure nginx
After all the above steps are completed, the key step is to install and configure nginx. Just upload nginx.zip and use upzip nginx.zip.
7.1. Modify nginx configuration
Modify the configuration of nginx and pay attention to the address of your IP and the front-end splicing, which is used to intercept and jump to the back-end service.
#user nobody;
user root root;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 8888;
server_name 172.20.10.12;
client_max_body_size 7m;
#charset koi8-r;
charset utf-8;
location / {
root /usr/local/gljy/gljy-ui/dist;
try_files $uri $uri/ /index.html;
index index.html;
error_page 404 /index.html;
}
#注意这里前后都要加/
location /urule/{
#这里8091后面没有加/是因为在规则引擎服务的properties配置文件没有加/
proxy_pass http://172.20.10.12:8091;
client_max_body_size 100M;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#注意这里前后都要加/
location /toplink/ {
#这里后面加了/是因为yml的项目路径默认加了一个 /
proxy_pass http://172.20.10.12:8081/;
client_max_body_size 100M;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
7.2. Start nginx
Enter the sbin directory,
cd /usr/local/nginx/sbin
./nginx
# 指定配置文件启动(我指定的就是默认的配置文件)
./nginx -c /usr/local/nginx/conf/nginx.conf
查看是否启动成功命令:ps -ef | grep nginx
停止nginx ./nginx -s stop
重启nginx ./nginx -s reload -c /usr/local/nginx/conf/nginx.conf
Go to the two specified background service script paths and restart the two background services:
sh server.sh restart
Visit localhost:8888/
You're done! ! !