ElasticSearch5.6.5集群部署及调优、Head和Bigdesk插件安装


一、简介

Elasticsearch是一个基于Apache Lucene的开源搜索引擎。无论在开源还是专有领域,Lucene可以被认为是迄今为止最先进、性能最好的、功能最全的搜索引擎库。

Elasticsearch不仅仅是Lucene和全文搜索,我们还能这样去描述它:

·       分布式的实时文件存储,每个字段都被索引并可被搜索

·        分布式的实时分析搜索引擎

·        可以扩展到上百台服务器,处理PB级结构化或非结构化数据


二、环境准备

主机 系统 配置 IP
node1 Centos7.4 CPU*2-MEM*4G 172.16.10.172
node2 Centos7.4 CPU*2-MEM*4G 172.16.10.190
node3 Centos7.4 CPU*2-MEM*4G 172.16.10.193

系统前期优化:(三台服务器分别按以下调试)

1.安装常用软件

yum install -y  ntpdate net-tools vim  lrzsz unzip gcc gcc-c++

2.关闭FirewalldNetworkManagerSelinux

systemctl stop firewalld

systemctl disable firewalld

systemctl stop NetworkManager

systemctl disable NetworkManager

setenforce 0                 

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux

3.时间同步

echo "0 */3 * * * /usr/sbin/ntpdate ntp5.aliyum.com >/dev/null 2>&1; /sbin/hwclock -w">>/etc/crontab

4.PAM认证

vim/etc/security/limit.conf     #追加到配置文件

*           soft   nofile       102400

*           hard   nofile       102400

*           soft   nproc        102400

*           hard   nproc        102400

5.增加虚拟内存

Vim  /etc/sysctl.conf #追加到配置文件

vm.max_map_count=655360

使用sysctl –p刷新配置

6.配置免密码登陆:

[root@node1 ~]# ssh-keygen

[root@node1 ~]# ssh-copy-id 172.16.10.190

[root@node1 ~]# ssh-copy-id 172.16.10.193

7.配置hosts

172.16.10.172 node1

172.16.10.190 node2

172.16.10.193 node3

8.注意:

es(elasticsearch)版本2.x以上需要JDK 1.8以上
运行es不能使用root用来来运行
es目录必须指定一个普通用户和组(授权)
es对内存和CPU的消耗比较高
es使用的端口看开放iptables:9200,9300等
es配置其他插件实现资源等可视化监控
es的版本和插件之间版本要匹配


三、Jdk安装:

软件包:jdk-8u171-linux-x64.tar.gz

tar xf jdk-8u171-linux-x64.tar.gz -C /usr/local/

cd /usr/local/

mv jdk1.8.0_171/ jdk1.8

cat /etc/profile.d/jdk8.sh

export JAVA_HOME=/usr/local/jdk1.8

export CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/jar/tools.jar:$JAVA_HOME/jre/lib

export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH

source /etc/profile.d/jdk8.sh

验证:java –version


四、ElasticSearch集群安装

软件包:elasticsearch-5.6.5.tar.gz

注意:ElasticSearch安装不能用root用户安装三台服务器分别按以下调试

1.新建用户、组

groupadd es

useradd es -g es

2.解压、创建目录、授权

tar xf elasticsearch-5.6.5.tar.gz -C /usr/local/

cd /usr/local/

mv elasticsearch-5.6.5 elasticsearch

mkdir /usr/local/elasticsearch/data/

mkdir /usr/local/elasticsearch/logs/

chown -R es.es /usr/local/elasticsearch

3.elasticsearch目录介绍

目录

作用

/bin

运行es实例和管理插件的一些脚本

/config

配置文件路径,包含elasticsearch.yml

/data

在节点上每个索引/碎片的数据文件的位置,可以多个目录

/lib

Es使用的库

/logs

日志存放目录

/plugins

已经安装的插件存放位置

/modules

模块目录

4.修改配置文件elasticsearch.yml(内置调优)

