开篇废话

没错,前面扯了一堆SQL SERVER,其实我连Elastic
Search根本没动手玩过(是不是与时代有点脱节了?),那今天我就准备尝试安装一个ELK的简单集群出来(这个集群是使用我的小米笔记本创建了两个虚拟机,虚拟出来的一个集群,没钱买阿里云)

虚拟机的操作系统实CentOS 7 64位,不同的Linux版本可能略有差异~

直接安装Elastic Search

安装Master Node

本文也是参考官网文档进行安装,大家可以直接看官网文档,一般来说,比较新一些。

官方文档:
https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started-install.html

<https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started-install.html>

1)找个合适的文件夹下载安装包:
curl -L -O https://
artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.2.0-linux-x86_64.tar.gz
友情提示,如果下载速度比较慢,可以拿迅雷这类软件下载好,上传到服务器,迅雷这类软件在下载这种热门资源的时候,还是有速度上的提升的。

2)解压下载下来的文件

本文的版本号均为7.2.0,安装不同的版本时,灵活应变就行。
tar -xvf elasticsearch-7.2.0-linux-x86_64.tar.gz
3)修改配置文件

进入解压后的elasticsearch-7.2.0 文件夹中的config文件夹,并修改elasticsearch.yml 文件中的配置:
cluster.name: jax-elk-group1 node.name: master node.master: true network.host:
0.0.0.0 http.cors.enabled: true http.cors.allow-origin: "*"
cluster.initial_master_nodes: ["master"]
此时我们在elasticsearch-7.2.0文件夹下执行


./bin/elasticsearch


由于我虚拟机内存不够大的原因,他会抛个异常:


ERROR: [2] bootstrap checks failed [1]: max file descriptors [4096] for
elasticsearch process is too low, increase to at least [65535] [2]: max virtual
memory areas vm.max_map_count [65530] is too low, increase to at least [262144]


对于第一个报错ELK官网是这么解释的:


是由于Elasticsearch需要使用大量的文件描述符或文件句柄,用完文件描述符可能是灾难性的,也有可能导致数据丢失,需要确保将运行Elasticsearch的用户能打开文件描述符数量的限制增加到65,536或更高。

官网链接在这里:
https://www.elastic.co/guide/en/elasticsearch/reference/current/file-descriptors.html

<https://www.elastic.co/guide/en/elasticsearch/reference/current/file-descriptors.html>

官网解决方案的链接:
https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-system-settings.html#limits.conf

<https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-system-settings.html#limits.conf>

然而,我照官网做了之后,并不管什么用,最终找到了一篇文章:

http://www.kxtry.com/archives/1635 <http://www.kxtry.com/archives/1635>

首先第一个问题,需要修改文件etc/security/limits.conf中的一些配置:

执行命令:
sudo vi /etc/security/limits.conf
像文件最后添加内容:
* soft nofile 65536
* hard nofile 131072 (貌似只添加这句就行)

* soft nproc 2048

* hard nproc 4096

然后退出当前的终端重新连接进入,这步非常重要,不重新进不起作用的~

第二个问题需要修改/etc/sysctl.conf中的一些配置:

执行命令:
sudo vi /etc/sysctl.conf
向文件最后添加记录:
vm.max_map_count=655360
保存并退出后执行命令:
sudo sysctl -p
这步跟上面退出终端重新进入一样重要,不执行这个配置不会生效的。

执行完这两步,然后重新执行就可以启动成功了~
./bin/elasticsearch
可以在新开一个终端执行下面命令来验证安装的成果:
curl http://服务器ip <http://服务器ip> <>:9200/
此时如果安装的没问题,会打印类似下面的内容:
{ "name" : "master", "cluster_name" : "jax-elk-group1", "cluster_uuid" :
"NtmpxdwtRQOiT8sv8bJrvg", "version" : { "number" : "7.2.0", "build_flavor" :
"default", "build_type" : "tar", "build_hash" : "508c38a", "build_date" :
"2019-06-20T15:54:18.811730Z", "build_snapshot" : false, "lucene_version" :
"8.0.0", "minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know,
for Search" }
如果你想在后台启动elastic search进程,那么可以在启动时加个 -d参数:
./bin/elasticsearch –d
到此为止,我们的Master节点(主节点)就安装完毕了

安装Slave node

接下来,我们再次来安装一台Slave节点(从节点),并且跟我们当前的Master节点组成一个Elastic search集群。

Slave节点的大部分步骤和Master节点是一样的,唯一的区别在于elasticsearch.yml 文件中的配置。
cluster.name: jax-elk-group1 node.name: node-01 network.host: 0.0.0.0
http.cors.enabled:true http.cors.allow-origin: "*"
cluster.initial_master_nodes: ["master"]discovery.zen.ping.unicast.hosts:
["192.168.154.135"]
配置的时候,需要注意以下几点:

* cluster.name 一定要跟Master节点配置的一样
* node.name 是一个唯一标识,一定不要跟Master节点配置的一样,各个不同的Salve也不要重复
* discovery.zen.ping.unicast.hosts中的IP列表是集群中其他节点的IP地址列表
到这里为止,我们整个集群都安装完成了

使用ElasticSearch-Head可视化界面

默认我们只能通过命令行或者Http的方式来操作Elastic Search,elasticsearch-head
则是一款开源的ElasticSearch管理界面,它的项目主页为:https://github.com/mobz/elasticsearch-head
<https://github.com/mobz/elasticsearch-head>

使用起来也非常简单:

* 下载他的源码,不管是使用Clone还是直接使用Github的download zip功能
* 执行命令:npm install 还原npm依赖,(依赖于Node.js和npm)
* 还原完成后,执行npm start命令启动项目
* 浏览器中打开http://localhost:9100/ <http://localhost:9100/>
* 修改浏览器中最上方的连接地址(默认是http://localhost:9200 <http://localhost:9200>)

<https://img2018.cnblogs.com/blog/602207/201907/602207-20190722213638765-707049806.png>

该项目可以在任意一台能访问到ElasticSearch的机器上安装,装在你的本地机器也可以哦~

ELK的安装就介绍到这里喽~更多的ELK的知识,还需要多多探索哦~

友情链接
KaDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:637538335
关注微信