CentOS上安装ElasticSearch5.4集群
最近学习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
这时候我们看见下面的提示,说明就成功了
执行 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.****.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.****.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