Consul 开启鉴权 以及 Spring配置文件如何添加acl

分类: beat365英国在线体育 时间: 2025-09-16 01:34:09 作者: admin 阅读: 9493
Consul 开启鉴权 以及 Spring配置文件如何添加acl

Consul安装Consul官网下载地址:https://developer.hashicorp.com/consul/install

Consul设置秘钥代码语言:javascript代码运行次数:0运行复制{

"acl": {

"enabled": true,

"default_policy": "deny",

"tokens": {

"master": "xxxxxxxxx-xxxxxxxxx-xaaaaaa"

}

}

}Consul启动脚本代码语言:javascript代码运行次数:0运行复制nohup ./consul agent -server -bootstrap-expect=1 -data.dir=./consuldata -node=consul-server-1 -bind=0.0.0.0 -config-dir=./acl.hcl -enable-script-checks=true -client=0.0.0.0 -ui &启动脚本详解

nohup: 这个命令用于在后台运行程序,即使终端关闭也不会中断程序的执行。./consul agent: 这启动了Consul代理程序。-server: 这指定了Consul代理作为服务器运行。-bootstrap-expect=1: 这个参数指定了在启动期间预期的服务器节点数。在这种情况下,只有一个服务器节点。-data.dir=./consuldata: 这个参数指定了Consul数据存储的目录。-node=consul-server-1: 这定义了Consul服务器的节点名称。-bind=0.0.0.0: 这指定了Consul绑定到的IP地址。-config-dir=./acl.hcl: 这指定了ACL配置文件的目录。-enable-script-checks=true: 这启用了脚本检查功能。-client=0.0.0.0: 这指定了Consul绑定到的客户端IP地址。-ui: 这启用了Consul的Web用户界面。Consul配置权限Spring配置文件Consul的aclTokne秘钥添加添加配置前,先看看aclToken的字段吧。

代码语言:javascript代码运行次数:0运行复制package com.tencent.tsf.discovery;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import org.springframework.beans.factory.annotation.Value;

import org.springframework.boot.context.properties.ConfigurationProperties;

import org.springframework.cloud.commons.util.InetUtils;

@ConfigurationProperties("tsf.discovery")

public class TsfDiscoveryProperties {

protected static final String MANAGEMENT = "management";

private InetUtils.HostInfo hostInfo;

@Value("${tsf_token:${consul.token:${CONSUL_TOKEN:${spring.cloud.consul.token:${SPRING_CLOUD_CONSUL_TOKEN:}}}}}")

private String aclToken;

private List tags;

private boolean enabled;

......

}源码分析如下:tsf.discovery.aclToken。或者tsf_token、或者consul.token。

所以就知道了注册中心的配置了。我使用的是consul.token!

特殊说明:

上述文章均是作者实际操作后产出。烦请各位,请勿直接盗用!转载记得标注原文链接:www.zanglikun.com

相关文章

[office] excel制作简单斜线表头和复杂斜线表头并打字的方法 #其他#其他#媒体
參(参)
正在阅读:笔记本电脑怎么恢复出厂设置 笔记本电脑恢复出厂设置方法【详解】笔记本电脑怎么恢复出厂设置 笔记本电脑恢复出厂设置方法【详解】
石家庄Apple授权专营店网点分布