Elasticsearch5.6.3 cluster installation and head, logstash offline plug-in installation

BACKGROUND:
According to the project requirements, the need for data synchronization timing mysql database into es, es build two machines so selected cluster environment, build environment involves elasticsearch, elasticsearch-head plug, logstash, logstash-input-jdbc plug
mounting environment:
operating system: CentOS Linux release 7.3.1611 (Core)
Jdk version: openJdk1.8 (needs to be installed in advance, jdk version can not be lower than 1.8)
installation package:
elasticsearch-5.6.3;
nodejs (the latest version can be), elasticsearch-head (the latest version can be);
Logstash-5.6.3 (es needs and consistent version, this version has been integrated logstash-input-jdbc plug-in, you no longer need to install the plug-in)

Elasticsearch (referred es) Installation:

1. Create elk directory / home directory, and the installation package uploaded to elk:

Create a directory command:

mkdir elk

The results are as follows:
Here Insert Picture Description

2, extract elasticsearch-5.6.3.tar.gz, obtained after extracting file folder elasticsearch-5.6.3:

Unzip command:

tar -zxvf elasticsearch-5.6.3.tar.gz
结果如下:

Here Insert Picture Description

3, modify the configuration file elasticsearch.yml es related configuration items:

#集群名称 
cluster.name: es-5.6.3 
#节点名称
node.name: node-34  
#数据存储目录(多个路径用逗号分隔)
path.data: /var/es/data
#日志目录
path.logs: /var/es/logs
#是否锁定物理内存地址
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
#修改一下ES的监听地址,这样别的机器才可以访问
network.host: 0.0.0.0
#监听端口(默认的就好)
http.port: 9200
#配置节点
discovery.zen.ping.unicast.hosts: ["192.168.1.33", "192.168.1.34"]
#配置最大主节点数
discovery.zen.minimum_master_nodes: 1
#增加新的参数,这样head插件才可以访问es
http.cors.enabled: true
http.cors.allow-origin: "*"

Note: The configuration file directory you need to create two well in advance

4. Start es

Es not start because the root user, you must create an ordinary user to start es

(1) create a user-es:
useradd es
(2) set a password for the user es:
passwd es 

Here Insert Picture Description

(3) to empower users

The user needs to operate the appropriate permissions to the file:

chown -R es /home/elk
chown -R es /var/es/data
chown -R es /var/es/logs
(4) Start es:
切换到es用户:
su es

Enter the directory: /home/elk/elasticsearch-5.6.3/bin/, reads as follows:
Here Insert Picture Description

启动es:
./elasticsearch
后台启动命令:
./elasticsearch -d

Start log is as follows:
Here Insert Picture Description

通过启动日志可以看到启动失败,有两个错误:
错误1:max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
解决方案:修改/etc/security/limits.conf配置文件,添加如下内容:

* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096

修改前:
Here Insert Picture Description
修改后:
Here Insert Picture Description

错误2:max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
解决方案:修改配置:在/etc/sysctl.conf 中加入vm.max_map_count=524288
执行命令:

vi /etc/sysctl.conf

Here Insert Picture Description

执行命令使修改生效:

sudo sysctl -p

修改后再次启动es,可以看到启动成功了
Here Insert Picture Description
验证es是否启动成功,可以打开浏览器访问如下地址:http://localhost:9200,结果发现无法访问:
Here Insert Picture Description

排查是否防火墙问题:CentoOs7通过firewall进行防火墙配置
查看防火墙状态:

systemctl status firewalld

Here Insert Picture Description

可以看到防火墙开启,我们可以关闭防火墙
关闭防火墙命令:

systemctl stop firewalld

也可以不关闭防火墙,转而开放9200端口,另外由于es一般部署在集群内,集群各节点之间是通过9300端口进行互通的,因此还要开放9300端口
永久打开9200/TCP端口:

firewall-cmd --permanent --add-port=9200/tcp

#重启防火墙,使添加的端口生效:

firewall-cmd --reload

再次访问,结果如下:
Here Insert Picture Description
至此,es安装成功!

Elasticsearch-head插件安装

Elasticsearch内有海量数据和大规模集群,但是并没有提供管理客户端,所以如果我们想要管理这些数据和集群,那么肯定得借助其他的一些工具进行管理。
而ElasticSearch-head就是一款能连接ElasticSearch搜索引擎,并提供可视化的操作页面对ElasticSearch搜索引擎进行各种设置和数据检索功能的管理插件,如在head插件页面编写RESTful接口风格的请求,就可以对ElasticSearch中的数据进行增删改查、创建或者删除索引等操作。类似于使用navicat工具连接MySQL这种关系型数据库,对数据库做操作。
下图为head插件的运行页面:
Here Insert Picture Description
下面介绍如何安装head插件:
安装思路:服务器环境经常为内网环境,不允许连接互联网,这样会让一些服务的安装变得复杂,elasticsearch-head同样如此。因此我们先在一台能联网的服务器(虚拟机即可)上进行在线安装,安装成功后再将其打包,放到内网环境上进行离线安装

