为什么要用到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的配置文件。