0
点赞
收藏
分享

微信扫一扫

elasticsearch集群、kibana、head 部署

环境准备

操作系统:centos7

硬件需求:硬盘500G,内存32G,CPU 8核

3台服务器:机器A,机器B,机器C(最少3台服务器)

下载包并安装:elasticsearch-6.2.2.tar.gz、kibana-6.2.2-linux-x86_64.tar.gz、elasticsearch-head.tar.gz、jdk-8u162-linux-x64.tar.gz

centos 7修改主机名

hostnamectl set-hostname es-208

修改 /etc/hosts 添加本机hostname


jdk必须1.8以上,但是不建议用9

服务器规划:

IP

说明

172.16.2.65

elasticsearch、elasticsearch-head、kibana

172.16.2.66

elasticsearch

172.16.2.36

elasticsearch

备注:因机器数量只有3台服务器,节点配置使用默认配置(node.master、 node.data默认是true)

默认情况下,elasticsearch 集群中每个节点都有成为主节点的资格,也都存储数据,还可以提供查询服务。当扩容服务器可增加data和client节点进行负载。

端口规划

服务

端口

elasticsearch

9200(程序连接端口)、9300(集群之间通讯)

elasticsearch-head

9100

kibana

5601

iptable:

需限制以上端口,不允许随意连接。

centos7防火墙配置例句

firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="172.16.2.36" port protocol="tcp" port="9200" accept"

systemctl restart firewalld.service


启动顺序:

先启动elasticsearch所有节点

再启动elasticsearch-head

最后启动kibana


部署

1、jdk

检查jdk版本:java -version (jdk1.8版本及以上)

jdk1.8部署 

cd /data/tools/

tar -zxvf jdk-8u162-linux-x64.tar.gz

ln -s jdk1.8.0_162 jdk

vim /etc/profile

export JAVA_HOME=/data/tools/jdk

export PATH=/data/tools/jdk/bin:$PATH

保存

source /etc/profile


2、elasticsearch

创建es用户、目录并解压软件包、修改权限

useradd  es

cd /data/server

tar -zxvf elasticsearch-ysten-6.2.2.tar.gz

ln -s elasticsearch-6.2.2 elasticsearch

chown -R es.es /data/server/elasticsearch-6.2.2

chown -R es.es /data/server/elasticsearch

mkdir -p /data/data/es/data

mkdir -p /data/data/es/logs

chown -R es.es /data/data/es


修改系统参数:

vim  /etc/sysctl.conf   文件最后添加一行

vm.swappiness = 0

vm.max_map_count=262144


执行 sysctl -p

#查看结果:

sysctl -a|grep vm.max_map_count


#修改文件最大数

vim /etc/security/limits.conf

* soft nofile 262144

* hard nofile 262144

#centos 7 改

vim /etc/security/limits.d/20-nproc.conf

* soft nofile 262144

* hard nofile 262144

es soft memlock unlimited

es hard memlock unlimited


elasticsearch配置文件修改

/data/server/elasticsearch/config/jvm.options 

vim /data/server/elasticsearch/config/jvm.options     #2行

-Xms4g

-Xmx4g

/data/server/elasticsearch/config/elasticsearch.yml 

###es6.0修改配置

vim /data/server/elasticsearch/config/elasticsearch.yml

cluster.name: es-nginx-access

node.name: node-172-16-2-65

path.data: /data/data/es/data

path.logs: /data/data/es/logs

network.host: 172.16.2.65

http.port: 9200

transport.tcp.port: 9300

discovery.zen.ping.unicast.hosts: ["172.16.2.65", "172.16.2.36", "172.16.2.36"]

discovery.zen.minimum_master_nodes: 2

cluster.routing.allocation.disk.watermark.low: 92%

cluster.routing.allocation.disk.watermark.high: 95%

http.cors.enabled: true

http.cors.allow-origin: "*"



#reindex.remote.whitelist: ["172.16.2.12:9200"]  #迁移数据使用,不迁移不用配置



###es7.0修改配置

#Ysten

cluster.name: hlj-es-logs

node.name: node-195

path.data: /data/data/es/data01,/data/data/es/data02,/data/data/es/data03,/data/data/es/data04,/data/data/es/data05

path.logs: /data/data/es/logs

network.host: x.x.x.x

http.port: 9200

transport.tcp.port: 9300

discovery.seed_hosts: ["x.x.x.x", "x.x.x.x","x.x.x.x"]

cluster.initial_master_nodes: ["node-195", "node-196","node-197"]

http.cors.enabled: true

