如今有两台服务器分别为10.19.40.63和10.19.40.64,分别在这两台服务器上安装两个节点。java
一、下载elasticsearch-6.4.1.tar.gz安装包node
二、解压安装包:tar -zxvf elasticsearch-6.4.1.tar.gz。python
三、在10.19.40.63服务器上建立elasticsearch01和elasticsearch02目录,在10.19.40.64服务器上建立elasticsearch03和elasticsearch04目录,将解压的文件拷贝到四个目录下。es6
四、在四个节点的config目录下的elasticsearch.yml配置文件进行配置各节点的信息。配置信息以下npm
#集群的名称 cluster.name: es6 #节点名称,其他两个节点分别为node-2 和node-3 node.name: node-1 #指定该节点是否有资格被选举成为master节点,默认是true,es是默认集群中的第一台机器为master,若是这台机挂了就会从新选举master node.master: true #容许该节点存储数据(默认开启) node.data: true #索引数据的存储路径 path.data: /usr/local/elk/elasticsearch/data #日志文件的存储路径 path.logs: /usr/local/elk/elasticsearch/logs #设置为true来锁住内存。由于内存交换到磁盘对服务器性能来讲是致命的,当jvm开始swapping时es的效率会下降,因此要保证它不swap bootstrap.memory_lock: true #绑定的ip地址 network.host: 0.0.0.0 #设置对外服务的http端口,默认为9200 http.port: 9200 # 设置节点间交互的tcp端口,默认是9300 transport.tcp.port: 9300 #Elasticsearch将绑定到可用的环回地址,并将扫描端口9300到9305以尝试链接到运行在同一台服务器上的其余节点。#这提供了自动集群体验,而无需进行任何配置。数组设置或逗号分隔的设置。每一个值的形式应该是host:port或host#(若是没有设置,port默认设置会transport.profiles.default.port 回落到transport.tcp.port)。#请注意,IPv6主机必须放在括号内。默认为127.0.0.1, [::1] discovery.zen.ping.unicast.hosts: ["192.168.8.101:9300","192.168.8.103:9300", "192.168.8.104:9300"] #若是没有这种设置,遭受网络故障的集群就有可能将集群分红两个独立的集群 - 分裂的大脑 - 这将致使数据丢失 discovery.zen.minimum_master_nodes: 3
五、建立用户组和用户用来管理elasticsearch:json
groupadd elsearchbootstrap
useradd elsearch -g elsearch -p elasticsearch数组
chown -R elsearch:elsearch elasticsearch01服务器
chown -R elsearch:elsearch elasticsearch02网络
六、在经过指令:su es,转换用户到es。进入elasticsearch/bin目录。执行./elasticsearch -d启动服务。
七、若是报下图错误:
须要修改以下配置文件:
/etc/security/limits.conf文件须要添加以下参数
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
/etc/sysctl.conf文件须要添加以下参数
vm.max_map_count = 655360
/etc/security/limits.d/20-nproc.conf文件添加以下参数
soft nproc 4096
在修改完配置文件后,进行热加载:
sysctl -p
一、须要安装相应的依赖包node.js和python
二、解压elasticsearch-head-master.zip压缩包
三、cd elasticsearch-head-master目录,执行以下指令:npm install
四、若是在执行npm install时,报以下错误:
则须要执行以下指令:
npm install phantomjs-prebuilt@2.1.14 --ignore-scripts
五、以下配置文件
#在文件末尾添加便可,此处须要注意yml的格式问题(有的博友已经遇到了不生效,详见评论---20180927) http.cors.enabled: true http.cors.allow-origin: "*"
六、启动head:npm run start
一、能够经过命令:unzip 文件夹 进行解压elasticsearch-analysis-ik-6.4.1.zip。
二、在plugins目录下建立ik目录,将解压的文件复制到ik目录下。
三、从新启动elasticsearch。
四、若是日志中出现以下内容,则安装成功:
一、查看集群的状态信息
http://10.19.40.63:9200/_cluster/health?pretty
二、查看索引
curl http://10.19.40.63:9200/_cat/indices/index?v
三、建立索引
curl -XPUT http://10.19.40.63:9200/index
四、查看索引的基本信息
curl -XGET http://10.19.40.63:9200/index/_settings
五、查看索引的所有映射
curl http://10.19.40.63:9200/index/_mapping
六、查看分词效果
http://10.19.40.63:9200/_analyze
{
"analyzer":"standard",
"text":"中华人民共和国国歌"
}
七、建立文档映射
curl -H "Content-Type:application/json" -XPOST http://10.19.40.63:9200/index//_mapping -d'
{ "fulltext": {
"_all": {
"analyzer": "ik"
}, "properties": {
"content": {
"type" : "string",
"boost" : 8.0,
"term_vector" : "with_positions_offsets",
"analyzer" : "ik",
"include_in_all" : true
}
}
}
八、插入文档
curl -H "Content-Type:application/json" -XPOST http://10.19.40.63:9200/index/fulltext/1 -d' {"content":"美国留给伊拉克的是个烂摊子吗"}'九、查询索引 curl -H "Content-Type:application/json" -XPOST http://10.19.40.63:9200/index/fulltext/_search -d' { "query" : { "match" : { "content" : "美国" }} }'