0%

配置

在 resources 目录下 (application.yml 同目录)创建 banner.txt 文件, springboot 启动时会自动加载这个文件替换原有的 spring boot banner.

生成banner

其他配置

  • banner.txt 内配置
${AnsiColor.BRIGHT_RED}: 设置控制台中输出内容的颜色
${application.version}: 用来获取MANIFEST.MF文件中的版本号
${application.formatted-version}: 格式化后的${application.version}版本信息
${spring-boot.version}: Spring Boot的版本号
${spring-boot.formatted-version}: 格式化后的${spring-boot.version}版本信息
  • application.yml 配置
spring:
  banner:
    charset: UTF-8
    location: classpath:banner.txt
    image:
      location: classpath:banner.gif
      width: 76
      height:
      margin: 2
      invert: false
  • 关闭 banner
@SpringBootApplication
public class SpringbootBannerApplication {

    public static void main(String[] args) {
        SpringApplication springApplication = new SpringApplication(SpringbootBannerApplication.class);
        //Banner.Mode.OFF 关闭
        springApplication.setBannerMode(Banner.Mode.OFF);
        springApplication.run(args);
    }
}

内网穿透工具frp

通过在公网服务器部署 frp 服务端( frps ),内网部署 frp 客户端( frpc ),实现通过公网访问内网的服务.

frp目录说明

├── frpc //客户端
├── frpc_full.ini
├── frpc.ini//客户端配置
├── frps//服务端
├── frps_full.ini
├── frps.ini//服务端配置
└── LICENSE

配置

  • frps.ini
[common]
#服务端口
bind_port = 7000
#监听地址
#bind_addr = 0.0.0.0

#认证token
#token = big_cat
#http服务端口
vhost_http_port = 7080
#https服务端口
vhost_https_port = 70443
  • frpc.ini
[common]
#frps的ip地址
server_addr = 114.114.114.114
#frps的端口
server_port = 7000
#认证token
#token = big_cat

[web-01]
# 远端服务器定义好了 http 服务的端口 这里不需要指定
# 只需要指定 custom/sub_domains 用来做路由即可 
# 如果只是代理一台 则指定服务端ip 使用ip访问即可
type = http
#本地http服务端口
local_port = 8081
#本地http服务地址
local_ip = 127.0.0.1
# 直接使用服务端的公网ip绑定(这样一个frps只能代理一个http客户端)
#custom_domains = 118.118.118.118
# 或者指定域名 可以使用其他域名继续绑定
custom_domains = frp1.com

[web-02]
type = http
local_port = 8082
#本地http服务地址
local_ip = 127.0.0.1
# 直接使用服务端的公网ip绑定(这样一个frps只能代理一个http客户端)
#custom_domains = 118.118.118.118
# 或者指定域名 可以使用其他域名继续绑定
custom_domains = frp2.com

[ssh]
type = tcp
local_port = 22
local_ip = 127.0.0.1
# 在服务端注册端口 服务端将监听 7022 ssh root@118.118.118.118 -p 7022 即可代理到本机 ssh 登录
remote_port = 7022

启动

# 启动服务端服务
nohup ./frps -c ./frps.ini &
# 启动客户端服务
nohup ./frpc -c ./frpc.ini &

注意: http/https 服务是在服务端配置中定义的端口,客户端指定协议后会自动关联,ssh 等使用 tcp 的则是在客户端定义好 remote_port ,服务端开放此端口即可。

说明

在 springboot 中一个接口有多个实现,我们希望通过配置来控制运行时实例化哪个对象,springboot 中 @Conditional 注解可以帮助我们细粒度控制 bean 的实例化。

Spring Bootorg.springframework.boot.autoconfigure.condition 包下定义了以下注解:

注解名 作用
@ConditionalOnJava 基于JVM版本作为判断条件.
@ConditionalOnBean 当容器中有指定的Bean的条件下.
@ConditionalOnClass 当类路径下游指定的类的条件下.
@ConditionalOnExpression 基于SpEL表达式作为判断条件.
@ConditionalOnJndi 在JNDI存在的条件下查找指定的位置.
@ConditionalOnMissingBean 当容器中没有指定Bean的情况下.
@ConditionalOnMissingClass 当类路径下没有指定的类的情况下.
@ConditionalOnNotWebApplication 当前项目不是web项目的条件下.
@ConditionalOnProperty 指定的属性是否有指定的值.
@ConditionalOnResource 类路径是否有指定的值.
@ConditionalOnSingleCandidate 当指定Bean在容器中只有一个,或者虽然有多个但是指定首选的Bean.
@ConditionalOnWebApplication 当前项目是web项目的条件下.

@ConditionalOnExpression

@Component
// user.label 属性等于 user2 创建TestBean
// @ConditionalOnExpression("'${user.label}'.equals('user2')")

// 可以使用 && || 等运算符
// @ConditionalOnExpression("'${user.label}'.equals('user3') && '${xxx}'.equals('xx')")
// @ConditionalOnExpression("'${user.label}'.equals('${xxx}')")

// 当环境变量 user.label=user2 创建TestBean, 注意: 这个环境变量可以通过 application.yml 传入
@ConditionalOnExpression("#{'user2'.equals(environment['user.label'])}")
public class TestBean {
    @PostConstruct
    public void init() {
        System.out.println(111);
    }
}

@ConditionalOnProperty

@Component
// 当有 user.label 这个属性时创建 TestBean
// @ConditionalOnProperty(name = "user.label")
// 当有 user.label 和 xxx 两个属性时创建 TestBean
// @ConditionalOnProperty(name = {"user.label", "xxx"})
// 当有 user.label 这个属性且值为 user2 时创建 TestBean
@ConditionalOnProperty(name = "user.label", havingValue = "user2")
public class TestBean {
    @PostConstruct
    public void init(){
        System.out.println(111);
    }
}

自定义 Conditional

Bean对象

  • 两个 User Bean
@Data
@NoArgsConstructor
public class User1 {
    private String name;
    private int age;
}

@Data
@NoArgsConstructor
public class User2 {
    private String name;
    private int age;
}

方法一

  • 为每类对象创建一个 Conditional,如下为 User1和User2分别创建一个
public class MyConditional1 implements Condition {
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        String v = context.getEnvironment().getProperty("user.label");
        if (v.equals("user1")) return true;
        return false;
    }
}

public class MyConditional2 implements Condition {
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        String v = context.getEnvironment().getProperty("user.label");
        if (v.equals("user2")) return true;
        return false;
    }
}
  • springboot 实例化 bean
@Bean
@Conditional(MyConditional1.class)
public User init(){
    System.out.println(111);
    return new User();
}

@Bean
@Conditional(MyConditional2.class)
public User2 init2(){
    System.out.println(222);
    return new User2();
}
  • application.propeties
# 如果 label 匹配 bean 的label,该 bean 就会被实例化
user.label=user1

方法二

  • 新增注解给要实例化的对象打上标签
