【无标题】

一、后端部署

1、jdk部署

2、Tomcat部署

3、MySQL部署

1.卸载mariadb,否则安装MySql会出现冲突(先查看后删除再查看)

2.在线下载MySQL安装包(也可提前下载好上传)

3.将MySQL安装包解压到指定目录

4.开始安装,-ivh 其中i表示安装,v表示显示安装过程,h表示显示进度

5.启动MySQL服务

6.登录mysql修改密码

4、防火墙设置

5、项目部署

二、前端部署

1、Nginx简介

2.Nginx使用

3、Nginx负载均衡

3.1.Nginx安装

3.2.tomcat负载均衡

3.3.Nginx配置

重启Nginx服务,让配置生效

出现权限问题

4、项目部署步骤

5、附录

一、后端部署

将jdk、Tomcat、MySQL的Linux版安装包复制到Linux客户端工具

1、jdk部署

#解压jdk
tar -zxvf jdk-8u151-linux-x64.tar.gz

#配置环境变量
vim /etc/profile

#java environment
export JAVA_HOME=(jdk解压路径)
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH


 

#设置环境变量生效
source /etc/profile

测试jdk是否安装完成

java -version(出现jdk版本代表成功)

2、Tomcat部署

解压tomcat
tar -zxvf apache-tomcat-8.5.20.tar.gz

启动tomcat

./start.sh

测试Tomcat是否部署完成

http://ip:8080(出现Tomcat主页代表成功)

3、MySQL部署

1.卸载mariadb,否则安装MySql会出现冲突(先查看后删除再查看)

[root@192 ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[root@192 ~]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
[root@192 ~]# rpm -qa|grep mariadb

2.在线下载MySQL安装包(也可提前下载好上传)
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.35-1.el7.x86_64.rpm-bundle.tar

3.将MySQL安装包解压到指定目录

mkdir mysql-5.7
tar -xvf mysql-5.7.35-1.el7.x86_64.rpm-bundle.tar -C mysql-5.7

4.开始安装,-ivh 其中i表示安装,v表示显示安装过程,h表示显示进度

cd mysql-5.7
rpm -ivh mysql-community-common-5.7.35-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.35-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.35-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.35-1.el7.x86_64.rpm

5.启动MySQL服务

systemctl start mysqld

6.登录mysql修改密码

[root@192 mysql-5.7]# grep "password" /var/log/mysqld.log
2022-10-12T13:19:16.313408Z 1 [Note] A temporary password is generated for root@localhost: o8N#/CfWD+sh(最开始的密码)
[root@192 mysql-5.7]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.

#设置密码校验策略(0 or LOW),要不密码太LOW不让你过
set global validate_password_policy=0;
#设置密码校验长度,要不密码太短不让你过(多次测试发现密码最小长度为4)
set global validate_password_length=4;
#更新密码
set password = password("123456");
#输入后使修改生效还需要下面的语句
FLUSH PRIVILEGES;
#可以退出,试试用新密码重新登录
exit

#Centos7下无法远程连接mysql数据库
#数据库没有授权,允许以root身份远程登录mysql
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
#输入后使修改生效还需要下面的语句
FLUSH PRIVILEGES;

#Navicat链接MySQL测试
#查看MySQL版本
rpm -qa | grep mysql

4、防火墙设置

#开放端口
firewall-cmd --zone=public --add-port=端口号/tcp --permanent
#跟新防火墙规则
firewall-cmd --reload
#防火墙列表
firewall-cmd --zone=public --list-ports
#防火墙状态
systemctl status firewalld
#启动防火墙
systemctl start firewalld
#关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service 

5、项目部署

#1.启动后台项目测试
http://localhost:8080/
#2.maven install将项目打包
#3.将打包好的项目放入tomcat/webapps/
#4.启动tomcat
./start.sh
#5.浏览器测试 

http://ip:8080/项目具体方法

二、前端部署

1、Nginx简介
1.负载均衡:流量分摊

2.反向代理:处理外网访问内网问题

3.动静分离:判断动态请求还是静态请求,选择性的访问指定服务器

2.Nginx使用
默认端口是80
http://localhost:8080/ssm
http://localhost:80/ssm
http://localhost/ssm
/etc/nginx/nginx.conf 配置上游服务upstream
/etc/nginx/conf.d/default.conf

3、Nginx负载均衡
3.1.Nginx安装

  1. 添加 nginx 官方提供的 yum 源(需要联网且时间较长)
    rpm -Uvh http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.14.2-1.el7_4.ngx.x86_64.rpm

  2. 使用 yum 安装 nginx
    yum install nginx

注1:yum方式安装nginx,它的安装根目录为/etc/nginx
注2:查看nginx版本
rpm -qa | grep nginx

  1. 启动及设置开机启动
    systemctl start nginx.service
    systemctl enable nginx.service

  2. 设置防火墙开放 80 端口
    firewall-cmd --zone=public --add-port=80/tcp --permanent
    firewall-cmd --reload && firewall-cmd --list-port

  3. 测试 nginx 是否可被访问,应该显示nginx的欢迎界面
    http://服务器IP地址:80/

3.2.tomcat负载均衡
#准备2个tomcat
cp -r apache-tomcat-8.5.20/ apache-tomcat-8.5.20_8081/

#第2个修改的配置如下

  1. HTTP端口,默认8080,如下改为8081
    2.远程停服务端口,默认8005,如下改为8006
    3.AJP端口,默认8009,如下改,8010

#测试访问
http://192.168.195.139:8080/
http://192.168.195.139:8081/

3.3.Nginx配置
配置模板如下

#user nobody;
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;


#服务器的集群
upstream  tomcat_list {  #服务器集群名字
    server    127.0.0.1:8080  weight=1;   #服务器1   weight是权重的意思,权重越大,分配的概率越大。
    #server    172.17.0.4:8080  weight=2; #服务器2   weight是权重的意思,权重越大,分配的概率越大
} 

server {
    listen       80;            #监听80端口,可以改成其他端口
    #server_name  localhost;    #当前服务的域名
server_name  www.zking.com; #当前服务的域名(虚拟域名也可以)
root         html/crm;      #将要访问的网站的根目录,nginx节点会自动继承父节点的配置

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

location / {
        #该句代码是为解决history路由不能跳转的问题,在vue-router官网有介绍 
	try_files $uri $uri/  /index.html;
}
location  ^~/api/ {
	#^~/api/表示匹配前缀是api的请求,proxy_pass的结尾有/, 则会把/api/*后面的路径直接拼接到后面,即移除api
	proxy_pass http://tomcat_list/;
}
    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}


# 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;
#    }
#}

}
根据上面配置模板

在nginx.conf添加

upstream tomcat_list { #服务器集群名字
server 127.0.0.1:8080 weight=1; #服务器1 weight是权重的意思,权重越大,分配的概率越大。
server 127.0.0.1:8081 weight=1; #服务器2 weight是权重的意思,权重越大,分配的概率越大
}

在default.conf添加

location / {
#root /usr/share/nginx/html;
#proxy_pass http://172.17.0.3:8080;
proxy_pass http://tomcat_list;
index index.html index.htm;
}

重启Nginx服务,让配置生效
systemctl restart nginx

出现权限问题
#现象:connect() to 192.168.195.139:8080 failed (13: Permission denied) while connecting to upstream
#解决方案:执行下面命令
setsebool -P httpd_can_network_connect 1

#将前端项目打包,生成dist文件夹,点击index.html访问项目测试
npm run build

4、项目部署步骤
1.确保前台项目能用
2.将前台项目打包 npm run build (测试本地项目打包后没问题)
build/utils.js
config/index.js
3.做ip/host主机映射
将虚拟机ip映射域名www.zking.com
4.完成Nginx动静分离的default.conf的相关配置
定义规则:URL符合xxx标准走动态请求,不符合走静态请求
^~api
5.将前台项目打包 npm run build (配合Nginx动静分离)
注意:修改action.js 地址,添加api的路径配置
6.将前端构建好的dist项目,上传到云服务器/usr/local/…
7.server{
server_name:www.zking.com
root:/usr/local/mypro/dist
}
8.systemctl restart nginx
9.www.zking.com完成整个前后端分离项目的测试

5、附录
附录一:linux 里rpm包到底是干什么用的
Linux RPM全称是“RedHat Package Manager”,最早是Red Hat公司开发的,后来在CentOS、Fedora、SUSE都用它。
而rpm包则是软件编译完成后按照RPM机制打包起来的一个文件,可以用rpm命令安装的一个软件安装包,
它省去了Linux软件安装中编译的步骤,安装成功后软件就可以用了。

附录二:centos7中虚拟域名设置
vim /etc/hosts

附录三:
在进行Nginx+Tomcat 负载均衡的时候遇到了这个权限问题,在error.log日志中,我们可以看到如下:
connect() to 127.0.0.1:8080 failed (13: Permission denied) while connecting to upstream
解决方案参考《解决Nginx的connect() to 127_0_0_18080 failed (13 Permission denied) while connect_Osheep-昔日暖阳-CSDN博客_connect() to 127_0_0_18080 failed (13 permission.mht》

附录四:hbuilderX打包vue项目白屏问题
将项目目录下的config文件夹里的index.js文件中,将build对象下的assetsPublicPath中的“/”,改为“./”后,再打包生成的 dist 文件
build: {
// assetsPublicPath: ‘/’,//修改前
assetsPublicPath: ‘./’,//修改后
}

附录五:hbuilderX打包vue项目,element-ui的icon图标无法正常显示问题
问题:使用vue-cli3脚手架搭建的项目,在打包文件上服务器的时候,其他的css,js样式都能正确加载出路径,
但是element的icon图标却不能正常加载出来。

问题分析:
加载的路径https://yxq.linksign.cn/static/css/static/fonts/element-icons.535877f.woff
本应该加载的路径https://yxq.linksign.cn/static/fonts/element-icons.535877f.woff
打包的路径
事实上是打包时候读取的文件路径多了两层;
找到build文件的utils.js 中有打包的路径,看看generateLoaders();
Extract CSS when that option is specified, 指定该选项时提取CSS
发现少了个公共路径,加上pubilcPath
if (options.extract) {
return ExtractTextPlugin.extract({
use: loaders,
fallback: ‘vue-style-loader’,
// 解决icon路径加载错误
publicPath:‘…/…/’
})
} else {
return [‘vue-style-loader’].concat(loaders)
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值