CentOS上安装ElasticSearch5.4集群

来源:互联网 发布:linux执行了bin文件 编辑:程序博客网 时间:2024/05/18 19:20

最近学习Elasticsearch,顺便记录下操作步骤,供日后参考

安装环境 CentOS release 6.6

1、因Elasticsearch是基于java写的,所以它的运行环境中需要java的支持,在Linux下执行命令:java -version,检查Jar包是否安装

安装java版本至少是1.8以上


2、首先准备下载Elasticsearch5.5.2 安装包

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.2.2.tar.gz


3、下载到/usr/local 目录下,解压

tar -zxvf  elasticsearch-5.2.2.tar.gz


4、因为Elasticsearch5.0之后,不能使用root账户启动,我们先创建一个elasticsearch组和账户

useradd  elasticsearch -g elasticsearch -p elasticsearch

chown -R elasticsearch:elasticsearch elasticsearch-5.2.2


5、启动elasticsearch

cd /usr/local/elasticsearch5.2.2/

su elasticsearch

./bin/elasticsearch


这时候我们看见下面的提示,说明就成功了

[plain] view plain copy
 print?
  1. [elasticsearch@vmlnx-sma bin]$ ./elasticsearch  
  2. [2017-03-02T21:43:21,185][INFO ][o.e.n.Node               ] [] initializing ...  
  3. [2017-03-02T21:43:21,264][INFO ][o.e.e.NodeEnvironment    ] [uY3prpy] using [1] data paths, mounts [[/ (/dev/mapper/VolGroup-lv_root)]], net usable_space [43.5gb], net total_space [54.6gb], spins? [possibly], types [ext4]  
  4. [2017-03-02T21:43:21,265][INFO ][o.e.e.NodeEnvironment    ] [uY3prpy] heap size [1.9gb], compressed ordinary object pointers [true]  
  5. [2017-03-02T21:43:21,268][INFO ][o.e.n.Node               ] node name [uY3prpy] derived from node ID [uY3prpyqTHim5twauiVWhQ]; set [node.name] to override  
  6. [2017-03-02T21:43:21,271][INFO ][o.e.n.Node               ] version[5.2.2], pid[5602], build[f9d9b74/2017-02-24T17:26:45.835Z], OS[Linux/3.10.5-3.el6.x86_64/amd64], JVM[Oracle Corporation/OpenJDK 64-Bit Server VM/1.8.0_121/25.121-b13]  
  7. [2017-03-02T21:43:22,226][INFO ][o.e.p.PluginsService     ] [uY3prpy] loaded module [aggs-matrix-stats]  
  8. [2017-03-02T21:43:22,226][INFO ][o.e.p.PluginsService     ] [uY3prpy] loaded module [ingest-common]  
  9. [2017-03-02T21:43:22,226][INFO ][o.e.p.PluginsService     ] [uY3prpy] loaded module [lang-expression]  
  10. [2017-03-02T21:43:22,227][INFO ][o.e.p.PluginsService     ] [uY3prpy] loaded module [lang-groovy]  
  11. [2017-03-02T21:43:22,227][INFO ][o.e.p.PluginsService     ] [uY3prpy] loaded module [lang-mustache]  
  12. [2017-03-02T21:43:22,227][INFO ][o.e.p.PluginsService     ] [uY3prpy] loaded module [lang-painless]  
  13. [2017-03-02T21:43:22,228][INFO ][o.e.p.PluginsService     ] [uY3prpy] loaded module [percolator]  
  14. [2017-03-02T21:43:22,228][INFO ][o.e.p.PluginsService     ] [uY3prpy] loaded module [reindex]  
  15. [2017-03-02T21:43:22,228][INFO ][o.e.p.PluginsService     ] [uY3prpy] loaded module [transport-netty3]  
  16. [2017-03-02T21:43:22,229][INFO ][o.e.p.PluginsService     ] [uY3prpy] loaded module [transport-netty4]  
  17. [2017-03-02T21:43:22,230][INFO ][o.e.p.PluginsService     ] [uY3prpy] no plugins loaded  
  18. [2017-03-02T21:43:24,689][INFO ][o.e.n.Node               ] initialized  
  19. [2017-03-02T21:43:24,689][INFO ][o.e.n.Node               ] [uY3prpy] starting ...  
  20. [2017-03-02T21:43:24,929][INFO ][o.e.t.TransportService   ] [uY3prpy] publish_address {10.245.250.65:9300}, bound_addresses {10.245.250.65:9300}  
  21. [2017-03-02T21:43:24,948][INFO ][o.e.b.BootstrapChecks    ] [uY3prpy] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks  
  22. [2017-03-02T21:43:28,010][INFO ][o.e.c.s.ClusterService   ] [uY3prpy] new_master {uY3prpy}{uY3prpyqTHim5twauiVWhQ}{AqALBH68RCucWcPmHCE6dw}{10.245.250.65}{10.245.250.65:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)  
  23. [2017-03-02T21:43:28,034][INFO ][o.e.h.HttpServer         ] [uY3prpy] publish_address {10.245.250.65:9200}, bound_addresses {10.245.250.65:9200}  
  24. [2017-03-02T21:43:28,034][INFO ][o.e.n.Node               ] [uY3prpy] started  
  25. [2017-03-02T21:43:28,061][INFO ][o.e.g.GatewayService     ] [uY3prpy] recovered [0] indices into cluster_state  