http.cors.allow-origin: "*"

http.cors.allow-credentials: true

:wq!


备注

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

node.name: 节点名,建议使用ip方式,例子:node-172-16-2-65


path.data:索引数据目录

path.logs:日志文件目录

network.host:设置本机ip

http.port:服务端口,默认9200

transport.tcp.port:集群通讯端口

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

discovery.zen.minimum_master_nodes:N/2 + 1,N是集群中节点的数量(向下取整),3个节点写2,5个节点写3

# 下面两行配置为haad插件配置

http.cors.enabled: truehttp.cors.allow-origin: "*"


启动、关闭脚本

服务启动、关闭脚本 

cd /data/server/elasticsearch

#启动脚本

vim start.sh

#!/bin/bash

su es -s /bin/bash -c "/data/server/elasticsearch/bin/elasticsearch -d"


#关闭脚本

vim killes.sh

#!/bin/bash

ps -ef | grep '/data/server/elasticsearch/' | grep -v grep|awk '{print $2}' | xargs -i -t kill  {}

启动:/data/server/elasticsearch/start.sh

关闭:/data/server/elasticsearch/killes.sh

1,查看es集群状态​http://ip:port/_cat/health?v​

2,集群节点健康查看​http://ip:port/_cat/nodes?v​

curl -sXGET http://ip:9200/_cluster/health/?pretty

3,列出集群索引​http://ip:port/_cat/indices?v​

4.删除索引

curl -XDELETE 'http://172.16.2.12:9200/applog.*'


到此elasticsearch集群搭建完毕!


elasticsearch节点下线:

在其中一台es上执行:

curl  -H "Content-Type:application/json" -XPUT 192.168.16.221:9200/_cluster/settings -d '{"transient" :{"cluster.routing.allocation.exclude._ip": "192.168.16.221"}}' 

红色IP为要下线的节点IP

Elasticsearch 集群就会自动把这个 IP 上的所有分片(紫色状态块),都自动转移到其他节点上。等到转移完成,这个空节点就可以毫无影响的下线了。和 _ip 类似的参数还有 _host, _name 等。此外,这类参数不单是 cluster 级别,也可以是 index 级别。下一小节就是 index 级别的用例。

检查集群状态


curl -XGET 'http://ES_SERVER:9200/_cluster/health?pretty'


从es-head上看到需要下线的节点数据块为空时,可以关停下线节点

参考url: ​https://blog.csdn.net/zxf_668899/article/details/53945145#节点下线​


elasticsearch pinyin 拼音插件安装


需根据es版本查找到对应的pinyin插件版本下载:

2.13提供6.2.4版本pinyin下载:elasticsearch-analysis-pinyin-6.2.4.tar.gz


进入es的插件目录

cd /data/server/elasticsearch/plugins

wget http://x.x.x.x:8080/elasticsearch/elasticsearch-analysis-pinyin-6.2.4.tar.gz

tar -zxvf elasticsearch-analysis-pinyin-6.2.4.tar.gz

rm -rf elasticsearch-analysis-pinyin-6.2.4.tar.gz

#无需修改配置,重启es服务

#验证方法:

curl  -H "Content-Type:application/json" -XGET IP:9200/_analyze/?pretty -d '{"analyzer": "pinyin","text": "xxx"}'





3、elasticsearch-head插件

nodejs安装

nodejs安装 

cd /data/tools

tar -zxvf node-v8.10.0-linux-x64-ysten.tar.gz

ln -s node-v8.10.0-linux-x64 nodejs

vim /etc/profile

#set node

export NODE_HOME=/data/tools/nodejs

export PATH=$PATH:$NODE_HOME/bin

export NODE_PATH=$NODE_HOME/lib/node_modules

source /etc/profile

node -v


elasticsearch-head 

/data/server

tar -zxvf elasticsearch-head-ysten.tar.gz

chown es.es -R /data/server/elasticsearch-head/

cd /data/server/elasticsearch-head/

检查是否安装成功grunt -version

显示grunt-cli v1.2.0grunt v1.0.1 即成功

备注:请使用提供的下载包安装,否则需要执行 npm install -g grunt-cli、npm install 等需翻墙。

修改Gruntfile.js文件,添加 hostname: '*':

vim /data/server/elasticsearch-head/Gruntfile.jsconnect: {  server: {    options: {        hostname: '*',        port: 9100,        base: '.',        keepalive: true     }   }}


修改_site/app.js 文件第4354行

vim /data/server/elasticsearch-head/_site/app.jsthis.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://172.16.2.65:9200";

