目录一、前言Elasticsearch 是一个开源的分布式搜索和分析引擎,用于全文搜索、布局化搜索、分析和可视化大规模数据。 它被筹划成一个可扩展的实时搜索引擎,可以大概处理大规模数据,并提供快速的搜索和分析功能。 以下是一些 Elasticsearch 的特性和用途:
总的来说,Elasticsearch是一个功能强大且机动的搜索和分析引擎,实用于各种场景,包括日志分析、实时监控、全文搜索等。 本例将在3台机器上搭建 Elasticsearch 集群: [code]192.168.72.151 node-1 192.168.72.152 node-2 192.168.72.153 node-3[/code]二、使用 RPM 安装 Elasticsearch导入 Elasticsearch GPG 密钥下载并安装公共署名密钥 [code]rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch[/code]从 RPM 存储库安装在 /etc/yum.repos.d/ 创建 elasticsearch.repo [code][elasticsearch] name=Elasticsearch repository for 8.x packages baseurl=https://artifacts.elastic.co/packages/8.x/yum gpgcheck=1 gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch enabled=0 autorefresh=1 type=rpm-md[/code]实行 yum install 下令 [code]yum install --enablerepo=elasticsearch elasticsearch -y[/code]默认生成的目录
启动 Elasticsearch 下令: [code]systemctl enable elasticsearch.service systemctl start elasticsearch.service[/code]三、设置根本安全性首次启动 Elasticsearch 时,会为用户生成暗码,并自动为用户设置 TLS ,可以随时调解 TLS 设置,更新节点证书 生成证书1、在恣意节点上进入 Elasticsearch 的安装目录,使用 elasticsearch-certutil 为集群生成 CA 。 [code]bin/elasticsearch-certutil ca[/code]
2、利用上一步的 elastic-stack-ca.p12 为集群生成证书和私钥。 [code]bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12[/code]
3、将证书拷贝到其他节点上。 使用TLS加密节点间通讯1、进入 Elasticsearch 设置目录,编辑 elasticsearch.conf 文件: [code]cluster.name: my-cluster node.name: node-1 xpack.security.enabled: true xpack.security.transport.ssl.enabled: true xpack.security.transport.ssl.verification_mode: certificate xpack.security.transport.ssl.client_authentication: required xpack.security.transport.ssl.keystore.path: elastic-certificates.p12 xpack.security.transport.ssl.truststore.path: elastic-certificates.p12[/code]2、实行以下下令将证书暗码保存到 Elasticsearch 的 keystore [code]bin/elasticsearch-keystore add xpack.security.transport.ssl.keystore.secure_password bin/elasticsearch-keystore add xpack.security.transport.ssl.truststore.secure_password[/code]3、为集群中的每个节点完成前面的步调。 4、在集群的每个节点上,重新启动 Elasticsearch 。 四、为 Elasticsearch 加密 HTTP 客户端通讯1、 在恣意单个节点上,从安装 Elasticsearch 的目录中,运行Elasticsearch HTTP 证书工具生成证书署名哀求(CSR)。 [code]bin/elasticsearch-certutil http[/code]
该下令生成一个 .zip 文件,其中包含 Elasticsearch 和 Kibana 使用的证书和密钥。每个文件夹都包含一个 README.txt ,说明如何使用这些文件。 2、解压缩生成的 elasticsearch-ssl-http.zip 文件。这个压缩文件包含用于Elasticsearch和Kibana的目录。 [code]/elasticsearch |_ README.txt |_ http.p12 |_ sample-elasticsearch.yml[/code] [code]/kibana |_ README.txt |_ elasticsearch-ca.pem |_ sample-kibana.yml[/code]3、在集群中的每个节点上,完成以下步调: 复制上面 elasticsearch 文件夹中的 http.p12 到 Elasticsearch 的设置目录下。 编辑 elasticsearch.yml ,启用 HTTPS 安全性,并指定 http.12 文件的位置。 [code]xpack.security.http.ssl.enabled: true xpack.security.http.ssl.keystore.path: http.p12[/code]将私钥暗码添加到 Elasticsearch 的安全设置中。 [code]bin/elasticsearch-keystore add xpack.security.http.ssl.keystore.secure_password[/code]4、重新启动 Elasticsearch 五、设置集群编辑 elasticsearch.yml3个节点的设置文件除了ip、节点名之外,都一样 [code]cluster.name: my-clusters node.name: node-1 path.data: /var/lib/elasticsearch path.logs: /var/log/elasticsearch indices.memory.index_buffer_size: 20% indices.memory.min_index_buffer_size: 96mb thread_pool: search: size: 32 analyze: size: 30 queue_size: 1000 indices.requests.cache.size: 2% indices.queries.cache.size: 10% indices.fielddata.cache.size: 20% indices.breaker.fielddata.limit: 40% network.host: 0.0.0.0 http.port: 9200 transport.port: 9300 transport.compress: true http.max_content_length: 100mb discovery.seed_hosts: ["192.168.72.151", "192.168.72.152","192.168.72.153"] cluster.initial_master_nodes: ["node-1", "node-2","node-3"] cluster.fault_detection.leader_check.interval: 5s discovery.cluster_formation_warning_timeout: 10s cluster.publish.timeout: 30s cluster.routing.allocation.node_initial_primaries_recoveries: 16 cluster.routing.allocation.node_concurrent_recoveries: 8 indices.recovery.max_bytes_per_sec: 125mb[/code]集群默认是通过9300端口连接的,记得防火墙还要开通9300 启动集群依次启动各个节点 [code]service elasticsearch start[/code]设置暗码 [code]bin/elasticsearch-setup-passwords interactive[/code]查抄集群状态 [code]curl -XGET --user elastic:password http://192.168.72.151:9200/_cluster/health?pretty[/code]也可以在欣赏器直接访问 请留意,上述步调中的IP地址、端口和目录路径应根据你的实际情况举行调解。 总结以上为个人履历,盼望能给各人一个参考,也盼望各人多多支持脚本之家。 来源:https://www.jb51.net/server/328783kz2.htm 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |
|手机版|小黑屋|梦想之都-俊月星空
( 粤ICP备18056059号 )|网站地图
GMT+8, 2025-7-1 18:38 , Processed in 0.031140 second(s), 18 queries .
Powered by Mxzdjyxk! X3.5
© 2001-2025 Discuz! Team.