ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

ES-elasticsearch-集群搭建

2021-08-04 18:31:08  阅读:244  来源: 互联网

标签:http kibana xx 集群 ES elasticsearch 10.60 es


一、基础环境搭建

#关闭selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
systemctl stop firewalld.service && systemctl disable firewalld.service
#配置服务器代理,更新服务器内核、依赖等【选做】
#设置yum代理
echo 'proxy=http://xx.xx.xx.xx:3128' >> /etc/yum.conf
mkdir -p /etc/yum.repos.d/backup && mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/
#通过代理下载阿里yum源
wget -e 'http_proxy=http://xx.xx.xx.xx:3128' http://mirrors.aliyun.com/repo/Centos-7.repo -O /etc/yum.repos.d/Centos-7.repo
wget -e 'http_proxy=http://xx.xx.xx.xx:3128' http://mirrors.aliyun.com/repo/epel-7.repo -O /etc/yum.repos.d/epel-7.repo
#更新内核、依赖
yum install -y epel-release
yum clean all && yum makecache && yum update -y

#修改主机名[对应的修改成es-node2\es-node3]
vim /etc/hostname
    es-node1

#修改hosts文件
vim /etc/hosts
10.60.4.x      es-node1
10.60.4.x      es-node2
10.60.4.x      es-node3

#重启服务器
reboot

二、下载es安装包

官网:https://www.elastic.co/cn/downloads/

elasticsearch-7.13.4-linux-x86_64.tar.gz

mkdir /app
cd /app
mv /tmp/elasticsearch-7.13.4-linux-x86_64.tar.gz  ./
#解压ES安装包
tar zxvf elasticsearch-7.13.4-linux-x86_64.tar.gz
#ES需要使用非root用户启动
groupadd elasticsearch
useradd elasticsearch -g elasticsearch -p elasticsearch
#修改es安装包为ES用户属主属组
chown -R elasticsearch:elasticsearch /app/elasticsearch-7.13.4

#修改es配置文件
vim /app/elasticsearch-7.13.4/config/elasticsearch.yml
    cluster.name: 集群名称
    node.name:  前端节点主机名
    path.data:  数据存放路径,若没有需要手动创建
    path.logs:  日志文件存放路径,若没有需要手动创建
    network.host: 当前服务器IP
    http.port:   服务端口
    discovery.seed_hosts:  集群节点
    cluster.initial_master_nodes: 集群可选做master的节点

#附一份其中某节点的配置文件[其他两个节点,只需要修改node.name 与network.host 即可]
[root@es-node1 ~]# cat /app/elasticsearch-7.13.4/config/elasticsearch.yml |grep -v '^#'
    cluster.name: my-application
    node.name: es-node1
    path.data: /data/es/data
    path.logs: /data/es/logs
    network.host: 10.60.4.x
    http.port: 9200
    discovery.seed_hosts: ["es-node1", "es-node2","es-node3"]
    cluster.initial_master_nodes: ["es-node1", "es-node2","es-node3"]

#创建es数据及日志目录
mkdir -p /data/es/{data,logs}
chown -R elasticsearch:elasticsearch /data/es

#修改JVM的使用内存大小,建议为服务器内存的一半
vim /app/elasticsearch-7.13.4/config/jvm.options
    -Xms16g
    -Xmx16g

#修改vm.max_map_count 的大小[如果启动的时候,有报错,可根据系统建议的大小进行修改]
vim /etc/sysctl.conf
    vm.max_map_count=262144

#修改后,立即生效
sysctl -p

#使用es用户启动ES
su - elasticsearch
cd /app/elasticsearch-7.13.4/bin
./elasticsearch -d

三、查看服务状态

#ES正常启动后,会启动9200与9300端口
[root@es-node2 ~]# ss -tnlp |grep '9[2-3]00'
LISTEN     0      128    10.60.4.40:9200                     *:*                   users:(("java",pid=2747,fd=323))
LISTEN     0      128    10.60.4.40:9300                     *:*                   users:(("java",pid=2747,fd=295))

#9200作为HTTP协议,主要用于外部通讯
#9300作为TCP协议,jar之间就是通过tcp协议通讯

#查看集群状态
curl http://10.60.4.x:9200/  #查看当前节点
{
  "name" : "es-node1", #当前节点主机名
  "cluster_name" : "my-application", #所属于集群名称
  "cluster_uuid" : "Qhp6u-p6Qqe85AzK4Xq4-g", #集群ID
  "version" : {
    "number" : "7.13.4", #ES版本
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "c5f60e894ca0c61cdbae4f5a686d9f08bcefc942",
    "build_date" : "2021-07-14T18:33:36.673943207Z",
    "build_snapshot" : false,
    "lucene_version" : "8.8.2",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

curl http://10.60.4.x:9200/_cluster/health?pretty  #查看当前集群状态
{
  "cluster_name" : "my-application",  #集群名称
  "status" : "green",   #集群状态 green 最健康状态 red 非健康状态 、yellow 亚健康状态;基本的分片可用,但是备份不可用(或者是没有备份)
  "timed_out" : false,
  "number_of_nodes" : 3, #节点数
  "number_of_data_nodes" : 3, #数据节点数
  "active_primary_shards" : 0,
  "active_shards" : 0,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 0,
  "delayed_unassigned_shards" : 0,
  "number_of_pending_tasks" : 0,
  "number_of_in_flight_fetch" : 0,
  "task_max_waiting_in_queue_millis" : 0,
  "active_shards_percent_as_number" : 100.0
}

四、安装kibana

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

#解压kibana
tar zxvf kibana-7.13.4-linux-x86_64.tar.gz
mv kibana-7.13.4-linux-x86_64 /app/

#配置nginx,让kibana监听nginx负载均衡,防止后端es某节点宕机后kinaba还能继续试用
#在nginx的http模块中添加配置
 upstream elasticsearch {
        zone elasticsearch 64K;
        server 10.60.4.x:9200;
        server 10.60.4.x:9200;
        server 10.60.4.x:9200;
    }
    server {
        listen 9222;
        location / {
        proxy_pass http://elasticsearch;
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }

#配置kibana
vim /app/kibana-7.13.4-linux-x86_64/config/kibana.yml
    server.port: 5601   #kibane端口
    server.host: "10.60.4.x" #本机IP
    server.name: "10.60.4.x" #本机IP
    elasticsearch.hosts: ["http://10.60.4.x:9222"]  #nginx服务器IP

#启动kibana
cd /app/kibana-7.13.4-linux-x86_64/bin/
./kibana --allow-root   #kibana 禁止使用root用户启动,可切换用户启动或强制使用root启动
#后台启动
nohup ./kibana --allow-root &
#在当前目录下有nohup.out日志文件,可以查kibana日志

五、访问kibana

浏览器上访问http://xx.xx.xx.xx:5601/即可打开kibana web界面

标签:http,kibana,xx,集群,ES,elasticsearch,10.60,es
来源: https://blog.csdn.net/weixin_40230682/article/details/119375759

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有