执行 curl http://localhost:9200


打开另一个终端进行测试:
curl 'http://localhost:9200/?pretty'


你能看到以下返回信息:


{
   "status": 200,
   "name": "Shrunken Bones",
   "version": {
      "number": "1.4.0",
      "lucene_version": "4.10"
   },
   "tagline": "You Know, for Search"
}


说明安装成功。

但是我们希望能够使用ip访问,那么还需要设置相关内容

跳转到Elasticsearch的config配置文件下,使用vim打开elasticsearch.yml,找到里面的"network.host",将其改为本机IP,保存。


cd elasticsearch/config/


vim elasticsearch.yml


重启ElasticSearch,然后使用http://192.168.37.137:9200/访问。


我们常见错误:


1、启动 elasticsearch 如出现异常  can not run elasticsearch as root  

解决方法:创建ES 账户,修改文件夹 文件 所属用户 组


2、启动异常:ERROR: bootstrap checks failed
system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk


问题原因:因为Centos6不支持SecComp,而ES5.2.1默认bootstrap.system_call_filter为true进行检测,所以导致检测失败,失败后直接导致ES不能启动。详见 :https://github.com/elastic/elasticsearch/issues/22899


解决方法:在elasticsearch.yml中配置bootstrap.system_call_filter为false,注意要在Memory下面:
bootstrap.memory_lock: false
bootstrap.system_call_filter: false


3、启动后,如果只有本地可以访问,尝试修改配置文件 elasticsearch.yml
中network.host(注意配置文件格式不是以 # 开头的要空一格, : 后要空一格)
为 network.host: 0.0.0.0

默认端口是 9200

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


4、ERROR: bootstrap checks failed


max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
max number of threads [1024] for user [lishang] likely too low, increase to at least [2048]

解决方法:切换到root用户,编辑limits.conf 添加类似如下内容


vi /etc/security/limits.conf 


添加如下内容:


* soft nofile 65536


* hard nofile 131072


* soft nproc 2048


* hard nproc 4096


5、max number of threads [1024] for user [lish] likely too low, increase to at least [2048]


解决:切换到root用户,进入limits.d目录下修改配置文件。


vi /etc/security/limits.d/90-nproc.conf 


修改如下内容:


* soft nproc 1024


#修改为


* soft nproc 2048




6、max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]


解决:切换到root用户修改配置sysctl.conf


vi /etc/sysctl.conf 


添加下面配置:


vm.max_map_count=655360


并执行命令:


sysctl -p


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






问题一:警告提示

[2016-11-06T16:27:21,712][WARN ][o.e.b.JNANatives ] unable to install syscall filter: 

java.lang.UnsupportedOperationException: seccomp unavailable: requires kernel 3.5+ with CONFIG_SECCOMP and CONFIG_SECCOMP_FILTER compiled in
at org.elasticsearch.bootstrap.Seccomp.linuxImpl(Seccomp.java:349) ~[elasticsearch-5.0.0.jar:5.0.0]
at org.elasticsearch.bootstrap.Seccomp.init(Seccomp.java:630) ~[elasticsearch-5.0.0.jar:5.0.0]

报了一大串错误,其实只是一个警告。

解决:使用心得linux版本,就不会出现此类问题了。

 

问题二:ERROR: bootstrap checks failed

max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
max number of threads [1024] for user [lishang] likely too low, increase to at least [2048]

解决:切换到root用户,编辑limits.conf 添加类似如下内容

vi /etc/security/limits.conf 

添加如下内容:

* soft nofile 65536

* hard nofile 131072

* soft nproc 2048

* hard nproc 4096

 

问题三:max number of threads [1024] for user [lish] likely too low, increase to at least [2048]

