因为Elasticsearch
是 java
开发的,所以需要先安装 java
,才能正常运行 Elasticsearch
java
的下载地址: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
将安装软件下载到指定目录下,并解压下载下来的jdk
cd /usr/local/src
wget http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
tar -zxf jdk-8u101-linux-x64.tar.gz
解压后编辑/etc/profile文件
vim /etc/profile
在文件的末尾处加上以下代码
export JAVA_HOME=/usr/local/src/jdk1.8.0_111
export JAVA_BIN=/usr/local/src/jdk1.8.0_111/bin
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME JAVA_BIN PATH CLASSPATH
然后保存退出,如果想快速查看效果的话,可以执行下面命令,如:
source /etc/profile
然后再执行查看java版本命令,如果能查出java版本,则表示安装成功
java -version
下面开始安装搜索引擎ES
Elasticsearch-5.2.0 下载地址: https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.2.0.tar.gz
cd /usr/local/src
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.2.0.tar.gz
tar -zxf elasticsearch-5.2.0.tar.gz
# 将 elasticsearch-5.2.0 目录拷贝到 /usr/local 目录下
mv elasticsearch-5.2.0 /usr/local/
这里需要注意的是,es
规定 root
用户不能启动 es
,所以需要创建一个用户来启动 es
# 创建用户名为 es 的用户
useradd es -p
# 设置 es 用户的密码
passwd es
# 将 /usr/local/elasticsearch-5.2.0 的拥有者设置为 es
chown -R es:es /usr/local/elasticsearch-5.2.0
# 创建 es 的 data 和 logs 目录
mkdir -p /data/elasticsearch/data /data/elasticsearch/logs
chown -R es:es /data/elasticsearch
下面开始编辑 es
的配置文件 /usr/local/elasticsearch-5.1.2/config/elasticsearch.yml
,找到下面每行前面的关键词,改成冒号右边的内容
# 记住,每行命令的前面需要空一格
cluster.name: juanpi-goods-cluster
node.name: node-1
path.data: /data/elasticsearch/data
path.logs: /data/elasticsearch/logs
network.host: 你自己的服务器ip
http.port: 9200
discovery.zen.ping.unicast.hosts: ["集群服务器ip地址"]
改完保存退出
切换到 es
用户,启动 es
su es
/usr/local/elasticsearch-5.2.0/bin/elasticsearch -d
# 使用 ps 查看 es是否已经启动成功
ps aux |grep elasticsearch
因为我没有启动成功,只能查看错误日志进行排查
tail -n 300 /data/elasticsearch/logs/juanpi-goods-cluster.log
# 下面为日志报错内容
[2017-01-23T14:56:35,068][INFO ][o.e.n.Node ] [node-1] initializing ...
[2017-01-23T14:56:35,312][INFO ][o.e.e.NodeEnvironment ] [node-1] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [5.8gb], net total_space [8.3gb], spins? [unknown], types [rootfs]
[2017-01-23T14:56:35,313][INFO ][o.e.e.NodeEnvironment ] [node-1] heap size [1.9gb], compressed ordinary object pointers [true]
[2017-01-23T14:56:35,315][INFO ][o.e.n.Node ] [node-1] node name [node-1], node ID [6sAQZ0J7QF2-TB-ar4B3yA]
[2017-01-23T14:56:35,344][INFO ][o.e.n.Node ] [node-1] version[5.1.2], pid[3966], build[c8c4c16/2017-01-11T20:18:39.146Z], OS[Linux/3.10.0-229.el7.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_111/25.111-b14]
[2017-01-23T14:56:38,539][INFO ][o.e.p.PluginsService ] [node-1] loaded module [aggs-matrix-stats]
[2017-01-23T14:56:38,539][INFO ][o.e.p.PluginsService ] [node-1] loaded module [ingest-common]
[2017-01-23T14:56:38,539][INFO ][o.e.p.PluginsService ] [node-1] loaded module [lang-expression]
[2017-01-23T14:56:38,539][INFO ][o.e.p.PluginsService ] [node-1] loaded module [lang-groovy]
[2017-01-23T14:56:38,539][INFO ][o.e.p.PluginsService ] [node-1] loaded module [lang-mustache]
[2017-01-23T14:56:38,539][INFO ][o.e.p.PluginsService ] [node-1] loaded module [lang-painless]
[2017-01-23T14:56:38,539][INFO ][o.e.p.PluginsService ] [node-1] loaded module [percolator]
[2017-01-23T14:56:38,539][INFO ][o.e.p.PluginsService ] [node-1] loaded module [reindex]
[2017-01-23T14:56:38,539][INFO ][o.e.p.PluginsService ] [node-1] loaded module [transport-netty3]
[2017-01-23T14:56:38,539][INFO ][o.e.p.PluginsService ] [node-1] loaded module [transport-netty4]
[2017-01-23T14:56:38,540][INFO ][o.e.p.PluginsService ] [node-1] no plugins loaded
[2017-01-23T14:56:43,376][INFO ][o.e.n.Node ] [node-1] initialized
[2017-01-23T14:56:43,376][INFO ][o.e.n.Node ] [node-1] starting ...
[2017-01-23T14:56:43,624][INFO ][o.e.t.TransportService ] [node-1] publish_address {192.168.0.117:9300}, bound_addresses {192.168.0.117:9300}
[2017-01-23T14:56:43,629][INFO ][o.e.b.BootstrapCheck ] [node-1] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks
[2017-01-23T14:56:43,631][ERROR][o.e.b.Bootstrap ] [node-1] node validation exception
bootstrap checks failed
max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2017-01-23T14:56:43,647][INFO ][o.e.n.Node ] [node-1] stopping ...
[2017-01-23T14:56:43,738][INFO ][o.e.n.Node ] [node-1] stopped
[2017-01-23T14:56:43,738][INFO ][o.e.n.Node ] [node-1] closing ...
[2017-01-23T14:56:43,758][INFO ][o.e.n.Node ] [node-1] closed
可以看到上面报了两个错误
第一个错误修改方法:
vim /etc/security/limits.conf
# 在最后面追加下面内容
es hard nofile 65536
es soft nofile 65536
修改后重新登录 es
用户,使用如下命令查看是否修改成功
ulimit -Hn
第二个我提高了 vm.max_map_count 的大小
vim /etc/sysctl.conf
# 在最后面追加下面内容
vm.max_map_count=262144
使用 sysctl -p
查看修改后的结果
接下来再重新启动 es,使用下面命令看是否开启成功
curl http://192.168.0.117:9200
# 如果有下面内容表示安装成功
{
"name" : "node-1",
"cluster_name" : "juanpi-goods-cluster",
"cluster_uuid" : "6YBIPIEIRXyyg-rfUTyq0g",
"version" : {
"number" : "5.2.0",
"build_hash" : "c8c4c16",
"build_date" : "2017-01-11T20:18:39.146Z",
"build_snapshot" : false,
"lucene_version" : "6.3.0"
},
"tagline" : "You Know, for Search"
}
OK,到此 elasticsearch-5.2.0
安装成功
补充,今天在自己的阿里云上安装 es 又出现了新的错误,下面为提示错误内容:
system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
找了半天,终于通过 google 查找到了答案,在es配置中加入下面命令即可:
bootstrap.system_call_filter: false
详细文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/system-call-filter-check.html