第一步:在互联网环境上安装head插件,制作离线包:

1、下载nodejs,head插件

Here Insert Picture Description

2、创建head-plugin目录

mkdir /usr/inspur/head-plugin

3、将下载好的node、head上传至tools目录,解压node和head

注意,此处要将node和head放到同一个目录下

tar -zxvf node-v12.2.0-linux-x64.tar.gz
unzip elasticsearch-head-master.zip

Here Insert Picture Description

4、配置node、npm环境

ln -s /opt/tools/node-v12.2.0-linux-x64/bin/node /usr/local/bin/node 
ln -s /opt/tools/node-v12.2.0-linux-x64/bin/npm /usr/local/bin/npm

5、使用npm安装grunt

npm install -g grunt-cli

安装成功后会发现/usr/inspur/head-plugin/node-12.14.0/bin目录下多了grunt文件:
参考第二步配置grunt环境变量

ln –s /opt/tools/node-v12.2.0-linux-x64/bin/grunt /usr/local/bin/grunt	

Here Insert Picture Description

6、使用命令验证nodejs、npm、grunt安装是否成功,能够看到版本号说明安装成功

node -v
npm –v
grunt -version

Here Insert Picture Description

7、进入 elasticsearch-head 文件夹,执行命令,安装依赖的npm包

npm install grunt --save
npm install

注意:npm install 默认使用 http://www.npmjs.org 地址安装依赖,如果网络没有进行翻墙设置有时候现在第三方依赖包会出现卡死,或者安装失败的情况。使用国内镜像站点解决:
执行命令:

npm config set registry https://registry.npm.taobao.org
再次执行npm install命令就会发现安装成功

8、修改 elasticsearch-head 目录下的 Gruntfile.js 文件,在 options 属性内增加 hostname,设置为 0.0.0.0。

connect: {
  server: {
      options: {
          hostname: '0.0.0.0',
          port: 9100,
          base: '.',
          keepalive: true
      }
  }
}

9、在线安装成功后,制作离线包,打包node、head

tar zcf tools.tar.gz node-v12.14.0 elasticsearch-head	

得到离线包:es-head.tar.gz
至此,head插件离线包制作完毕!

第二步: 进行离线包的安装:

将第一步中制作好的离线包(es-head.tar.gz)拷贝到内网环境/home/elk/elasticsearch-head目录下,然后解压压缩包:
Here Insert Picture Description
进入目录/home/elk/elasticsearch-head/node-12.14.0/bin,内容如下:
Here Insert Picture Description
制作软连接:

ln -s /home/elk/elasticsearch-head/node-12.14.0/bin/node /usr/local/bin/node 
ln -s /home/elk/elasticsearch-head/node-12.14.0/bin/npm /usr/local/bin/npm
ln -s /home/elk/elasticsearch-head/node-12.14.0/bin grunt /usr/local/bin/grunt

进入/home/elk/elasticsearch-head/elasticsearch-head目录,执行命令启动head插件:

grunt server

后台启动命令:

setsid grunt server

看到如下界面说明执行成功:
Here Insert Picture Description
浏览器中访问:http://localhost:9100 // 服务器ip换成自己的即可
Here Insert Picture Description
至此,elasticsearch-head离线包安装成功!

Logstash安裝

下载与elasticsearch对应版本的Logstash安装包logstash-5.6.3.tar.gz,上传到已经创建好的目录/home/elk下,然后解压:
Here Insert Picture Description
测试logstash,执行命令:

./home/elk/logstash-5.6.3/bin/logstash -e 'input { stdin{} } output { stdout{} }'

The results are as follows:
Here Insert Picture Description
Input hello, and then press Enter:
Here Insert Picture Description
At this point, logstash successful installation!

If you want to synchronize data into mysql elasticsearch, need logstash-input-jdbc plug, the plug installation is more complex, the need now successfully installed in the Internet environment, and then packaged into packets into the network offline environment .
However, I found that downloaded within logstash-5.6.3.tar.gz have integrated logstash-input-jdbc plug-in, no need to install, and therefore no longer here to explain the installation logstash-input-jdbc widget sense interested can go online Baidu!

Published an original article · won praise 1 · views 25

Guess you like

Origin blog.csdn.net/yixiongmao/article/details/104016832