22.前后端项目部署实战

1.前后端分离项目介绍

1.什么是前后端项目?

简单来说,就是将前端项目和后端项目进行独立部署,互相之间通过token进行数据交互。

2.前后端分离与动静分离有什么区别?

动静分离,是将动态页面编译成静态,然后缓存到CDN上面。
前后端分离,前端项目被编译成HTML,但是JS会通过Ajax获取数据,所以前端页面内容依然是动态的。

3.前后端项目采用renren-fast来实现

4.前后端项目环境

服务 台数 地址 功能
MySQL 3台 10.0.0.51,10.0.0.52,10.0.0.53 配置pxc集群,保证高度一致性
Redis 3台 10.0.0.54,10.0.0.55,10.0.0.56 配置RedisCluster集群
后端 3台 10.0.0.7,10.0.0.8,10.0.0.9 Nginx负载+Java动态环境
前端 3台 10.0.0.4,10.0.0.5,10.0.0.6 Nginx负载+Nginx静态环境

PS:
1.先导入数据库;
2.后端所有节点都需要连接MySQL、Redis
3.前端项目需要连接后端项目

2.后端MySQL集群配置

数据库集群架构图如下:

1.安装数据库(配置PXC集群)

[[email protected] ~]# yum install mariadb mariadb-server -y
[[email protected] ~]# systemctl start mariadb
[[email protected] ~]# systemctl enable mariadb
[[email protected] ~]# mysqladmin password 123456
[[email protected] ~]# mysql -uroot -p123456
MariaDB [(none)]> grant all privileges on *.* to 'all'@'%' identified by '123456';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> create database renren_fast charset utf8;
[[email protected] ~]# systemctl restart mariadb

3.后端Redis集群配置

Redis集群架构图如下:

1.安装Redis

[[email protected] ~]# yum install redis-server -y
[[email protected] ~]# vim /etc/redis.conf +61
bind 127.0.0.1 172.16.1.52
[[email protected] ~]# systemctl restart redis
[[email protected] ~]# systemctl enable redis

4.后端项目配置集群

后端项目编译后,连接MySQL、Redis集群架构图如下:

1.克隆renren_fast后端项目

[[email protected] ~]# git clone https://gitee.com/renrenio/renren-fast.git
[[email protected] ~]# cd renren-fast/

2.配置renren-fast后端项目连接数据库

1.导入数据至数据库
[[email protected] renren-fast]# mysql -h10.0.0.51 -uall -p123456 -B renren_fast < db/mysql.sql

2.修改连接数据库的配置
[[email protected] renren-fast]# vim src/main/resources/application-dev.yml
spring:
    datasource:
        type: com.alibaba.druid.pool.DruidDataSource
        druid:
            driver-class-name: com.mysql.cj.jdbc.Driver
            url: jdbc:mysql://10.0.0.51:3306/renren_fast?
useUnicode=true&characterEncoding=UTF-8&serverTimezone=As
ia/Shanghai
            username: all
            password: 123456

3.使用mvn编译renren-fast后端项目【10.0.0.7】,在web02,web03上进行部署

1.编译项目
[[email protected] renren-fast]# yum install java maven -y
[[email protected] renren-fast]# mvn install -Dmaven.test.skip=true

2.拷贝jar包至其他机器,然后通过java命令运行
[[email protected] renren-fast]# scp target/renren-fast.jar [email protected]:~
[[email protected] renren-fast]# scp target/renren-fast.jar [email protected]:~
[[email protected] ~]# yum install java -y
[[email protected] ~]# java -jar ~/renren-fast.jar &
[[email protected] ~]# yum install java -y
[[email protected] ~]# java -jar ~/renren-fast.jar &

3.配置Nginx负载均衡,调度到后端多台Java项目
[[email protected] conf.d]# cat fast.cheng.com.conf
upstream fast {
    server 172.16.1.8:8080;
    server 172.16.1.9:8080;
}

server {
    listen 80;
    server_name fast.cheng.com;

    location / {
    proxy_pass http://fast;
    proxy_set_header Host $http_host;
    }
}

