爲什麼要用到ES集羣:
橫向可擴展性:只需要增加一臺服務器,做一點兒配置,啓動一下ES進程就可以併入集羣;
分片機制提供更好的分佈性:同一個索引分成多個分片(sharding),這點類似於HDFS的塊機制;分而治之的方式來提升處理效率,相信大家都不會陌生;
高可用:提供複製(replica)機制,一個分片可以設置多個複製,使得某臺服務器宕機的情況下,集羣仍舊可以照常運行,並會把由於服務器宕機丟失的複製恢復到其它可用節點上;這點也類似於HDFS的複製機制(HDFS中默認是3份複製);
ES集羣安裝:
[1].部署環境
節點名稱 | 服務器 | 端口 | 路徑 |
主節點 | 10.10.11.41 | 9200 | /opt/elasticsearch/elasticsearch-5.6.3 |
從節點 | 10.10.11.42 | 9200 | /opt/elasticsearch/elasticsearch-5.6.3 |
從節點 | 10.10.11.43 | 9200 | /opt/elasticsearch/elasticsearch-5.6.3 |
[2].安裝步驟
每個服務器都需要按照以下步驟
(1).下載
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.3.tar.gz
(2).解壓
tar -zxvf elasticsearch-5.6.3.tar.gz
(3).修改配置文件
vi (自己的地址)/elasticsearch-5.6.3/config/elasticsearch.yml
1.主節點配置(10.10.11.41)
cluster.name: es-cluster
node.name: node-01
node.master: true
node.data: true
http.port: 9200
discovery.zen.ping.unicast.hosts: ["10.10.11.41","10.10.11.42","10.10.11.43"]
#discovery.zen.ping.multicast.enabled: true
discovery.zen.minimum_master_nodes: 1
network.host: 10.10.11.41
http.cors.enabled: true
http.cors.allow-origin: "*"
2.從節點配置(10.10.11.42)
cluster.name: es-cluster
node.name: node-02
node.master: false
node.data: true
http.port: 9200
discovery.zen.ping.unicast.hosts: ["10.10.11.41"]
#discovery.zen.ping.multicast.enabled: true
discovery.zen.minimum_master_nodes: 1
network.host: 10.10.11.42
http.cors.enabled: true
http.cors.allow-origin: "*"
3.從節點配置(10.10.11.43)
cluster.name: es-cluster
node.name: node-03
node.master: false
node.data: true
http.port: 9200
discovery.zen.ping.unicast.hosts: ["10.10.11.41"]
#discovery.zen.ping.multicast.enabled: true
discovery.zen.minimum_master_nodes: 2
network.host: 10.10.11.43
http.cors.enabled: true
http.cors.allow-origin: "*"
[3].關閉防火牆
自己選擇:
關閉防火牆命令:systemctl stop firewalld.service
關閉開機自啓動:systemctl disable firewalld.service
[4].修改最大文件數以及內存
sudo vim /etc/security/limits.conf
在文件最後加入:
* soft nofile 65536
* hard nofile 65536
* soft nproc 10240
* hard nproc 10240
vm.max_map_count=655360
Root 用戶修改 max_map_count
sudo vim /etc/sysctl.conf
在文件最後加入
vm.max_map_count=655360
並執行命令:
sudo sysctl -p
[5].啓動
sh bin/elasticsearch &
[6].遇坑處理
https://blog.csdn.net/zhang89xiao/article/details/68925294
[7].python3安裝
https://www.cnblogs.com/rookie404/p/6142151.html
[8].使用PIP安裝mongo-connector
pip3.6 install 'mongo-connector[elastic5]'
開啓mongo-connector
sudo mongo-connector -m 10.10.13.101:20002 -t 10.10.13.101:9200 -d elastic2_doc_manager &
命令詳解
-m mongodb_host:port —— 數據源地址,mongodb數據庫地址。
-t target_host:port —— 數據目的地地址,elasticsearch/solr/mongodb集羣地址。建議爲集羣中的協調節點的地址。
-d xxx_doc_manager —— 數據目的地的document類型。例如:
將mongodb中的數據同步到elasticsearch,使用elastic_doc_manager或elastic2_doc_manager。
將mongodb中的數據同步到solr,使用solr_doc_manager。
將mongodb中數據同步到其他mongodb,使用mongo_doc_manager。
-n db.collection —— 待同步的數據庫及其collection。默認同步所有數據庫。
-i filed_name —— 待同步的字段。默認同步所有字段。
-o mongodb_oplog_position.oplog —— mongo-connector的oplog。默認在mongo-connector命令執行目錄下
創建oplog.timestamp文件。
建議重新分配存儲位置(也可重新分配存儲文件名),例如 /opt/mongo-connector.oplog。
--auto-commit-interval —— 數據同步間隔。默認在不同系統上有不同的值。設置爲0表示mongodb中的任何操作立即同步到數據目的地。
--continue-on-error —— 一條數據同步失敗,日誌記錄該失敗操作,繼續後續同步操作。默認爲中止後續同步操作。
其他參數包括設置日誌輸出行爲(時間、間隔、路徑等)、設置mongodb登錄賬戶和密碼、設置(數據目的地)Http連接的證書等、
設置mongo-connector的配置文件。