Elasticsearch安装

发布时间 2023-11-01 17:15:30作者: MegaloBox

Docker

单节点

修改max_map_count值

sysctl -w vm.max_map_count=262144

创建持久化目录并配置权限

mkdir /opt/elasticsearch
setfacl -m u:1000:rwx -R /opt/elasticsearch/

创建配置文件

mkdir config
$ cat > elasticsearch.yml << EOF
cluster.name: "docker-cluster"
network.host: 0.0.0.0
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
EOF

运行容器

docker run --name elasticsearch -p 9200:9200 -p 9300:9300 \
-e "discovery.type=single-node" \
-e "cluster.name=elasticsearch" \
-e "ES_JAVA_OPTS=-Xms512m -Xmx1024m" \
-v /opt/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-v /opt/elasticsearch/data:/usr/share/elasticsearch/data \
-v /opt/elasticsearch/logs:/usr/share/elasticsearch/logs \
-v /opt/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-d elasticsearch:7.17.5

初始化密码

$ docker exec -it elasticsearch bash
root@2001b18921ee:/usr/share/elasticsearch# /usr/share/elasticsearch/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]

Curl登录测试

root@2001b18921ee:/usr/share/elasticsearch# curl -XGET -u elastic 'localhost:9200/_xpack/security/user?pretty'
Enter host password for user 'elastic':
{
  "elastic" : {
    "username" : "elastic",
    "roles" : [
      "superuser"
    ],
    "full_name" : null,
    "email" : null,
    "metadata" : {
      "_reserved" : true
    },
...