Elasticsearch集群+Elasticsearch-head安装和常见问题解决

1 篇文章 0 订阅
1 篇文章 0 订阅
  1. JDK8的安装就不多说了

  2. Elasticsearch-6.3.2的安装

下载地址https://www.elastic.co/downloads/elasticsearch

<1>解压elasticsearch安装包 (安装在 /opt/elasticsearch/elasticsearch-6.3.2/)

unzip elasticsearch-6.3.2.zip

 <2>创建elasticsearch用户,root用户启动elasticsearch会失败

groupadd elsearch

useradd elsearch -g elsearch

chown -R elsearch:elsearch /opt/elasticsearch/elasticsearch-6.3.2/

<3>修改配置文件elasticsearch.yml

要想能其他机器访问需要配置network.host: 192.168.142.103

3.安装Elasticsearch-head

1.安装nodejs、npm

yum -y install nodejs npm

2.如果没有安装git,还需要先安装git

yum -y install git

3.下载

git clone https://github.com/mobz/elasticsearch-head.git

4.git下载完成后,进入目录,进行操作:

cd elasticsearch-head/

npm install   (npm会比较慢,也可以用淘宝镜像cnpm,自行安装)

5.修改Gruntfile.js文件

 

6.修改_site/app.js

 

7.npm run start启动。Elasticsearch-head默认端口是9100,Elasticsearch的http端口9200,tcp端口9300(节点间交互用9300)

4.Elasticsearch的多节点配置

1.主节点配置

#节点名称

node.name: master

#是否有主节点资格

node.master: true

#集群名称

cluster.name: elasticsearch

#节点ip

network.host: 192.168.142.103

#节点端口

http.port: 9200

transport.tcp.port: 9300

#master最少多少个

discovery.zen.minimum_master_nodes: 1

#节点列表 默认端口9300,非9300需要带上端口号,自动轮询发现

discovery.zen.ping.unicast.hosts: ["192.168.142.103:9300","192.168.142.103:9301","192.168.142.103:9302"]

#是否支持跨域

http.cors.enabled: true

# *表示支持所有域名

http.cors.allow-origin: "*"

2.从节点配置,扩充方法类似。记得拷贝整个elasticsearch,需要删除data目录下文件,或者分开手动设置data目录

#节点名称

node.name: node1

#是否有主节点资格

node.master: false

#集群名称

cluster.name: elasticsearch

#节点ip

network.host: 192.168.142.103

#节点端口

http.port: 9201

transport.tcp.port: 9301

#master最少多少个

discovery.zen.minimum_master_nodes: 1

#节点列表 默认端口9300,非9300需要带上端口号,自动轮询发现

discovery.zen.ping.unicast.hosts:["192.168.142.103:9300","192.168.142.103:9301","192.168.142.103:9302"]

#是否支持跨域

http.cors.enabled: true

# *表示支持所有域名

http.cors.allow-origin: "*"

3.全部启动之后,可写shell脚本在后台启动和停止

 

Elasticsearch配置详情

cluster.name: elasticsearch

配置es的集群名称,默认是elasticsearch,es会自动发现在同一网段下的es,如果在同一网段下有多个集群,就可以用这个属性来区分不同的集群。

node.name: "Franz Kafka"

节点名,默认随机指定一个name列表中名字,该列表在es的jar包中config文件夹里name.txt文件中,其中有很多作者添加的有趣名字。

node.master: true

指定该节点是否有资格被选举成为node,默认是true,es是默认集群中的第一台机器为master,如果这台机挂了就会重新选举master。

node.data: true

指定该节点是否存储索引数据,默认为true。

index.number_of_shards: 5

设置默认索引分片个数,默认为5片。

index.number_of_replicas: 1

设置默认索引副本个数,默认为1个副本。

path.conf: /path/to/conf

设置配置文件的存储路径,默认是es根目录下的config文件夹。

path.data: /path/to/data

设置索引数据的存储路径,默认是es根目录下的data文件夹,可以设置多个存储路径,用逗号隔开,例:

path.data: /path/to/data1,/path/to/data2

path.work: /path/to/work

设置临时文件的存储路径,默认是es根目录下的work文件夹。

path.logs: /path/to/logs

设置日志文件的存储路径,默认是es根目录下的logs文件夹

path.plugins: /path/to/plugins

设置插件的存放路径,默认是es根目录下的plugins文件夹

bootstrap.mlockall: true

