1.下载安装包
1.1 下载elasticsearch 7.13.3
curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.13.3-linux-x86_64.tar.gz
1.2 解压文件
tar -zxf elasticsearch-7.13.3-linux-x86_64.tar.gz
1.3 将解压文件移动至所要存储的文件目录下
mv elasticsearch-7.13.3 /data/elasticsearch
2.创建普通用户
为了安全问题,es不允许root用户直接运行,新建用户
2.1添加用户
#添加用户 adduser es #添加密码 passwd es 1234567890
2.2 将解压后的es目录给es用户授权
chown -R es:es /data/elasticsearch
2.3 在es用户下创建elasticsearch的数据和日志目录
mkdir elasticsearch cd elasticsearch mkdir data mkdir logs
3. 修改eleasticsearch.yml文件
3.1 进入到es的config目录下
cd /data/elasticsearch/config/
3.2 修改yml文件
vi elasticsearch.yml # 集群名 cluster.name: my-es # 节点名 node.name: node-2 # 是否有资格主节点 node.master: true # 是否存储数据 node.data: true # 最大集群节点数 node.max_local_storage_nodes: 5 # ip地址 network.host: 0.0.0.0 # es的httpo的端口 http.port: 9200 # 内部节点之间沟通端口 transport.tcp.port: 9700 # 节点发现 discovery.zen.ping.unicast.hosts: ["192.168.12.46:9700", "192.168.12.3:9700", "192.168.12.2:9700", "192.168.12.45:9700", "192.168.12.47:9700"] # 初始化新的集群是需要此配置来选举新的master # cluster.initial_master_nodes: ["node-1","node-2","node-3","node-4","node-5"] cluster.initial_master_nodes: node-1 # es保存数据及日志的路径 path.data: /home/es/elasticsearch/data path.logs: /home/es/elasticsearch/logs
4. 修改配置文件
新创建的es用户最大可创建的文件数太小,最大虚拟内存太小,切换到root用户,进行一下配置
4.1 切换到root用户 并 进行limits.conf文件配置
# 切换root用户 su # 配置最小文件数 vi /etc/security/limits.conf # 文件末尾增加下面内容 es soft nofile 65535 es hard nofile 65537
4.2 进行20-文件配置
vi /etc/security/limits.d/20-nproc.conf # 文件末尾增加下面内容,最多可创建的文件数 es soft nofile 65536 es hard nofile 65536 # * 代表Linux所有用户名称 * hard nproc 4096
4.3 进行sysctl.conf配置
vi /etc/sysctl.conf # 文件末尾增加下面内容 vm.max_map_count=655360 # 保存文件后,重新加载,输入命令 sysctl -p
5.设置ES的JVM占用内存参数
启动之前,设置ES的JVM占用内存参数,防止内存不足错误
vi /data/elasticsearch/config/jvm.options # 改为最小内存4g,最大内存4g ################################################################ ## ## The heap size is automatically configured by Elasticsearch ## based on the available memory in your system and the roles ## each node is configured to fulfill. If specifying heap is ## required, it should be done through a file in jvm.options.d, ## and the min and max should be set to the same value. For ## example, to set the heap to 4 GB, create a new file in the ## jvm.options.d directory containing these lines: ## -Xms4g -Xmx4g ## ## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html ## for more information ## ################################################################