Elastic Search 學習入門之Elastic Search的安裝配置
ElasticSearch是什麼
普通的檢索: 從網頁/文章中,找到對應的關鍵字資訊。搜尋引擎: 通過關鍵字,找到對應的網頁,為了實現這個搜尋引擎,在檢索過程彙總,關鍵字可能出現標題,正文,摘要等等,需要在相應的多個欄位中新增索引。
在資料庫中檢索的時候,使用like關鍵字,索引會失效,速度變慢。在搜尋引擎中,為了提高檢索效率,給多個欄位新增索引的操作,稱為全文索引。
搜尋引擎所使用的索引的結構稱之為倒排索引。即通過關鍵字,查詢對應的文章,就是需要為關鍵字對應相關的文章建立索引的過程。之前官網為elasticsearch,太長了不便記憶了,就改為elastic.co,官網地址
1. ES和SOLR對比
- 介面
類似webservice的介面
REST風格的訪問介面
- 分散式儲存
solrCloud solr4.x才支援
es是為分散式而生的
- 支援的格式
solr xml json
es json
- 近實時搜尋
2. ES和MySQL的對比
MySQL |
ElasticSearch |
database(資料庫) |
index(索引庫) |
table(表) |
type(型別) |
row(行) |
document(文件) |
column(列) |
field(欄位) |
ElasticSearch的安裝配置
實際上ES的安裝配置是非常簡單的,沒有繁瑣的安裝配置,可以稱之為零配置,開箱即用。
說明一點:es新版本的操作必須要在普通使用者下面進行操作
1. ES安裝配置一(基於ElasticSearch2.3和CentOS6)
- 下載地址:
https://www.elastic.co/downloads/past-releases/elasticsearch-2-3-0
或者再github官網elastic專案下載都可以下載到各個版本的es
-
安裝要求
JDK版本最低1.7
3. 安裝
同一個安裝包既可以在windows下使用,也可以在linux下使用,我們這裡就在linux下來操作。
opt]# pwd
/opt
opt]# unzip soft/elasticsearch-2.3.0.zip
4. 驗證
訪問es的安裝伺服器,http://<es_ip>:9200
當頁面出現這個狀態的時候,就說明es安裝成功了。
5. 配置檔案說明
- logging.yml
日誌配置檔案,es也是使用log4j來記錄日誌的,所以logging.yml裡的設定按普通log4j配置來設定就行了。
- elasticsearch.yml
es的基本配置檔案,需要注意的是key和value的格式“:”之後需要一個空格。
修改如下配置之後,就可以從別的機器上進行訪問了
修改cluster.name
修改node.name
Transport.tcp.port:9300 設定節點間互動的tcp埠,預設為9300
2. ES安裝配置二(基於ElasticSearch6.2和CentOS6)
安裝elasticsearch 5.x以上遇到的問題
- requires kernel 3.5+ with CONFIG_SECCOMP and CONFIG_SECCOMP_FILTER
centos6.x的核心太低,需要centos7或者升級centos6.x對應的核心至3.5以上。這裡選擇升級centos6.x對應的核心。
- 檢視核心:
執行more /etc/issue和uname -a檢視linux核心資訊
可以看到核心資訊太低,只有2.6左右,需要做升級。
- 升級
a. 匯入public key
sudo rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
有如下錯誤:
無法在伺服器使用curl命令訪問https域名,原因是nss版本有點舊了,yum -y update nss更新一下,重新curl即可!
b. 安裝ELRepo到CentOS
可以去http://elrepo.org/tiki/tiki-index.php 選擇要安裝的ELRepo。
一般會安裝到最新版核心
~]$ sudo rpm -Uvh https://www.elrepo.org/elrepo-release-6-8.el6.elrepo.noarch.rpm
~]$ sudo yum --enablerepo=elrepo-kernel install kernel-lt -y
c. 編輯grub.conf檔案,修改Grub引導順序
sudo vim /etc/grub.conf
因為一般新安裝的核心在第一個位置,所以設定default=0,表示啟動新核心
重啟之後檢視linux核心
搞定!
2. max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
編輯limits.conf 新增類似如下內容
sudo vim /etc/security/limits.conf
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
3.max number of threads [1024] for user [bigdata] is too low, increase to at least [4096]
進入/etc/security/limits.d/目錄下修改配置檔案90-nproc.conf
4.max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
修改配置檔案/etc/sysctl.conf
新增如下內容:vm.max_map_count = 262144
生效:~]$ sudo sysctl -p
5. system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk(這個問題沒遇到,遇到的可以採用下面方法)
這是在因為Centos6不支援SecComp,而ES5.2.0預設bootstrap.system_call_filter為true進行檢測,所以導致檢測失敗,失敗後直接導致ES不能啟動。
在elasticsearch.yml中配置bootstrap.system_call_filter為false,注意要在Memory下面:
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
重啟電腦!
啟動成功:
- 叢集配置:
node.master: true
node.data: true
discovery.zen.ping.unicast.hosts: ["bigdata01", "bigdata02", "bigdata03"]
3. ES安裝配置三(基於ElasticSearch6.5和CentOS7)
1: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
]$ sudo vim /etc/security/limits.conf
#ElasticSearch配置
* soft nofile 65536
* hard nofile 131072
2: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
]$ sudo vim /etc/sysctl.d/99-sysctl.conf
#ElasticSearch
vm.max_map_count = 262144
重啟電腦!
bin]$ ./elasticsearch
啟動成功: