日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Apollo 分布式配置中心 搭建篇

發布時間:2024/9/27 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Apollo 分布式配置中心 搭建篇 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章目錄

          • 一、介紹
            • 1. 痛點
            • 2. 為什么選擇Apollo
          • 二、快速開始
            • 2.1. 安裝mysql
            • 2.2. 下載腳本
            • 2.3. 初始化腳本
          • 三、服務端配置
            • 3.1. 下載安裝包
            • 3.2. 創建目錄
            • 3.3. 解壓
            • 3.4. 配置
            • 3.5. 啟動
            • 3.6. 防火墻策略
            • 3.6. 效果驗證
          • 四、測試
            • 4.1. 引入依賴
            • 4.2. 配置
            • 4.3. 測試類
            • 4.4. 啟動項目
            • 4.5. 效果圖

一、介紹

Apollo(阿波羅)是攜程框架部門研發的分布式配置中心,能夠集中化管理應用不同環境、不同集群的配置,配置修改后能夠實時推送到應用端,并且具備規范的權限、流程治理等特性,適用于微服務配置管理場景。
– 摘自Apollo官網

1. 痛點

修改配置后,需要重啟項目
大量重復的配置,不便于管理

2. 為什么選擇Apollo

Apollo VS Spring Cloud Config
Spring Cloud Config 依賴于GitHub,所有配置都是寫在文件中,然后通過提交GitHub上來生效的,不同的環境用不用的文件區分
Apollo VS 阿里云應用配置管理ACM

依賴于阿里云,不便于后續遷移
阿里云已經放棄了該項目,不再維護

二、快速開始

這里安裝mysql需要提前安裝docker環境
docker yum 安裝
https://blog.csdn.net/weixin_40816738/article/details/121595991

2.1. 安裝mysql

docker mysql:8.0.27

2.2. 下載腳本

鏈接:https://github.com/apolloconfig/apollo/tree/master/scripts/sql

2.3. 初始化腳本

直接運行腳本,不需要提前創建數據庫



初始化后,就會有2個數據庫

三、服務端配置
3.1. 下載安裝包

下載鏈接:https://github.com/ctripcorp/apollo/releases

wget https://github.com/apolloconfig/apollo/releases/download/v1.9.2/apollo-adminservice-1.9.2-github.zipwget https://github.com/apolloconfig/apollo/releases/download/v1.9.2/apollo-configservice-1.9.2-github.zipwget https://github.com/apolloconfig/apollo/releases/download/v1.9.2/apollo-portal-1.9.2-github.zip
3.2. 創建目錄
mkdir apollo-adminservice-1.9.2 mkdir apollo-configservice-1.9.2 mkdir apollo-portal-1.9.2
3.3. 解壓
unzip apollo-adminservice-1.9.2-github.zip unzip apollo-configservice-1.9.2-github.zip unzip apollo-portal-1.9.2-github.zip
3.4. 配置
  • apollo-adminservice配置
cd apollo-adminservice-1.9.2/config/ vim application-github.properties

這里需要修改數據的連接地址、用戶名、密碼

  • apollo-configservice配置
cd apollo-adminservice-1.9.2/config application-github.properties

這里需要修改數據的連接地址、用戶名、密碼

  • apollo-portal配置
cd apollo/apollo-portal-1.9.2/config vim application-github.properties

這里需要修改數據的連接地址、用戶名、密碼

vim apollo-env.properties

將其他環境都注釋掉,打開第一個和第二個即可

3.5. 啟動
  • apollo-configservice啟動
cd apollo/apollo-configservice-1.9.2/script ./startup.sh

  • apollo-adminservice啟動
cd apollo/apollo-adminservice-1.9.2/script ./startup.sh

  • apollo-portal啟動
cd apollo/apollo-portal-1.9.2/script ./startup.sh


如無意外,至此,adminservice、configservice、portal都起來了

3.6. 防火墻策略
firewall-cmd --zone=public --add-port=3306/tcp --permanent firewall-cmd --zone=public --add-port=8080/tcp --permanent firewall-cmd --zone=public --add-port=8070/tcp --permanent firewall-cmd --reload systemctl status firewalld
3.6. 效果驗證

http://192.168.159.139:8080/

http://192.168.159.139:8070/signin
初始賬號密碼是:apollo/admin

四、測試
4.1. 引入依賴
<dependency><groupId>com.ctrip.framework.apollo</groupId><artifactId>apollo-client</artifactId><version>1.5.0</version></dependency>
4.2. 配置

application.properties

server.port=9000# 配置Appid app.id=hello# 配置 Apollo Meta Server apollo.meta=http://192.168.159.139:8080/# 配置本地緩存路徑 apollo.cacheDir=C:/Users/gblfy/Desktop/apollo/data# 配置Environment env=DEVapollo.bootstrap.enabled=true
4.3. 測試類
package com.gblfy.apolloclient.controller;import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;@RestController @RequestMapping("/hello") public class HelloController {@Value("${my.name}")private String name;@GetMapping("/index")public String getName() {return name;} }
4.4. 啟動項目
4.5. 效果圖

http://localhost:9000/hello/index

總結

以上是生活随笔為你收集整理的Apollo 分布式配置中心 搭建篇的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。