apollo部署心得

1.github下载apollo源码 : https://github.com/ctripcorp/apollo.git

2.具体的使用方法详见wiki : https://github.com/ctripcorp/apollo/wiki/Apollo%E5%BC%80%E5%8F%91%E6%8C%87%E5%8D%97

3.本地打包apollo源码:为了避免打包出错,最好是删除test里面的方法,其他的未尝试过, apollo源码里面包含主要的三个部分

  • apolloconfig-service,作为eureka注册服务中心meta-service,apolloadmin-service和apolloconfig-service都要注册到该服务,
  • apolloconfig-service和apolloadmin-service 共用数据库
  • apolloconfig-service修改如下配置文件: 
    • (bootstrap.yml)
      •   包含eureka注册服务信息
        eureka:
          instance:
            hostname: ${hostname:localhost}
            preferIpAddress: true
            status-page-url-path: /info
            health-check-url-path: /health
          server:
            peerEurekaNodesUpdateIntervalMs: 60000
            enableSelfPreservation: false
          client:
            serviceUrl:#(meta-service地址,和configservice一起部署)
              defaultZone: http://10.108.135.88:8080/eureka/        
            healthcheck:
              enabled: true
            eurekaServiceUrlPollIntervalSeconds: 60
        
        
        management:
          health:
            status:
              order: DOWN, OUT_OF_SERVICE, UNKNOWN, UP
    • (application.yml) 
      •  包含应用的一些端口信息,名字信息
        spring:
          application:
            name: apollo-configservice
          profiles:
            active: ${apollo_profile}
        ctrip:
          appid: 100003171
        server:
          port: 8080
        logging:
          file: /opt/logs/100003171/apollo-configservice.log
  • apolloadmin-service修改如下文件(bootstrap.yml ):
    • (bootstrap.yml)
      •  包含eureka注册信息 
        eureka:
          instance:
            hostname: ${hostname:localhost}
            preferIpAddress: true
            status-page-url-path: /info
            health-check-url-path: /health
          client:
            serviceUrl:
              defaultZone: http://10.108.135.88:8080/eureka/
            healthcheck:
              enabled: true
            eurekaServiceUrlPollIntervalSeconds: 60
        management:
          health:
            status:
              order: DOWN, OUT_OF_SERVICE, UNKNOWN, UP 
    • (application.yml)
      •  包含应用本身的一些信息
        spring:
          application:
            name: apollo-adminservice
          profiles:
            active: ${apollo_profile}
        
        ctrip:
          appid: 100003172
          
        server:
          port: 8090
          
        logging:
          file: /opt/logs/100003172/apollo-adminservice.log
  •  apolloportal-service修改如下信息
    • apollo-env.properties  (填写各环境下的meta-service地址) 
      dev.meta=http://10.108.135.88:8080  (填写dev环境下的meta-service地址)
      fat.meta=http://fat-url
      uat.meta=${uat_meta}
      lpt.meta=${lpt_meta}
      pro.meta=${pro_meta}
    •  portal不需要注册eureka信息

  •  准备好数据库环境,源码里面自带数据库脚本,跑入数据库即可
  •  修改build.bat文件
    • @echo off
      
      rem apollo config db info
      set apollo_config_db_url="jdbc:mysql://10.xx.xx.xx:3306/ApolloConfigDB?characterEncoding=utf8" (数据库地址)
      set apollo_config_db_username="username"
      set apollo_config_db_password="password"
      
      rem apollo portal db info
      set apollo_portal_db_url="jdbc:mysql://10.xx.xx.xx:3306/ApolloPortalDB?characterEncoding=utf8"
      set apollo_portal_db_username="username"
      set apollo_portal_db_password="password"
      
      rem meta server url, different environments should have different meta server addresses
      set dev_meta="http://10.108.135.xx:8080"
      set fat_meta="http://10.108.135.xx:8080"
      set uat_meta="http://10.108.135.xx:8080"
      set pro_meta="http://10.108.135.xx:8080"
      
      set META_SERVERS_OPTS=-Ddev_meta=%dev_meta% -Dfat_meta=%fat_meta% -Duat_meta=%uat_meta% -Dpro_meta=%pro_meta%
      
      rem =============== Please do not modify the following content =============== 
      rem go to script directory
      cd "%~dp0"
      
      cd ..
      
      rem package config-service and admin-service
      echo "==== starting to build config-service and admin-service ===="
      
      call mvn clean package -DskipTests -pl apollo-configservice,apollo-adminservice -am -Dapollo_profile=github -Dspring_datasource_url=%apollo_config_db_url% -Dspring_datasource_username=%apollo_config_db_username% -Dspring_datasource_password=%apollo_config_db_password%
      
      echo "==== building config-service and admin-service finished ===="
      
      echo "==== starting to build portal ===="
      
      call mvn clean package -DskipTests -pl apollo-portal -am -Dapollo_profile=github,auth -Dspring_datasource_url=%apollo_portal_db_url% -Dspring_datasource_username=%apollo_portal_db_username% -Dspring_datasource_password=%apollo_portal_db_password% %META_SERVERS_OPTS%
      
      echo "==== building portal finished ===="
      
      pause

       配置好上述信息后,即可执行脚本,apolloconfig-service和apolloadmin-service每个环境都要部署一套,且需要注意的是ApolloPortalDB只需要在生产环境部署一个即可,而ApolloConfigDB需要在每个环境部署一套,如fat、uat和pro分别部署3套ApolloConfigDB。

    • 打包完成后获取config,admin,portal下面的github.zip包,上传置相应的环境,解压以后按照config-admin-portal的顺序依次执行config目录下的脚本即可。

以上,后续有时间继续更新

posted @ 2019-01-18 16:39  南风顾  阅读(1414)  评论(0编辑  收藏  举报