启动grunt server后台启动nohup grunt server &

启动脚本:/data/server/elasticsearch-head/start.sh

访问:http://172.16.2.65:9100/​


4、kibana

kibana版本要和es版本相同

cd /data/servertar -zxvf kibana-ysten-6.2.2.tar.gz

修改配置文件 config/kibana.ymlserver.port: 5601server.host: "172.16.2.65"server.name: "es-nginx-access-kibana"elasticsearch.url: "http://172.16.2.35:9200"

启动:/data/server/kibana/start.sh

访问:http://172.16.2.65:5601/


5、监控


1、对9200和9300端口监控

2、脚本监控集群健康状态

#!/bin/bash

es_ip="172.16.2.65"

result=`/bin/curl -sXGET http://${es_ip}:9200/_cluster/health/?pretty | grep "status"|awk -F '[ "]+' '{print $4}'`


if [ "green" == "$result" ]; then

  echo 0

elif [ "yellow" == "$result" ]; then

  echo 1

else

  echo 2

fi




nginx配置

由于es集群服务器只提供了一台服务器具备公网ip,使用nginx转发es

cd /data/server/nginx-1.14.0

. /configure  --prefix= /data/server/nginx 

make  &&  make  install 


vim nginx.conf


#user  nobody;

worker_processes  4;

#error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

worker_rlimit_nofile 102400;

events {

    worker_connections  102400;

    use epoll;

}


