CentOS7.9-ES7 部署,开机自启
CentOS7.9-ES7 部署
-
下载 https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.11.2-linux-x86_64.tar.gz
-
解压
tar -zxvf elasticsearch-7.11.2-linux-x86_64.tar.gz
-
移动目录
mv elasticsearch-7.11.2 /usr/local/
-
修改es相关配置文件(重点配置)
# vim config/elasticsearch.yml # 集群名 cluster.name: es-cluster # 节点名 node.name: node-master # 数据存放位置 path.data: /usr/local/elasticsearch-7.11.2/data # 日志存放位置 path.logs: /usr/local/elasticsearch-7.11.2/logs # bind 地址,0 表示任意 network.host: 0.0.0.0 # 默认初始 master 节点 cluster.initial_master_nodes: ["node-master"]
-
修改 jvm 相关配置
# 重点配置堆内存大小, 本人为虚拟机只给 512m,请结合实际情况调优 -Xms512m -Xmx512m
-
因为 es 不允许使用 root, 所以添加 es 用户
useradd esuser chown -R esuser:esuser /usr/local/elasticsearch-7.11.2/
-
运行时可能出现以下错误
ERROR: [2] bootstrap checks failed [1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535] [2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144] ERROR: Elasticsearch did not exit normally - check the logs at /usr/local/elasticsearch-7.11.2/logs/es-cluster.log
-
修改限制
vim /etc/security/limits.conf # 输入如下参数 * soft nofile 65536 * hard nofile 131072 * soft nproc 2048 * hard nproc 4096
-
修改系统设置
vim /etc/sysctl.conf vm.max_map_count=262145
sysctl -p
-
配置开机自启
vim /etc/init.d/elasticsearch
#!/bin/bash #chkconfig: 345 63 37 #description: elasticsearch #processname: elasticsearch-7.11.2 export ES_HOME=/usr/local/elasticsearch-7.11.2 case $1 in start) su esuser<<! cd $ES_HOME ./bin/elasticsearch -d -p pid exit ! echo "elasticsearch is started" ;; stop) pid=`cat $ES_HOME/pid` kill -9 $pid echo "elasticsearch is stopped" ;; restart) pid=`cat $ES_HOME/pid` kill -9 $pid echo "elasticsearch is stopped" sleep 1 su esuser<<! cd $ES_HOME ./bin/elasticsearch -d -p pid exit ! echo "elasticsearch is started" ;; *) echo "start|stop|restart" ;; esac exit 0
chmod 777 elasticsearch chkconfig --add elasticsearch chkconfig elasticsearch on
-
安装 ik 分词
-
方式 1,使用在线安装
./elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.11.2/elasticsearch-analysis-ik-7.11.2.zip
- 方式 2,使用源码安装
# 下载
wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.11.2/elasticsearch-analysis-ik-7.11.2.zip
# 解压
mkdir -p /usr/local/elasticsearch-7.11.2/plugins/ik
unzip -n ~/elasticsearch-analysis-ik-7.11.2.zip -d /usr/local/elasticsearch-7.11.2/plugins/ik/
# 重启 elasticsearch
/etc/init.d/elasticsearch restart