
1.linux内核调整
1)vi /etc/security/limits.conf * hard nofile 131072 * soft nofile 65536 * soft nproc 4096 * hard nproc 4096 * soft memlock unlimited * hard memlock unlimited 2)vi /etc/sysctl.conf vm.max_map_count = 655360 fs.file-max = 1645037 3)执行 sysctl -p 确认更改
2.需要事先准备 jdk1.7及以上版本,安装head插件,node环境
安装jdk,node命令 tar -zxvf elasticsearch-6.8.9.tar.gz && elasticsearch-7.15.2-linux-x86_64.tar.gz && head-plugin.tar.gz && node-v6.10.2-linux-x64.tar.gz
3.配置环境变量
#jdk8 export JAVA_HOME=/usr/local/java8#指定jdk放置的路径 export PATH=$JAVA_HOME/bin:$PATH export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar #node export NODE_PATH=/opt/ES6/head/node-v6.10.2-linux-x64#指定node放置的路径 export PATH=$NODE_PATH/bin:$PATH
4.安装成功命令查看
[root@localhost ~]# node -v v6.10.2 [root@localhost ~]# java -version java version "1.8.0_231" Java(TM) SE Runtime Environment (build 1.8.0_231-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)
5.设置用户及目录权限
#创建用户组 groupadd elasticsearch #创建用户并添加至用户组 useradd elasticsearch -g elasticsearch #更改用户密码(输入 123456) passwd elasticsearch #修改目录权限 chown -R elasticsearch:elasticsearch /opt/ES6/elasticsearch/*
6.es集群配置文件修改elasticsearch.yml
master节点
vi /opt/ES6/elasticsearch/config/elasticsearch.yml
cluster.name: my-application #集群的名字,其他节点这里必须相同 node.name: node1 #节点名称,用于在日志中区分。节点名字不能相同 #指定该节点是否有资格被选举成为master节点,默认是true #es是默认集群中的第一台机器为master,如果这台机挂了就会重新选举master node.master: true ##允许该节点存储数据(默认开启) node.data: true path.data: /opt/ES6/elasticsearch/to/data #数据的默认存放路径 path.logs: /opt/ES6/elasticsearch/to/logs #日志的默认存放路径 #设置为true来锁住内存。因为内存交换到磁盘对服务器性能来说是致命的, #当jvm开始swapping时es的效率会降低,所以要保证它不swap bootstrap.memory_lock: true network.host: 0.0.0.0 #当前节点的IP地址或者填0.0.0.0 http.port: 9200 #对外提供服务的端口,9300为集群服务的端口 ##添加如下内容 #culster transport port transport.tcp.port: 9300 transport.tcp.compress: true #启用head插件必须配置,解决跨域访问问题(!!!必要) http.cors.enabled: true http.cors.allow-origin: "*" #节点发现配置,主节点和其他节点都需要配置 discovery.zen.ping.unicast.hosts: ["IP","IP"] ##集群节点IP地址,也可以使用els、els.es2.com等名称,需要各节点能够解析 discovery.zen.minimum_master_nodes: 2 #避免脑裂,集群节点数最少为半数+1,至少是1
7.集群配置jvm.options
vi /opt/ES6/elasticsearch/config/jvm.options
################################################################ ## importANT: JVM heap size ################################################################ ## You should always set the min and max JVM heap ## size to the same value. For example, to set ## the heap to 4 GB, set: ## -Xms4g ## -Xmx4g ## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html ## for more information ################################################################ # Xms represents the initial size of total heap space # Xmx represents the maximum size of total heap space -Xms256m #根据服务器内存大小分配 -Xmx256m
8.node1节点配置:需要linux内核调整,安装jdk,node,配置环境变量,设置用户及目录权限
注意
1.用scp拷贝到另外一台机器要把 data下的node删除
2.node.master: true 不用配置
9.监控API
GET /_cat
/_cat/health
/_cat/nodes
/_cat/master
/_cat/indices
/_cat/allocation
/_cat/shards
/_cat/shards/{index}
/_cat/thread_pool
/_cat/segments
/_cat/segments/{index}
10.启动es集群,先启动主节点,在启动节点
cd /opt/ES6/elasticsearch/bin
./elasticsearch
11.head配置
1.如果使用老版本的elasticsearch-head服务端的es会返回下面的错误信息,{“error”:“Content-Type header [application/x-www-form-urlencoded] is not supported”,“status”:406}。es6.0的版本不支持,浏览器请求头信息带Content-Type header [application/x-www-form-urlencoded], 需要修改 _site/vendor.js 。找到对应的行 if ( !s.crossDomain && !headers[“X-Requested-With”] ) { 的前面增加一行
headers[“Content-Type” ] = “application/json”
2.默认es是不支持跨域访问的,如何解决es不支持跨域访问?
在/etc/elasticsearch/elasticsearch.yml配置文件中加入以下内容,然后重启服务。
http.cors.enabled: true
http.cors.allow-origin: “*”
3.在head插件目录下 cd /data/elasticsearch-head/
后台行运grunt server &
12.访问集群
通过api查看该集群所有node
通过访问head查看
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)