倒排索引
由属性值来确定记录的位置,因而称为倒排索引(类似hadoop统计单词个数,加入了单词出现的文档编号和频率)
elasticsearch的全文搜索支持相似度及权重配置(略)
Elasticsearch集群
通过cluster.name设置集群名称,每个节点通过node.name指定节点的名称。
节点的类型主要有4种:
- master节点
配置文件中node.master属性为true(默认为true),就有资格被选为master节点。
master节点用于控制整个集群的操作。比如创建或删除索引,管理其它非master节点等。
- data节点
配置文件中node.data属性为true(默认为true),就有资格被设置成data节点。
data节点主要用于执行数据相关的操作。比如文档的CRUD。
- 客户端节点
配置文件中node.master属性和node.data属性均为false。不能作为master节点,也不能作为data节点。
可以作为客户端节点,用于响应用户的请求,把请求转发到其他节点
- 部落节点
当一个节点配置tribe.*的时候,它是一个特殊的客户端,它可以连接多个集群,在所有连接的集群上执
行搜索和其他操作。
集群搭建
mkdir -p /haoke/es-cluster/node01
docker cp elasticsearch:/usr/share/elasticsearch/config/elasticsearch.yml /root/elasticsearch.yml
cp elasticsearch.yml /haoke/es-cluster/node01/elasticsearch.yml
docker cp elasticsearch:/usr/share/elasticsearch/config/jvm.options /root/jvm.options
cp jvm.options /haoke/es-cluster/node01/jvm.options
vi /haoke/es-cluster/node01/elasticsearch.yml (minimum_master_nodes,官方推荐:(N/2)+1,N为集群中节点数)
cluster.name: es-itcast-cluster
network.host: 0.0.0.0
network.publish_host: 172.26.10.222
node.name: node01
node.master: true
node.data: true
http.port: 9200
transport.tcp.port: 9300
discovery.zen.ping.unicast.hosts: ["172.26.10.222:9300","172.26.10.223:9300"]
discovery.zen.minimum_master_nodes: 1
http.cors.enabled: true
http.cors.allow-origin: "*"
chmod 777 node01/
mkdir -p /haoke/es-cluster/node01/data
chmod 777 /haoke/es-cluster/node01/data
复制一份虚拟机
cp node01 node02
chmod 777 node02/
rm -rf node02/data
mkdir -p /haoke/es-cluster/node02/data
chmod 777 /haoke/es-cluster/node02/data
vi /haoke/es-cluster/node02/elasticsearch.yml
cluster.name: es-itcast-cluster
network.host: 0.0.0.0
network.publish_host: 172.26.10.223
node.name: node02
node.master: true
node.data: true
http.port: 9200
transport.tcp.port: 9300
discovery.zen.ping.unicast.hosts: ["172.26.10.222:9300","172.26.10.223:9300"]
discovery.zen.minimum_master_nodes: 1
http.cors.enabled: true
http.cors.allow-origin: "*"
#创建容器
docker create --name es-node01 --net host \
-v /haoke/es-cluster/node01/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v /haoke/es-cluster/node01/jvm.options:/usr/share/elasticsearch/config/jvm.options \
-v /haoke/es-cluster/node01/data:/usr/share/elasticsearch/data elasticsearch:6.5.4
docker create --name es-node02 --net host \
-v /haoke/es-cluster/node02/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v /haoke/es-cluster/node02/jvm.options:/usr/share/elasticsearch/config/jvm.options \
-v /haoke/es-cluster/node02/data:/usr/share/elasticsearch/data elasticsearch:6.5.4
#启动容器
--docker start es-node01 && docker logs -f es-node01
--docker start es-node02 && docker logs -f es-node02
报错:max virtual memory areas vm.max_map_count [65530] is too low, increase to at least
vi /etc/sysctl.conf
vm.max_map_count=655360
sysctl -p
docker start es-node01 && docker logs -f es-node01
docker start es-node02 && docker logs -f es-node02