草庐IT

使用docker搭建es集群

frrree 2023-04-03 原文

使用docker搭建es集群

一、安装es

1.1 拉取es镜像
docker pull elasticsearch:7.9.3(重点7.x开始不需要手动下载x-pack)
1.2 配置es并启动
mkdir -p data/es/config
cd data/es
mkdir -p node1/data
chmod 777 data
mkdir node2/data
chmod 777 data
mkdir node3/data
chmod 777 data

cd config
vim es1.yml

配置

cluster.name: elasticsearch-cluster
node.name: es1
network.bind_host: 0.0.0.0
network.publish_host: (此处填ip)
http.port: 9200
transport.tcp.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true
discovery.zen.ping.unicast.hosts: ["ip:9300","ip:9301","ip:9302"]
discovery.zen.minimum_master_nodes: 2
cluster.initial_master_nodes: ["es1"]
xpack.security.enabled: true
xpack.security.authc.accept_default_password: true
xpack.security.transport.ssl.enabled: true
#xpack.security.transport.ssl.verification_mode: certificate
#xpack.security.transport.ssl.keystore.path: /usr/share/elasticsearch/config/elastic-certificates.p12
#xpack.security.transport.ssl.truststore.path: /usr/share/elasticsearch/config/elastic-certificates.p12
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type

重复动作生成es2.yml、es3.yml
调整jvm限制

vim /etc/sysctl.conf
vm.max_map_count=262144
启用配置
sysctl -p

启动es
docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9200:9200 -p 9300:9300 -v /data/es/config/es1.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /data/es/node1/data:/usr/share/elasticsearch/data --name ES01 elasticsearch:7.9.3

docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9201:9201 -p 9301:9301 -v /data/es/config/es2.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /data/es/node1/data:/usr/share/elasticsearch/data --name ES02 elasticsearch:7.9.3

docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9202:9202-p 9302:9302 -v /data/es/config/es3.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /data/es/node1/data:/usr/share/elasticsearch/data --name ES03 elasticsearch:7.9.3
1.3开启端口
firewall-cmd --add-port=9300/tcp
firewall-cmd --add-port=9301/tcp
firewall-cmd --add-port=9302/tcp
1.4验证
http://ip:9200/_cat/health?v

状态为green为健康

二、安装ik分词器

docker exec -it ES01 bash
elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.9.3/elasticsearch-analysis-ik-7.9.3.zip

重复此动作

es默认分词器对中文分词非常不友好,会把一句话拆成每一个字(想要了解可以去查下资料)

三、安装elasticsearch-head:5

docker pull mobz/elasticsearch-head:5
docker run -d -p 9100:9100 --name head5  mobz/elasticsearch-head:5

访问页面
http://ip:9100/

四、安装Kibana

docker pull kibana:7.9.3
cd /data
mkdir -p kibana/config
cd kibana/config
vim kibana.yml

server.name: kibana
server.host: "0"
elasticsearch.hosts: [ "http://ip:9200","http://ip:9201","http://ip:9202" ]
xpack.monitoring.ui.container.elasticsearch.enabled: true
#elasticsearch.username: elastic
#elasticsearch.password: "123456"
#xpack.security.enabled: true
xpack.security.encryptionKey: "c77effba756146d382ebc79b279fd694"
i18n.locale: "zh-CN"

启动
docker run -d --name=kibana --restart=always -p 5601:5601 -v /data/kibana/config/kibana.yml:/usr/share/kibana/config/kibana.yml kibana:7.9.3

五、开启es安全认证

生成证书

docker exec -it ES01 bash
bin/elasticsearch-certutil ca
执行完此操作后会生成(这里会配置一个密码,执行下一步操作会用)

执行此命令的设置密码不用设,直接回车

bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12

将此处生成的文件放到config下

并给他配置权限(执行两次)

chmod 777 elastic-certificates.p12 

分配用户组

chown elasticsearch elastic-certificates.p12 

更改es配置

vim es1.yml

将上面注释的配置打开

xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: /usr/share/elasticsearch/config/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: /usr/share/elasticsearch/config/elastic-certificates.p12		

全部修改完了后重启es
重启es后要生成密码,进入es容器

docker exec -it ES01 bash
bin/elasticsearch-setup-passwords interactive

这里会让配置好多密码,挨个配置,配置成功后修改kibana配置
这里我已经配置过了不呢重复执行,从网上找了个图片

打开上面kibana.yml的注释

elasticsearch.username: elastic
elasticsearch.password: "123456"
xpack.security.enabled: true

重启kibana,再访问

六、安装metricbeat

docker pull docker.elastic.co/beats/metricbeat:7.9.3
cd /data
mkdir -p metricbeat/config
cd metricbeat/config
vim metricbeat.yml 

配置信息

metricbeat.modules:
- module: system
  period: 10s
  metricsets:
    - cpu
    - load
    - memory
    - network
    - process
    - process_summary
    #- core
    #- diskio
    #- socket
  processes: ['.*']
  process.include_top_n:
    by_cpu: 5      # include top 5 processes by CPU
    by_memory: 5   # include top 5 processes by memory
- module: system
  period: 1m
  metricsets:
    - filesystem
    - fsstat
  processors:
  - drop_event.when.regexp:
     system.filesystem.mount_point: '^/(sys|cgroup|proc|dev|etc|host|lib)($|/)'
- module: system
  period: 15m
  metricsets:
    - uptime

