[root@host-10-146-112-217 /]# service iptables status
未关闭,则需要手动关闭防火墙,步骤:
[root@host-10-146-112-217 /]# setup
按enter进入防火墙设置界面,将[*]的按空格键取消,再保存,如下图:
[root@host-10-146-112-218 ~]# vi /etc/sysconfig/i18n
将内容改成:
LANG=“zh_CN.GBK”
LANGUAGE=“zh_CN.GB18030:zh_CN.GB2312:zh_CN”
SYSFONT=“latarcyrheb-sun16”
SUPPORTED=“zh_CN.GB18030:zh_CN:zh:en_US.UTF-8:en_US:en”
Elasticsearch5.x以上的版本需要jdk1.8版本,则需要在安装前,确保安装环境的JDK版本为1.8版本。如果版本不是1.8版本,则自行安装。
jdk安装方法:
1、将安装包上传到opt文件夹下
2、解压
[root@localhost java]# tar -zxvf jdk-7u79-linux-x64.tar.gz
方法一:设置环境变量
[root@localhost java]# vi /etc/profile
下载地址: https://www.elastic.co/cn/downloads
点击下面图标进行下载。
下载版本如下图
上面只是根据此刻最新的界面截图来说明。可以选择稍微稳定一定的版本下载。>>历史版本由此进
在root用户下新增es用户,具体操作如下:
[root@135 home]# useradd es
[root@135 home]# passwd es
以下都用该用户来进行相关的配置。
给其赋予管理员权限
先cd /home/es,进入es下,
[root@135 es]# vi /etc/sudoers
加入如下内容:
es ALL=(ALL) ALL
使用x! 退出readonly文件
把下载的Elasticsearch版本放在es用户下
[root@135 es]# pwd
/home/es
[root@135 es]# ls
elasticsearch-xxx.tar.gz
执行解压指令对elasticsearch文件进行解压。
[root@135 es]# tar -xvf elasticsearch-xxx.tar.gz
[root@135 es]# ls
elasticsearch-xxx elasticsearch-xxx.tar.gz
有很多参数可以配置,可以参考官网。这里介绍基本的一些参数配置,保证可以正常启动ELasticsearch即可。
Elasticsearch对系统具有较高的要求,具体一些系统参数的配置,详情见:官网系统参数配置
配置文件/home/es/elasticsearch-xxx/config/jvm.options,按照如下修改
将Xms8g 中的数字修改,目前系统64G内存,建议改成Xms20g。
详细说明:jvm配置
配置文件/home/es/elasticsearch-xxx/config/elasticsearch.yml,将
Bootstrap . memory_lock: true 前的#去掉,保存。
且配置/etc/security/limits.conf
es soft memlock unlimited
es hard memlock unlimited
如下图:
注:上述配置中es soft nofile 65536 是 4.3的配置。
通过下里面的指令可以判断是否已经禁用swapping。
详细说明
配置elasticsearch可处理的文件数量,必须为65536或者更多。
配置/etc/security/limits.conf
es soft nofile 65536
es hard nofile 65536
详细说明
配置 /etc/sysctl.conf文件,添加行 vm.max_map_count=262144
并且执行命令: sysctl -p
详细说明
vim /etc/security/limits.d/90-nproc.conf.
将soft nproc 后的数字改成2048.
1、先在es下创建logs和data文件夹。
[root@host-10-146-112-217 es]#mkdir /esdata/data
[root@host-10-146-112-217 es]#mkdir /esdata/logs
2、配置文件/home/es/elasticsearch-5.2.2/config/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.
#
http.cors.enabled: true
http.cors.allow-origin: "*"
# 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: es_cluster
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: es217
#
# 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: /home/es/esdata/data
#
# Path to log files:
#
path.logs: /home/es/esdata/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
bootstrap.memory_lock: true
#
# 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: 0.0.0.0
#
# Set a custom port for HTTP:
#
http.port: 19200-19300
transport.tcp.port: 19300-19400
#
# 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: ["10.146.112.111", "10.146.112.222", "10.146.112.333", "10.146.112.444", "10.146.112.555"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
# discovery.zen.minimum_master_nodes: 5
#
# 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
以下对上述参数进行详细的说明:
bootstrap.memory_lock: 禁用交换内存。
cluster.name:集群名称,当有多个ES节点时,相同集群名称的节点则会自动组合成一个集群。
node.name: 节点名称,如果不设置会自动生成一个
path.data: 设置索引数据的存储路径,默认是es根目录下的data文件夹,可以设置多个存储路径,用逗号隔开,例:path.data: /path/to/data1,/path/to/data2
path.logs: 日志文件存储的位置,最好与data放在相同路径下。
network.host:节点启动绑定的主机IP
http.port: es对外提供服务的端口
transport.tcp.port: 设置节点间交互的tcp端口
discovery.zen.ping.unicast.hosts:设置集群中master节点的初始列表,可以通过这些节点来自动发现新加入集群的节点。
下面两个配置使安装的插件生效。
http.cors.enabled: true
http.cors.allow-origin: “*”
注意:path.data与path.logs对应的文件需是es用户权限,在home文件夹下执行指令chown -R -v es:es esdata
[root@host-10-146-112-217 home]# chown -R -v es:es es
详细说明
执行指令su - es,切换至es用户下。
在路径/home/es/elasticsearch-xxx下,执行bin/elasticsearch -d 启动。 -d表示在后台启动,也可以使用&符号替代。
查看Elasticsearch是否已经启动:
[es@135 elasticsearch-xxx]$ ps -ef | grep elasticsearch
es 1734 1 99 09:29 pts/1 00:00:23 /opt/jdk1.8.0_111//bin/java -Xms8g -Xmx8g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -server -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -Djdk.io.permissionsUseCanonicalPath=true -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Dlog4j.skipJansi=true -XX:+HeapDumpOnOutOfMemoryError -Des.path.home=/home/es/elasticsearch-xxx -cp /home/es/elasticsearch-xxx/lib/elasticsearch-5.0.2.jar:/home/es/elasticsearch-xxx/lib/* org.elasticsearch.bootstrap.Elasticsearch -d
es 1801 1635 0 09:30 pts/1 00:00:00 grep --color=auto elasticsearch
就写到这里吧,想到下一章写什么了。see UUU…
如果只是测试的话,一台机器,2G内存够了
比较好的集群配置:
推荐服务器配置如下,且最好有5台相同配置的服务器组成一个Elasticsearch集群。
CPU:24cores Intel® Xeon® CPU E5-2620 v3 @ 2.40GHz
内存:64GB
操作系统:Centos 7 64位
磁盘空间:1T