此文檔是基於ElasticSearch5.4.2版本的部署文檔,旨在說明ElasticSearch的安裝部署步驟,做爲後續ElasticSearch的安裝部署參考。java
ElasticSearch是業界最流行的開源搜索引擎,基於apache-luncene的開源實現,同類比和apache-solr有不少類似處,但在部署、可擴展性和功能方面有差別。node
ElasticSearch和solr在使用場景也有不同的針對性,ElasticSearch基於json格式的數據配置,而solr基於schema格式的配置,在使用場景上,ElasticSearch更偏向於查詢、過濾和分組分析統計方面,他支持range、關聯的查詢;而solr更加偏向於文本的全文檢索;對於高級檢索的支持並無那麼強。sql
ElasticSearch安裝,包括插件的支持須要如下的依賴:apache
ntpd service status
tar -zvxf elasticsearch-5.4.2.tar.gz
cluster.name: elasticsearch #集羣名稱(集羣名稱需配置成一致)
node.name: es-node-01 #節點名稱
node.master: true #是不是master節點(集羣環境下配置)
node.data: true #是不是數據節點
path.data: /usr/local/es-5.4/data #數據文件存儲路徑
path.logs: /usr/local/es-5.4/logs #日誌文件存儲路徑
network.host: 192.168.1.23 #對外暴露的IP地址
http.port: 9200 #es的http訪問端口
http.cors.enabled: true #http跨域訪問設置
http.cors.allow-orign: "" #請求訪問限制,爲不限制
discovery.zen.ping.unicast.hosts: ["192.168.11.11", "192.168.11.12"] #集羣節點列表配置
discovery.zen.ping_timeout: 120s #集羣節點ping值超時時間配置json
ElasticSearch在使用上須要對系統參數進行調優處理,以知足es的平常應用vim
vim /etc/sysctl.conf
設置 vm.max_map_count = 262144
設置完成後執行如下命令生效
sysctl -papi
配置進程最大打開文件描述符跨域
vim /etc/security/limits.conf
在文件最後添加:cors
ElasticSearch支持不少插件安裝,包括kibana監控、ElasticSearch-sql支持、ElasticSearch-head插件,此處,僅介紹ElasticSearch-head插件安裝;head插件是一個基於node.js的ElasticSearch的UI管理界面,基於此插件,咱們能夠在head界面中:dom
maven依賴
<!-- https://mvnrepository.com/art... -->
<dependency>
<groupId>org.apache.lucene</groupId> <artifactId>lucene-core</artifactId> <version>6.6.0</version>
</dependency>
<!-- https://mvnrepository.com/art... -->
<dependency>
<groupId>org.apache.lucene</groupId> <artifactId>lucene-highlighter</artifactId> <version>6.6.0</version>
</dependency>
<!-- https://mvnrepository.com/art... -->
<dependency>
<groupId>org.apache.lucene</groupId> <artifactId>lucene-queries</artifactId> <version>6.6.0</version>
</dependency>
java代碼
Settings settings = Settings.builder().put("client.transport.sniff", true). put("client.transport.ignore_cluster_name", false).put("cluster.name","es-cluster").build(); TransportClient client = new PreBuiltTransportClient(settings). addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("192.168.11.11"),9300)) .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("192.168.11.12"),9300)); Map<String, Object> map = new HashMap<String, Object>(); Random ran = new Random(); map.put("nickname", "測試" + ran.nextInt(100)); map.put("sex", ran.nextInt(100)); map.put("age", ran.nextInt(100)); map.put("mobile", "15014243232"); IndexResponse response = client.prepareIndex("users", "user").setSource(map).get(); System.out.println(response);