CentOS7下安装elasticsearch5.6.3

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

执行命令解压

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

配置环境变量

vi /etc/profile

在结尾处添加如下代码,java目录根据自己填写状况定

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/profile

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

51b12bb32e9cd70fadf9166b8d0aee9d1d7.jpg

4265bd71eac8505f09ca7f62f41322c10be.jpg

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

2、上传elasticsearch包

解压

tar -zxvf elasticsearch-5.6.3.tar.gz

移动到自己到自己的目录

mv elasticsearch-5.6.3 /usr/local/

3、新建用户组及用户

elasticsearch不允许root用户启动服务,所以需要新建用户及用户组

groupadd elsearch

useradd esuser -g elsearch

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

cd /user/local

chown -R esuser:elsearch elasticsearch-5.6.3/

查看目录权限

84f6fa961dc57dc3daff84052106a11b970.jpg

4、创建es数据文件夹和日志文件夹

173842ba583269a0364242aba38e94e747e.jpg

5、修改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: “*”

 

转载于:https://my.oschina.net/muziH/blog/1840772

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值