CentOS7下安装elasticsearch5.6.3

一、安装jdk,elasticsearch5.x版本之后须要的是1.8或以上java,下载对应版本jdk,上传到服务器上html

执行命令解压java

upload]# tar -zxvf jdk-8u171-linux-x64.tar.gznode

配置环境变量linux

vi /etc/profilebootstrap

在结尾处添加以下代码,java目录根据本身填写情况定vim

JAVA_HOME=/usr/local/jdk1.8.0_171
JRE_HOME=/usr/local/jdk1.8.0_171/jre
CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH安全

保存退出,执行命令服务器

source /etc/profileapp

生效环境变量,测试java是否安装成功cors

出现如图显示,jdk安装成功

二、上传elasticsearch包

解压

tar -zxvf elasticsearch-5.6.3.tar.gz

移动到本身到本身的目录

mv elasticsearch-5.6.3 /usr/local/

三、新建用户组及用户

elasticsearch不容许root用户启动服务,因此须要新建用户及用户组

groupadd elsearch

useradd esuser -g elsearch

进入es安装目录平级目录,修改文件夹权限

cd /user/local

chown -R esuser:elsearch elasticsearch-5.6.3/

查看目录权限

四、建立es数据文件夹和日志文件夹

五、修改es配置文件

进入config目录编辑elasticsearch.yml

vi elasticsearch.yml

# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: sengled-test-lg
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: sengled-test-node2
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /usr/local/elasticsearch-5.6.3/data
#
# Path to log files:
#
path.logs: /usr/local/elasticsearch-5.6.3/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: xxx.xxx.xxx.xxx
#
# Set a custom port for HTTP:
#
http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.zen.ping.unicast.hosts: ["host1", "host2"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes: 3
#
# For more information, consult the zen discovery module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true

执行ES文件,进入到bin 目录下执行 ./elasticsearch 命令就能够了,执行 ./elasticesrarch -d 是后台运行   

若是没有什么问题话,就能够安全生成了;而后执行curl 'http://本身配置的IP地址:9200/' 命令,就出现下面的结果

启动过程当中可能会出现问题

问题1.max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

解决方法:

切到root 用户:进入到security目录下的limits.conf;执行命令 vim /etc/security/limits.conf 在文件的末尾添加下面的参数值:

                                    * soft nofile 65536

                                    * hard nofile 131072

                                    * soft nproc 2048

                                   * hard nproc 4096

                               前面的*符号必须带上,而后从新启动就能够了。执行完成后可使用命令 ulimit -n 查看进程数

问题2.max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

解决方法:

最大虚拟内存过小
root用户执行命令:
[root@localhost ~]# sysctl -w vm.max_map_count= 655360
 

ps:别的机器进行访问时须要开放9200端口和9300端口,9200是http协议端口,9300是tcp协议端口,为java client服务的。我这里没有单独打开端口,只是关闭了防火强,CentOS7关闭防火墙和CentOS6不同,7的防火墙是firewalld的服务,执行命令

//临时关闭
systemctl stop firewalld
//禁止开机启动
systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

 

集群时须要添加一些配置,我搭了三个虚拟机作集群,想cluster.name相同时发现并非集群,在es配置文件中须要添加额外配置

discovery.zen.ping.unicast.hosts: ["xxx.xxx.xxx","xxx.xxx.xxx","xxx.xxx.xxx"]
discovery.zen.minimum_master_nodes: 3

解释说明:
bootstrap.memory_lock: false  这是锁定内存,在一篇调优文章中这个设置成true时会减小内存交换的消耗,这里先设置成false
bootstrap.system_call_filter: false  这个配置设置true在CentOS6或以上时会出现错误, 由于Centos6不支持SecComp

cluster.name 集群名字,同一个集群中使用相同名字,单机就随意 node.name: node-01 节点名字 node.master: 是否为集群的master机器 node.data: true 是否做为数据节点 network.host: xxx.xxx.xxx.xxx 这个不用天然是配置ip地址的 http.port: 9200 端口号,不配置的话默认9200 discovery.zen.ping.unicast.hosts: [“xxx.xxx.xxx”,”xxx.xxx.xxx”,”xxx.xxx.xxx”] 这个就是配置集群的时候要用的到了,[]中填上集群中其余集群的ip的地址,若是是master的话请把全部salve的机器地址填上 discovery.zen.minimum_master_nodes: 2 关于这个值配置多少合适的话你们去搜一下,本身权衡一下集群,这里我用了3台机器模拟集群,因此填上2。 http.cors.enabled: true 这个参数的设置和下面一个配置就关于ip的访问策略了,若是你发现其余ip地址访问不了就有能够这参数没有配置 http.cors.allow-origin: “*”

相关文章
相关标签/搜索