@Target({ElementType.TYPE,ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Conditional(MyConditional.class)
public @interface MyConditionalAnnotation {
    String label();
}
  • MyConditional.java
public class MyConditional extends SpringBootCondition {
    @Override
    public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
        Map<String, Object> annotationAttributes = metadata.getAnnotationAttributes(MyConditionalAnnotation.class.getName());
        // 获取注解所传入的 label
        Object value = annotationAttributes.get("label");
        if (value == null) {
//            return new ConditionOutcome(false, "ERROR");
            return ConditionOutcome.noMatch("ERROR");
        }
        // user.label 的值是通过application.propeties传入
        String v = context.getEnvironment().getProperty("user.label");
        if (v.equals(value)){
            // 如果匹配就实例化该 bean
            return ConditionOutcome.match("OK");
        }
        return ConditionOutcome.noMatch("ERROR");
    }
}

注意:代码中通过 application.propeties 传入配置优先级比较高,所以通过context可以获取到,如果通过别的配置文件可能无法获取则需要手动加载。

Properties properties = new Properties();
try {
    properties.load(conditionContext.getResourceLoader().getResource("test.properties").getInputStream());
} catch (IOException ex) {
    ex.printStackTrace();
}
String v = properties.getProperty("user.label");
  • springboot 创建bean
// 通过自定义注解设置 label
@MyConditionalAnnotation(label = "MyUserLabel1")
@Bean
public User1 init(){
    System.out.println(111);
    return new User1();
}

@MyConditionalAnnotation(label = "MyUserLabel2")
@Bean
public User2 init2(){
    System.out.println(222);
    return new User2();
}
  • application.propeties
# 如果 label 匹配 bean 的label,该 bean 就会被实例化
user.label=MyUserLabel2

说明

EphemeralContainers:官方说明

kubectl 版本为 v1.18 或者更高 beta 功能 默认不开启,需要手动开启, v1.22 版本开始成为正式功能无需开启.

如果执行kubectl debug xxxx 报以下错误说明需要手动开启临时容器功能:

error: ephemeral containers are disabled for this cluster (error from server: "the server could not find the requested resource").

手动开启操作

master节点

  • 修改apiserver
    编辑/etc/kubernetes/manifests/kube-apiserver.yaml

--feature-gates=xxxxx后面添加,EphemeralContainers=true,注意逗号.

  • 修改controller-manager
    编辑/etc/kubernetes/manifests/kube-controller-manager.yaml

--feature-gates=xxxxx后面添加,EphemeralContainers=true,注意逗号.

  • 修改kube-scheduler
    编辑/etc/kubernetes/manifests/kube-scheduler.yaml

--feature-gates=xxxxx后面添加,EphemeralContainers=true,注意逗号.

所有节点

  • 修改kubelet
    编辑/var/lib/kubelet/kubeadm-flags.env

添加--feature-gates=EphemeralContainers=true

修改后如下

KUBELET_KUBEADM_ARGS="--cgroup-driver=systemd --network-plugin=cni --pod-infra-container-image=k8s.gcr.io/pause:3.2 --feature-gates=EphemeralContainers=true"
  • 重启kubelet
systemctl daemon-reload
systemctl restart kubelet 

储能系统

储能系统(Energy Storage System,简称ESS):是一个可完成存储电能和供电的系统,具有平滑过渡、削峰填谷、调频调压等功能。可以使太阳能、风能发电平滑输出,减少其随机性、间歇性、波动性给电网和用户带来的冲击;通过谷价时段充电,峰价时段放电可以减少用户的电费支出;在大电网断电时,能够孤岛运行,确保对用户不间断供电。

名词 说明
BA 储能电池组
BMS 电池管理系统
PCS 储能变流器,功率变换系统
EMS 能量管理系统

变流器控制策略

  • PQ控制:指恒定有功无功控制,控制储能变流器输出的有功功率和无功功率等于其参考功率。PQ控制是新能源并网最常用的控制方式,只有在储能系统并网模式下才可能运用
  • VF控制:指储能变流器维持输出电压和频率不变;而输出的有功功率和无功功率由负荷决定
  • VSG控制:虚拟同步机模式,该模式下储能可以构网,同时可以和并网型或者构网型系统并机运行

名词

  • 使能:所谓使能信号,英文叫Enable,通过这个信号可以控制某颗芯片/某个电路有没有被“启用”。一个大型的数字系统中,通常都需要使用多个芯片/电路单元来配合完成一个功能。而这些芯片并不是每时每刻都在工作的。因此需要用使能信号来控制应该“启动”哪个芯片来工作。

术语解释

术语 英文 说明
AC Alternating Current 交流电压
DC Direct Current 直流电压
整流器 Rectifier 将交流电转变成直流电的电子设备
逆变器 inverter 把直流电能(电池、蓄电瓶)转变成交流电(一般为220V,50Hz正弦波)
继电器 Relay 通常应用于自动控制电路中,用较小的电流去控制较大电流的一种“自动开关”。在电路中起着自动调节、安全保护、转换电路等作用
变压器 transformer 变换(升高或降低)交流电压,但不改变电源频率的电能转换器
台区 - 指(一台)变压器的供电范围或区域