手册

微服务Linux集群部署

1455
黄辉松
2021-03-31 18:50:00
分享链接

EIP7部署文档-集群部署

1.搭建eurekaServer

1.1打包

本次eurekaServer搭建采用的集群方式。分别在10.10.0.18410.10.0.185机器上部署。

eurekaServer下创建两个application-server1.ymlapplication-server2.yml文件。配置内容如下:

 

使用eclipse打包如下:打开Run->Run Configurations...

 

执行完命令后,jar包生成在项目目录下的target目录下。

1.2部署

将步骤一的jar分别上传至服务器(255.255.255.0255.255.255.1 此为虚拟ip)的/home/hotent/eurekaServer/目录下,无eurekaServer目录则自行创建。

同时在eurekaServer目录下创建一个用于启动服务的shell脚本文件:start.sh

并执行chmod +x start.sh赋予执行权限。

 

255.255.255.0机器的start.sh内容如下:

#!/bin/bash

nohup java -jar eurekaServer-1.0.0.jar --spring.profiles.active=server1  >eurekaServer.out 2>&1 &

255.255.255.1 机器的start.sh内容如下:

#!/bin/bash

nohup java -jar eurekaServer-1.0.0.jar --spring.profiles.active=server2  >eurekaServer.out 2>&1 &

 

eurekaServer目录下运行shell脚本命令:./start.sh 即可启动。

1.3检测

在内网电脑浏览器分别访问:http://255.255.255.0:8761/和http://255.255.255.1:8761/

出现以上页面则代表eurekaServer启动成功。

2.前端vue部署

前端vuemvuefvue应用,分别代表eip的管理端、应用端。

管理端前端的根路径:/web/manage

应用端前端的根路径:/web/front

2.1sso.js配置

sso.js作为前端请求后端的地址的集合,sso.js文件的位置在public目录下。

 

管理端sso

window.context = {

  manage: 'http://255.255.255.0/mvue', //管理端页面

  front: 'http://255.255.255.0/fvue', //前端页面

  mobile: 'http://255.255.255.0/mobilevue', //手机端页面

  form: 'http://255.255.255.0/form',

  portal: 'http://255.255.255.0/portal',

  bpmRunTime: 'http://255.255.255.0/bpm-runtime',

  bpmModel: 'http://255.255.255.0/bpm-model',

  uc: 'http://255.255.255.0/uc',

  mc: 'http://255.255.255.0/mc'

};

应用端sso

window.context = {

  manage: 'http://255.255.255.0/mvue', //管理端页面

  front: 'http://255.255.255.0/fvue', //前端页面

  mobile: 'http://255.255.255.0/mobilevue', //手机端页面

  form: 'http://255.255.255.0/form',

  portal: 'http://255.255.255.0/portal',

  bpmRunTime: 'http://255.255.255.0/bpm-runtime',

  bpmModel: 'http://255.255.255.0/bpm-model',

  uc: 'http://255.255.255.0/uc',

};

2.2vue打包

在应用的根路径下,执行npm run build命令进行打包。若无依赖则先执行npm install进行依赖下载。打包命令完成后,会在根路径下生成一个dist目录,该目录的内容就是即将要部署的前端包。

 

管理端和应用端的操作方式一样。

2.3部署

将步骤(2)打包好的dist上传至255.255.255.0服务器的/home/hotent/web目录下,并将管理端的dist目录更名为mvue,应用端更名为fvue

2.4配置nginx

nginx.conf的负载均衡配置如下:

http {

  upstream bpm-model {

    server 255.255.255.3:8087;

    server 255.255.255.4:8087;

    server 255.255.255.5:8087;

  }

  upstream bpm-runtime {

    server 255.255.255.3:8086;

    server 255.255.255.4:8086;

    server 255.255.255.5:8086;

  }

  upstream form {

    server 255.255.255.3:8082;

    server 255.255.255.4:8082;

    server 255.255.255.5:8082;

  }

  upstream mc {

    server 255.255.255.3:8085;

    server 255.255.255.4:8085;

    server 255.255.255.5:8085;

  }

  upstream portal {

    server 255.255.255.3:8084;

    server 255.255.255.4:8084;

    server 255.255.255.5:8084;

  }

  upstream uc {

    server 255.255.255.3:8088;

    server 255.255.255.4:8088;

    server 255.255.255.5:8088;

  }

  server {

    listen       80;

    server_name  localhost;

 

    location / {

      root   /home/hotent/web;

      index  index.html index.htm;

    } 

    location /fvue {

      root   /home/hotent/web;

      index  index.html;

      try_files $uri $uri/ /fvue/index.html;

    }

    location /mvue {

      root   /home/hotent/web;

      index  index.html;

      try_files $uri $uri/ /mvue/index.html;

    }

    location =/mvue {            

      rewrite ^(.*)$ http://255.255.255.0:80/mvue/;

    }

    location =/fvue {

      rewrite ^(.*)$ http://255.255.255.0:80/fvue/;

    }

    location /bpm-model {

      rewrite ^/bpm-model/(.*)$ /$1 break;

      proxy_pass http://bpm-model/;

    }  

    location /bpm-runtime {

      rewrite ^/bpm-runtime/(.*)$ /$1 break;

      proxy_pass http://bpm-runtime/;

    }

    location /form {

      rewrite ^/form/(.*)$ /$1 break;

      proxy_pass http://form/;

    }

    location /mc {

      rewrite ^/mc/(.*)$ /$1 break;

      proxy_pass http://mc/;

    }

    location /portal {

      rewrite ^/portal/(.*)$ /$1 break;

      proxy_pass http://portal/;

    }

    location /uc {

      rewrite ^/uc/(.*)$ /$1 break;

      proxy_pass http://uc/;

    }

  }

}

 

启动nginx即可完成前端的部署。


管理端:http://255.255.255.0/mvue/home

应用端:http://255.255.255.0/fvue/home

3.后端微服务部署

3.1maven打包

在每个微服务模块下的pom.xml文件放开下图的build标签,才能单独打包出每个微服务各自jar包。

 

eclipse菜单栏下:打开Run->Run Configurations...

 

等待命令运行完之后,在每个微服务模块目录下会生成一个target目录,微服务的jar就在target目录里面。

3.2jar上传至服务器

本文档以255.255.255.3服务器为例

jar包所在位置:模块目录下的target文件夹里。

将打包好的每个微服务jar上传至255.255.255.3服务器的/home/hotent/app/下各自的目录内(如下图)。没有对应目录则自行创建。

3.3外置配置文件

jar的配置文件采用:内外配置文件结合的方式,即jar内置配置文件+jar外置配置文件。

jar的同级目录下创建一个application-uat.yml文件,每个微服务都要,用作应用的外置配置文件。

该文件主要用于配置数据库、redisactivemqeureka信息。

下面以bpm-model微服务的application-uat.yml为例:

 

上图中绿色框的内容,每个微服务都不一样,其他的配置项保持不变即可。

配置区别如下:

 

spring.application.name

spring.datasource....url

server.port

bpm-model

bpm-model-eureka

255.255.255.0:3306/htbpm

8087

bpm-runtime

bpm-runtime-eureka

255.255.255.0:3306/htbpm

8086

form

form-eureka

255.255.255.0:3306/htform

8082

mc

mc-eureka

255.255.255.0:3306/htmc

8085

portal

portal-eureka

255.255.255.0:3306/htportal

8084

uc

uc-eureka

255.255.255.0:3306/htuc

8088


3.4创建启动脚本

每个微服务目录下都创建一个用于启动服务的shell脚本文件:start.sh

并执行chmod +x start.sh赋予执行权限。

不同微服务的start.sh文件内容如下:

 

start.sh文件内容

bpm-model

#!/bin/bash

nohup java -jar bpm-model.jar --spring.config.location=classpath:/config/application.yml,application-uat.yml >bpm-model.out 2>&1 &

bpm-runtime

#!/bin/bash

nohup java -jar bpm-runtime.jar --spring.config.location=classpath:/config/application.yml,application-uat.yml >bpm-runtime.out 2>&1 &

