🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] # 目录 | 文件夹 | 作用 | | --- | --- | | /bin | 运行elasticsearch实例和管理插件的一些脚本 | | /config | 配置文件路径,包含elasticsearch.yml | | /data | 在节点上每个索引/碎片的数据文件的位置.可以有多个目录 | | /lib | ElasticSearch使用的库 | | /logs | 日志的文件夹 | | /plugins | 已经安装的插件的存放位置 | 启动成功会生成个data和logs文件夹 ~~~ //mac es7 brew tap elastic/tap brew install elastic/tap/elasticsearch-full ~~~ # es配置 配置文件位于config目录中 - elaticsearch.yml es的相关配置 - jvm.options jvm相关参数 - log4j2.properties 日志相关配置 --- ## jvm.options文件 里面有个 -Xms1g -Xmx2g 表示默认使用内存1G,可以调小点 --- ## elasticsearch.yml关键配置 * `cluster.name` 集群名称,以此作为是否同一集群的判断条件 * `node.name` 节点名称,以此作为集群中不同节点的区分条件 * `network.host/http.port` 网络地址和端口,用于http和transport服务使用 * `path.data` 数据存储地址 * `path.log` 日志存储地址 如果装了插件不能成功连接到es,添加下面的2个命令 ~~~ # header插件 # 是否支持跨域 http.cors.enabled: true # *表示支持所有域名 http.cors.allow-origin: "*" ~~~ **elasticsearch配置说明** * Development与Production模式说明 * 以transport的地址是否绑定在localhost为判断标准network.host,只要绑定的不是localhost他就认为你在线上模式 - Development模式下在启动时会以warning的方式提示配置检查异常 - Production 模式下启动会以error的方式提示配置检查异常并退出 ## 参数修改的第二种方式 * bin/elasticsearch -E配置名称=配置值 ~~~ bin/elasticsearch -Ehttp.port=19200 ~~~ ## es7需要jdk11 进入bin文件下:`cd bin` 修改es7.4指向java\_home配置 `vi elasticsearch ` 添加一下几行内容: ~~~ #配置自己的jdk11 export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-11.0.5.jdk/Contents/Home export PATH=$JAVA_HOME/bin:$PATH #添加jdk判断 if [ -x "$JAVA_HOME/bin/java" ]; then JAVA="/Library/Java/JavaVirtualMachines/jdk-11.0.5.jdk/Contents/Home/bin/java" else JAVA=`which java` fi ~~~ 上面路径换成自己的 启动es: ./elasticsearch(启动时要切换为普通用户,root身份启动报错!) 这时如果出现以下警告信息: ~~~ OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release. ~~~ 这是提醒你 cms 垃圾收集器在 jdk9 就开始被标注为 @deprecated 这时候去修改jvm.options文件配置 将 `-XX:+UseConcMarkSweepGC` 改为 `-XX:+UseG1GC` 保存文件后退出,再次启动es,若出现 permisson denied错误信息,证明应该给对应的操作用户授权(这点栽了好多坑!!可以切换成root身份给当前普通用户授权,授权的基本上是jdk所在路径、es所在路径及启动时涉及到的一些路径,授权命令:chown -R username 路径地址) # kibana配置 打开 config/kibana.yml这个配置文件,告诉kibana他elasticsearch.url在什么地方 默认`localhost:9200` 下载成功,浏览器访问 `localhost:5601`就可以看到了 **汉化** [https://github.com/anbai-inc/Kibana\_Hanization](https://github.com/anbai-inc/Kibana_Hanization) 7.x配置文件 ~~~ i18n.locale: "zh-CN" ~~~ 配置文件位于config文件夹中 kibana.yml关键配置说明 * server.host/server.port 访问kibana用的地址和端口,如果你想让外网访问你的kibana就要修改这个 * elasticsearch.url待访问elasticsearch的地址 **常用功能** * Discover 数据搜索查看 * Visualize 图标制作 * Dashboard 仪表盘制作 * Timelion 时序数据的高级可视化分析 * DevTools 开发者工具 * Management 配置 # 启动es集群 本地启动集群的方式 1. `./bin/elasticsearch` 2. `./bin/elasticsearch -Ehttp.port=8200 -Epath.data=node2` 3. `./bin/elasticsearch -Ehttp.port=7200 -Epath.data=node3` --- 然后我们启动完就可以用 `http://localhost:9200/_cat/nodes` 看到里面有对应的节点了 `http://localhost:9200/_cat/nodes?v` 可以看到详细说明 master 中* 表示那个是主节点 里面还有cpu,内存等信息 --- 地址栏输入 `http://localhost:9200/_cluster/stats` 可以看到cluster的详细信息 # es配置文件 elasticsearch.yml配置详解 ~~~ # 变量可以用${}这样的形式赋予 #node.rack: ${RACK_ENV_VAR} ~~~ ~~~ # 集群的名称 cluster.name: jdxia ~~~ ~~~ # 节点名称 node.name: "w1" # 1. You want this node to never become a master node, only to hold data. # This will be the "workhorse" of your cluster. # 他是子节点,存储数据 #node.master: false #node.data: true # 2. You want this node to only serve as a master: to not store any data and # to have free resources. This will be the "coordinator" of your cluster. # 假如你的设置是这样,他只做master,不做索引和分片,master节点就是协调各个节点 #node.master: true #node.data: false # # 3. You want this node to be neither master nor data node, but # to act as a "search load balancer" (fetching data from nodes, # aggregating results, etc.) # 都设置为false,他是做了个负载均衡器 #node.master: false #node.data: false ~~~ 数据读取是由集群中各个节点共同完成的,而数据的修改是由集群的master来完成的 ~~~ # 每个节点定义与之关联的属性,进行碎片分配时的过滤,这边使用默认值就行 #node.rack: rack314 # 设置一台服务器能运行的节点数目,一般一台服务器就部署1台 #node.max_local_storage_nodes: 1 ~~~ ~~~ #定义碎片的数量 #index.number_of_shards: 5 #定义副本的数量 #index.number_of_replicas: 1 ~~~ ~~~ #定义配置文件的位置 #path.conf: /path/to/conf #定义索引数据存放的位置 #path.data: /path/to/data #也可以定义多个路径 #path.data: /path/to/data1,/path/to/data2 #定义临时文件的路径 #path.work: /path/to/work #定义日志文件的路径 #path.logs: /path/to/logs #定义插件的位置 #path.plugins: /path/to/plugins ~~~ ~~~ # 插件的名字,如果这个节点这个插件没有安装就不能启动 #plugin.mandatory: mapper-attachments,lang-groovy ~~~ ~~~ # 设为true表示会锁定一些内存给es,一般这个内存是给jvm的 bootstrap.mlockall: true ~~~ ~~~ # elasticsearch绑定的地址,可以(IPv4 or IPv6) #network.bind_host: 192.168.0.1 # es发布的地址,就是和其他节点通信的地址 #network.publish_host: 192.168.0.1 # 如果这边设置,上面的2个设置可以都不用设置了 #network.host: 192.168.0.1 # 定义是否压缩tcp传输的数据 #transport.tcp.compress: true # http协议的端口 #http.port: 9200 # 设置http交互中传输内容的最大长度 #http.max_content_length: 100mb # 禁用和启用http协议 #http.enabled: false ~~~ ~~~ # es的持久化存储,local是本地文件 gateway.type: local # 控制集群在达到多少个节点后才会开始数据恢复功能,可以避免集群初期自动发现share分片不全的问题,比如设置5,集群必须有5个节点才能进行数据分片 #gateway.recover_after_nodes: 1 # 初始化数据恢复过程的超时时间 #gateway.recover_after_time: 5m # 初始化数据恢复过程的超时时间,这个具体是节点都启动成功,过了5分钟才能进行数据恢复 #gateway.recover_after_time: 5m # 设置在集群中多少个节点启动成功后就马上开始数据恢复 #gateway.expected_nodes: 2 ~~~ ~~~ #是设置一个节点的并发数量,初始恢复过程中 #cluster.routing.allocation.node_initial_primaries_recoveries: 4 # 添加删除节点和负载均衡时的个数 #cluster.routing.allocation.node_concurrent_recoveries: 2 #设置恢复时限制的宽带,0就是无限制 #indices.recovery.max_bytes_per_sec: 20mb # 限制从其他分片,最大打开并发流的限制 #indices.recovery.concurrent_streams: 5 ~~~ ~~~ # 设置多少个节点,可以成为候选节点的个数,如果你集群中节点数量比较多可以设置为2~4 #discovery.zen.minimum_master_nodes: 1 #自动发现其他节点的,超时时间,网络环境比较差可以设置高点 #discovery.zen.ping.timeout: 3s # 设置是否打开多播协议发现其他节点 discovery.zen.ping.multicast.enabled: true # 设置集群中master节点,初始化列表,里面的host用来自动发现加入集群的节点 #discovery.zen.ping.unicast.hosts: ["host1", "host2:port"] # 设置log,debug的打印四份 # # query查询 #index.search.slowlog.threshold.query.warn: 10s #index.search.slowlog.threshold.query.info: 5s #index.search.slowlog.threshold.query.debug: 2s #index.search.slowlog.threshold.query.trace: 500ms # fetch获取 #index.search.slowlog.threshold.fetch.warn: 1s #index.search.slowlog.threshold.fetch.info: 800ms #index.search.slowlog.threshold.fetch.debug: 500ms #index.search.slowlog.threshold.fetch.trace: 200ms #index.indexing.slowlog.threshold.index.warn: 10s #index.indexing.slowlog.threshold.index.info: 5s #index.indexing.slowlog.threshold.index.debug: 2s #index.indexing.slowlog.threshold.index.trace: 500ms # 设置jvm的gc打印时间 #monitor.jvm.gc.young.warn: 1000ms #monitor.jvm.gc.young.info: 700ms #monitor.jvm.gc.young.debug: 400ms #monitor.jvm.gc.old.warn: 10s #monitor.jvm.gc.old.info: 5s #monitor.jvm.gc.old.debug: 2s # 开始jsonp的数据交换格式 http.jsonp.enable: true ~~~ # 简单的集群管理 es提供了一套api,叫做cat api,可以查看es中各种各样的数据 ~~~ GET /_cat/health?v ~~~ * green:每个索引的primary shard和replica shard都是active状态的 * yellow:每个索引的primary shard都是active状态的,但是部分replica shard不是active状态,处于不可用的状态 * red:不是所有索引的primary shard都是active状态的,部分索引有数据丢失了