http {

    include       mime.types;

    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

                      '$status $body_bytes_sent "$http_referer" '

                      '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;

    tcp_nopush     on;

    #keepalive_timeout  0;

    keepalive_timeout  65;

    #gzip  on;

    include conf.d/*.conf;

}



cd /data/server/nginx/conf/conf.d

cat upstream.conf

upstream es {

#    keepalive 500;

    server  192.168.16.207:9200;

    server  192.168.18.208:9200;

    server  192.168.18.209:9200;

}



cat vhost.conf

#es

server {

    listen 8888;

    access_log  logs/es.access.log main;

    error_log  logs/es.error.log;

    root   html;

    index  index.html index.htm;

    location / {

        proxy_pass http://es;

        proxy_http_version 1.1;

        proxy_set_header Connection "";

        proxy_set_header Host $http_host;

        proxy_redirect off;

        proxy_set_header X-Real-IP $remote_addr;

        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    }

}





数据清理\切割脚本


脚本名称

脚本文件

脚本存放路径

crontab计划

nignx日志切割脚本

/data/server/nginx/sbin

10 0 * * * /data/server/nginx/sbin/nginx_logcut.sh  >/dev/null 2>&1

es日志清理

/data/script/

30 0 * * * /data/script/clear_logs.sh > /dev/null 2>&1

es-curator索引管理(定时清理)

elasticsearch-curator

/data/server/elasticsearch-curator/

5 0 * * * /data/server/elasticsearch-curator/del_es_index.sh


elasticsearch-curator索引管理

概述

curator允许对索引和快照执行许多不同的操作,包括:1、从别名添加或删除索引(或两者!)2、更改分片路由分配3、关闭索引4、创建索引5、删除索引6、删除快照7、打开被关闭的索引8、对索引执行forcemerge段合并操作9、reindex索引,包括来自远程集群的索引10、更改索引的每个分片的副本数11、rollover索引12、生成索引的快照(备份)13、还原快照

目前只用到定时删除索引功能

官网地址:


安装

1、

rpm --import ​​https://packages.elastic.co/GPG-KEY-elasticsearch​​
vim /etc/yum.repos.d/curator.repo


#centos7增加

[curator-5]
name=CentOS/RHEL 7 repository for Elasticsearch Curator 5.x packages
baseurl=​​https://packages.elastic.co/curator/5/centos/7​​
gpgcheck=1
gpgkey=​​https://packages.elastic.co/GPG-KEY-elasticsearch​​
enabled=1

##centos6增加

[curator-5]
name=CentOS/RHEL 6 repository for Elasticsearch Curator 5.x packages
baseurl=​​https://packages.elastic.co/curator/5/centos/6​​
gpgcheck=1
gpgkey=​​https://packages.elastic.co/GPG-KEY-elasticsearch​​
enabled=1


2、

yum install -y elasticsearch-curator
curator_cli --version
curator --version

wget http://x.x.x.x:8080/fkfo/elasticsearch-curator.tar.gz

cd /data/server/

定时删除索引,保留最近N天索引配置:config.yml

# Remember, leave a key empty if there is no value.  None will be a string,
# # not a Python "NoneType"
 
client:
  hosts:
    - ​​x.x.x.x​​​​​​​​​​
  port: 9200
  url_prefix:
  use_ssl: False
  certificate:
  client_cert:
  client_key:
  ssl_no_validate: False
  http_auth:
  timeout: 30
  master_only: False
 
logging:
  loglevel: INFO
  logfile: /data/server/elasticsearch-curator/logs
  logformat: default
  blacklist: ['elasticsearch', 'urllib3']

action.yml

# Remember, leave a key empty if there is no value.  None will be a string,
# # not a Python "NoneType"
# #
# # Also remember that all examples have 'disable_action' set to True.  If you
# # want to use this action as a template, be sure to set this to False after
# # copying it.
 
actions:
  1:
    action: delete_indices
    description: >-
      Delete indices older than 7 days (based on index name), for logstash-
      prefixed indices. Ignore the error if the filter does not result in an
      actionable list of indices (ignore_empty_list) and exit cleanly.
    options:
      ignore_empty_list: True
      disable_action: False
    filters:
    - filtertype: pattern
      kind: timestring
      value: '%Y.%m.%d'
    - filtertype: age
      source: name
      direction: older
      timestring: '%Y.%m.%d'
      unit: days
      unit_count: 7

del_es_index.sh

#!/bin/bash
 
#crontab
#5 0  * * * /data/server/elasticsearch-curator/​​del_es_index.sh​​
 
curator_path='/data/server/elasticsearch-curator'
curator --config  $curator_path/​​config.yml​​ $curator_path/​​action.yml​​



基于磁盘的碎片分配

设置

可能的值

描述

cluster.routing.allocation.disk.threshold_enabled

布尔值(默认为true)

这启用和禁用磁盘分配决策程序。

cluster.routing.allocation.disk.watermark.low

字符串值(默认为85%)

这表示磁盘的最大使用; 此后,无法将其他碎片分配给该磁盘。此设置对新创建索引的主要碎片没有影响,特别是对以前从未分配过的任何碎片。

默认 85% 当达到时,replica 不再写入

cluster.routing.allocation.disk.watermark.high

字符串值(默认为90%)

这表示分配时的最大使用量; 如果在分配时达到这一点,Elasticsearch将把该碎片分配给另一个磁盘。

 默认 90% 当达到时,shards 会尝试写入其他节点

cluster.routing.allocation.disk.watermark.flood_stage

字符串值(默认为95%)

这意味着ElasticSearch对每个索引强制执行只读索引块(index.blocks.read-only-allow-delete),该索引在节点上分配了一个或多个碎片,其中至少有一个磁盘超过了洪泛阶段。这是防止节点耗尽磁盘空间的最后手段。一旦有足够的磁盘空间允许索引操作继续,则必须手动释放索引块。

默认 95% 当达到时,所有索引变为 readonly状态

cluster.info.update.interval

字符串值(默认30s)

这是磁盘用法,检查两个时间之间的间隔。

cluster.routing.allocation.disk.include_relocations

布尔值(默认为true)

这决定在计算磁盘使用率时是否考虑当前分配的分片。


动态设置

PUT _cluster/settings{"transient": {

"cluster.routing.allocation.disk.watermark.low": "96%","cluster.routing.allocation.disk.watermark.high": "98%","cluster.routing.allocation.disk.watermark.flood_stage": "99%"

}}

ElasticHD 

ElasticHD 是一款 ElasticSearch的可视化应用。不依赖ES的插件安装,更便捷;导航栏直接填写对应的ES IP和端口就可以操作Es了。

下载地址:

cat start.sh #!/bin/bash

nohup /data/server/ElasticHD/ElasticHD -p x.x.x.x:9800 &

访问地址:http://x.x.x.x:9800​


故障排查


1、es-nginx日志收集中 es磁盘空间不足,导致无法分片,es启动自保模式索引只读,br34_access_loader_server程序报错无法写入

解决办法,

1、清理磁盘空间

2、调整磁盘碎片水位线

es-head

动态设置

PUT _cluster/settings
{
"transient": {

"cluster.routing.allocation.disk.watermark.low": "96%",
"cluster.routing.allocation.disk.watermark.high": "98%",
"cluster.routing.allocation.disk.watermark.flood_stage": "99%"

}
}


3、es-head执行 ,关闭只读

es-head

PUT _settings

{
"index": {
"blocks": {
"read_only_allow_delete": "false"
}
}
}











举报

相关推荐

0 条评论