部署环境
3台服务器: 192.168.58.201 192.168.58.203 192.168.58.205
,部署地址为/opt/soft/
,ES版本为5.4.3
组件准备
下载ElasticSearch
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.4.3.tar.gz
编译hanlp-ext
git clone https://github.com/hualongdata/hanlp-ext.git
cd hanlp-ext
gradle -p es-plugin jar buildPluginZip
# 获得插件:hanlp-ext/es-plugin/distributions/elasticsearch-hanlp-5.4.3.zip
HanLP-1.3.4-offline-tar.gz
下载地址:https://pan.baidu.com/s/1o8Rri0y
安装ElasticSearch
解压
hosts=(192.168.58.201 192.168.58.203 192.168.58.205)
installDir=/opt/soft
hanlpDataDir=/opt/data
if [ ! ${#hosts[@]} = 3 ]; then echo "hosts should set to has three servers"; exit; fi
tar xzf elasticsearch-5.4.3.tar.gz -C ${installDir}
es_home=${installDir}/elasticsearch-5.4.3
ln -s ${installDir}/elasticsearch-5.4.3 ${installDir}/elasticsearch
${es_home}/bin/elasticsearch-plugin install file://`pwd`/elasticsearch-hanlp-5.4.3.zip
tar xzf HanLP-1.3.4-offline.tar.gz -C ${hanlpDataDir}
ln -s ${hanlpDataDir}/HanLP-1.3.4-offline ${hanlpDataDir}/HanLP
cp sysctl.conf ${es_home}/config/
配置
集群配置
sed -i 's|#cluster.name: my-application|cluster.name: iask-cluster|g' ${es_home}/config/elasticsearch.yml
sed -i 's|#network.host: 192.168.0.1|network.host: 0.0.0.0|g' ${es_home}/config/elasticsearch.yml
sed -i "s|#discovery.zen.ping.unicast.hosts: \[\"host1\", \"host2\"]|discovery.zen.ping.unicast.hosts: \[\"${hosts[0]}\", \"${hosts[1]}\", \"${hosts[2]}\"]|g" ${es_home}/config/elasticsearch.yml
sed -i 's|#discovery.zen.minimum_master_nodes: 3|discovery.zen.minimum_master_nodes: 2|g' ${es_home}/config/elasticsearch.yml
HanLP配置
echo "-Djava.security.policy=file://${es_home}/plugins/elasticsearch-hanlp/plugin-security.policy" >> ${es_home}/config/jvm.options
echo 'ES_CLASSPATH="$ES_HOME/lib/*:$ES_HOME/plugins/elasticsearch-hanlp/"' >> ${es_home}/bin/elasticsearch.in.sh
sed -i 's|^root=/opt/app/HanLP/$|root=${hanlpDataDir}/HanLP|g' ${es_home}/plugins/elasticsearch-hanlp/hanlp.properties
sudo ln -s ${es_home}/config/sysctl.conf /etc/sysctl.d/es-sysctl.conf
sudo sysctl -w vm.max_map_count=262144
系统设置
设置最大文件描述符数量,在/etc/security/limits.conf文件中添加2行
* soft nofile 65536
* hard nofile 65536
命令如下,这里需要使用root权限
echo "* soft nofile 65536" >> /etc/security/limits.conf
echo "* hard nofile 65536" >> /etc/security/limits.conf
启动
bin/elasticsearch -d #后台启动
常见问题
-
max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
:(解决办法: /etc/security/limits.conf添加 两行"* soft nofile 65536\n* hard nofile 65536"
,需要重新ssh或打开终端) -
max number of threads [3815] for user [user] is too low, increase to at least [4096]
(解决办法:/etc/security/limits.conf添加两行"* soft nproc 4096\n* hard nproc 4096"
) -
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
(解决办法:sudo sysctl -w vm.max_map_count=262144
(当前session有效),同时再修改配置文件echo "vm.max_map_count=262144" >>/etc/sysctl.conf
(后续打开的session也有效)) -
java.lang.ClassNotFoundException: org.elasticsearch.plugin.analysis.AnalysisHanLPPlugin
(解决办法:一般是HanLP没有正确打包,缺少了es-plugin-5.4.3.jar。正确的打包命令是gradle -p es-plugin jar buildPluginZip
) -
SEVERE: 没有找到hanlp.properties,可能会导致找不到data
(解决办法:因为没有把HanLP目录配置到CLASSPATH,/bin/elasticsearch.in.sh
修改ES_CLASSPATH="$ES_HOME/lib/*:$ES_HOME/plugins/elasticsearch-hanlp/"
) -
seccomp unavailable: CONFIG_SECCOMP not compiled into kernel, CONFIG_SECCOMP and CONFIG_SECCOMP_FILTER are needed
(解决办法:elasticsearch.yml添加以下内容bootstrap.memory_lock: false bootstrap.system_call_filter: false
) -
Native library (com/sun/jna/linux-x86/libjnidispatch.so) not found in resource path
(解决办法:原因有很多,我遇到的问题是在64位Centos上安装了32位的JDK,重新安装64位JDK后,问题解决)