#node1配置文件

cd /usr/local/elasticsearch/config

[root@node1 config]# cat elasticsearch.yml |egrep -v "^#|^$"

cluster.name: es-cluster

node.name: node-1

path.data: /usr/local/elasticsearch/data/

path.logs: /usr/local/elasticsearch/logs/

bootstrap.memory_lock: true

bootstrap.system_call_filter: false

network.host: 172.16.10.172

http.port: 9200

http.compression: true

discovery.zen.ping.unicast.hosts: ["172.16.10.172:9300", "172.16.10.190:9300","172.16.10.193:9300"]

discovery.zen.minimum_master_nodes: 2

http.cors.enabled: true

http.cors.allow-origin: "*"


#node2配置文件

[root@node2 config]# egrep -v "^#|^$" elasticsearch.yml

cluster.name: es-cluster

node.name: node-2

path.data: /usr/local/elasticsearch/data/

path.logs: /usr/local/elasticsearch/logs/

bootstrap.memory_lock: true

bootstrap.system_call_filter: false

network.host: 172.16.10.190

http.port: 9200

http.compression: true

discovery.zen.ping.unicast.hosts: ["172.16.10.172:9300", "172.16.10.190:9300","172.16.10.193:9300"]

discovery.zen.minimum_master_nodes: 2

http.cors.enabled: true

http.cors.allow-origin: "*"


#node3配置文件

[root@node3 config]# egrep -v "^#|^$" elasticsearch.yml

cluster.name: es-cluster

node.name: node-3

path.data: /usr/local/elasticsearch/data/

path.logs: /usr/local/elasticsearch/logs/

bootstrap.memory_lock: true

bootstrap.system_call_filter: false

network.host: 172.16.10.193

http.port: 9200

http.compression: true

discovery.zen.ping.unicast.hosts: ["172.16.10.172:9300", "172.16.10.190:9300","172.16.10.193:9300"]

discovery.zen.minimum_master_nodes: 2

http.cors.enabled: true

http.cors.allow-origin: "*


解释说明:

cluster.name 集群名字,同一个集群中使用相同名字,单机就随意

node.name: node-1 节点名字 

path.data:分配给当前节点的索引数据所在的位置:

path.logs:日志文件所在位置

bootstrap.memory_lock: true:设置为true,memory_lock来锁定物理内存,避免使用内存交换(SWAP)来提高性能(elasticsearch 2.4版本后)

(bootstrap.mlockall: true:这个是坑,如果加入配置,服务将无法启动,原因无法找到这个参数,这个参数是在elasticsearch 2.4之前版本才有)

bootstrap.system_call_filter:系统环境检测,设置关闭防止导致es无法启动

network.host:ES节点网络地址

http.port:Http传输监听定制端口:默认是9200

http.compression:web服务器和浏览器客户端传送数据时,将网页数据/客户端响应数据在发送给对方前先进行压缩再传输

discovery.zen.ping.unicast.hosts:设置集群中master节点的初始列表

discovery.zen.minimum_master_nodes:设置参数来保证集群中的节点可以通知其他N个有master资格节点,默认 1 

http.cors.enabled和http.cors.allow-origin:允许head插件通过web访问


注:

node.master: true:指定该节点是否有资格被选举成为node,默认是true,es是默认集群中的第一台机器为master,如果这台机挂了就会重新选举master。

node.data: true:指定该节点是否存储索引数据,默认为true

#3种配置高性能集群拓扑结构的模式,如下: 
a.如果你想让节点从不选举为主节点,只用来存储数据,可作为负载器 
node.master: false 
node.data: true 
b.如果想让节点成为主节点,且不存储任何数据,并保有空闲资源,可作为协调器 
node.master: true 
node.data: false 
c. 如果想让节点既不称为主节点,又不成为数据节点,那么可将他作为搜索器,从节点中获取数据,生成搜索结果等 
node.master: false 
node.data: false 


