CentOS上安装ElasticSearch集群

主机名IP地址
node1192.168.1.101
node2192.168.1.102
node3192.168.1.103
node4192.168.1.104

1.创建账号
ES默认不允许使用root账号运行

useradd es
passwd es

2.关闭防火墙和修改ulimit信息

systemctl stop firewalld
systemctl disable firewalld

修改ulimit,参考centos7修改打开文件数

3.配置hosts

vim /etc/hosts

192.168.1.101 node1
192.168.1.102 node2
192.168.1.103 node3
192.168.1.104 node4

4.创建目录

mkdir elasticsearch
mkdir elasticsearch/{data,logs}

5.解压ES

tar -zxvf elasticsearch-7.12.1-linux-x86_64.tar.gz
cd elasticsearch-7.12.1

6.修改elasticsearch.yml配置文件

vim config/elasticsearch.yml

修改配置:

# es集群名称
cluster.name: fingerprint-es
# es节点名称
node.name: node1
# es数据存储目录
path.data: /app/es/elasticsearch/data
path.logs: /app/es/elasticsearch/logs
# 锁定物理内存地址,防止es内存被交换出去,避免磁盘频繁读取
bootstrap.memory_lock: true
# 绑定IP,0.0.0.0表示有系统指定
network.host: 0.0.0.0
# http访问端口
http.port: 9200
# 主机发现,配置其他节点
discovery.seed_hosts: ["node2", "node3", "node4"]
# 可选选举为主节点的节点主机名,配置所有节点
cluster.initial_master_nodes: ["node1", "node2", "node3", "node4"]

7.启动es

bin/elasticsearch -d

启动时提示告警:`warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME
Future versions of Elasticsearch will require Java 11; your Java version from [/usr/local/jdk1.8.0_241/jre] does not meet this requirement. Consider switching to a distribution of Elasticsearch with a bundled JDK. If you are already using a distribution with a bundled JDK, ensure the JAVA_HOME environment variable is not set.
warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME`,ES推荐使用自带的jdk,配置环境变量:

vim /etc/profile
export ES_JAVA_HOME=/app/es/elasticsearch/jdk

启动提示: ERROR: [1] bootstrap checks failed. You must address the points described in the following [1] lines before starting Elasticsearch.bootstrap check failure [1] of [1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

vim /etc/sysctl.conf

# 追加内容
vm.max_map_count=655360

sysctl -p

8.验证结果

curl http://node1:9200/

结果:

{
  "name" : "node1",
  "cluster_name" : "fingerprint-es",
  "cluster_uuid" : "g_fJwx-oRhGy1rSo1wFqrw",
  "version" : {
    "number" : "7.12.1",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "3186837139b9c6b6d23c3200870651f10d3343b7",
    "build_date" : "2021-04-20T20:56:39.040728659Z",
    "build_snapshot" : false,
    "lucene_version" : "8.8.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

查看所有节点:

curl node1:9200/_cat/nodes
192.168.1.101 21 75 1 0.08 0.07 0.11 cdfhilmrstw - node4
192.168.1.102 15 62 1 0.04 0.05 0.11 cdfhilmrstw * node1
192.168.1.103 20 62 1 0.03 0.08 0.12 cdfhilmrstw - node2
192.168.1.104 24 75 1 0.23 0.13 0.14 cdfhilmrstw - node3

*的节点表示选举的主节点

如果觉得我的文章对你有用,请随意赞赏