CentOS 7下ElasticSearch集群搭建案例

最近在网上看到很多ElasticSearch集群的搭建方法,本人在这人使用Elasticsearch5.0.1版本,介绍如何搭建ElasticSearch集群并安装head插件和其他插件安装方法。

一、搭建环境(2台CentOS 7系统服务器

所需软件

  Elasticsearch-5.0.1.tar.gz
  node-v4.2.2-linux-x64.tar.gz

基础环境Java

  yum -y install java-1.8*
  java -version #检查java是否安装成功

测试环境关闭防火墙和selinux

    关闭防火墙
        systemctl stop firewalld
        systemctl diable firewalld
    关闭selinux
        sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config   #需要重启系统

配置主机名和hosts文件

  配置hostname
        sed -i 's/localhost/es1/g' /etc/hostname
     
sed -i 's/localhost/es1/g' /etc/hostname
  配置hosts vi /etc/hosts #添加一下内容 
     172.16.81.133 es1
     172.16.81.134 es2

创建用户

        useradd elasticsearch
        passwd elasticsearch   #然后输入两次密码即可!

二、安装es软件(tar.gz解压安装)

         tar -zxvf elasticsearch-5.0.1.tar.gz
         mv elasticsearch-5.0.1 elasticsearch5
         cd elasticsearch5

创建data和logs目录

         mkdir -p es
         mkdir -p es/data
         mkdir -p es/logs

修改配置文件

            cd /opt/elasticsearch5/config
            vi elasticsearch.yml
            es1配置文件如下:
                cluster.name: es-cluster    #集群名,不同名称代表不同集群
                node.name: es1    #节点名称,自定义
                path.data: /opt/elasticsearch5/es/data    #数据路径
                path.logs: /opt/elasticsearch5/es/logs    #日志路径
                bootstrap.memory_lock: false    #关闭锁内存
                network.host: 172.16.81.133    #绑定IP地址
                http.port: 9200    #绑定端口
                discovery.zen.ping.unicast.hosts: ["es1", "es2"]    #集群列表,类型数组,可以是IP或域名
                discovery.zen.minimum_master_nodes: 2    #节点数不能超过节点总数量
                http.cors.enabled: true    #开启http网络节点发现
                http.cors.allow-origin: "*"    #允许所有同网段节点发现
            es2配置文件如下:
                cluster.name: es-cluster    #集群名,不同名称代表不同集群
                node.name: es2    #节点名称,自定义
                path.data: /opt/elasticsearch5/es/data    #数据路径
                path.logs: /opt/elasticsearch5/es/logs    #日志路径
                bootstrap.memory_lock: false    #关闭锁内存
                network.host: 172.16.81.134    #绑定IP地址
                http.port: 9200    #绑定端口
                discovery.zen.ping.unicast.hosts: ["es1", "es2"]    #集群列表,类型数组,可以是IP或域名
                discovery.zen.minimum_master_nodes: 2    #节点数不能超过节点总数量
                http.cors.enabled: true    #开启http网络节点发现
                http.cors.allow-origin: "*"    #允许所有同网段节点发现

配置内核参数

            vi /etc/security/limits.conf    #添加以下内容
                * soft nofile 65536
                * hard nofile 131072
                * soft nproc 2048
                * hard nproc 4096
            vi /etc/sysctl.conf 
                添加下面配置:
                vm.max_map_count=655360
                并执行命令:
                sysctl -p

修改文件权限

            chown -R elasticsearch:elasticsearch elasticsearch5

切换到elasticsearch启动程序

            su - elasticsearch
            cd /opt/elasticsearch5/bin
            ./elasticsearch  #观察输出信息
            ./elasticsearch &    #后台运行

查看端口

            netstat -lntp
            结果:
            tcp        0      0 0.0.0.0:9100            0.0.0.0:*               LISTEN      8892/grunt                  
            tcp6       0      0 172.16.81.133:9200      :::*                    LISTEN      5250/java           
            tcp6       0      0 172.16.81.133:9300      :::*                    LISTEN      5250/java           
            存在9100、9200、9300上述上个端口即可!

三、安装elasticsearch-head插件

安装依赖包和工具包

yum -y install wget git bizp2

git项目到本地

cd /opt
git clone git://github.com/mobz/elasticsearch-head.git

安装node、npm、grunt

wget https://nodejs.org/dist/v4.2.2/node-v4.2.2-linux-x64.tar.gz
tar -zxvf node-v4.2.2-linux-x64.tar.gz

设置链接

ln -s /opt/node-v4.2.2-linux-x64/bin/node /usr/sbin/node
ln -s /opt/node-v4.2.2-linux-x64/bin/npm /usr/sbin/npm

设置npm代理镜像

npm config set registry https://registry.npm.taobao.org

安装、配置grunt

npm install -g grunt
ln -s /opt/node-v4.2.2-linux-x64/lib/node_modules/grunt/bin/grunt /usr/sbin/grunt

修改elasticsearch-head配置文件

                cd /opt/elasticsearch-head
                vi _site/app.js
                // 把localhost改为ip
                this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200";
                this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://172.16.81.89:9200";
                修改Gruntfile.js
                connect: {
                    server: {
                        options: {                                                                                                                  
                            hostname: "0.0.0.0", #添加这里
                            port: 9100,
                            base: '.',
                            keepalive: true
                        }   
                    }   
                }

安装head

 cd /opt/elasticsearch-head
 npm install

启动head

grunt server &

浏览器访问(最好是谷歌浏览器)

接口:
http://172.16.81.133:9200/
集群:
http://172.16.81.133:9100/   #五角星代表主节点,圆点代表数据节点 查看主master是谁: http://172.16.81.133:9200/_cat/master 更多URL信息 http://172.16.81.133:9200/_cat

最后在介绍下5.x安装插件的方法,这儿我们举例安装!

我们将安装geoip的插件(可以解析外网地址显示在地图上)

cd /opt/elasticsearch5/bin

[root@es1 bin]# ./elasticsearch-plugin install –help   #我们看到了所支持的插件
Install a plugin

The following official plugins may be installed by name:
analysis-icu
analysis-kuromoji
analysis-phonetic
analysis-smartcn
analysis-stempel
discovery-azure-classic
discovery-ec2
discovery-file
discovery-gce
ingest-attachment
ingest-geoip
ingest-user-agent
lang-javascript
lang-Python
mapper-attachments
mapper-murmur3
mapper-size
repository-azure
repository-gcs
repository-hdfs
repository-s3
store-smb
x-pack

Non-option arguments:

安装插件:

[root@es1 bin]# ./elasticsearch-plugin install ingest-geoip
-> Downloading ingest-geoip from elastic
[=================================================] 100% 
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: plugin requires additional permissions @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
* java.lang.RuntimePermission accessDeclaredMembers
See http://docs.Oracle.com/javase/8/docs/technotes/guides/security/permissions.html
for descriptions of what these permissions allow and the associated risks.

Continue with installation? [y/N]y
-> Installed ingest-geoip

验证:

cd /opt/elasticsearch5/plugins
[root@es1 plugins]# ls
ingest-geoip  #会看到刚刚安装的插件,需要重启es集群配置生效

ElasticSearch集群到此就完成了!

文章来源网络,作者:运维,如若转载,请注明出处:https://shuyeidc.com/wp/223771.html<

(0)
运维的头像运维
上一篇2025-04-16 03:04
下一篇 2025-04-16 03:05

相关推荐

  • 个人主题怎么制作?

    制作个人主题是一个将个人风格、兴趣或专业领域转化为视觉化或结构化内容的过程,无论是用于个人博客、作品集、社交媒体账号还是品牌形象,核心都是围绕“个人特色”展开,以下从定位、内容规划、视觉设计、技术实现四个维度,详细拆解制作个人主题的完整流程,明确主题定位:找到个人特色的核心主题定位是所有工作的起点,需要先回答……

    2025-11-20
    0
  • 社群营销管理关键是什么?

    社群营销的核心在于通过建立有温度、有价值、有归属感的社群,实现用户留存、转化和品牌传播,其管理需贯穿“目标定位-内容运营-用户互动-数据驱动-风险控制”全流程,以下从五个维度展开详细说明:明确社群定位与目标社群管理的首要任务是精准定位,需明确社群的核心价值(如行业交流、产品使用指导、兴趣分享等)、目标用户画像……

    2025-11-20
    0
  • 香港公司网站备案需要什么材料?

    香港公司进行网站备案是一个涉及多部门协调、流程相对严谨的过程,尤其需兼顾中国内地与香港两地的监管要求,由于香港公司注册地与中国内地不同,其网站若主要服务内地用户或使用内地服务器,需根据服务器位置、网站内容性质等,选择对应的备案路径(如工信部ICP备案或公安备案),以下从备案主体资格、流程步骤、材料准备、注意事项……

    2025-11-20
    0
  • 如何企业上云推广

    企业上云已成为数字化转型的核心战略,但推广过程中需结合行业特性、企业痛点与市场需求,构建系统性、多维度的推广体系,以下从市场定位、策略设计、执行落地及效果优化四个维度,详细拆解企业上云推广的实践路径,精准定位:明确目标企业与核心价值企业上云并非“一刀切”的方案,需先锁定目标客户群体,提炼差异化价值主张,客户分层……

    2025-11-20
    0
  • PS设计搜索框的实用技巧有哪些?

    在PS中设计一个美观且功能性的搜索框需要结合创意构思、视觉设计和用户体验考量,以下从设计思路、制作步骤、细节优化及交互预览等方面详细说明,帮助打造符合需求的搜索框,设计前的规划明确使用场景:根据网站或APP的整体风格确定搜索框的调性,例如极简风适合细线条和纯色,科技感适合渐变和发光效果,电商类则可能需要突出搜索……

    2025-11-20
    0

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注