# 直接发送elasticsearch
output.elasticsearch:
  hosts: ["ip:9200","ip:9201","ip:9202"]
  username: "elastic"
  password: "1234556"

# 要加载仪表板,可以在metricbeat设置中启用仪表板加载。当仪表板加载被启用时,Metricbeat使用Kibana API来加载样本仪表板。只有当Metricbeat启动时,才会尝试仪表板加载。
# 设置kibana服务地址
setup.kibana:
  host: "ip:5601"
  username: "elastic"
  password: "123456"
# 加载默认的仪表盘样式
setup.dashboards.enabled: true
# 设置如果存在模板,则不覆盖原有模板
setup.template.overwrite: false

启动metricbeat

docker run -d --privileged=true  \
  --name=metricbeat \
  --user=root \
  --volume="$(pwd)/metricbeat.yml:/usr/share/metricbeat/metricbeat.yml:ro" \
  --volume="/var/run/docker.sock:/var/run/docker.sock:ro" \
  --volume="/sys/fs/cgroup:/hostfs/sys/fs/cgroup:ro" \
  --volume="/proc:/hostfs/proc:ro" \
  --volume="/:/hostfs:ro" \
  docker.elastic.co/beats/metricbeat:7.9.3

有关使用docker搭建es集群的更多相关文章

  1. ruby - 如何使用 Nokogiri 的 xpath 和 at_xpath 方法 - 2

    我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div

  2. ruby - 使用 RubyZip 生成 ZIP 文件时设置压缩级别 - 2

    我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看ruby​​zip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d

  3. ruby - 为什么我可以在 Ruby 中使用 Object#send 访问私有(private)/ protected 方法? - 2

    类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc

  4. ruby-on-rails - 使用 Ruby on Rails 进行自动化测试 - 最佳实践 - 2

    很好奇,就使用ruby​​onrails自动化单元测试而言,你们正在做什么?您是否创建了一个脚本来在cron中运行rake作业并将结果邮寄给您?git中的预提交Hook?只是手动调用?我完全理解测试,但想知道在错误发生之前捕获错误的最佳实践是什么。让我们理所当然地认为测试本身是完美无缺的,并且可以正常工作。下一步是什么以确保他们在正确的时间将可能有害的结果传达给您? 最佳答案 不确定您到底想听什么,但是有几个级别的自动代码库控制:在处理某项功能时,您可以使用类似autotest的内容获得关于哪些有效,哪些无效的即时反馈。要确保您的提

  5. ruby - 在 Ruby 中使用匿名模块 - 2

    假设我做了一个模块如下:m=Module.newdoclassCendend三个问题:除了对m的引用之外,还有什么方法可以访问C和m中的其他内容?我可以在创建匿名模块后为其命名吗(就像我输入“module...”一样)?如何在使用完匿名模块后将其删除,使其定义的常量不再存在? 最佳答案 三个答案:是的,使用ObjectSpace.此代码使c引用你的类(class)C不引用m:c=nilObjectSpace.each_object{|obj|c=objif(Class===objandobj.name=~/::C$/)}当然这取决于

  6. ruby - 使用 ruby​​ 和 savon 的 SOAP 服务 - 2

    我正在尝试使用ruby​​和Savon来使用网络服务。测试服务为http://www.webservicex.net/WS/WSDetails.aspx?WSID=9&CATID=2require'rubygems'require'savon'client=Savon::Client.new"http://www.webservicex.net/stockquote.asmx?WSDL"client.get_quotedo|soap|soap.body={:symbol=>"AAPL"}end返回SOAP异常。检查soap信封,在我看来soap请求没有正确的命名空间。任何人都可以建议我

  7. python - 如何使用 Ruby 或 Python 创建一系列高音调和低音调的蜂鸣声? - 2

    关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。

  8. ruby-on-rails - 'compass watch' 是如何工作的/它是如何与 rails 一起使用的 - 2

    我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t

  9. ruby - 使用 ruby​​ 将 HTML 转换为纯文本并维护结构/格式 - 2

    我想将html转换为纯文本。不过,我不想只删除标签,我想智能地保留尽可能多的格式。为插入换行符标签,检测段落并格式化它们等。输入非常简单,通常是格式良好的html(不是整个文档,只是一堆内容,通常没有anchor或图像)。我可以将几个正则表达式放在一起,让我达到80%,但我认为可能有一些现有的解决方案更智能。 最佳答案 首先,不要尝试为此使用正则表达式。很有可能你会想出一个脆弱/脆弱的解决方案,它会随着HTML的变化而崩溃,或者很难管理和维护。您可以使用Nokogiri快速解析HTML并提取文本:require'nokogiri'h

  10. ruby - 在 64 位 Snow Leopard 上使用 rvm、postgres 9.0、ruby 1.9.2-p136 安装 pg gem 时出现问题 - 2

    我想为Heroku构建一个Rails3应用程序。他们使用Postgres作为他们的数据库,所以我通过MacPorts安装了postgres9.0。现在我需要一个postgresgem并且共识是出于性能原因你想要pggem。但是我对我得到的错误感到非常困惑当我尝试在rvm下通过geminstall安装pg时。我已经非常明确地指定了所有postgres目录的位置可以找到但仍然无法完成安装:$envARCHFLAGS='-archx86_64'geminstallpg--\--with-pg-config=/opt/local/var/db/postgresql90/defaultdb/po

随机推荐