在suse Linux环境下搭建ES集群

来源:互联网 发布:warframe无网络连接 编辑:程序博客网 时间:2024/05/17 19:19

想成长为大牛的小白心血帖

虚拟机:virtualbox
系统:suse Linux 11 sp3
elasticsearch:5.6.4
kibana:5.6.4

一.安装jdk1.8

参考:https://jingyan.baidu.com/album/d5c4b52bebcb64da570dc571.html?picindex=2

1.       下载地址:

http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

选择版本:jdk-8u152-linux-x64.tar.gz

2.       解压安装包

在usr目录下新建java文件夹,并将jdk-8u152-linux-x64.tar.gz拷贝到该文件夹中

cd /

cd usr

mkdir java

cd /home/suse-jiao/Downloads

mv jdk-8u152-linux-x64.tar.gz /usr/java  注释:在当前目录下将该文件移动到usr/java文件夹下

tar –zxvf jdk-8u152-linux-x64.tar.gz


3.       配置环境变量

vi /etc/profile


在文档末尾插入红框中的文字,注意间隔使用的是冒号。(注:输入i,开始插入操作,结束插入,按ESC键,然后输入:wq!  表示保存并退出)。

source /etc/profile,使环境变量配置立即生效。

4.       检测jdk安装是否成功:

javac

java -version

echo $JAVA_HOME

echo $CLASSPATH

echo $PATH

添加安装成功后的上述命令显示


二、安装elasticsearch

2.1 下载elasticsearch

在suse环境下的浏览器firefox中输入一下网址:

https://www.elastic.co/cn/downloads/elasticsearch

下载elasticsearch-5.6.4.tar.gz

获得root权限:su

在usr文件夹中新建文件夹 elasticsearch

mkdir /elasticsearch

打开elasticsearch-5.6.4.tar.gz所在文件夹:cd Downloads

将安装包移动到新建的文件夹中

mv elasticsearch-5.6.4.tar.gz  /usr/elasticsearch

在新建的文件目录下解安装包

tar –xvf elasticsearch-5.6.4.tar.gz

mv elasticsearch-5.6.4 elasticsearch-node1

 

2.2 启动elasticsearch

es 5.X无法从root用户启动,所以要新建用户

根目录下执行

useradd es-xue

chown R es-xue  /usr/elasticsearch/elasticsearch-node1/

su s-xue

然后在su-xue用户下

chmod 777 es-xue /usr/elasticsearch/elasticsearch-node1/

我的安装路径是/usr/elasticsearch/elasticsearch-node1,进入bin目录

cd  /usr/elasticsearch/elasticsearch-node1/bin

./elasticsearch                 

启动成功,如下显示


问题1.

could not find any executable java binary.Please install java in your PATH or set JAV_HOME.

解决办法:返回去检查jdk环境变量配置。

问题2

1. Error occurred during initialization of VM  

2. Could not allocate metaspace: 1073741824 bytes 

解决办法:

修改虚拟机的内存:由2G变为4G(修改虚拟机内存:关闭suse后,在virtualBox中选择   设置->系统->内存大小)

但还有其他办法,不过没看懂,参考这里http://hllvm.group.iteye.com/group/topic/39890

问题3:

如果以root身份运行将会出现以下问题

解决办法:

参考:http://blog.csdn.net/hingcheung/article/details/77144574

2.3 创建ES数据文件和日志文件

在usr/elasticsearch目录下创建ES-data,然后在ES-data下创建data和logs文件夹

在根目录下:

mkdir data

chown –R es-xue/data/

sue s-xue

cd data

mkdir –p /es/data

mkdir –p /es/logs

接下来在elasticsearch.yml中配置数据路径参数

2.4 配置elasticsearch.yml


问题1.

VI E138: Can't write viminfo file/*/.viminfo!的解决办法

受这篇博客的启发:http://blog.csdn.net/zwc946676027/article/details/46829393,对虚拟机进行了重启,清除了tmp文件

问题2:

在配置中尝试network配置中尝试network.host设置为127.0.0.1或者本机的ip地址10.0.2.15,均不可以,

