Elasticsearch入门

Elasticsearch介绍

Solr和ES对比

搜索分词

  • 正排索引

  • 倒排索引

lucene简介

源数据都被抽象成Document

基础

ESearch流程:

document -> 过滤粉丝 -> 倒排索引

  • 无视数据来源,但是必须按照document规范格式.

  • 节点的分发: document id % 节点数

  • 数据汇聚:

  • 节点能力相近,不能差异太大
  • 横向扩展问题: 单点故障问题
  • 纵向扩展问题: 高可用, 主从架构

    • 从主机: 1.备份数据 2.分担主检索压力
    • 一台机器不能同时放同一个主从.
  • 创建lucene进程

集群搭建

/path/es/config/elasticsearch.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
cluster.name: es6.2
#节点名称,其余两个节点分别为node-2 和node-3
node.name: node-1
#指定该节点是否有资格被选举成为master节点,默认是true,es是默认集群中的第一台机器为master,如果这台机挂了就会重新选举master
node.master: true
#允许该节点存储数据(默认开启)
node.data: true
bootstrap.memory_lock: true
network.host: 0.0.0.0
http.port: 9200
transport.tcp.port: 9300
discovery.zen.ping.unicast.hosts: ["192.168.80.147", "192.168.80.148", "192.168.80.149"]
discovery.zen.minimum_master_nodes: 2

操作

1
2
3
4
5
6
7
8
[root@node6 ~]# scp -r es root@node8:`pwd`
[root@node6 ~]# chown -R es:es /opt/es
[root@node6 ~]# cd /opt
[root@node6 opt]# ll
total 0
drwxr-xr-x. 7 es es 131 Jan 25 14:33 elasticsearch-6.5.4
lrwxrwxrwx. 1 es es 20 Jan 25 12:19 es -> elasticsearch-6.5.4/
[root@node6 opt]# ll es/

问题:

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@node6 ~]# vim /etc/security/limits.conf
es soft memlock unlimited
es hard memlock unlimited
[root@node6 ~]# vim /etc/sysctl.conf
[root@node6 ~]# sysctl -p
vm.max_map_count = 655360
fs.file-max = 655360
[root@node6 es]# ulimit -n 65536
[root@node6 es]# ulimit -u 4096
### 依次打开
vi /etc/security/limits.conf
vi /etc/security/limits.d/20-nproc.conf
vi /etc/sysctl.conf

nvm安装: https://github.com/creationix/nvm

插件安装

1
2
3
4
5
# head
git clone git://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head
npm install
npm run start

问题: 安装head插件失败

1
2
3
4
5
6
7
PhantomJS not found on PATH
Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-linux-x86_64.tar.bz2
Saving to /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
Receiving...

###解决方案
PHANTOMJS_CDNURL=https://npm.taobao.org/mirrors/phantomjs/ npm install phantomjs-prebuilt

Rest简介

资源 GET PUT POST DELETE HEAD
URI 获取对象的当前状态 改变对象的状态 创建对象 删除对象 获取头信息
Donate comment here