单节点安装
- 去官网“https://www.elastic.co/cn/downloads/”下载,例:elasticsearch-7.4.2-linux-x86_64.tar.gz
- 上传到centos服务器
-
tar -zxvf elasticsearch-7.4.2-linux-x86_64.tar.gz解压文件,然后移动到本地的es文件夹,mv elasticsearch-7.4.2 /usr/local - 进入es文件目录
cd /usr/local/elasticsearch-7.4.2/,修改es配置文件vim /usr/local/elasticsearch-7.4.2/config/elasticsearch.yml- 修改集群名称和节点名称,可选
- 修改es数据文件和日志文件存放路径,data目录没有则需新建
- 修改IP设置
- 修改es集群初始启动节点
- 修改集群名称和节点名称,可选
- 创建es服务的用户,不能直接用root用户启动,否则会报错“ java.lang.RuntimeException: can not run elasticsearch as root”,
useradd es && chown -R es:es /usr/local/elasticsearch-7.4.2 && su es && cd /usr/local/elasticsearch-7.4.2/bin && ./elasticsearch - 启动时,可能报“max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]”、“ max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]”和“max number of threads [3756] for user [es] is too low”等三个错误,处理方案如下:
-
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
-
- 再次重启es,可设置后台启动
./elasticsearch -d,注意一定要切换到es用户,不能用root用户,启动成功,访问“http://192.168.126.118:9200/”,如下