一、安装Elasticsearch
1、官网(https://www.elastic.co/cn/downloads/elasticsearch)下载 elasticsearch-6.3.0.tar.gz
2、使用MobaXterm登陆服务器,上传安装包到soft目录下
[root@xxx] cd /
[root@xxx] mkdir soft
3、解压安装
[root@xxx] cd /soft
[root@xxx] tar -zxvf elasticsearch-6.3.0.tar.gz
4、为方便使用,将elasticsearch-6.3.0文件夹名字修改为elasticsearch
5、配置外网访问
[root@xxx elasticsearch] cd /soft/elasticsearch
[root@xxx elasticsearch-6.3.0] vim ./config/elasticsearch.yml
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 0.0.0.0 #修改为0.0.0.0,表示让外网访问
#
# Set a custom port for HTTP:
#
#http.port: 9200
#
# For more information, consult the network module documentation.
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
discovery.zen.ping.unicast.hosts: ["192.168.26.28"] #配置服务器公网地址
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes:
#
# For more information, consult the zen discovery module documentation.
6、elasticsearch不能使用超级用户root运行,需要建立一个账号用于启动
#添加用户
[root@xxx elasticsearch] adduser eslian
#设置密码
[root@xxx elasticsearch] passwd eslian
7、给eslian用户授权elasticsearch目录
[root@xxx elasticsearch] sudo chown -R eslian /usr/elasticsearch
[root@xxx elasticsearch] sudo chgrp -R eslian /usr/elasticsearch
8、切换至elasticsearch目录,并以eslian用户运行
[root@xxx elasticsearch] cd /soft/elasticsearch
[root@xxx elasticsearch] su eslian
[root@xxx elasticsearch] ./bin/elasticsearch
备注:如果想后台运行,执行 ./bin/elasticsearch -d
停止elasticsearch服务
#前台启动,使用Ctrl+C停止
#后台运行,使用kill -9停止
[root@xxx elasticsearch] ps -ef|grep elasticsearch
[root@xxx elasticsearch] kill -9 进程号
9、测试是否启动成功
新开一个终端,用curl访问
[root@xxx /] curl 'http://127.0.0.1:9200/?pretty'
返回下面结果证明成功
{
"name" : "4nu2-gx",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "nMlrViNkSWejHskq0cVNXw",
"version" : {
"number" : "6.3.0",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "424e937",
"build_date" : "2018-06-11T23:38:03.357887Z",
"build_snapshot" : false,
"lucene_version" : "7.3.1",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
注意:安装完成后外部访问(如使用Java代码操作)elasticsearch,不要忘记开放9200端口,如果是阿里云服务器,应该给9200端口添加安全组规则。
二、Elasticsearch安装经常报错的解决方法
1、java.lang.RuntimeException: can not run elasticsearch as root
提示不能使用root用户来启动elasticsearch
解决方法:su cylian 切换用户来启动即解决
2、java.io.FileNotFoundException: /soft/elasticsearch/logs/elasticsearch.log(Permission denied)
提示权限不足
解决方法:切换到root用户,执行上述步骤7即可
3、max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
解决方法:切换到root用户,编辑 limits.conf
vim /etc/security/limits.conf
#添加如下内容:
* soft nofile 65536
* hard nofile 65536
* soft nproc 2048
* hard nproc 4096
#注意要有*号
4、max number of threads [3802] for user [eslian] is too low, increase to at least [4096]
解决方法:切换到root用户,进入limits.d目录下修改配置文件
vim /etc/security/limits.d/90-nproc.conf
#修改如下内容:
* soft nproc 1024
#修改为
* soft nproc 4096
5、max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
解决方法:切换到root用户,修改配置sysctl.conf
vim /etc/sysctl.conf
#添加下面配置:
vm.max_map_count=655360
#并执行命令:
sysctl -p
配置完成后,重新启动elasticsearch,即可启动成功。
网友评论