elasticsearch 使用

这里填写标题

  • 1. elasticsearch 使用
    • 1.1. elasticsearch 启动报错解决
      • 1.1.1. `max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]`
      • 1.1.2. 无法通过外部 ip 访问 elasticsearch
      • 1.1.3. `ERROR: [1] bootstrap checks failed [1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured`
      • 1.1.4. `ERROR: [1] bootstrap checks failed [1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured`
      • 1.1.5. `ERROR: bootstrap checks failed memory locking requested for elasticsearch process but memory is not locked`
      • 1.1.6. docker 版本的数据目录与日志目录持载到本地无法启动, 提示 `Permission Denied`
    • 1.2. 限制 elasticsearch 使用的内存容量

1. elasticsearch 使用

1.1. elasticsearch 启动报错解决

1.1.1. max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

临时解决办法: 切换 root 用户执行如下命令

sysctl -w vm.max_map_count=262144

永久解决办法: 在 /etc/sysctl.conf 文件最后添加一行

echo "vm.max_map_count=262144" >> /etc/sysctl.conf
sysctl -p  #使修改立即生效

查看修改结果:

sysctl -a|grep vm.max_map_count

显示:

vm.max_map_count = 262144

1.1.2. 无法通过外部 ip 访问 elasticsearch

# 修改 config/elasticsearch.yml 下约第 55 行, 修改为当前 es 地址或 0.0.0.0
network.host: 0.0.0.0

1.1.3. ERROR: [1] bootstrap checks failed [1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured

修改 config/elasticsearch.yml, 放开 node.name 注释, 可更改名称

node.name: node-1

1.1.4. ERROR: [1] bootstrap checks failed [1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured

# 打开第 68 行注释, ip 替换 host1 等, 多节点请添加多个 ip 地址, 单节点可写按默认来
# 配置以下三者, 最少其一
#[discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes]
cluster.initial_master_nodes: ["node-1"] #这里的 node-1 为 node-name 配置的值

1.1.5. ERROR: bootstrap checks failed memory locking requested for elasticsearch process but memory is not locked

这是因为设置了锁定内存参数 bootstrap.memory_lock=true

1.1.6. docker 版本的数据目录与日志目录持载到本地无法启动, 提示 Permission Denied

添加容器环境变量 TAKE_FILE_OWNERSHIP=true

1.2. 限制 elasticsearch 使用的内存容量

直接设置环境变量:

export ES_HEAP_SIZE=2g
export ES_JAVA_OPTS="-Xms16g -Xmx16g"

或者命令行方式启动:

ES_HEAP_SIZE=2g ES_JAVA_OPTS="-Xms16g -Xmx16g" /bin/elasticsearch -d

你可能感兴趣的:(database,elasticsearch,java)