下载地址:
Download Elasticsearch | Elastic
下载的安装包是elasticsearch-7.12.0-linux-x86_64.tar.gz
解压缩文件
tar -zxvf elasticsearch-7.12.0-linux-x86_64.tar.gz
#编辑文件
vim config/elasticsearch.yml
# 加入如下配置
# 集群名称,一个 Elasticsearch 集群有一个唯一的名字标识,默认就是elasticsearch
cluster.name: elasticsearch
#数据存放路径
path.data: /data/esdata/data
#日志存放路径
path.logs: /data/esdata/data/logs
# 节点名称,如果未设置,默认为随机生成的名称
node.name: node-1
#本机IP地址(设置可以访问的ip地址)
network.host: 0.0.0.0
#es暴露对外的端口
http.port: 9200
#初始主节点的名称或ID,可放集群中可知的node.name
cluster.initial_master_nodes: ["node-1"]
修改配置文件/etc/sysctl.conf
在配置文件中加入以下内容:
# 一个进程可以拥有的 VMA(虚拟内存区域)的数量,默认值为 65536
vm.max_map_count=655360
不然启动会报错
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
重新加载
sysctl -p
后台启动es
./bin/elasticsearch -d
配置用户名密码
启用 X-Pack 安全功能
在 elasticsearch.yml 配置文件中,添加以下配置来启用基本安全功能:
xpack.security.enabled: true
#discovery.type: single-node
xpack.security.transport.ssl.enabled: true
启用SSL
当设置了 network.host: 0.0.0.0
之后,es会无法启动,要求你配置SSL,启动会提示
io.netty.handler.codec.DecoderException: javax.net.ssl.SSLHandshakeException: No available authentication scheme
使用 elasticsearch-certutil 工具生成自签名证书以及相关配置如下:
运行 elasticsearch-certutil ca 命令:
bin/elasticsearch-certutil ca
你将被提示输入证书相关的信息。一般情况下,可以直接按 Enter 使用默认值。
选择输出格式:
你会看到如下提示:
Please enter the desired output file [elastic-stack-ca.p12]:
输入文件名或按 Enter 使用默认文件名 elastic-stack-ca.p12。
接下来你会看到:
Enter password for elastic-stack-ca.p12 :
输入一个密码并记住它,你将在稍后使用。
最终,你会看到如下信息:
CA certificate written to /path/to/elasticsearch/bin/elastic-stack-ca.p12
运行 elasticsearch-certutil cert 命令并指定 CA 证书:
./bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12
你将被提示输入 CA 证书的密码(之前设置的密码)。
输入一个密码并记住它,你将在配置 Elasticsearch 时使用它。
设置为如下时访问不需要密码
cluster.initial_master_nodes: ["node-1"]
xpack.security.enabled: true
#discovery.type: single-node
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: /home/es/elasticsearch-7.12.0/config/elastic-certificates.p12
xpack.security.transport.ssl.keystore.password: password
xpack.security.transport.ssl.truststore.path: /home/es/elasticsearch-7.12.0/config/elastic-certificates.p12
xpack.security.transport.ssl.truststore.password: password
如果要输入密码登录,在上述生成秘钥时密码敲回车,不输入密码!
bin/elasticsearch-certutil ca
配置文件为
cluster.initial_master_nodes: ["node-1"]
xpack.security.enabled: true
#discovery.type: single-node
#xpack.license.self_generated.type: basic
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: /home/es/elasticsearch-7.12.0/config/elastic-certificates.p13
xpack.security.transport.ssl.truststore.path: /home/es/elasticsearch-7.12.0/config/elastic-certificates.p13
设置内置用户的密码
运行以下命令来设置内置用户的密码,该命令会提示你设置几个内置用户(如 elastic、kibana、logstash_system 等)的密码。
./bin/elasticsearch-setup-passwords interactive
Initiating the setup of passwords for reserved users elastic,apm_system,kibana,kibana_system,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_system]:
Reenter password for [kibana_system]:
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_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]
重启es后,访问需要用户密码
查看ES索引和状态:
http://XX.XX.XX.XX:9200/_cat/indices?v
删除ES索引
curl -u elastic:password -XDELETE 'http://XX.XX.XX.XX:9200/res_operation_log'
新建ES索引
curl -u elastic:iwhalecloud123 -XPUT 'http://XX.XX.XX.XX:9200/exchangelogcutjhx_0 ' -H 'Content-Type: application/json' -d '
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
},
"mappings": {
"properties": {
"field1": { "type": "text" },
"field2": { "type": "keyword" }
}
}
}'
参考文章:
Linux安装elasticsearch单机版_linux 安装es-CSDN博客
Elasticsearch单机部署(Linux)_elasticsearch 单机部署-CSDN博客
Linux安装elasticsearch单机版_linux 安装es-CSDN博客
https://www.jianshu.com/p/ea1c9cb14515
ElasticSearch 7配置密码认证及创建用户_please enter the desired output file [elastic-stac-CSDN博客