C# + Web Api + Elasticsearch 参考 => http://www.cnblogs.com/eggTwo/p/4039779.html
一、准备工作
*安装JDK7及以上版本*下载ElasticSearch安装包(https://www.elastic.co/downloads/elasticsearch 用 zip或 tar.gz)
mv elasticsearch-5.2.2.tar.gz /usr/local/
cd /usr/local
tar zxvf elasticsearch-5.2.2.tar.gz
ln -sv elasticsearch-5.2.2 elasticsearch
groupadd elsearch
useradd elsearch -g elsearch -p elasticsearch
cd /usr/local
chown -R elsearch:elsearch elasticsearch
四、修改文件
vim /usr/local/elasticsearch/config/elasticsearch.yml
#必须设置ip,设成外部能访问的地址
network.host:192.168.1.105
#用head插件时,设置成跨域
http.cors.enabled:true
http.cors.allow-origin:"*"
#修改系统参数
vim /etc/security/limits.conf
* soft nproc 65536
* hard nproc 65536
* soft nofile 65536
* hard nofile 65536
#修改系统参数
vim /etc/sysctl.conf
vm.max_map_count= 262144
sysctl -p
五、切换到elsearch用户再启动
su elsearch
cd elasticsearch/bin
./elasticsearch
六、正常的话就可以访问 http://192.168.1.105:9200
==========================异常排查======================================
Exception in thread "main" java.lang.RuntimeException: bootstrap checks failed
常见错误一
initial heap size [268435456] not equal to maximum heap size [2147483648]; this can cause resize pauses and prevents mlockall from locking the entire heap
#/usr/java/elasticsearch/config/jvm.options
#将-Xmx2g改成-Xmx256m,也就是heap size [268435456] /1024/1024的值
常见错误二
please set [discovery.zen.minimum_master_nodes] to a majority of the number of master eligible nodes in your cluster
# /usr/local/elasticsearch/config/elasticsearch.yml
# discovery.zen.ping.unicast.hosts: ["192.168.1.105"]
# discovery.zen.minimum_master_nodes: 3
常见错误三
max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
#/etc/security/limits.conf 修改配置
max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]
# /etc/sysctl.conf 修改配置
常见错误五
如果是用root账号启动,会报以下错误
Exception in thread "main" java.lang.RuntimeException: don't run elasticsearch as root.
#新见elsearch账号