docker下 安裝 apollo

官網(wǎng)下載sql ,創(chuàng)建ApolloConfigDB,ApolloPortalDB數(shù)據(jù)庫

https://github.com/ctripcorp/apollo/tree/master/scripts/sql

創(chuàng)建容器

docker run -d  --name apollo     -p 8090:8090     -p  8080:8080  -p 8070:8070   nobodyiam/apollo-quick-start:latest

起不起來, 修改demo.sh

下載demo.sh

 docker cp  apollo:/apollo-quick-start/demo.sh  . 
 

修改成對應(yīng)的數(shù)據(jù)源,密碼當(dāng)中不要有一些特殊的符號,比如&,坑很大

apollo_config_db_url=jdbc:mysql://10.8.0.5:3306/ApolloConfigDB?characterEncoding=utf8
apollo_config_db_username=root
apollo_config_db_password=

# apollo portal db info
apollo_portal_db_url=jdbc:mysql://10.8.0.5:3306/ApolloPortalDB?characterEncoding=utf8
apollo_portal_db_username=root
apollo_portal_db_password=

修改注冊的eureka的ip,否則會已docker的ip注冊

增加ip -Deureka.instance.ip-address=10.8.0.1


SERVER_JAVA_OPTS="$BASE_JAVA_OPTS -Dspring.profiles.active=github -Deureka.service.url=$eureka_service_url -Deureka.instance.ip-address=10.8.0.1"

啟動apollo

上傳demo.sh ,啟動

 docker cp demo.sh  apollo:/apollo-quick-start/
 docker restart apollo 

使用一些坑

將org.springframework.boot:spring-boot-devtools這樣的依賴,去掉,否則apollo一有改動,就重啟

一些有用的case

https://github.com/ctripcorp/apollo-use-cases

動態(tài)開始日志級別

在apolo 創(chuàng)建 logging.level=debug

java 客戶端

package com.cc.config;

import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfig;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener;

import java.util.Set;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.logging.LogLevel;
import org.springframework.boot.logging.LoggingSystem;
import org.springframework.stereotype.Service;

/**
 * Created by kl on 2018/6/25. Content :動態(tài)日志配置
 */
@Service
public class LoggerConfiguration {
    private static final Logger logger = LoggerFactory.getLogger(LoggerConfiguration.class);
    private static final String LOGGER_TAG = "logging.level";

    @Resource
    private LoggingSystem loggingSystem;

    @ApolloConfig
    private Config config;

    @ApolloConfigChangeListener
    private void onChange(ConfigChangeEvent changeEvent) {
        refreshLoggingLevels();
    }

    @PostConstruct
    private void refreshLoggingLevels() {
        Set<String> keyNames = config.getPropertyNames();
        for (String key : keyNames) {
            if (LOGGER_TAG.equalsIgnoreCase(key)) {
                String strLevel = config.getProperty(key, "info");
                LogLevel level = LogLevel.valueOf(strLevel.toUpperCase());
                loggingSystem.setLogLevel(key.replace(LOGGER_TAG, ""), level);
                logger.info("日志級別:{}->改為了:{}", key, strLevel);
            }
        }
    }

}


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容