1.elasticsearch簡介
- ElasticSearch是一個基於Lucene的搜索服務器。它提供了一個分佈式多用戶能力的全文檢索引擎,基於RESTful web接口。Elasticsearch是用Java開發的,並作爲Apache許可條款下的開放源碼發佈,是當前流行的企業級搜索引擎。設計用於雲計算中,能夠達到實時搜索,穩定,可靠,快速,安裝使用方便。
2.elasticsearch官網(官網打開速度有點慢)
- elasticsearch官網下載地址:https://www.elastic.co/cn/downloads/elasticsearch
- Elasticsearch7.6.2下載地址:https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.6.2-linux-x86_64.tar.gz
3.elasticsearch下載安裝
下載elasticsearch安裝包
- yum -y install wget----------------------------(未安裝wget請先安裝)
- wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.6.2-linux-x86_64.tar.gz
解壓elasticsearch7.x
- tar -zxvf elasticsearch-7.6.2-linux-x86_64.tar.gz
運行elasticsearch7.x(出現異常信息請看下面elasticsearch7.x異常信息解決 )
- (bin目錄下)./elasticsearch -------------------------------- (啓動)
- (bin目錄下)./elasticsearch -d -------------------------------- (後臺啓動)
- curl 127.0.0.1:9200 --------------------------------------------- (訪問es)
4.elasticsearch7.x異常信息解決
異常信息一:
- OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x000000074a660000, 3046768640, 0) failed; error='Not enough space' (errno=12)
- 錯誤原因jvm內存溢出,需要修改jvm.options文件的-Xms1g-Xmx1g(根據自身機器情況修改,es運行很佔內存,建議虛擬機的話就多分配點內存,雲服務就購買運行內存大一點的機器)
- (config目錄下) vim jvm.options
- -Xms1g-Xmx1g(默認是1g)
異常信息二:
- java.lang.RuntimeException: can not run elasticsearch as root
- 錯誤原因是es不能使用root用戶進行啓動
- useradd xxx ---------------------------------------------------------- 新建用戶
- passwd xxx -----------------------------------------------------------設置密碼
- su xxx -----------------------------------------------------------切換用戶
異常信息三:
- Exception in thread "main" java.nio.file.AccessDeniedException: /home/temp/elasticsearch7.x/elasticsearch-7.6.2/config/jvm.options
- 錯誤原因該用戶沒有可執行權限
- su root ------------------------------------------------------------------ 切換回root用戶
- chmod -R 777 /home/temp/elasticsearch7.x ------------------ 給予執行權限
異常信息四:
- max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
- elasticsearch用戶擁有的內存權限太小,至少需要262144;解決方法修改sysctl.conf,追加vm.max_map_count = 655360
- su root ----------------------------------------------------(切換回root用戶在進行操作)
- vim /etc/sysctl.conf
- vm.max_map_count = 655360
- sysctl -p
異常信息五:
- 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
- 需要配置[discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes]任意一項
- (config目錄) vim elasticsearch.yml
- cluster.initial_master_nodes: ["127.0.0.0", "[::1]"]
5.設置外網訪問(出現異常信息請看異常信息四和異常信息五)
修改elasticsearch.yml配置
- (config目錄) vim elasticsearch.yml
- network.host: 0.0.0.0
- cluster.initial_master_nodes: ["127.0.0.0", "[::1]"]
這時候如果你是第一次安裝,沒有開放防火牆端口,則通過IP是無法進行連接的,阿里雲配置安全組即可!!
- firewall-cmd --permanent --add-port=9200/tcp --------------------(開放9200端口)
- firewall-cmd --reload ----------------------------------------------------- (重啓防火牆)
6.elasticsearch7.x集羣配置
- -----------------------------------node1--------------------------------------------------------
- cluster.name: my-es
- node.name: node-1
- http.port: 9200
- ----------------------------------------------------------------------------------------------------
- -----------------------------------node2--------------------------------------------------------
- cluster.name: my-es
- node.name: node-2
- http.port: 9201
- ----------------------------------------------------------------------------------------------------
- (bin目錄下)./elasticsearch -d -------------------------------- (後臺啓動)
查看是否配置成功
- curl http://127.0.0.1:9200/_cluster/health?pretty=true
ps:es集羣配置非常簡單,只要在同一網段啓動的es就會自動加入集羣配置,簡單配置只要修改下節點名稱即可(這樣配置請不要設置network.host和cluster.initial_master_nodes,不然則需要相應的配置)詳細配置如下圖
#集羣名稱 cluster.name: elasticsearch #節點名稱 node.name: node-a #是不是有資格競選主節點 node.master: true #是否存儲數據 node.data: true #最大集羣節點數 node.max_local_storage_nodes: 3 #網關地址 network.host: 192.168.11.220 #端口 http.port: 9200 #內部節點之間溝通端口 transport.tcp.port: 9300 #es7.x 之後新增的配置,寫入候選主節點的設備地址,在開啓服務後可以被選爲主節點 discovery.seed_hosts: ["192.168.11.220:9300","192.168.11.220:9301","192.168.11.220:9302"] #es7.x 之後新增的配置,初始化一個新的集羣時需要此配置來選舉master cluster.initial_master_nodes: ["node-a", "node-b","node-c"] #數據存儲路徑 path.data: /home/es/software/es/data #日誌存儲路徑 path.logs: /home/es/software/es/logs