DNF 安装 Elasticsearch
# 第一步:导入 Elasticsearch PGP Key
shell > rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
# 第二步:创建 Elasticsearch RPM Repo File
shell > vim /etc/yum.repos.d/elasticsearch.repo
# 粘贴以下内容
[elasticsearch]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=0
autorefresh=1
type=rpm-md
#第三步:安装 Elasticsearch
shell > dnf install --enablerepo=elasticsearch elasticsearch
手动下载RPM 安装
# 第一步:下载RPM,这里举例的是清华大学镜像
shell > wget https://mirrors.tuna.tsinghua.edu.cn/elasticstack/7.x/yum/7.6.1/elasticsearch-7.6.1-x86_64.rpm
# 第二步:安装
shell > rpm --install elasticsearch-7.6.1-x86_64.rpm
启动 Elasticsearch 并加入开机启动项
shell > systemctl enable elasticsearch.service --now
保留用户
| Name | Description |
| ------------- | ------------- |
| elastic | 内置的超级用户 |
| kibana | 用户Kibana用于连接Elasticsearch并与之通信。 |
| logstash_system | Logstash用户在将监控信息存储在Elasticsearch中时使用。 |
| beats_system | Beats在Elasticsearch中存储监视信息时使用的用户。 |
| apm_system | APM服务器在Elasticsearch中存储监视信息时使用的用户。 |
| remote_monitoring_user | 用户Kibana用于连接Elasticsearch并与之通信。 |
| kibana | Metricbeat用户在Elasticsearch中收集和存储监视信息时使用。它具有remote_monitoring_agent和 remote_monitoring_collector内置角色。 |
安全设置
# 初始化保留账户密码(这里密码我全部设置成qq111222,以下操作将会使用)
shell > /usr/share/elasticsearch/bin/elasticsearch-setup-passwords interactive
# 开启认证
shell > vim /etc/elasticsearch/elasticsearch.yml
# 增加
xpack.security.enabled: true
http.cors.enabled: true
http.cors.allow-origin: '*'
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
用户角色管理 (RESTfull风格请求)
# 查看 所有角色
shell > curl -XGET -u elastic:qq111222 'localhost:9200/_xpack/security/role'
# 添加/修改 角色
shell > curl -XPOST -u elastic:qq111222 'localhost:9200/_xpack/security/role/testRole1' -H "Content-Type: application/json" -d '{"cluster":["all"],"indices":[{"names":["*"],"privileges":["all"]}]}'
# 查看 角色
shell > curl -XGET -u elastic:qq111222 'localhost:9200/_xpack/security/role/testRole1'
# 删除 角色
shell > curl -XDELETE -u elastic:qq111222 'localhost:9200/_xpack/security/role/testRole1'
用户管理 (RESTfull风格请求)
# 查看 所有角色
shell > curl -XGET -u elastic:qq111222 'localhost:9200/_xpack/security/user'
# 添加/修改 用户
shell > curl -XPOST -u elastic:qq111222 'localhost:9200/_xpack/security/user/testUser1' -H "Content-Type: application/json" -d '{
"password" : "qq111222",
"full_name" : "test user one",
"email" : "[email protected]",
"roles" : [ "testRole1" ],
"metadata" : {
"intelligence" : 7
}
}'
# 查看 角色
shell > curl -XGET -u elastic:qq111222 'localhost:9200/_xpack/security/user/testUser1'
# 删除 角色
shell > curl -XDELETE -u elastic:qq111222 'localhost:9200/_xpack/security/user/testUser1'