zoukankan      html  css  js  c++  java
  • docker-compose 发布 spring cloud

    部署流程

    打开项目总pom.xml文件

    找到<dockerHost>节点,把IP地址修改成要上传镜像的IP地址

    如 <dockerHost>http://192.168.1.250:2375</dockerHost>

    如果要指定上传的签名文件,修改签名文件路径(所有证书在doc/deploy/cert/目录下)

    <dockerCertPath>d:kintechcerts</dockerCertPath>

    找到<baseImage>这里修改成服务器上的基础镜像的名称后面跟TAG号

    如<baseImage>mycentoscn:7.5.1804</baseImage>

    修改配置中心数据(修改mysql数据库和Redis链接)

    修改springColud.config项目下/src/man/resurces/config/config-prod.yml文件

    Datasource数据的地址

    Redis的地址

    kintechWebAPIURL内部访问的IP地址(也如果在同一台服务器直接用服务器内部IP也可以)

    recipients 系统发邮件的邮箱地址

    在本机配置环境变量(如果已配置,不要再重新配置)

    新建系统变量名MAVEN (请根据实际maven的安装目录)

    值C:Program FilesJetBrainsIntelliJ IDEA 2017.1.3pluginsmavenlibmaven3in

    新建系统变量JAVA_HOME  (请根据实际java的安装目录,只要到jdk目录不要到bin目录)

    值C:Program FilesJavajdk1.8.0_60

    再在系统变量Path变量后面添加%JAVA_HOME%;%MAVEN%

    1停止服务(如非首次部署)

      登录远程服务器,进入docker目录

    cd docker

    (新增)备份所有镜像为文件(运行shell文件,会删除老的镜像备份,再备份所有现在正在使用的镜像为tar文件),命令如下

    ./kpsimagesbak.sh

    停止服务

    docker-compose stop

    确定服务是否停止

    移除所有容器

        docker rm -f  $(docker ps -aq)

        (查看所有容器docker ps -a)

    移除所有镜象

    docker rmi -f  $(docker images -aq)

    (删除一个镜像docker rmi -f  IMAGE ID)

    查看镜象是否移除

     docker images

     导入父镜象

      docker load -i mycentoscn.tar

    docker images

    
    

    2 生成并上传镜像

    打开项目doc/deploy目录,在资源管理器打开

    重命名deploy.batsh为deploy.bat 然后双击执行 按y开始

    @echo off
    echo 是否开始编译并上传镜像?
    echo [y]开始编译并上传镜像  [u]开始编译并自动上传所有镜像  [n]退出
    set /p key=  
    if /i "%key%"=="n" exit
      
    :next
    setlocal
    set "deploy_dir=%cd%"
    echo "%deploy_dir%"
    cd ..
    cd ..
    set "parent_dir=%cd%"
    echo "%parent_dir%"
    cd %deploy_dir%
    
    echo "maven compile starting"
    call mvn  -f %parent_dir% clean install
    echo "maven compile completed"
    
    if /i "%key%"=="u" goto all
    
    echo 是否开始上传镜像?
    echo [a]上传所有 [b]上传除registry,config  [c]上传除registry,config,zuul [1]上传registry [2]上传config [3]上传zuul [4]上传webUI [5]上传APICommon [6]上传APIPO [7]上传APISYS [8]上传APIWMS [9]上传APIEQ  [10]上传APIScan  [11]上传webAPIScreen
    
    set /p n=  
    if /i "%n%"=="a" goto all
    if /i "%n%"=="b" goto b
    if /i "%n%"=="c" goto c
    if /i "%n%"=="1" goto registry
    if /i "%n%"=="2" goto config
    if /i "%n%"=="3" goto zuul
    if /i "%n%"=="4" goto webUI
    if /i "%n%"=="5" goto common
    if /i "%n%"=="6" goto po
    if /i "%n%"=="7" goto sys
    if /i "%n%"=="8" goto wms
    if /i "%n%"=="9" goto eq
    if /i "%n%"=="10" goto scan
    if /i "%n%"=="11" goto screen
    
    
    
    :registry
    start /MIN  build.bat  %parent_dir%/springCloud.registry
    goto end
    
    :config
    start /MIN  build.bat  %parent_dir%/springCloud.config
    goto end
    
    :zuul
    start /MIN  build.bat  %parent_dir%/springCloud.zuul
    goto end
    
    
    :webUI
    start /MIN  build.bat  %parent_dir%/kps.webUI
    goto end
    
    :common
    start /MIN  build.bat  %parent_dir%/kps.webAPICommon
    goto end
    
    :po
    start /MIN  build.bat  %parent_dir%/kps.webAPIPO
    goto end
    
    :sys
    start /MIN  build.bat  %parent_dir%/kps.webAPISYS
    goto end
    
    :wms
    start /MIN  build.bat  %parent_dir%/kps.webAPIWMS
    goto end
    
    :eq
    start /MIN  build.bat  %parent_dir%/kps.webAPIEQ
    goto end
    
    :scan
    start /MIN  build.bat  %parent_dir%/kps.appAPIScan
    goto end
    :screen
    start /MIN  build.bat  %parent_dir%/kps.webAPIScreen
    goto end
    :all
    start /MIN  build.bat  %parent_dir%/springCloud.registry
    start /MIN  build.bat  %parent_dir%/springCloud.config
    start /MIN  build.bat  %parent_dir%/springCloud.zuul
    start /MIN  build.bat  %parent_dir%/kps.webUI
    start /MIN  build.bat  %parent_dir%/kps.webAPICommon
    start /MIN  build.bat  %parent_dir%/kps.webAPIPO
    start /MIN  build.bat  %parent_dir%/kps.webAPISYS
    start /MIN  build.bat  %parent_dir%/kps.webAPIWMS
    start /MIN  build.bat  %parent_dir%/kps.webAPIEQ
    start /MIN  build.bat  %parent_dir%/kps.appAPIScan
    start /MIN  build.bat  %parent_dir%/kps.webAPIScreen
    goto end
    
    
    :b
    start /MIN  build.bat  %parent_dir%/springCloud.zuul
    start /MIN  build.bat  %parent_dir%/kps.webUI
    start /MIN  build.bat  %parent_dir%/kps.webAPICommon
    start /MIN  build.bat  %parent_dir%/kps.webAPIPO
    start /MIN  build.bat  %parent_dir%/kps.webAPISYS
    start /MIN  build.bat  %parent_dir%/kps.webAPIWMS
    start /MIN  build.bat  %parent_dir%/kps.webAPIEQ
    start /MIN  build.bat  %parent_dir%/kps.appAPIScan
    start /MIN  build.bat  %parent_dir%/kps.webAPIScreen
    goto end
    
    
    :c
    start  /MIN  build.bat  %parent_dir%/kps.webUI
    start /MIN  build.bat   %parent_dir%/kps.webAPICommon
    start /MIN  build.bat  %parent_dir%/kps.webAPIPO
    start /MIN  build.bat  %parent_dir%/kps.webAPISYS
    start /MIN  build.bat   %parent_dir%/kps.webAPIWMS
    start /MIN  build.bat  %parent_dir%/kps.webAPIEQ
    start /MIN  build.bat  %parent_dir%/kps.appAPIScan
    start /MIN  build.bat  %parent_dir%/kps.webAPIScreen
    goto end
    
    :end
    echo Uploading docker image file, Press any key to exit!
    pause>nul
    exit

    如果有报错(上传镜像时) Failed to execute goal com.spotify:docker-maven-plugin:0.4.13:build (default-cli) on project docker: Exception caught: An HTTPS URI for DOCKER_HOST must be provided to use Docker client certificates

    ---------报错解决开始------------

    请参考这里:https://blog.csdn.net/u012930316/article/details/82997664

    在服务器的/root/docker/下生成证书(所有要输入密码key的地方都全填123456)

    openssl genrsa -aes256 -out ca-key.pem 4096  (输入123456)

    openssl req -new -x509 -days 3650 -key ca-key.pem -sha256 -out ca.pem  (输入123456,其他全回车为空)

    openssl genrsa -out server-key.pem 4096

    openssl req -sha256 -new -key server-key.pem -out server.csr  (全回车为空)

    openssl x509 -req -days 3650 -sha256 -in server.csr -CA ca.pem -CAkey ca-key.pem -CAcreateserial -out server-cert.pem         (输入123456)

    openssl genrsa -out key.pem 4096

    openssl req -new -key key.pem -out client.csr    (全为空,直接回车)

    openssl x509 -req -days 3650 -sha256 -in client.csr -CA ca.pem -CAkey ca-key.pem -CAcreateserial -out cert.pem             (输入123456)

    rm -v client.csr server.csr   (按y,y)

    chmod -v 0400 ca-key.pem key.pem server-key.pem

    chmod -v 0444 ca.pem server-cert.pem cert.pem

    修改文件  /lib/systemd/system/docker.service

    在-H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock 这一行后添加

    --tlsverify --tlscacert=/root/docker/ca.pem --tlscert=/root/docker/server-cert.pem --tlskey=/root/docker/server-key.pem

    再在服务器上运行

    systemctl daemon-reload

    systemctl restart docker(重启)

    修改hppt为https   <dockerHost>https://192.168.1.250:2375</dockerHost>

    把/root/docker/目录下的征生成的所有证书文件拷贝到部署的本地机器上,
    然后修改pom.xml文件,configuration中添加dockerCertPath节点,如下
    <dockerHost>${dockerHost}</dockerHost> 这里要用https
    
    <dockerCertPath>e:kintechcerts</dockerCertPath>
    
    
    

    -------报错解决结束----------------

    问题解决以后重新执行以上操作(运行deploy.bat)

    (上传镜像如果10个镜像一起上传预计需要15分钟,视网络情况而定)

    3 修改webui项目(单独上传helka平台)

      修改kps.webUI/src/man/resources/application.ym 三个地方名称,端口,ID

    修改webui项目下pom.xml 

    4 CMD进入webui根目录,执行maven命令(也可单独发布一个站点的时候使用这个命令)

    mvn clean package docker:build

    5 Xshell登录远程服务器,查看镜象是否已上传

    docker images

    6 运行

    运行所有镜像:进入docker目录运行docker-compose up -d(docker附加工具,用于编排服务顺序) (启动所有镜像可能要一段时间,3-5分钟左右,可以打开9088网页查看)

    (只运行一个镜像:docker-compose up -d  registry(镜像名称))

    如果运行报错:ERROR: for registry  Cannot start service registry: driver failed programming external connectivity on endpoint registry (5975285ae1dde916bfbbb3a3ed4b4327255004817de01cc29319719787316ef4):  (iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 9088 -j DNAT --to-destination 172.18.0.2:9088 ! -i br-0caf7a6ba8bc: iptables: No chain/target/match by that name.

    请参考:https://blog.csdn.net/tengdazhang770960436/article/details/77963182

    =====解决办法 命令开始=====

    pkill docker

    iptables -t nat -F

    ifconfig docker0 down

    brctl delbr docker0

    docker -d

    service docker restart

    再重新运行

    docker-compose up -d

    =====解决办法 命令结束=====

    7 查看运行状态:

    docker-compose ps

    8 查看单个服务正在启动情况docker-compose logs -f  --tail 500 kps

    使用命令: docker-compose logs -f  --tail 500 registry

    查看注册中心是否启动,显示如下说明注册中心启动成功

    9 在浏览器中查看

    http://192.168.1.250:9088/

    11 还原修改

       还原deploy.bat修改

       还原webui修改

      

    12 启动缓慢请重启机器(主机)

          重启虚拟机(  shutdown -r now  )

  • 相关阅读:
    nput keyup 500ms 延时输入 事件处理
    browser-sync默认地址如何转成127.0.0.1
    overflow:scroll-css知识备忘
    圆角的css样式
    支付宝开发
    C#代码与javaScript函数的相互调用
    高性能web开发 如何加载JS,JS应该放在什么位置?
    Makefile自动生成头文件依赖
    一步步教你如何写Makefile
    (一):U-BOOT启动分析--概述
  • 原文地址:https://www.cnblogs.com/hanjun0612/p/14781750.html
Copyright © 2011-2022 走看看