Docker:部署若依前后端分离版

Docker:部署若依前后端分离版

  • [1. 停止天翼云上的原来跑的若依项目](#1. 停止天翼云上的原来跑的若依项目)
  • [2. 停止腾讯云上的若依项目](#2. 停止腾讯云上的若依项目)
  • [3. 使用Docker部署](#3. 使用Docker部署)
    • [3.1 天翼云数据库&Redis](#3.1 天翼云数据库&Redis)
      • [3.1.1 部署数据库](#3.1.1 部署数据库)
      • [3.1.2 部署Redis数据库](#3.1.2 部署Redis数据库)
      • [3.1.1 部署Nginx(这里被天翼云坑了换的腾讯云运行nginx)](#3.1.1 部署Nginx(这里被天翼云坑了换的腾讯云运行nginx))
    • [3.2 腾讯云部署后端&前端&Nginx](#3.2 腾讯云部署后端&前端&Nginx)
      • [3.2.1 部署前端](#3.2.1 部署前端)
      • [3.2.2 部署后端](#3.2.2 部署后端)
  • 注意
  • 参考

1. 停止天翼云上的原来跑的若依项目

powershell 复制代码
ps -ef|grep 'java'

可以看到ruoyi 的进程是4969

kill -9 4969停止服务

2. 停止腾讯云上的若依项目

3. 使用Docker部署

3.1 天翼云数据库&Redis

3.1.1 部署数据库

powershell 复制代码
# 1.删除原来的MySQL容器
docker rm -f mysql

# 2.进入root目录
cd ~

# 3.创建并运行新mysql容器,挂载本地目录
docker run -d \
  --name mysql \
  -p 3306:3306 \
  -e TZ=Asia/Shanghai \
  -e MYSQL_ROOT_PASSWORD=fanzhen123456789 \
  -v ./mysql/data:/var/lib/mysql \
  -v ./mysql/conf:/etc/mysql/conf.d \
  -v ./mysql/init:/docker-entrypoint-initdb.d \
  mysql




3.1.2 部署Redis数据库

powershell 复制代码
# 拉取redis镜像
docker pull redis

# 启动容器的时候,并为其设置密码
docker run -d --name myredis -p 6379:6379 redis --requirepass "123456"

3.1.1 部署Nginx(这里被天翼云坑了换的腾讯云运行nginx)

powershell 复制代码
0. docker pull nginx:1.17.10
[root@rcodunix9knh8vfc ~]# docker pull nginx:1.17.10

1.创建nginx容器
[root@VM-8-7-centos nginx]# docker run -d --name nginx -p 8880:80 nginx:1.17.10

2.创建挂在目录
mkdir -p /data/nginx/{conf,log,html}

3.把Nginx容器中的文件进行复制
nginx.conf复制到主机
docker cp nginx:/etc/nginx/nginx.conf /data/nginx/conf/nginx.conf

4.将conf.d文件夹复制到主机
docker cp nginx:/etc/nginx/conf.d /data/nginx/conf/conf.d

5.把html目录复制到主机
docker cp nginx:/usr/share/nginx/html /data/nginx/

6.停止刚刚创建的nginx容器
docker stop nginx

7.删除刚刚创建的容器
docker rm nginx

8.重新创建容器
docker run -d --name nginx -p 8880:80 \
-v /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /data/nginx/conf/conf.d:/etc/nginx/conf.d \
-v /data/nginx/log:/var/log/nginx \
-v /data/nginx/html:/usr/share/nginx/html \
--privileged=true nginx:1.17.10

注意:
上面/data/nginx/html是服务器的地址
/usr/share/nginx/html是容器中的地址


9. 进入nginx的docker容器中
[root@VM-8-7-centos html]# docker exec -it aed99f4c5a55  /bin/bash

10.把容器中nginx配置生效
[root@VM-8-7-centos html]# docker exec -it  aed99f4c5a55  nginx -s reload

天翼云的坑

验证挂载


3.2 腾讯云部署后端&前端&Nginx

3.2.1 部署前端

前端项目需要 npm install => npm install --registry=https://registry.npm.taobao.org

前段buildnpm run build:prod

会得到dist,然后将其打包,上传服务器到 /workspace(自己新建的文件夹),然后再解压。

powershell 复制代码
fanzhen@fanzhendembp-2 ruoyi-ui % unzip dist.zip -d ./dist


前期的conf文件

powershell 复制代码
server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html/dist/dist;
        index  index.html index.htm;
    }

    #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   /usr/share/nginx/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;
    #}
}
powershell 复制代码
使用此命令重新加载nginx文件
[root@VM-8-7-centos html]# docker exec -it  aed99f4c5a55  nginx -s reload


3.2.2 部署后端

需要改的地方

先clean后install

ruoyi-admin.jar移动到/root/workspace

DockerFile

powershell 复制代码
# 基础镜像
FROM  java:8
# author
MAINTAINER guanhc

EXPOSE 8081

# 挂载目录
VOLUME /root/workspace
# 创建目录
RUN mkdir -p /home/ruoyi
# 指定路径
WORKDIR /home/ruoyi
# 复制jar文件到路径
COPY ruoyi-admin.jar /home/ruoyi/ruoyi-admin.jar
# 启动认证服务
ENTRYPOINT ["java","-jar","ruoyi-admin.jar"]

查看日志

powershell 复制代码
[root@VM-8-7-centos workspace]# docker logs 6cdecb251e20


重启Nginx

nginx重新配置

powershell 复制代码
upstream ruoyi{
    server 101.42.49.137:8081 weight=10;
}

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html/dist/dist;
        index  index.html index.htm;
    }

     location /prod-api/{
                proxy_set_header Host $http_host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header REMOTE-HOST $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_pass http://ruoyi/;
        }

    #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   /usr/share/nginx/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;
    #}
}

别忘了 [root@VM-8-7-centos html]# docker exec -it aed99f4c5a55 nginx -s reload

最后跑起来了,当然可以部署多台后端服务器。

注意

docker阿里镜像申请https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors

参考

  1. https://blog.csdn.net/Pan_peter/article/details/128807946
相关推荐
UpUpUp……2 小时前
Linux--JsonCpp
linux·运维·服务器·c++·笔记·json
Clockwiseee3 小时前
文件上传总结
运维·服务器·学习·文件上传
liyi_hz20083 小时前
O2OA(翱途)开发平台系统安全-用户登录IP限制
运维·服务器·网络·o2oa开发
hi,编程哥3 小时前
Docker、ECS 与 K8s 网段冲突:解决跨服务通信中的路由问题
docker·容器·kubernetes
武汉格发Gofartlic3 小时前
FEKO许可证的安全与合规性
大数据·运维·安全
How_doyou_do3 小时前
项目全栈实战-基于智能体、工作流、API模块化Docker集成的创业分析平台
运维·docker·容器
阳光普照世界和平5 小时前
Jenkins:库博静态工具CI/CD 的卓越之选
运维·ci/cd·jenkins
愚戏师5 小时前
Linux复习笔记(三) 网络服务配置(web)
linux·运维·笔记
liudongyang1235 小时前
jenkins 启动报错
java·运维·jenkins
掘金-我是哪吒6 小时前
分布式微服务系统架构第126集:集群,数据库扩展,多节点分布,分库,分表,分片,分表,运维
运维·数据库·分布式·微服务·系统架构