启动后,如果只有本地可以访问,尝试修改配置文件 elasticsearch.yml (‘#’ 表示注释掉了)中network.host(注.配置文件格式     :冒号后要空一格) 

为network.host: 0.0.0.0      默认端口是 9200

注意:关闭防火墙 或者开放9200端口



再次启动时,不必再做对es-xue用户做elasticsearch-node1文件夹的授权,直接在elasticsearch-node1/bin目录下运行

./elasticsearch –d

表示ES后台执行,然后 curl localhost:9200  出现以下结果:



在浏览器中显示:


三、安装head插件


head  插件是最好安装的其中一个, elasticsearch  head是集群管理工具、数据可化、增工具, Elasticsearch  语句可视

 

1)      下载head插件

下载head插件源代码:https://github.com/mobz/elasticsearch-head

在root用户权限下解压到和elasticsearch-node1同级的安装路径(我的是/usr/elasticsearch)

unzip elasticsearch-head-master.zip

在root@/usr/elasticsearch下修改文件名称:mv elasticsearch-head-master head

 

2)      安装node.js

参考:https://www.cnblogs.com/valor-xh/p/6293485.html?utm_source=itdadao&utm_medium=referral

head插件的本质是一个nodejs工程,需要先安装nodejs

用Linux自带的firefox浏览器下载nodejs:http://nodejs.cn/download/

选择Linux系统64位

将下载的文件安装在和elasticsearch-node1(elasticsearch的安装目录)同级的目录下

解压node-v8.9.0-linux-x64.tar.gz

修改/etc/profile文件,在文件末尾添加



然后执行source/etc/profile




输入node –v,验证nodejs是否安装成功

输入npm –v,验证npm是否成功

修改 cd 命令进入到elasticsearch-node1/config 文件中,vi elasticsearch.yml文件下添加 :http.cors.enabled:true

http.cors.allow-origin:"*"

3)    安装grunt

root权限下:打开node安装路径,执行命令

npm install –g grunt

修改head路径下的Gruntfile.js

 

4)      安装head插件

安装head插件的过程中,遇到phantomjs not found on path问题

并且默认提供链接不能下载,在firefox中打开http://phantomjs.org/download.html

下载phantomjs-2.1.1-linux-x86_64.tar.bz2

将其拷贝到head/tmp/phantomjs中

再次安装head插件


切换用户到es-xue

安装成功,启动gruntserver

cd /head/node_modules/grunt/bin
grunt server

 

再次启动elasticsearch

cd /elasticsearch-node1/bin
./elasticsearch -d


问题: 

ERROR: bootstrap checks failed

max file descriptors [4096] for elasticsearch process likely toolow, increase to at least [65536]

原因:无法创建本地文件问题,用户最大可创建文件数太小

解决方案: 

切换到root用户,编辑limits.conf配置文件, 添加类似如下内容:

vi /etc/security/limits.conf

添加如下内容:

* soft nofile 65536

* hard nofile 131072 

* soft nproc 2048

* hard nproc 4096

注意*和字母之间的空格,否则永远不会生效。

 

备注:* 代表Linux所有用户名称(比如hadoop)保存、退出、重新登录才可生效

 

问题: 

max virtual memory areas vm.max_map_count [65530] likely too low, increase toat least [262144] 

原因:最大虚拟内存太小 

解决方案:切换到root用户下,修改配置文件sysctl.conf

vi /etc/sysctl.conf

添加下面配置:

vm.max_map_count=655360

并执行命令:

sysctl -p

然后重新启动elasticsearch,即可启动成功。


问题

max size virtual memory [4930928640] for user [es-xue] is too low, increase to [unlimited]

max size virtual memory [52729364480] for user [elastic] is too low, increase to [unlimited]