解决:切换到root用户,进入limits.d目录下修改配置文件。

vi /etc/security/limits.d/90-nproc.conf 

修改如下内容:

* soft nproc 1024

#修改为

* soft nproc 2048

 

问题四:max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]

解决:切换到root用户修改配置sysctl.conf

vi /etc/sysctl.conf 

添加下面配置:

vm.max_map_count=655360

并执行命令:

sysctl -p

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





一、 安装JDK


1.1下载安装

cd /usr/local/src

tar -zxvf jdk-8u131-linux-x64.tar.gz

mv jdk1.8.0_131 /usr/local/java

 

1.2修改配置文件

vim /etc/profile                      //最后面添加

export JAVA_HOME=/usr/local/java

CLASSPATH=/usr/local/java/lib/dt.jar/usr/local/java/lib/tools.jar

PATH=/usr/local/java/bin:$PATH

export PATH JAVA_HOMECLASSPATH

source /etc/profile     //导入配置文件

java -version              //查看java版本

 

二、安装Elasticsearch


官网:https://www.elastic.co/downloads

参考:http://blog.csdn.net/u013365215/article/details/70159159


2.1下载安装

cd /usr/local/src/

curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.4.0.tar.gz

tar -xvf elasticsearch-5.4.0.tar.gz

mv elasticsearch-5.4.0 /usr/local/

cd /usr/local/elasticsearch-5.4.0/


2.2系统调优

1)配置系统最大打开文件描述符数

vim /etc/sysctl.conf

vm.max_map_count = 262144

执行以下命令生效

sysctl -p

 

2)配置进程最大打开文件描述符

vim /etc/security/limits.conf           //文件最后

* soft nofile 65536

* hard nofile 65536

 

2.3编写ES Master节点配置文件

vim config/elasticsearch.yml

cluster.name: my-es

node.name: node-1

network.host: 192.168.19.141

http.port: 9200

transport.tcp.port: 9300

discovery.zen.ping.unicast.hosts: ["192.168.19.141","192.168.19.142","192.168.19.143"]

discovery.zen.minimum_master_nodes: 2

#避免出现跨域问题

http.cors.enabled: true

http.cors.allow-origin: "*"

第二个、第三个节点的配置只需修改成对应的即可。


2.4启动ES

用root账号启动会报错:java.lang.RuntimeException: can not runelasticsearch as root

技术分享

                        

因为Elasticsearch5.0之后,不能使用root账户启动,我们先创建一个elasticsearch组和账户:

groupadd elsearch

useradd elsearch -g elsearch -p elasticsearch

chown -R elsearch.elsearch /usr/local/elasticsearch-5.4.0/


后台启动:

su -elsearch -c "/usr/local/elasticsearch-5.4.0/bin/elasticsearch -d"

技术分享


2.5安装head开源插件

参考:http://blog.csdn.net/ronmy/article/details/63685254

只在master上安装插件即可。elasticsearch5不可以直接通过plugin -install mobz/elasticsearch-head安装,并且head需要在node环境下运行,具体步骤如下:


第一步:安装node

curl -sL -o /etc/yum.repos.d/khara-nodejs.repohttps://copr.fedoraproject.org/coprs/khara/nodejs/repo/epel-7/khara-nodejs-epel-7.repo

yum install -y nodejs nodejs-npm

查看安装版本

技术分享

 

第二步:安装grunt

cd /usr/lib/node_modules/npm/

npm install grunt-cli

npm install grunt

查看版本:

/usr/lib/node_modules/npm/node_modules/.bin/grunt -version

技术分享


第三步:安装head

yum install -y git

cd /usr/local/

git clone git://github.com/mobz/elasticsearch-head.git

cd elasticsearch-head/

npm install

注意:这步可以会有一些报错信息,可以忽略。

 

vim _site/app.js

# 修改 『http://localhost:9200』字段到本机ES端口与IP

技术分享

 

第四步:启动head并在后台运行

./node_modules/grunt/bin/gruntserver &

技术分享


浏览器访问:

技术分享

注意:若不能形成集群,可能是 iptables 或者 selinux 的原因

 

2.6开机自启

vim /etc/rc.local

su - elsearch -c "/usr/local/elasticsearch-5.3.1/bin/elasticsearch -d"

/usr/local/elasticsearch-head/node_modules/grunt/bin/grunt server &

保存退出后,给自启文件赋予执行权限(若不加,Centos7不会开机执行)

chmod +x /etc/rc.d/rc.local

原创粉丝点击