elasticsearch添加用户名和密码

1.修改elasticsearch.yml配置文件

[bdp@host66 config]$vim elasticsearch.yml
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: elasticsearch-66
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: node-66
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
#
#-----------------------------Indexing & Cache config---------------------------
#index.max_script_fields: 128

#
#
#
#
#
#
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
#path.data: /path/to/data
#
# Path to log files:
#
#path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.zen.ping.unicast.hosts: ["host1", "host2"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes: 
#
# For more information, consult the zen discovery module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true

http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
#xpack.license.self_generated.type: trial

 

 
 

2.重新启动es,设置密码

[bdp@host66 bin]$./bin/elasticsearch-setup-passwords interactive
Initiating the setup of passwords for reserved users elastic,apm_system,kibana,logstash_system,beats_system,remote_monitoring_user.
You will be prompted to enter passwords as the process progresses.
Please confirm that you would like to continue [y/N]y


Enter password for [elastic]: 
Reenter password for [elastic]: 
Enter password for [apm_system]: 
Reenter password for [apm_system]: 
Enter password for [kibana]: 
Reenter password for [kibana]: 
Enter password for [logstash_system]: 
Reenter password for [logstash_system]: 
Enter password for [beats_system]: 
Reenter password for [beats_system]: 
Enter password for [remote_monitoring_user]: 
Reenter password for [remote_monitoring_user]: 
Changed password for user [apm_system]
Changed password for user [kibana]
Changed password for user [logstash_system]
Changed password for user [beats_system]
Changed password for user [remote_monitoring_user]
Changed password for user [elastic]

3.es启动脚本

[bdp@host66 elasticsearch-6.8.2]$cat start.sh 
export JAVA_HOME=/home/bdp/shangeshishi/jdk1.8.0_131
export PATH=$JAVA_HOME/bin:$PATH

nohup ./bin/elasticsearch > elasticsearch.log 2>&1 &
tail -f elasticsearch.log

4.加密后的访问Header的方式为

http://host:9201/?auth_user=elastic&auth_password=123456

Elasticsearch 7.x版本中,设置用户名密码是为了进行安全访问控制。以下是基本步骤: 1. **修改elasticsearch.yml文件**: 打开`config/elasticsearch.yml`(Windows用户可能需要在安装目录下找到),找到`xpack.security.enabled: true`这一行,确保X-Pack插件已经启用。然后添加或编辑如下部分: ```yaml xpack.security.authc.accept_if_username_in_path: false xpack.security.http.ssl.enabled: true # 如果使用HTTPS xpack.security.transport.ssl.enabled: true # 如果有内部集群通信 cluster.name: your_cluster_name node.name: unique_node_identifier http.cors.enabled: true http.cors.allow-origin: "*" http.cors.support.credentials: true http.username: your_username http.password: your_password ``` 2. **创建用户**: 使用curl命令或者通过Kibana界面(如果已安装)创建用户。例如,创建一个名为`admin`的管理员用户: ```bash curl -XPOST "localhost:9200/_xpack/security/user/admin" -H 'Content-Type: application/json' -d' { "password": "your_password", "username": "admin", "roles": ["cluster_admin"] }' ``` 或者在Kibana UI的Security -> Users界面添加。 3. **配置HTTP基本认证**: 在启动Elasticsearch时,它会自动监听http端口(默认9200),并等待基本认证。你可以通过`ELASTICSEARCH_HTTP_AUTH`环境变量传递认证信息,但推荐的方式是在`elasticsearch.yml`中直接设置如上所示。 4. **重启服务**: 修改配置后,记得重启Elasticsearch服务(`bin/elasticsearch restart`)以便新的设置生效。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值