(参考:https://stackoverflow.com/questions/42510873/elasticsearch-5-x-donot-start-max-size-virtual-memory-for-user-elastic-is-too

修改/etc/security/limits.conf,添加

* hard memlock unlimited
* soft memlock unlimited
*  - as unlimited

 

参考:

Elasticsearch的前后台运行与停止(tar包方式)

linux安装Elasticsearch5.6.x详细步骤以及问题解决方案


四 安装kibana插件

4.1 安装kibana插件

kibana是一个ElasticSearch的管理工具,它也是提供了对ES集群操作的API.

下载:https://www.elastic.co/downloads/past-releases/kibana-5-6-4

版本:kibana-5.6.4   (和ElasticSearch版本一致)

Suse Linux系统下下载到本地,解压到和ElasticSearch安装同级的目录,我的是/usr/elasticsearch/

根目录下:

tar -xzf kibana-5.2.2-linux-x86_64.tar.gz

mv tar -xzf kibana-5.2.2-linux-x86_64.tar.gz kibana

es-xue

cd /usr/elasticsearch/kibana/conf

vi kibana.yml

server.host: “localhost”

elasticsearch.url=http://localhost:9201

保存并关闭配置文件后:

cd /usr/elasticsearch/kibana/bin

./kibana

kibana成功,如下所示:

 

在浏览器中输入:http://localhost:5601

5601kibana的端口


 

问题:kibanastaus: red    

根本原因是在配置kibana.yml中elasticsearch.url的值不存在,需要设置自己已经搭建好的ES链接。



五 搭建ES集群

       以上在虚拟机内将ES建好,并启动起来了可以访问了。将安装好的elasticsearch-node1复制两份,分别重命名为elasticsearch-node2和elasticsearch-node3,对三个节点进行yml文件的配置,配置参数如下:

       es-node1的elasticsearch.yml配置参数

cluster.name: elasticsearch-try node.name: es-node1node.master: truenode.data: truenode.max_local_storage_nodes: 3 path.data: /data/es/data/path.logs: /data/es/logs/ bootstrap.memory_lock: falsebootstrap.system_call_filter: false network.host: 0.0.0.0transport.tcp.port: 9303http.port: 9203 http.cors.enabled: truehttp.cors.allow-origin: "*" discovery.zen.ping.unicast.hosts:["localhost:9301"]discovery.zen.minimum_master_nodes: 1

es-node2的elasticsearch.yml配置参数

cluster.name: elasticsearch-try node.name: es-node2node.master: truenode.data: truenode.max_local_storage_nodes: 3 path.data: /data/es/data/path.logs: /data/es/logs/ bootstrap.memory_lock: falsebootstrap.system_call_filter: false network.host: 0.0.0.0transport.tcp.port: 9305http.port: 9205 http.cors.enabled: truehttp.cors.allow-origin: "*" discovery.zen.ping.unicast.hosts: ["localhost:9301"]discovery.zen.minimum_master_nodes: 1

es-node3的elasticsearch.yml配置参数

cluster.name: elasticsearch-try node.name: es-node3node.master: truenode.data: truenode.max_local_storage_nodes: 3 path.data: /data/es/data/path.logs: /data/es/logs/ bootstrap.memory_lock: falsebootstrap.system_call_filter: false network.host: 0.0.0.0transport.tcp.port: 9303http.port: 9203 http.cors.enabled: truehttp.cors.allow-origin: "*" discovery.zen.ping.unicast.hosts:["localhost:9301"]discovery.zen.minimum_master_nodes: 1




终于将三个节点在虚拟机本地建起来了,5.6.4这个版本配置起来简直是要吐血。

elasticsearch配置:http://rockelixir.iteye.com/blog/1883373

问题main error rollingfilemanager


其实是因为将data文件夹建在了根目录下,没有赋予用户es-xue访问权限,在root权限下执行命令:chown –R es-xue /data/es

问题:

No log4j2 configuration file found. Usingdefault configuration: log ging only errors to console.


在config/elasticsearch.yml中添加了node.max_local_storage_nodes: 3

然后对elasticsearch做了es-xue授权

问题:elasticsearch5.X 版本中,index的相关设置将不在yml配置文件中定义,否则会出现以下错误提示:


es 2.*和5.*的配置差别:https://my.oschina.net/u/2475483/blog/849840











 

参考:https://www.cnblogs.com/lizichao1991/p/7809156.html


原创粉丝点击