1.下载es7.8.1,解压
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.8.1-linux-x86_64.tar.gz wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.8.1-linux-x86_64.tar.gz.sha512 shasum -a 512 -c elasticsearch-7.8.1-linux-x86_64.tar.gz.sha512 tar -xzf elasticsearch-7.8.1-linux-x86_64.tar.gz mv elasticsearch-7.8.1 es-cluster
2.创建用户
因为安全问题,Elasticsearch不允许root用户直接运行,需要创建新用户
useradd es
passwd es
chown -R es:es /opt/module/es-cluster
3.修改配置
当前搭建三个节点
cd /opt/module/es-cluster/config
vim elasticsearch.yml
#集群名称,三台集群,要配置相同的集群名称!!!
cluster.name: es-cluster
#节点名称 其它节点 node-2 node-3
node.name: node-1
#是否有资格被选举为master,ES默认集群中第一台机器为主节点
node.master: true
#是否存储数据
node.data: true
#最⼤集群节点数,为了避免脑裂,集群节点数最少为半数+1
node.max_local_storage_nodes: 3
#数据目录
#path.data: /usr/local/node-1/data
#log目录
#path.logs: /usr/local/node-1/logs
#修改network.host为0.0.0.0,表示对外开放,如对特定ip开放则改为指定ip
network.host: 0.0.0.0
#设置对外服务http端口,默认为9200
http.port: 9200
#内部节点之间沟通端⼝
transport.tcp.port: 9300
#写⼊候选主节点的设备地址,在开启服务后可以被选为主节点
discovery.seed_hosts: ["localhost:9300","localhost9301","localhost9302"]
#初始化⼀个新的集群时需要此配置来选举master
cluster.initial_master_nodes: ["node-1"]
#设置集群中N个节点启动时进行数据恢复,默认为1
gateway.recover_after_nodes: 2
#下面的两个配置在安装elasticsearch-head的时候会用到#开启跨域访问支持,默认为false
http.cors.enabled: true
#跨域访问允许的域名地址,(允许所有域名)以上使用正则
http.cors.allow-origin: "*"
#关闭xpack
xpack.security.enabled: false
4.修改服务器配置信息
修改改/etc/security/limits.conf
# 文件末尾中增加下面内容
es soft nofile 65536es hard nofile 65536
修改/etc/security/limits.d/20-nproc.conf
# 在文件末尾中增加下面内容es soft nofile 65536es hard nofile 65536* hard nproc 4096# 注: * 带表 Linux 所有用户名称
修改 /etc/sysctl.conf
# 在文件中增加下面内容vm.max_map_count=655360
重新加载
sysctl -p
5.启动软件
跟别在不同节点上启动ES软件
cd /opt/module/es-cluster# 启动bin/elasticsearch# 后台启动bin/elasticsearch -d
测试启动(当前只启动两个,看到节点数为2)