素材巴巴 > 程序开发 >

Apollo-1.开发部署-linux

程序开发 2023-09-14 20:45:41

一.官方文档

https://www.apolloconfig.com/#/zh/deployment/quick-start-docker

二.环境准备

  1.MySql 5.6.51.单独服务器192.168.2.13

https://downloads.mysql.com/archives/installer/

  2.JDK 1.8.X

https://www.oracle.com/java/technologies/downloads/

三.Apollo部署

  1.下载1.8 安装包

https://github.com/apolloconfig/apollo/releases/tag/v1.8.0

  2.下载后的文件

  3.解压后的文件目录

  4.生成数据库

  这个脚本我是1.8的。官网上最新的总出问题。但1.8的官网又没找到,大家对mysql熟悉的可以用最新的试试,生成的过程就不讲,网上一堆,大概是选择数据库->运行Sql文件

  5.修改配置

    1) 服务端口修改

        分别修改三个服务下的启动端口号配置文件:/scripts/startup.sh

    2) 数据库配置修改

        分别修改三个服务下的数据连接配置文件:/config/application-github.properties

# DataSource
 spring.datasource.url = jdbc:mysql://192.168.2.13:3306/ApolloConfigDB?characterEncoding=utf8&serverTimezone=UTC
 spring.datasource.username = root
 spring.datasource.password = mysql

    3) Apollo的meta配置

        修改apollo-portal服务的下的meta配置:apollo-portal/config/apollo-env.properties

local.meta=http://localhost:8080
 dev.meta=http://192.168.3.14:8080
 fat.meta=http://fill-in-fat-meta-server:8080
 uat.meta=http://fill-in-uat-meta-server:8080
 lpt.meta=${lpt_meta}
 pro.meta=http://fill-in-pro-meta-server:8080

   6.修改后的文件上传到 /usr/local/apollo

   7.创建三个bat文件,修改权限,启动,关闭

   8.修改权限bat文件,chmod777.bat

#!/bin/bash
chmod 777 /usr/local/apollo/apollo-configservice/scripts/shutdown.sh
chmod 777 /usr/local/apollo/apollo-configservice/scripts/startup.sh
chmod 777 /usr/local/apollo/apollo-adminservice/scripts/shutdown.sh
chmod 777 /usr/local/apollo/apollo-adminservice/scripts/startup.sh
chmod 777 /usr/local/apollo/apollo-portal/scripts/shutdown.sh
chmod 777 /usr/local/apollo/apollo-portal/scripts/startup.sh

  9.启动服务bat文件 startup.sh

#!/bin/bash
/usr/local/apollo/apollo-configservice/scripts/startup.sh
/usr/local/apollo/apollo-adminservice/scripts/startup.sh
/usr/local/apollo/apollo-portal/scripts/startup.sh

 10.关闭服务bat文件 shutdown.sh

#!/bin/bash
/usr/local/apollo/apollo-configservice/scripts/shutdown.sh
/usr/local/apollo/apollo-adminservice/scripts/shutdown.sh
/usr/local/apollo/apollo-portal/scripts/shutdown.sh

 11.分布执行 ./startup.sh,  ./shutdown.sh

  12.此时查看端口是否成功

ps -ef | grep 8070

  13.访问 192.168.3.14:8070

四.net core继承

  1.安装Com.Ctrip.Framework.Apollo.Configuration

  2.appsettings.json文件添加配置

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*",
  "apollo": {
    "AppId": "SampleApp", //AppId
    "MetaServer": "http://192.168.3.14:8080" // Eureka地址
  }
}

  3.代码继承

 .ConfigureWebHostDefaults(webBuilder =>
 {webBuilder.ConfigureAppConfiguration((context,builder)=> {IConfigurationSection configuration = builder.Build().GetSection("Apollo");builder.AddApollo(configuration).AddDefault(); });webBuilder.UseStartup();
 });

  4.应用

public class TestController : ControllerBase
 {private readonly IConfiguration configuration;public TestController(IConfiguration configuration){this.configuration = configuration;}public IActionResult Get(){IConfigurationSection section = this.configuration.GetSection("timeout");return Ok(section.Key + ":" + section.Value);}
 }

  5.这是最简单的应用,之后还有灰度发布,同步,集群,测试环境,生产环境


标签:

上一篇: 好用的前端下载插件 download.js 下一篇:
素材巴巴 Copyright © 2013-2021 http://www.sucaibaba.com/. Some Rights Reserved. 备案号:备案中。