form

#!/bin/bash

nohup java -jar form.jar --spring.config.location=classpath:/config/application.yml,application-uat.yml >form.out 2>&1 &

mc

#!/bin/bash

nohup java -jar mc.jar --spring.config.location=classpath:/config/application.yml,application-uat.yml >mc.out 2>&1 &

portal

#!/bin/bash

nohup java -jar portal.jar --spring.config.location=classpath:/config/application.yml,application-uat.yml >portal.out 2>&1 &

uc

#!/bin/bash

nohup java -jar uc.jar --spring.config.location=classpath:/config/application.yml,application-uat.yml >uc.out 2>&1 &


3.5启动

在每个微服务目录下,执行 ./start.sh 命令即可启动该微服务。

3.6检测

方法一:在微服务目录下,(以bpm-model为例)执行tail -f bpm-model.out命令,可以实时查看微服务的运行日志。看到如下日志,即代表服务启动成功。

***********************

********应用已启动********

***********************

 

方法二:打开eurekaServer页面(http://255.255.255.0:8761/或http://255.255.255.1:8761/),可以查看具体机器具体的微服务情况。如下图所示:三台机器上的服务均正常启动。

 

 

至此,部署已经完成。

 

:如果需要集成cas单点登录,则继续下面的第4步骤。否则可以忽略。

4.cas单点登录集成

4.1数据库配置

配置文件在cas-ninestar项目的src/main/resources下的application.yml

数据库的url地址:uc微服务模块的数据库地址:如图红框所示,为需要修改的项。

 

4.2打成war

按照下图的指示,把cas项目打出war包。

 

生成的cas.war包在项目目录的target目录下。

4.3上传并运行

cas.var包上传服务器(以255.255.255.0为例)至tomcatwebapps目录下,并进入tomcatbin下执行./startup.sh启动tomcat

4.4检测

浏览器访问:http://255.255.255.0:8080/cas/login(如下图),输入账号密码成功登陆则说明cas运行成功。

 

4.5配置前端

修改前端的sso.js文件,如下(以255.255.255.0:8080为例):

/单点配置

window.ssoConfig = {

  mode: "cas",

  url: 'http://255.255.255.0:8080/cas',

  logout: 'http://255.255.255.0:8080/cas/logout'

}

 

应用端和管理端均要修改。

4.6配置后端

在每个微服务的外置配置文件application-uat.yml底下,添加如下配置信息:(注意yml文件的缩进写法)

system:

  saas:

    enable: false

sso:

  enable: true

  mode: cas

  cas:

    url: http://255.255.255.0:8080/cas

 

4.7重启服务

重新启动每一个微服务,即可。

4.8检测

清除浏览器缓存,正常访问管理端或者应用端的地址,将跳转至如下页面,并成功登录,则说明单点登录集成成功。

 

5.  openOffice安装

5.1 下载tar.gz

下载地址:http://www.openoffice.org/zh-cn/ (需要下载rpm格式的)

5.2 上传 tar.gz

将下载好的tar.gz包上传至/opt/openoffice/目录下,目录不存在则自行创建

5.3 解压tar.gz

/opt/openoffice/下执行命令:

tar -zxvf Apache_OpenOffice_4.1.7_Linux_x86-64_install-rpm_zh-CN.tar.gz

5.4 安装rpm文件

进入解压后的目录/opt/openoffice/zh-CN/RPMS/下,执行:rpm -ivh *.rpm

5.5 安装openoffice

进入到desktop-integration/opt/openoffice/zh-CN/RPMS/desktop-integration/)下执行:

rpm -ivh openoffice4.1.7-redhat-menus-4.1.7-9800.noarch.rpm

至此,已安装完成。

5.6 检测

安装成功后会在/opt下出现一个openoffice4文件。

5.7 项目配置

portal微服务模块下的application-uat.yml里添加openoffice的配置项:

file:

  file.dir: /home/hotent/conver/

重启portal微服务,即可启动openoffice

发表评论
评论通过审核后显示。