介绍
全文搜索属于最常见的需求,开源的 Elasticsearch (以下简称 Elastic)是目前全文搜索引擎的首选。
它可以快速地储存、搜索和分析海量数据。维基百科、Stack Overflow、Github 都采用它。
Elastic 的底层是开源库 Lucene。但是,你没法直接用 Lucene,必须自己写代码去调用它的接口。
Elastic 是 Lucene 的封装,提供了 REST API 的操作接口,开箱即用。
环境信息
序号
IP地址
系统
角色
节点名
1
192.168.10.101
CentOS7
master/node
es01
2
192.168.10.102
CentOS7
master/node
es02
3
192.168.10.103
CentOS7
master/node
es03
安装ElasticSearch
优化系统参数 修改limits.conf 编辑 /etc/security/limits.conf,追加以下内容;
1 2 * soft nofile 65536 * hard nofile 65536
此文件修改后需要重新登录用户,才会生效
修改sysctl.conf 在/etc/sysctl.conf文件最后添加一行
执行命令
安装包下载地址 1 wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.5.1-linux-x86_64.tar.gz
添加系统用户 添加用户,以普通用户启动ElasticSearch
解压ES安装包 1 2 3 4 5 6 7 cd /data/tar -zxvf elasticsearch-7.5.1-linux-x86_64.tar.gz ls elasticsearch-7.5.1-linux-x86_64.tar.gz elasticsearch-7.5.1 mkdir /data/elasticsearch-7.5.1/datamkdir /data/elasticsearch-7.5.1/logs
修改ES集群配置 配置文件在 /data/elasticsearch-7.5.1/config/elasticsearch.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 cluster.name: es-cluster-log node.name: es01 path.data: /data/elasticsearch-7.5.1/data path.logs: /data/elasticsearch-7.5.1/logs network.host: 0.0.0.0 http.port: 9200 transport.tcp.port: 9300 discovery.seed_hosts: ["192.168.10.101" ,"192.168.10.102" ,"192.168.10.103" ] cluster.initial_master_nodes: ["es01" , "es02" ,"es03" ] http.cors.enabled: true http.cors.allow-origin: "*" xpack.security.enabled: true xpack.license.self_generated.type: basic xpack.security.transport.ssl.enabled: true xpack.security.transport.ssl.verification_mode: certificate xpack.security.transport.ssl.keystore.path: elastic-certificates.p12 xpack.security.transport.ssl.truststore.path: elastic-certificates.p12
上面这个配置要 复制到 192.168.102/103上面 ,只需要把 node.name 改成对应的名称就可以
生成证书文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 bin/elasticsearch-certutil ca ... Please enter the desired output file [elastic-stack-ca.p12]: Enter password for elastic-stack-ca.p12 : bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12 ... ll *.p12 -rw------- 1 es es 3443 5月 6 14:11 elastic-certificates.p12 -rw------- 1 es es 2527 5月 6 14:06 elastic-stack-ca.p12
把证书密码添加到 keystore 秘钥中
1 2 3 bin/elasticsearch-keystore add xpack.security.transport.ssl.keystore.secure_password bin/elasticsearch-keystore add xpack.security.transport.ssl.truststore.secure_password
启动ElasticSearch
配置密码
1 bin/elasticsearch-setup-passwords interactive
查看集群
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 curl --location --request GET 'http://elastic:123456@192.168.10.101:9200/_cluster/health?pretty' { "cluster_name" : "es-cluster-log" , "status" : "green" , "timed_out" : false , "number_of_nodes" : 3, "number_of_data_nodes" : 3, "active_primary_shards" : 1, "active_shards" : 2, "relocating_shards" : 0, "initializing_shards" : 0, "unassigned_shards" : 0, "delayed_unassigned_shards" : 0, "number_of_pending_tasks" : 0, "number_of_in_flight_fetch" : 0, "task_max_waiting_in_queue_millis" : 0, "active_shards_percent_as_number" : 100.0 }