elasticsearch集群搭建、head插件安装

前言

好久没来更新博客,一是近期的状态不好,也被一些琐碎的事缠着,导致没能好好学习。

在上一篇的博客中记录了linux环境下elasticsearch的安装,比较简单,解压既可。es是分布式的搜索服务框架,只是在单机上跑体现不出它的优势,所以这篇主要来记录一下es6.x的集群搭建、以及head插件的安装。实验的环境:Ubuntu 、节点IP:10.1.13.32 10.1.13.27elasticsearch6.x

集群的搭建

在上一篇中,在32的服务器,已经搭建好了es服务,只要按部就班,在27上也搭起来即可,主要是修改elasticsearch.yml配置文件即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# ---------------------------------- Cluster -----------------------------------
#集群的名称
cluster.name: jintxes
# ------------------------------------ Node ------------------------------------
#节点名称,另外一个节点为node-2
node.name: node-1
#指定该节点是否有资格被选举成为master节点,默认是true,es是默认集群中的第一台机器为master,如果这台机挂了就会重新选举master
node.master: true
# ----------------------------------- Paths ------------------------------------
#索引数据的存储路径
path.data: /usr/local/elasticsearch/data
#日志文件的存储路径
path.logs: /usr/local/elk/elasticsearch/logs
# ---------------------------------- Network -----------------------------------
#绑定的ip地址
network.host: 0.0.0.0
#设置对外服务的http端口,默认为9200
http.port: 9200
#设置节点间交互的tcp端口,默认是9300
transport.tcp.port: 9300
# --------------------------------- Discovery ----------------------------------
#集群中节点的IP
discovery.zen.ping.unicast.hosts: ["10.1.13.27", "10.1.13.32"]
# ---------------------------------- Various -----------------------------------
xpack.security.enabled: false
http.cors.enabled: true
http.cors.allow-origin: "*"

把两台节点的es服务开起来, 浏览器查看http://10.1.13.32:9200/_cluster/health?pretty 看到下面的结果就表示集群搭建完毕。

你想输入的替代文字

head插件安装

head的插件功能可以方便我们在浏览器操作es,虽然没有solr那样的清爽的界面,但是该有的功能都具备。在安装这个插件的过程中,遇到挺多的问题,所以在这里也要记录一下。在安装head插件之前,需要先安装node,npm,grunt。head插件的运行是依赖于grunt的,而grunt的安装依赖于npm。

安装node

下载node的压缩包、解压开

1
2
3
wget https://npm.taobao.org/mirrors/node/latest-v4.x/node-v4.5.0-linux-x64.tar.gz

tar -zxvf node-v4.5.0-linux-x64.tar.gz

配置下环境变量vim /etc/profile,NODE_HOME /usr/local/填写你解压开的node路径

1
2
3
export NODE_HOME=/usr/local/node-v4.5.0-linux-x64
export PATH=$PATH:$NODE_HOME/bin/
export NODE_PATH=$NODE_HOME/lib/node_modules

执行 source /etc/profile让配置生效

1
source /etc/profile

输入node -v 查看是否安装成功

1
2
jintx@jintx-virtual-machine:~$ node -v
v4.5.0

安装npm

1
npm install -g cnpm --registry=https://registry.npm.taobao.org

npm -v查看是否安装成功

1
2
jintx@jintx-virtual-machine:~$ npm -v
2.15.9

安装grunt

1
npm install -g grunt

安装grunt-cli模块

1
npm install -g grunt-cli --registry=https://registry.npm.taobao.org --no-proxy

查看是否安装成功

1
2
root@jintxserver:/usr/local/elasticsearch/elasticsearch-6.2.3# grunt -version
grunt-cli v1.2.0

head插件下载

下载head源码

1
wget https://github.com/mobz/elasticsearch-head/archive/master.zip

解压master.zip得到elasticsearch-head-master文件夹

1
unzip master.zip

进入elasticsearch-head-master目录,执行下面命令

1
npm install

这时候目录下会多出一个node_modules的文件夹,修改head的配置文件Gruntfile.js,找到connect:server,添加hostname一项,如下

1
2
3
4
5
6
7
8
9
10
connect: {
server: {
options: {
hostname: '0.0.0.0',
port: 9100,
base: '.',
keepalive: true
}
}
}

在head目录下,启动head服务

1
2
3
4
root@jintxserver:/usr/local/elasticsearch-head-master# grunt server
Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:9100

浏览器输入 http://10.1.13.27:9100/ 看到下面的界面即成功。
你想输入的替代文字