[[email protected] conf.d]# nginx -t
[[email protected] conf.d]# systemctl restart nginx

4.域名解析:10.0.0.7  fast.cheng.com

4.通过浏览器访问http://fast.cheng.com/renren-fast/swagger/index.html后端进行测试

5.验证用户登录接口,测试后端项目是否成功

6.通过post测试是否成功

7.至此,后端集群项目部署成功。

5.前端项目集群配置

renren-fast-vue基于vue、element-ui构建开发,实现renren-fast后台管理前端功能,提供一套更优的前端解决方案。前端集群架构图如下:

1.克隆项目

[[email protected] ~]# git clone https://gitee.com/renrenio/renren-fast-vue.git
[[email protected] ~]# cd renren-fast-vue/

2.安装依赖包

[[email protected] renren-fast-vue]# curl --silent --location https://rpm.nodesource.com/setup_8.x | bash -
[[email protected] renren-fast-vue]# yum install nodejs npm -y --skip-broken
[[email protected] renren-fast-vue]# npm install -g cnpm --registry=https://registry.npm.taobao.org
[[email protected] renren-fast-vue]# cnpm install

3.修改前端连接后端的配置

[[email protected] renren-fast-vue]# vim static/config/index-prod.js
/**
 * 生产环境
 */
;(function () {
  window.SITE_CONFIG = {};

  // api接口请求地址
  window.SITE_CONFIG['baseUrl'] = 'http://fast.cheng.com/renren-fast';
...............

4.编译项目,然后推送到各个web节点

[[email protected] renren-fast-vue]# cnpm rebuild node-sass
[[email protected] renren-fast-vue]# cnpm run build

拷贝到各个节点
[[email protected] renren-fast-vue]# mkdir /code/renren-fast -p
[[email protected] renren-fast-vue]# cp -rp dist/* /code/renren-fast/
[[email protected] ~]# scp -rp /code [email protected]:/
[[email protected] ~]# scp -rp /code [email protected]:/

5.拷贝编译后的静态资源,在【10.0.0.5、10.0.0.6】进行部署

[[email protected] conf.d]# yum install nginx -y
[[email protected] conf.d]# cat renren.cheng.com.conf
server {
    listen 80;
    server_name renren.cheng.com;
    root /code/renren-fast;

    location / {
    index index.html;
    }
}
[[email protected] conf.d]# nginx -t
[[email protected] conf.d]# systemctl restart nginx

[[email protected] conf.d]# cat renren.cheng.com.conf
server {
    listen 80;
    server_name renren.cheng.com;
    root /code/renren-fast;

    location / {
    index index.html;
    }
}
[[email protected] conf.d]# nginx -t
[[email protected] conf.d]# systemctl restart nginx

6.在【10.0.0.4】安装Nginx并接入负载均衡,调度至后端web主机

[[email protected] ~]# yum install nginx -y
[[email protected] conf.d]# cat proxy_renren.cheng.com.conf
upstream renren {
    server 10.0.0.5:80;
    server 10.0.0.6:80;
}

server {
    listen 80;
    server_name renren.cheng.com;

    location / {
    proxy_pass http://renren;
    proxy_set_header Host $http_host;
    }
}
[[email protected] conf.d]# nginx -t
[[email protected] conf.d]# systemctl restart nginx

域名解析:10.0.0.4  renren.cheng.com

7.通过浏览器访问renren-fast前端,测试是否能正常登陆后台



原文地址:https://www.cnblogs.com/yinwu/p/11620432.html

时间: 2024-08-29 19:07:15

22.前后端项目部署实战的相关文章

Session(数据)共享的前后端分离Shiro实战

1,前言 本文期望描述如何使用Shiro构建基本的安全登录和权限验证.本文实战场景有如下特殊需求:1,在集群和分布式环境实现session共享:2,前端只使用HTML/CSS/JS.因此无法直接使用Shiro提供的SessionManager,以及Shiro针对web应用提供的Filter拦截方式.当然,除非是一定要通过共享缓存的方式共享session,否则还是使用Shiro默认的session管理,毕竟增加独立缓存就意味着维护成本的提高和可用性的下降. 2, Shiro架构 首先一睹官方给出的

【Liunx】前后端项目分离部署

一.部署前端代码 部署前端代码,就是一些静态文件,丢给nginx去解析前端node js + vue的部署 + nginx的部署 1.下载vue的代码 wget https://files.cnblogs.com/files/songzhixue/07-luffy_project_01.zip 2.编译vue的代码 编译vue的代码,生成dist静态文件夹,需要用到node js解释器环境 # 下载nodejs的源代码包 wget https://nodejs.org/download/rele

Docker部署前后端项目

本地(ubuntu19.04)安装docker: sudo apt install docker.io SSH连接服务器: 安装Docker: yum update yum -y install docker-io 启动docker service docker start 开机自启 systemctl enable docker.service 启动自带helloworld测试 docker run hello-world 关闭防火墙: systemctl disable firewalld

django前后端分离部署

部署静态文件: 静态文件有两种方式1:通过django路由访问2:通过nginx直接访问 方式1: 需要在根目录的URL文件中增加,作为入口 url(r'^$', TemplateView.as_view(template_name="index.html")), 在setting中更改静态资源位置 TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path

阶段一-01.万丈高楼,地基首要-第2章 单体架构设计与准备工作-2-2 前后端技术选型讲解

Struts有一些安全的漏洞, Spring.SrpingMVC和Spring Boot拦截器的机制是基于AOP,基于切面的拦截.是通过方法去拦截的.Struts是通过过滤器,过滤器是类拦截. 前端选型 vue.js渐进式的.例如有个老项目是jquery做的,现在用vue.js以后,经过周期性的迭代,逐渐的把jquery剔除掉,这就是渐进式的框架. 结束 原文地址:https://www.cnblogs.com/wangjunwei/p/12025029.html

部署前后端分离项目

路飞前后端项目部署 前言 使用软件 vue 部署前段 uwsgi uWSGI是一个全功能的HTTP服务器,实现了WSGI协议.uwsgi协议.http协议等.它要做的就是把HTTP协议转化成语言支持的网络协议.比如把HTTP协议转化成WSGI协议,让Python可以直接使用. centos7 系统环境 virtulenv 在虚拟环境中部署后端项目 nginx 使用nginx做反向代理 redis 存储数据 mysql(mariadb) 存储数据 supervisor Linux/Unix系统下的

前后端分离下的跨域问题

问题产生的原因 前后端分离项目中,前端和后台服务可能没有部署在一台服务器上.这样的话,前后端ip就会不一致,那么就会产生跨域,往往前后端项目部署的端口通常也可能会不一样,这样也会产生跨域问题.再就是使用的域名不一致也会产生这样的问题. 错误信息 Failed to load http://192.168.2.111:8080/login: No 'Access-Control-Allow-Origin' header ispresent on the requested resource. Or

ASP.NET Core 实战:使用 ASP.NET Core Web API 和 Vue.js 搭建前后端分离项目

 一.前言 这几年前端的发展速度就像坐上了火箭,各种的框架一个接一个的出现,需要学习的东西越来越多,分工也越来越细,作为一个 .NET Web 程序猿,多了解了解行业的发展,让自己扩展出新的技能树,对自己的职业发展还是很有帮助的.毕竟,现在都快到9102年了,如果你还是只会 Web Form,或许还是能找到很多的工作机会,可是,这真的不再适应未来的发展了.如果你准备继续在 .NET 平台下进行开发,适时开始拥抱开源,拥抱 ASP.NET Core,即使,现在工作中可能用不到. 雪崩发生时,没有一

vue+uwsgi+nginx部署前后端分离项目

一:vue+uwsgi+nginx部署 1.1:准备代码: # 路飞学城django代码 https://files.cnblogs.com/files/pyyu/luffy_boy.zip # vue代码 https://files.cnblogs.com/files/pyyu/07-luffy_project_01.zip 1.2:部署准备 1. 部署环境准备 ⑴ . 准备python3和虚拟环境解释器,python3,virtualenvwrapper. pip3 install -i h