5.启动elasticsearch 

su -  eselasticsearch

nohup /usr/local/elasticsearch/bin/elasticsearch & 

tail -f nohup.out 

集群效果图:

image.png

6.访问:http://172.16.10.172:9200/

{

  "name" : "node-1",

  "cluster_name" : "es-cluster",

  "cluster_uuid" : "y1PDOlDvQ5eRDRl0TANUsQ",

  "version" : {

    "number" : "5.6.5",

    "build_hash" : "1a2f265",

    "build_date" : "2017-10-06T20:33:39.012Z",

    "build_snapshot" : false,

    "lucene_version" : "6.6.1"

  },

  "tagline" : "You Know, for Search"

五、ElasticSearch-Head安装

Head插件介绍:

head插件是一个elasticsearch的集群管理工具,相交互的Web前台,它是完全由html5编写的独立网页程序。

#ES-Head主要作用

    a.它展现ES集群的拓扑结构,并且可以通过它来进行索引(Index)和节点(Node)级别的操作

    b.它提供一组针对集群的查询API,并将结果以json和表格形式返回

    c.它提供一些快捷菜单,用以展现集群的各种状态

head插件的安装(head 插件不能放在elasticsearch-5.6.5文件夹里,head 插件需要单独放,单独去执行)

yum -y install unzip zip openssl-devel wget

1.解压head

unzip elasticsearch-head-master.zip -d /usr/local/

2.安装node

tar xf node-v10.8.0-linux-x64.tar.gz

mv node-v10.8.0-linux-x64 /usr/local/node

ln -s /usr/local/node/bin/*  /usr/local/bin

3.验证是否安装配置成功:

node -v

4.安装grunt

cd  elasticsearch-head-master/

npm install -g grunt-cli  //执行后会生成node_modules文件夹

npm install --ignore-scripts

5.修改vim Gruntfile.js文件:增加hostname属性,设置为*

connect: {

    server: {

        options: {

            port: 9100,

            hostname: '*',

            base: '.',

            keepalive: true

        }

    }

}

6.修改 vim _site/app.js 文件:修改head的连接地址:

this.base_uri = this.config.base_uri || this.prefs.get(“app-base_uri”) || “http://localhost:9200“;

修改成ElasticSearch的机器地址

this.base_uri = this.config.base_uri || this.prefs.get(“app-base_uri”) || “http://172.16.10.172:9200“;

7.执行命令启动 head

cd /usr/local/elasticsearch-head-master/node_modules/grunt/bin

grunt server

后台启动命令(建议后台启动,查看out.log启动情况)

nohup grunt server &

8.访问http://172.16.10.172:9100/

image.png
六、ElasticSearch-Bigdesk安装

Bigdesk介绍

bigdesk是elasticsearch的一个集群监控工具,可以通过它来查看集群的各种状态,如:cpu、内存使用情况,索引数据、搜索情况,http连接数等。

注:至少两台这个工具才可用

1.下载软件包

[root@node1 elasticsearch]# cd plugins/

[root@node1 plugins]# git clone https://github.com/hlstudio/bigdesk

[root@node1 plugins]#cd /usr/local/elasticsearch/plugins/bigdesk/_site

2.启动bigdesk

[root@node1 _site]# python -m SimpleHTTPServe

3.访问:http://172.16.10.172:8000

连接之前:

image.png
连接之后:

image.png

image.png



结尾

       经过几天阅读相关资料,部署过程踩了很多坑,本文实践多次测试整理具有参考价值,以上过程内置调优参数,调优建议根据生产需求和官方文档进行调整相关参数,建议按照本文步骤流程实施部署,少走弯路少采坑。后续继续创建数据模拟、调优和模拟ES脑裂等等。本文纯属个人笔记,欢迎各位大佬指点指导。推荐架构:Elasticsearch + Logstash + Kibana(ELK)。


猜你喜欢

转载自blog.51cto.com/11895569/2157450
今日推荐