系统环境:
Centos7
elasticsearch-6.1.2.tar.gz
Java8
系统调优
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/bin/elasticsearch &"
2.5安装head开源插件
参考:http://blog.csdn.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/grunt server &
浏览器访问:
注意:若不能形成集群,可能是 iptables 或者 selinux 的原因
2.6开机自启
vim /etc/rc.local
su - elsearch -c "/usr/local/elasticsearch/bin/elasticsearch -d" cd /home/soft/elasticsearch-head ./node_modules/grunt/bin/grunt server & |
保存退出后,给自启文件赋予执行权限(若不加,Centos7不会开机执行)
chmod +x /etc/rc.d/rc.local
2.7 设置中文分词
安装插件
elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.1.2/elasticsearch-analysis-ik-6.1.2.zip
创建索引
curl -XPUT http://192.168.1.234:9200/index
创建map
curl -H 'Content-Type:application/json' http://192.168.1.234:9200/index/fulltext/_mapping -d'
{
"properties": {
"content": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
}
}
}'
分词
curl -H 'Content-Type:application/json' 'http://192.168.1.234:9200/index/_analyze?pretty=true' -d '
{
"text":"中华人民共和国",
"analyzer" : "ik_max_word"
}'