# Elasticsearch6.5.4集群 ## 环境要求 | 软件 | 版本 | 备注 | | --- | --- |--- | | centos| 7.5 | | | JDK | 1.8 | | 最近学习Elasticsearch,顺便记录下操作步骤,供日后参考 安装环境 CentOS release 7.5 1、因Elasticsearch是基于java写的,所以它的运行环境中需要java的支持,在Linux下执行命令:java -version,检查Jar包是否安装 安装java版本至少是1.8以上 ``` mkdir /app cd /app ``` 2、首先准备下载Elasticsearch6.5.4 安装包 ~~~ wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.5.4.tar.gz ~~~ 3、下载到/usr/local 目录下,解压 ``` tar -zxvf elasticsearch-6.5.4.tar.gz ``` 4、创建用户 useradd es 5、配置内存 cd elasticsearch-6.5.4 修改config/jvm.options为内存的一半大小 vi config/jvm.options -Xms512m -Xmx512m 6、配置资源限额 修改 max file 和 max virtual memory 参数 用root 或 sudo 用户 vi /etc/sysctl.conf 添加下面配置: vm.max_map_count=655360 并执行命令: sysctl -p 7、 修改/etc/security/limits.conf ``` grep -q "* - nofile" /etc/security/limits.conf || cat >> /etc/security/limits.conf << EOF ######################################## * soft nofile 65536 * hard nofile 65536 * soft nproc 4096 * hard nproc 4096 EOF ``` ## 修改elasticsearch.yml ``` vi /app/elasticsearch-6.5.4/config/elasticsearch.yml cluster.name: elasticsearch node.name: node-1 network.host: 0.0.0.0 http.port: 9200 node.max_local_storage_nodes: 2 http.cors.enabled: true http.cors.allow-origin: "*" ``` ## 赋权启动 ``` chown -R es:es /app/elasticsearch-6.5.4/ su - es -c '/app/elasticsearch-6.5.4/bin/elasticsearch -d' ``` 注:安装后出现如下问题,致使elasticsearch无法启动 ``` [root@zookeeper01 bin]# su - es -c '/app/elasticsearch-6.5.4/bin/elasticsearch -d OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000085330000, 2060255232, 0) failed; error='Cannot allocate memory' (errno=12) # # There is insufficient memory for the Java Runtime Environment to continue. # Native memory allocation (mmap) failed to map 2060255232 bytes for committing reserved memory. # An error report file with more information is saved as: # /root/elk/elasticsearch-6.5.4/bin/hs_err_pid3801.log解决: ``` 配置elasticsearch下的jvm.options: ``` # vi /etc/elasticsearch/jvm.options -Xms256m ##启用如下两项 -Xmx256m ##-Xms2g ##关闭如下两项 ##-Xmx2g ``` ②ElasticSearch默认的对外服务的HTTP端口是9200,节点间交互的TCP端口是9300。 ``` OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N [2017-12-21T19:27:28,046][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main] org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root ``` 4、因为Elasticsearch5.0之后,不能使用root账户启动,我们先创建一个elasticsearch组和账户 ``` useradd es chown -R es:es /app/elasticsearch-6.5.4/ su - es -c '/app/elasticsearch-6.5.4/bin/elasticsearch -d' ``` 192.168.235.154创建集群环境节点1 vi config/elasticsearch.yml ``` cluster.name: elasticsearch node.name: node-1 http.cors.enabled: true http.cors.allow-origin: "*" bootstrap.memory_lock: false bootstrap.system_call_filter: false network.host: 192.168.235.154 http.port: 9200 transport.tcp.port: 9300 discovery.zen.ping.unicast.hosts: ["192.168.235.154:9300","192.168.235.155:9300","192.168.235.157:9300"] ``` su - es -c '/app/elasticsearch-6.5.4/bin/elasticsearch -d' [root@localhost logs]# cd /app/elasticsearch-6.5.4/logs && tail -f elasticsearch.log 192.168.235.155创建集群环境节点2 vi config/elasticsearch.yml ``` cluster.name: elasticsearch node.name: node-2 http.cors.enabled: true http.cors.allow-origin: "*" bootstrap.memory_lock: false bootstrap.system_call_filter: false network.host: 192.168.235.155 http.port: 9200 transport.tcp.port: 9300 discovery.zen.ping.unicast.hosts: ["192.168.235.154:9300","192.168.235.155:9300","192.168.235.157:9300"] ``` su - es -c '/app/elasticsearch-6.5.4/bin/elasticsearch -d' [root@localhost logs]# cd /app/elasticsearch-6.5.4/logs && tail -f elasticsearch.log 192.168.235.157创建集群环境节点3 vi config/elasticsearch.yml ``` cluster.name: elasticsearch node.name: node-3 http.cors.enabled: true http.cors.allow-origin: "*" bootstrap.memory_lock: false bootstrap.system_call_filter: false network.host: 192.168.235.157 http.port: 9200 transport.tcp.port: 9300 discovery.zen.ping.unicast.hosts: ["192.168.235.154:9300","192.168.235.155:9300","192.168.235.157:9300"] ``` su - es -c '/app/elasticsearch-6.5.4/bin/elasticsearch -d' [root@localhost logs]# cd /app/elasticsearch-6.5.4/logs && tail -f elasticsearch.log ## 搭建效果 ![](https://img.kancloud.cn/e1/c0/e1c0a867fc7d14264cb97f1f09ba7d84_1260x402.png) ![](https://img.kancloud.cn/f9/ce/f9ce13b07b31780b3319e03cdc532255_1917x388.png) ![](https://img.kancloud.cn/f7/16/f7164305a0a46949258994758804ef87_1920x433.png) ![](https://img.kancloud.cn/ec/24/ec24879723669d9548f603efc8615199_1920x454.png)