设置为true来锁住内存。因为当jvm开始swapping时es的效率 会降低,所以要保证它不swap,可以把ES_MIN_MEM和ES_MAX_MEM两个环境变量设置成同一个值,并且保证机器有足够的内存分配给es。 同时也要允许elasticsearch的进程可以锁住内存,linux下可以通过`ulimit -l unlimited`命令。

network.bind_host: 192.168.0.1

设置绑定的ip地址,可以是ipv4或ipv6的,默认为0.0.0.0。

network.publish_host: 192.168.0.1

设置其它节点和该节点交互的ip地址,如果不设置它会自动判断,值必须是个真实的ip地址。

network.host: 192.168.0.1

这个参数是用来同时设置bind_host和publish_host上面两个参数。

transport.tcp.port: 9300

设置节点间交互的tcp端口,默认是9300。

transport.tcp.compress: true

设置是否压缩tcp传输时的数据,默认为false,不压缩。

http.port: 9200

设置对外服务的http端口,默认为9200。

http.max_content_length: 100mb

设置内容的最大容量,默认100mb

http.enabled: false

是否使用http协议对外提供服务,默认为true,开启。

gateway.type: local

gateway的类型,默认为local即为本地文件系统,可以设置为本地文件系统,分布式文件系统,hadoop的HDFS,和amazon的s3服务器,其它文件系统的设置方法下次再详细说。

gateway.recover_after_nodes: 1

设置集群中N个节点启动时进行数据恢复,默认为1。

gateway.recover_after_time: 5m

设置初始化数据恢复进程的超时时间,默认是5分钟。

gateway.expected_nodes: 2

设置这个集群中节点的数量,默认为2,一旦这N个节点启动,就会立即进行数据恢复。

cluster.routing.allocation.node_initial_primaries_recoveries: 4

初始化数据恢复时,并发恢复线程的个数,默认为4。

cluster.routing.allocation.node_concurrent_recoveries: 2

添加删除节点或负载均衡时并发恢复线程的个数,默认为4。

indices.recovery.max_size_per_sec: 0

设置数据恢复时限制的带宽,如入100mb,默认为0,即无限制。

indices.recovery.concurrent_streams: 5

设置这个参数来限制从其它分片恢复数据时最大同时打开并发流的个数,默认为5。

discovery.zen.minimum_master_nodes: 1

设置这个参数来保证集群中的节点可以知道其它N个有master资格的节点。默认为1,对于大的集群来说,可以设置大一点的值(2-4)

discovery.zen.ping.timeout: 3s

设置集群中自动发现其它节点时ping连接超时时间,默认为3秒,对于比较差的网络环境可以高点的值来防止自动发现时出错。

discovery.zen.ping.multicast.enabled: false

设置是否打开多播发现节点,默认是true。

discovery.zen.ping.unicast.hosts: ["host1", "host2:port", "host3[portX-portY]"]

设置集群中master节点的初始列表,可以通过这些节点来自动发现新加入集群的节点。

下面是一些查询时的慢日志参数设置

index.search.slowlog.level: TRACE

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

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

 

 

<4>启动并查看,需要使用非root用户启动

[elsearch@imok bin]$ ./elasticsearch -d

 

查看是否启动成功: curl http://自己配置的IP地址:9200/

[sunkang@localhost ~]$ curl 192.168.142.103:9200
{
  "name" : "node-1",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "-B5GsciBTgOgmXEqVpiDEw",
  "version" : {
    "number" : "6.4.1",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "e36acdb",
    "build_date" : "2018-09-13T22:18:07.696808Z",
    "build_snapshot" : false,
    "lucene_version" : "7.4.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

 

Elasticsearch启动常见错误

1、max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

每个进程最大同时打开文件数太小需要配置 vi /etc/security/limits.conf,然后重启服务器或者重新登录用户生效

# elasticsearch config start

*               soft    nofile          65536

*               hard    nofile          65536

*               soft    nproc           4096

*               hard    nproc           4096

# elasticsearch config end

2、max number of threads [3818] for user [es] is too low, increase to at least [4096]
问题同上,最大线程个数太低。修改配置文件/etc/security/limits.conf(和问题1是一个文件),增加配置上图已经配置该问题的配置

* soft nproc 4096
* hard nproc 4096

 

  1. max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

修改/etc/sysctl.conf文件,增加配置vm.max_map_count=262144然后sysctl -p生效

  1. Exception in thread "main" java.nio.file.AccessDeniedException: /usr/local/elasticsearch/elasticsearch-6.2.2-1/config/jvm.options

没有权限,执行安装操作中的步骤

chown -R elsearch:elsearch /opt/elasticsearch/elasticsearch-6.3.2/

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值