目录
安装依赖(已安装java8的机器可忽略此步)
依赖: java >= 8, Only Oracle’s Java and the OpenJDK are supported. 推荐安装 1.8.0_73 or later文章源自编程技术分享-https://mervyn.life/1777dc1a.html
- https://www.java.com/zh_CN/download/manual.jsp 下载对应系统的java
- tar zxvf jre-8u131-linux-x64.tar.gz
- 将该目录放置到想要安装的目录,然后加入linux环境变量$PATH 中
安装、启动es
单机部署
https://www.elastic.co/downloads/elasticsearch 下载编译好的二进制文件,解压后即可使用文章源自编程技术分享-https://mervyn.life/1777dc1a.html
如果系统存在多个java环境,需要在启动先指定JAVA_HOME,然后在进行启动,如:文章源自编程技术分享-https://mervyn.life/1777dc1a.html
export JAVA_HOME=/usr/local/java1.8.0 # 如已设置 JAVA_HOME 可以忽略此步
export ES_HEAP_SIZE=10g  #修改 Elasticsearch 的堆内存
bin/elasticsearch -d # 其中-d  表示 es 已守护进程的方式启动curl 'http://localhost:9200/?pretty' #测试es是否启动成功集群部署,以两台服务器为例
分别配置elasticsearch.yml文件文章源自编程技术分享-https://mervyn.life/1777dc1a.html
- 服务器A ip:192.168.140.129
cluster.name:app-demo
node.name: node-1
network.host: 192.168.140.129
discovery.zen.ping.unicast.hosts: ["192.168.140.128"]- 服务器B ip:192.168.140.128
cluster.name:app-demo
node.name: node-2
network.host: 192.168.140.128
discovery.zen.ping.unicast.hosts: ["192.168.140.129"]分别启动即可文章源自编程技术分享-https://mervyn.life/1777dc1a.html
curl  -u elastic '192.168.140.129:9200/_cat/nodes?v'  #测试集群状态文章源自编程技术分享-https://mervyn.life/1777dc1a.html
注意: ES启动时不能以 root 用户启动文章源自编程技术分享-https://mervyn.life/1777dc1a.html
动态变更配置
PUT /_cluster/settings
{
    "persistent" : {
        "discovery.zen.minimum_master_nodes" : 2  # 永久设置会在全集群重启时存活下来
    },
    "transient" : {
        "indices.store.throttle.max_bytes_per_sec" : "50mb" #临时设置会在第一次全集群重启后被移除
    }
}ES配置文件
配置文件默认在 $ES_HOME/config/ ,也可以在启动时指定加载对应的配置文件文章源自编程技术分享-https://mervyn.life/1777dc1a.html
es包含配置文件 elasticsearch.yml (配置 elasticsearch ) 、log4j2.properties( es 日志相关配置 )和 jvm.options文章源自编程技术分享-https://mervyn.life/1777dc1a.html
elasticsearch.yml文章源自编程技术分享-https://mervyn.life/1777dc1a.html
该文件yaml格式支持两种配置格式文章源自编程技术分享-https://mervyn.life/1777dc1a.html
path:
    data: /var/lib/elasticsearch
    logs: /var/log/elasticsearchpath.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch- 
path.data这个强烈建议进行修改文章源自编程技术分享-https://mervyn.life/1777dc1a.html设置索引数据的存储路径,默认是es根目录下的data文件夹,可以设置多个存储路径,用逗号隔开,例:文章源自编程技术分享-https://mervyn.life/1777dc1a.html path.data: /path/to/data1,/path/to/data2
- 
path.logs这个强烈建议进行修改
 设置日志文件的存储路径,默认是es根目录下的logs文件夹文章源自编程技术分享-https://mervyn.life/1777dc1a.html
- 
path.plugins
 插件路径文章源自编程技术分享-https://mervyn.life/1777dc1a.html
- 
cluster.name: elasticsearch
 配置es的集群名称,默认是elasticsearch,es会自动发现在同一网段下的es,如果在同一网段下有多个集群,就可以用这个属性来区分不同的集群。(最好 改成一个适当的名字来描述该集群的作用,同时也能防止同一个网段的其他机器测试时影影响)文章源自编程技术分享-https://mervyn.life/1777dc1a.html
- 
node.name: node-1
 节点名,默认为uuid前七位,也可以设置为主机的HOSTNAME , 如node.name: ${HOSTNAME}文章源自编程技术分享-https://mervyn.life/1777dc1a.html
- 
bootstrap.memory_lock: true
 设置为true来锁住内存。因为当jvm开始swapping时es的效率 会降低,所以要保证它不swap,可以把ES_MIN_MEM和ES_MAX_MEM两个环境变量设置成同一个值,并且保证机器有足够的内存分配给es。文章源自编程技术分享-https://mervyn.life/1777dc1a.html
- 
network.host: 0.0.0.0
 绑定本机网络地址,设置了此参数,es假设从开发模式变成成产模式,如果配置了0.0.0.0 最好开启防火墙防止外部ip直接连接文章源自编程技术分享-https://mervyn.life/1777dc1a.html
- 
discovery.zen.ping.unicast.hostsedit文章源自编程技术分享-https://mervyn.life/1777dc1a.html这个设置把组播的自动发现给关闭了,为了防止其他机器上的节点自动连入文章源自编程技术分享-https://mervyn.life/1777dc1a.html 
- 
discovery.zen.minimum_master_nodes
 设置这个参数来保证集群中的节点可以知道其它N个有master资格的节点。默认为1.文章源自编程技术分享-https://mervyn.life/1777dc1a.html此设置应该始终被配置为 master 候选节点的法定个数(大多数个)。法定个数就是 ( master 候选节点个数 / 2) + 1。 这里有几个例子:文章源自编程技术分享-https://mervyn.life/1777dc1a.html- 如果你有 10 个节点(能保存数据,同时能成为 master),法定数就是 6。
- 如果你有 3 个候选 master 节点,和 100 个 data 节点,法定数就是 2,你只要数数那些可以做 master 的节点数就可以了。
- 如果你有两个节点,你遇到难题了。法定数当然是 2,但是这意味着如果有一个节点挂掉,你整个集群就不可用了。 设置成1可以保证集群的功能,但是就无法保证集群脑裂了,像这样的情况,你最好至少保证有 3 个节点。
 
- 如果你有 10 个节点(能保存数据,同时能成为 master),法定数就是 
- 
gateway.recover_after_nodes: 8文章源自编程技术分享-https://mervyn.life/1777dc1a.html这将阻止 Elasticsearch 在存在至少 8 个节点(数据节点或者 master 节点)之前进行数据恢复。 这个值的设定取决于个人喜好:整个集群提供服务之前你希望有多少个节点在线?这种情况下,我们设置为 8,这意味着至少要有 8 个节点,该集群才可用。文章源自编程技术分享-https://mervyn.life/1777dc1a.html 
- 
gateway.recover_after_time: 5m文章源自编程技术分享-https://mervyn.life/1777dc1a.html
- 
gateway.expected_nodes: 10文章源自编程技术分享-https://mervyn.life/1777dc1a.html这意味着 Elasticsearch 会采取如下操作:文章源自编程技术分享-https://mervyn.life/1777dc1a.html - 等待集群至少存在 8 个节点
- 等待 5 分钟,或者10 个节点上线后,才进行数据恢复,这取决于哪个条件先达到。
 以上三个设置可以在集群重启的时候避免过多的分片交换。这可能会让数据恢复从数个小时缩短为几秒钟。文章源自编程技术分享-https://mervyn.life/1777dc1a.html 
 
		





评论