阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

CentOS 7下ElasticSearch集群搭建案例

253次阅读
没有评论

共计 4896 个字符,预计需要花费 13 分钟才能阅读完成。

最近在网上看到很多 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 集群到此就完成了!

Elasticsearch 安装使用教程 http://www.linuxidc.com/Linux/2015-02/113615.htm

分布式搜索 ElasticSearch 单机与服务器环境搭建  http://www.linuxidc.com/Linux/2012-05/60787.htm

ElasticSearch 的工作机制  http://www.linuxidc.com/Linux/2014-11/109922.htm

ElasticSearch 集群搭建实例  http://www.linuxidc.com/Linux/2015-02/114243.htm

ElasticSearch 的详细介绍 :请点这里
ElasticSearch 的下载地址 :请点这里

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2017-12/149964.htm

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计4896字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中