单机版 head插件安装 集群搭建:
单节点安装:
** 安装包下载
1)Elasticsearch官网: https://www.elastic.co/products/elasticsearch
1.1 新建用户
因 Elasticsearch 不能使用root的用户,所以需要新建 elasticsearch 用户。方法如:【新建用户用例】
1.2 上传及解压文件并配置文件
1)解压elasticsearch-6.6.1.tar.gz到/opt/module目录下
[root@bigdata01 software]# rz -y
[root@bigdata01 software]# tar -zxvf elasticsearch-6.1.1.tar.gz -C /opt/module/
2)在/opt/module/elasticsearch-6.6.1路径下创建data和logs文件夹
[root@bigdata01 elasticsearch-6.1.1]# mkdir ./data ./log
3)修改配置文件/opt/module/elasticsearch-6.1.1/config/elasticsearch.yml
[root@bigdata01 config]$ pwd
/opt/module/elasticsearch-6.1.1/config
[root@bigdata01 config]$ vi elasticsearch.yml
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
# Before you set out to tweak and tune the configuration, make sure you
# understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: node-01
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /opt/module/elasticsearch-6.1.1/data
#
# Path to log files:
#
path.logs: /opt/module/elasticsearch-6.1.1/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 192.168.109.111
#
# Set a custom port for HTTP:
#
#http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.zen.ping.unicast.hosts: ["host1", "host2"]
discovery.zen.ping.unicast.hosts: ["bigdata01"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes:
#
# For more information, consult the zen discovery module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
4)将文件夹设置文件所有者,切换到 elasticsearch 用户下。
[root@bigdata01 module]$ chown -R elasticsearch ./elasticsearch-6.1.1/
[root@bigdata01 module]$ ll
total 8
drwxr-xr-x 9 elasticsearch root 155 May 16 19:07 elasticsearch-6.1.1
drwxr-xr-x 8 root root 202 Mar 8 18:00 flume-1.8.0
drwxr-xr-x 11 elasticsearch elasticsearch 173 Nov 23 2019 hadoop-2.8.4
drwxr-xr-x 9 root root 171 Apr 5 08:27 hive-1.2.1
drwxr-xr-x 8 10 143 255 Jul 22 2017 jdk1.8.0_144
drwxr-xr-x 2 root root 4096 Mar 14 17:49 mysql
drwxr-xr-x 2 root root 25 Mar 20 07:40 practisedatas
drwxr-xr-x 14 root root 217 Apr 25 19:17 spark-2.1.0-bin-hadoop2.7
drwxr-xr-x 12 elasticsearch elasticsearch 4096 Mar 6 07:26 zookeeper-3.4.10
5)配置linux系统环境
(1)编辑limits.conf 添加类似如下内容
[elasticsearch@bigdata01 module]# sudo vi /etc/security/limits.conf
添加如下内容:
* soft nofile 65536
* hard nofile 131072
* soft nproc 4096
* hard nproc 4096
(2)进入limits.d目录下修改配置文件。
[elasticsearch@bigdata01 limits.d]# sudo vi /etc/security/limits.d/20-nproc.conf
修改如下内容:
soft nproc 1024
#修改为
soft nproc 4096
(3)修改配置sysctl.conf
[elasticsearch@bigdata01 limits.d]# sudo vi /etc/sysctl.conf
添加下面配置:
vm.max_map_count=655360
并执行命令:
[elasticsearch@bigdata01 limits.d]# sudo sysctl -p
vm.max_map_count = 655360
然后,重新启动elasticsearch,即可启动成功。
6)启动elasticsearch
[itstar@hadoop105 elasticsearch-5.6.1]$ bin/elasticsearch
若启动报错:Elasticsearch 常见问题
7)测试elasticsearch 是否启动成功
支持restful的API,输入以下可获得状态等信息。
curl -XGET ‘localhost:9200/_cat/health?v&pretty’
可查看全表信息。
curl -XGET ‘localhost:9200/index/_search?pretty’ -d ’
{
“query”:{match_all: {} }
}’
** 搭建常见问题:点我
集群搭建:
1)如配置单节点elasticsearch 一样,需要创建非root用户,配置linux系统环境。
2)使用 scp 命令将 elasticsearch-5.6.1 文件发送但其他需要安装的服务器节点。如
scp -r elasticsearch-6.1.1 elasticsearch@bigdata02:/opt/module/
3)修改配置文件
node.name: node-02
#修改为该服务器节点node名字,各个node节点名字不能重复
network.host: 192.168.109.111
#修改为当前节点服务器IP地址
#discovery.zen.ping.unicast.hosts: ["host1", "host2"]
discovery.zen.ping.unicast.hosts: ["bigdata01"]
#无需修改,(非主从架构),保存各个节点的信息,一般可配置为性能、资源较好的的服务器。
(1)cluster.name
如果要配置集群需要两个节点上的elasticsearch配置的cluster.name相同,都启动可以自动组成集群,这里如果不改cluster.name则默认是cluster.name=my-application
(2)nodename随意取但是集群内的各节点不能相同
(3)修改后的每行前面不能有空格,修改后的“:”后面必须有一个空格
集群搭建完毕!
head插件安装:
第一种安装方法:
安装elasticsearch-head.crx插件
Google浏览器:打开浏览器,进入“更多工具”——>“扩展程序”,将插件拖入即可完成安装
第二种安装方法:
下载插件:https://github.com/mobz/elasticsearch-head
nodejs官网下载安装包:https://nodejs.org/dist/
node-v6.9.2-linux-x64.tar.xz
拷贝
安装nodejs:
解压
配置环境变量:
export NODE_HOME=/usr/local/node-v6.9.2-linux-x64 export PATH=
P
A
T
H
:
PATH:
PATH:NODE_HOME/bin
查看node和npm版本:
node -v
npm -v
解压head插件到/opt/module目录下:
unzip elasticsearch-head-master.zip
查看当前head插件目录下有无node_modules/grunt目录:
没有:执行命令创建:npm install grunt --save --registry=https://registry.npm.taobao.org
安装head插件:
npm install -g cnpm --registry=https://registry.npm.taobao.org
安装grunt:
npm install -g grunt-cli --registry=https://registry.npm.taobao.org
编辑Gruntfile.js
vim Gruntfile.js
文件93行添加
hostname:‘0.0.0.0’
检查head根目录下是否存在base文件夹
没有:将 _site下的base文件夹及其内容复制到head根目录下
mkdir base
cp base/* …/base/
启动grunt server:
grunt server -d
如果提示grunt的模块没有安装:
Local Npm module “grunt-contrib-clean” not found. Is it installed?
Local Npm module “grunt-contrib-concat” not found. Is it installed?
Local Npm module “grunt-contrib-watch” not found. Is it installed?
Local Npm module “grunt-contrib-connect” not found. Is it installed?
Local Npm module “grunt-contrib-copy” not found. Is it installed?
Local Npm module “grunt-contrib-jasmine” not found. Is it installed?
执行以下命令:
npm install grunt-contrib-clean -registry=https://registry.npm.taobao.org
npm install grunt-contrib-concat -registry=https://registry.npm.taobao.org
npm install grunt-contrib-watch -registry=https://registry.npm.taobao.org
npm install grunt-contrib-connect -registry=https://registry.npm.taobao.org
npm install grunt-contrib-copy -registry=https://registry.npm.taobao.org
npm install grunt-contrib-jasmine -registry=https://registry.npm.taobao.org
最后一个模块可能安装不成功,但是不影响使用。
浏览器访问head插件:
http://192.168.111.104:9100