1. 准备工作(所有节点执行) 1.1 创建专用用户和目录 1 2 3 4 5 6 7 8 9 10 useradd esadmin passwd esadmin mkdir -p /export/servers/eschown -R esadmin:esadmin /export/servers/esvisudo
添加以下内容:
1.2 系统参数优化 1 2 vim /etc/security/limits.conf
添加以下内容:
1 2 3 4 5 6 7 8 9 * soft nofile 65535 * hard nofile 131072 * soft nproc 2048 * hard nproc 4096 esadmin soft memlock unlimited esadmin hard memlock unlimited bash # 修改内核参数 vim /etc/sysctl.conf
添加:
1 2 vm.max_map_count=655360 fs.file-max=655350
应用修改:
2. 安装Elasticsearch(所有节点执行) 2.1 下载并解压 1 2 3 4 5 6 su - esadmin cd /export/servers/eswget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.4.0-linux-x86_64.tar.gz tar zxvf elasticsearch-7.4.0-linux-x86_64.tar.gz cd elasticsearch-7.4.0/mkdir -p ./datas
2.2 配置文件设置 1 2 3 cd config/mv elasticsearch.yml elasticsearch.yml.bakvim elasticsearch.yml
集群配置示例(根据节点修改): 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 cluster.name: myes node.name: node01 path.data: /export/servers/es/elasticsearch-7.4.0/datas path.logs: /export/servers/es/elasticsearch-7.4.0/logs network.host: 0.0 .0 .0 http.port: 9200 discovery.seed_hosts: ["192.168.147.63" , "192.168.147.64" , "192.168.147.65" ]cluster.initial_master_nodes: ["node01" , "node02" , "node03" ]bootstrap.memory_lock: false http.cors.enabled: true http.cors.allow-origin: "*" indices.fielddata.cache.size: 30 % indices.breaker.fielddata.limit: 60 %
2.3 JVM配置调整
根据服务器内存调整(建议不超过物理内存的50%):
3. 启动集群 3.1 启动服务(每个节点执行) 1 2 3 su - esadmin cd /export/servers/es/elasticsearch-7.4.0/bin/elasticsearch -d
3.2 验证集群状态 1 2 curl -XGET 'http://localhost:9200/_cluster/health?pretty' curl -XGET 'http://localhost:9200/_cat/nodes?v'
4. 集群管理命令 4.1 常用API 1 2 3 4 5 6 7 8 9 10 11 12 13 14 curl -XGET 'http://localhost:9200/_cluster/health?pretty' curl -XGET 'http://localhost:9200/_cat/nodes?v' curl -XGET 'http://localhost:9200/_cat/indices?v' curl -XPUT 'http://localhost:9200/test_index' curl -XDELETE 'http://localhost:9200/test_index'
4.2 服务管理 1 2 3 4 5 6 7 8 9 10 11 ps -ef | grep elasticsearch kill -15 <pid>kill -9 <pid>nohup ./bin/elasticsearch > /dev/null 2>&1 &
5. 注意事项
内存配置 :JVM堆内存不要超过物理内存的50%,且不超过32GB
集群配置 :
discovery.seed_hosts 包含所有候选主节点
cluster.initial_master_nodes 只在首次启动集群时需要
生产建议 :
配置至少3个主节点
数据节点和主节点分离
考虑使用X-Pack安全功能
监控 :建议配置Kibana或Prometheus进行监控
日志 :定期清理日志或配置日志轮转
6. 故障排查
启动失败检查 :1 tail -n 100 logs/myes.log
常见问题 :
内存不足:调整JVM参数
文件描述符不足:检查limits.conf配置
无法加入集群:检查网络和discovery配置
7. 扩展配置(可选) 7.1 插件安装 1 2 bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.4.0/elasticsearch-analysis-ik-7.4.0.zip
7.2 生产环境推荐配置 1 2 3 4 thread_pool.search.size: 20 thread_pool.search.queue_size: 1000 indices.queries.cache.size: 10 %