Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6548197
  • 博文数量: 1005
  • 博客积分: 8199
  • 博客等级: 中将
  • 技术积分: 13071
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-25 20:19
个人简介

脚踏实地、勇往直前!

文章分类

全部博文(1005)

文章存档

2020年(2)

2019年(93)

2018年(208)

2017年(81)

2016年(49)

2015年(50)

2014年(170)

2013年(52)

2012年(177)

2011年(93)

2010年(30)

分类: 大数据

2018-12-12 16:04:36

CentOs下安装Elasticsearch集群

环境:

OS:CentOs 7

Elasticsearch:6.5.0



1.安装步骤

1.1 环境部署

数据库部署

节点

ip

角色

Host01

192.168.1.135


Host02

192.168.1.135


Host03

192.168.1.136




1.2 安装java

安装java,确保版本在1.8以上

[root@localhost ~]# java -version

java version "1.8.0_151"

Java(TM) SE Runtime Environment (build 1.8.0_151-b12)

Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)

安装部署省略


每台机器上都需要安装


1.3 创建非root用户

因为es不能在root用户下启动,所以需要创建非root用户,我这里创建crate用户

#useradd esuser


1.4 配置非root用户(esuser)环境变量


[crate@localhost ~]$ more .bash_profile

# .bash_profile


# Get the aliases and functions

if [ -f ~/.bashrc ]; then

        . ~/.bashrc

fi


# User specific environment and startup programs

JAVA_HOME=/usr/local/jdk1.8.0_151

PATH=$JAVA_HOME/bin:$PATH:$HOME/bin


export PATH

[crate@local



1.5 /etc/security/limits.conf修改和sysctl修改

在该文件最后面添加如下两项,然后退出重新登录

*        hard    nofile           65536

*        soft    nofile           65536

[root@localhost /]# sysctl -w vm.max_map_count=262144


1.6 下载安装介质

下载地址:我这里下载的是elasticsearch-6.5.0.tar.gz


1.7 解压安装

每台机器都要进行安装

[root@localhost ]# tar -xvf elasticsearch-6.5.0.tar.gz

[root@localhost ]# mv elasticsearch-6.5.0 elasticsearch

[root@localhost]# chown -R esuser:esuser ./elasticsearch


1.8 创建相关目录

每台机器上都要执行

[esuser@localhost elasticsearch]$cd /home/esuser/elasticsearch

[esuser@localhost elasticsearch]$ mkdir data


该目录用于存放数据文件


1.9 修改配置文件

vi /home/esuser/elasticsearch/config/elasticsearch.yml


cluster.name: my-cluster #集群名称

node.name: node-1            #节点名称,仅仅是描述名称,用于在日志中区分


path.data: /home/esuser/elasticsearch/data   #数据的默认存放路径

path.logs: /home/esuser/elasticsearch/logs   #日志的默认存放路径


network.host: 192.168.1.134                  #当前节点的IP地址

http.port: 9200                               #对外提供服务的端口,9300为集群服务的端口

discovery.zen.ping.unicast.hosts: ["192.168.1.134", "192.168.1.135","192.168.1.136"]      

若是自定义内部通信端口的话需要写上自定义的内部通信端口如下
#transport.tcp.port:9300 ##自定义节点之间内部通信端口,默认是9300
#discovery.zen.ping.unicast.hosts: ["192.168.1.134:9300", "192.168.1.135:9300","192.168.1.136:9300"] 这里的必须填写内部通信端口

#集群个节点IP地址,也可以使用els、els.shuaiguoxia.com等名称,需要各节点能够解析

discovery.zen.minimum_master_nodes: 2         #为了避免脑裂,集群节点数最少为 半数+1
http.cors.enabled: true
http.cors.allow-credentials: true
http.cors.allow-origin: "/.*/"
http.cors.allow-headers: WWW-Authenticate,X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization
xpack.security.enabled: false

将配置文件scp到另外的机器,然后相应修改红色部分


1.10 JVM配置

每台机器都要设置

由于Elasticsearch是Java开发的,所以可以通过/etc/elasticsearch/jvm.options配置文件来设定JVM的相关设定。如果没有特殊需求按默认即可。

不过其中还是有两项最重要的-Xmx1g与-Xms1gJVM的最大最小内存。如果太小会导致Elasticsearch刚刚启动就立刻停止。太大会拖慢系统本身


# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space

-Xms8g
-Xmx8g


1.11 设置内存大小

每台机器都要设置

vi /home/esuser/elasticsearch/bin/elasticsearch

export ES_HEAP_SIZE=4g


同时在配置文件elasticsearch.yml中添加如下项目:

bootstrap.mlockall: true


1.12 启动

每台机器都要启动

[root@localhost opt]# su - esuser

[esuser@localhost bin]$ cd /home/esuser/elasticsearch/bin

[esuser@localhost bin]$./elasticsearch –d


1.13 遇到的问题

1.13.1 bootstrap.mlockall

org.elasticsearch.bootstrap.StartupException: java.lang.IllegalArgumentException: unknown setting [bootstrap.mlockall]

将配置文件里该参数设置为false


1.13.2 修改limits.conf

解决办法:

vi /etc/security/limits.conf

root用户下添加如下2两项,然后退出使用esuser用户登陆,使其生效

*        hard    nofile           65536

*        soft    nofile           65536


1.13.3 修改max_map_count

#sysctl -w vm.max_map_count=262144

 
或是直接修改sysctl.conf文件
vi /etc/sysctl.conf
vm.max_map_count=262144


1.14 配置验证
在每个节点的配置文件里的最后添加如下配置项,启用xpack验证
xpack.security.enabled: true

重新启动每个节点,然后在其中一个节点上执行如下命令
./elasticsearch-setup-passwords interactive
这里会提示设置每个账号的密码,设置即可。

这里遇到了个小问题,把xpack.security.enabled: true添加到每个节点的配置文件重启之后,好像集群不可用,其中一个节点xpack生效了,但是另外两个节点xpack没有生效,后来我是在每个节点的配置文件添加了如下参数,重启动后等了一会好像就可以了。
node.data: true
node.master: true

阅读(1700) | 评论(0) | 转发(0) |
0

上一篇:java操作ES(RestClient)

下一篇:oracle审计例子

给主人留下些什么吧!~~