搭建es+kibana启动发现没有自动创建.security索引

在es8中.security 不是启动时创建

很多人误认为:

Elasticsearch 一启动,就会创建 .security

实际上 不是,ES8 的行为是:

启动
    │
    │
    ▼
Security 模块加载
    │
    │
    ▼
等待第一次真正需要保存安全数据
    │
    ├── 设置密码
    ├── 创建用户
    ├── 创建Role
    ├── API Key
    ├── Service Token
    ├── Kibana连接
    └── Enrollment Token
           │
           ▼
才创建
.security-7
或
.security-8

如果整个集群只有 elastic 内置用户登录过,而没有任何需要写入 Security Index 的操作,.security 可以不存在。

提前是elasticsearch必须开启

xpack.security.enabled: true

如何主动创建

如创建一个用户:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
POST /_security/user/test
{
"password":"123456",
"roles":[
"superuser"
]
}

curl -u elastic:321.321 \
-X POST localhost:9200/_security/user/test \
-H "Content-Type: application/json" \
-d'
{
"password":"123456",
"roles":["superuser"]
}'

这时 ES 会立即:

create index .security-8

然后再查看就能看到

1
2
3
4
curl -u elastic:321.321 localhost:9200/_cat/indices/.security*?v

#查看支持认证用户
curl -u elastic:321.321 localhost:9200/_security/_authenticate