以前在.net里如果要做全文搜索的话,一般都会使用Lucene.net配合盘古分词。使用起来麻烦而且还不容易查看数据,后来就出现了ElastiSearch。ES也是基于Lucene并采用java编写, 相当于对Lucene做了一层封装,我们只需要调用ES相关API即可,配合Kibana数据可视化工具可以很方便的分析和统计数据。
1.安装
这里以windows环境为例,linux类似。
移步到ES官网,下载ElasticSearch和Kibana
ES: https://www.elastic.co/downloads/elasticsearch
Kibana: https://www.elastic.co/downloads/kibana
这两个压缩包,解压之后即可用(ES自带jdk无需单独安装)。
▼双击elasticsearch.bat启动ES
▼双击kibana.bat启动Kibana
都启动完成之后,浏览器输入localhost:9200查看ES,如果有输出内容,则证明ES运行正常。打开localhost:5601如果能看到页面则Kibana正常运行。
原文链接:https://blog.csdn.net/catshitone/article/details/95939413
2.配置x-pack权限
x-pack在Elastic7.3.1版本里面已经集成,集成的是basic版本(永久免费,高级功能不能使用)。
x-pack给elasticsearch添加账号和密码的安全设置。
在config目录中Elasticsearch.yml中添加如下:代码
xpack.security.enabled: true
启动ES的xpack安全设定,重启ES。打开cmd进去es的bin目录
执行 elasticsearch-setup-passwords interactive
Initiating the setup of passwords for reserved users elastic,kibana,logstash_system,beats_system.You will be prompted to enter passwords as the process progresses.Please confirm that you would like to continue [y/N]y Enter password for[elastic]: passwords must be at least [6] characters longTry again.Enter password for[elastic]: Reenter password for[elastic]: Passwordsdonot match.Try again.Enter password for[elastic]: Reenter password for[elastic]: Enter password for[kibana]: Reenter password for[kibana]: Enter password for[logstash_system]: Reenter password for[logstash_system]: Enter password for[beats_system]: Reenter password for[beats_system]: Changed password for user [kibana]Changed password for user [logstash_system]Changed password for user [beats_system]Changed password for user [elastic]
需要设置 elastic,kibana,logstash,system密码
3.配置生成SSL(进去es的bin目录)
输入:
elasticsearch-certgen
Please enter the desired output file [certificate-bundle.zip]: cert.zip (压缩包名称) Enter instance name: my-application(实例名) Enter name for directories and files [p4mES]: elasticsearch(文件夹名) Enter IP Addresses for instance (comma-separated if more than one) []: 127.0.0.1(实例ip,多个ip用逗号隔开-就是每个节点的network.publish_host的ip ) Enter DNS names for instance (comma-separated if more than one) []: node-1(节点名,多个节点用逗号隔开) Would you like to specify another instance? Press 'y' to continue entering instance information: (到达这一步,不需要按y重新设置,按空格键就完成了) Certificates written to /usr/local/elasticsearch/bin/cert.zip(这个是生成的文件存放地址,不用填写)
注意:在一台配置就可以了,生成的秘钥拷贝到每个节点的config目录中.
cluster.name: //集群名称,每个节点都相同 node.name: //节点名,每个节点不同 network.host: 0.0.0.0 //如果需要外网访问不是设置成 node.master: true //是否有资格成为主节点 node.data:true //该节点是否存储数据 node.attr.rack: r1 //每个节点都可以定义一些与之关联的通用属性,用于后期集群进行碎片分配时的过滤 bootstrap.memory_lock: true //在ES运行起来后锁定ES所能使用的堆内存大小,锁定内存大小一般为可用内存的一半左右;锁定内存后就不会使用交换分区。如果不打开此项,当系统物理内存空间不足,ES将使用交换分区,ES如果使用交换分区,那么ES的性能将会变得很差 network.host: 0.0.0.0 //设置成0.0.0.0才会暴露给外网访问,不然外网访问不了。 network.publish_host/1.69 //可设置成内网ip,用于集群内各机器间通信 http.port: 8231 //es对外提供的http端口,默认 9200 transport.tcp.port: 8331 //设置集群节点通信的TCP端口,默认就是9300 discovery.seed_hosts: ["192.168.1.69:8331","192.168.1.5:8331","192.168.1.120:8331"] //写入候选主节点的设备地址,来开启服务时就可以被选为主节点 cluster.initial_master_nodes: ["node", "node-1","node-2"] //参数设置一系列符合主节点条件的节点的主机名或 IP 地址来引导启动集群 http.cors.enabled: true http.cors.allow-origin: "*" node.max_local_storage_nodes: # 开启x-pack安全验证 xpack.security.enabled: true #群集间的ssl通讯配置 xpack.security.transport.ssl.enabled: true xpack.security.transport.ssl.verification_mode: certificate xpack.security.transport.ssl.key: elasticsearch/elasticsearch.key xpack.security.transport.ssl.certificate: elasticsearch/elasticsearch.crt xpack.security.transport.ssl.certificate_authorities: [ "ca/ca.crt" ] #节点频繁超时 discovery.zen.ping_timeout: 10s //集群ping过程的超时等待时间(主要控制主节点的选举时间) discovery.zen.fd.ping_timeout: 120s //心跳的超时时间2两分钟 discovery.zen.fd.ping_interval: 30s //节点每隔30秒同master发送一次心跳 discovery.zen.fd.ping_retries: 10 //超过10次心跳没有回应,则认为该节点脱离master
注意:群集其他台(主源不能删除)的data的文件夹要先删除掉,启动成功后会根据配置那台生成对应的data文件
4. 进入D:\elasticsearch-7.3.2-windows-x86_64\elasticsearch-7.3.2\config
在jvm.options设置JVM堆通道的大小(最好设置可以使用的内存50%,最大不要超过32G)
-Xms8g --最小值8G -Xmx8g --最大值8G
全部配置先用9200默认端口完成,最后在设置成你需要修改的接口。不然又的配置设置还是调用9200导致配置出错