zoukankan      html  css  js  c++  java
  • apollo基本搭建

    1.数据库的准备

    # 下载源码  1.7.2 分支
    git clone --branch 1.7.2 https://hub.fastgit.org/ctripcorp/apollo.git
    # 创建 apolloportaldb
    sql文件地址: https://hub.fastgit.org/ctripcorp/apollo/tree/1.7.2/scripts/sql/apolloportaldb.sql
    # 创建 apolloconfigdb
    sql文件地址: https://hub.fastgit.org/ctripcorp/apollo/tree/1.7.2/scripts/sql/apolloconfigdb.sql
    说明:
        Apollo服务端共需要两个数据库:ApolloPortalDB和ApolloConfigDB,ApolloPortalDB只需要在生产环境部署一个即可,而ApolloConfigDB需要在每个环境部署一套,如dev、test、和pro分别部署3套ApolloConfigDB,sql文件(/root/apollo/scripts/sql)。
    2、修改自定义环境
    	# apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/Env.java
        
    	修改com.ctrip.framework.apollo.core.enums.Env类,在其中加入TEST枚举:
        	public enum Env{
                LOCAL, DEV, TEST, BETA, FWS, FAT, UAT, LPT, PRO, TOOLS, UNKNOWN;
                ...
                }
            
         # apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/EnvUtils.java
        
         修改com.ctrip.framework.apollo.core.enums.EnvUtils类,在其中加入TEST枚举的转换逻辑:
        public final class EnvUtils {
            public static Env transformEnv(String envName) {
             if (StringUtils.isBlank(envName)) {
               return Env.UNKNOWN;
             }
             switch (envName.trim().toUpperCase()) {
               ...
               case "TEST":
                 return Env.TEST;
               ...
               default:
                 return Env.UNKNOWN;
             }
            }
            }
    

    2.配置文件修改

    1)修改build.sh配置文件
    # 修改连接数据库信息
    # apollo config db info
    apollo_config_db_url=jdbc:mysql://10.2.1.15:3306/apolloconfigdb?characterEncoding=utf8
    apollo_config_db_username=apollo
    apollo_config_db_password=123
    
    # apollo portal db info
    apollo_portal_db_url=jdbc:mysql://10.2.1.15:3306/apolloportaldb?characterEncoding=utf8
    apollo_portal_db_username=apollo
    apollo_portal_db_password=123
    2) 修改三个服务配置文件
    [root@localhost ~]# cat apollo/apollo-adminservice/src/main/resources/application.yml
    spring:
      application:
        name: apollo-adminservice
      profiles:
        active: ${apollo_profile}
      cloud:
        inetutils:
          ignoredInterfaces:
            - docker0
            - eth1
    ctrip:
      appid: 100003172
    server:
      port: 8090
    logging:
      file:
        name: /opt/logs/100003172/apollo-adminservice.log
    eureka:
      instance:
        ip-address: 10.2.1.15 # 服务器ip 
    ————————
    [root@localhost ~]# cat apollo/apollo-adminservice/src/main/resources/application.yml
    spring:
      application:
        name: apollo-adminservice
      profiles:
        active: ${apollo_profile}
      cloud:
        inetutils:
          ignoredInterfaces:
            - docker0
            - eth1
    ctrip:
      appid: 100003172
    server:
      port: 8090
    logging:
      file:
        name: /opt/logs/100003172/apollo-adminservice.log
    eureka:
      instance:
        ip-address: 10.2.1.15
    [root@localhost ~]# cat apollo/apollo-co/src/main/resources/application.yml
    apollo-common/        apollo-configservice/ apollo-core/          
    [root@localhost ~]# cat apollo/apollo-co/src/main/resources/application.yml
    apollo-common/        apollo-configservice/ apollo-core/          
    [root@localhost ~]# cat apollo/apollo-configservice/src/main/resources/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
    ——————
    [root@localhost ~]# cat apollo/apollo-portal/src/main/resources/application.yml
    spring:
      application:
        name: apollo-portal
      profiles:
        active: ${apollo_profile}
      jpa:
        properties:
          hibernate:
            query:
              plan_cache_max_size: 192 # limit query plan cache max size
    
    server:
      port: 8070
      compression:
        enabled: true
      tomcat:
        use-relative-redirects: true
    
    logging:
      file: /opt/logs/100003173/apollo-portal.log
    
    management:
      health:
        status:
          order: DOWN, OUT_OF_SERVICE, UNKNOWN, UP
    

    3.制作镜像

    1) 代码打包(依赖java、mvn环境,需要提前安装)
    # 以上配置文件修改后,直接执行build.sh文件即可
    ./scripts/build.sh
    2) 构建镜像
    代码打包成功后,可以使用mvn进行镜像制作: 
        cd apollo
        mvn docker:build -pl apollo-configservice,apollo-adminservice,apollo-portal
    也可以自定义构建(因为端口已经修改,所以采用自定义):
        官方提供的Dockerfile文件位置: apollo/apollo-${service}/src/main/docker/
        这里以apollo-adminservice为例(需要修改Dockerfile中暴露的端口号)
        	cd apollo/apollo-adminservice/target
            cp apollo/apollo-adminservice/src/main/docker/Dockerfile .
            docker build -t  .
    3) 镜像制作后,上传到对应的镜像仓库,后面在服务器部署时,直接pull对应的镜像地址即可
    

    4.运行

    #  apollo-configservice、apollo-adminservice
    [root@localhost ~]# docker run -p 18080:8080 -d -v /store/logs:/opt/logs --name apollo-configservice apolloconfig/apollo-configservice
    [root@localhost ~]# docker run -p 18090:8090 -d -v /store/logs:/opt/logs --name apollo-adminservice apolloconfig/apollo-adminservice
    # apollo-portal
    [root@localhost ~]# docker run -p 18070:8070 -d -v /store/logs:/opt/logs --name apollo-portal apolloconfig/apollo-portal
  • 相关阅读:
    浪潮之巅阅读笔记
    人月神话阅读笔记3
    学习报告
    人月神话阅读笔记2
    学习报告
    第十一周学习总结
    软件杯项目——手写体识别
    第十周学习进度
    第九周学习进度
    《软件架构师的12项修炼》阅读笔记
  • 原文地址:https://www.cnblogs.com/Applogize/p/15214281.html
Copyright © 2011-2022 走看看