Linux系统中安装Elasticsearch并实现开机自动启动
安装环境
- Linux Centos 7
- Java 1.8环境
- Elasticsearch 7.5.0
安装 JAVA 运行环境
Elasticsearch 是用JAVA实现的,必须要有JDK支持,所以必须先安装JDK。
1 | yum update -y |
安装 Elasticsearch
下载安装包
Elasticsearch 去官网直接下载,本人使用的是 7.5.0 版本;
1 | wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.10.2-linux-x86_64.tar.gz |
解压安装包
1 | tar -zxvf elasticsearch-7.10.2-linux-x86_64.tar.gz -C /usr/local/ |
创建es用户
从5.0开始 elasticsearch 安全级别提高了 不允许采用root帐号启动 所以我们要添加一个用户用来启动 elasticsearch,创建es用户并给elasticsearch安装目录赋予权限。
1 | groupadd es |
修改配置文件
修改elasticsearch.yml配置文件
切换到es用户,修改 elasticsearch.yml 配置文件:
1 | su es |
配置文件修改参考:
1 | #集群的名称 |
修改jvm.options配置文件
优化elasticsearch占用内存,修改配置文件jvm.options
1 | -Xms32g |
配置elasticsearch启动文件和启动配置
创建elasticsearch的系统启动服务文件,进入到 cd /etc/init.d 目录
1 | cd /etc/init.d 【进入到目录】 |
编写启动脚本
1 |
|
修改文件权限
1 | chmod 777 elasticsearch |
添加和删除服务并设置启动方式
1 | # 添加系统服务 |
关闭和启动服务
1 | # 启动服务 |
设置服务是否开机启动
1 | # 开启开机自动启动服务 |
查看当前的开机启动服务命令
1 | chkconfig --list |
验证下服务是否正常运行
1 | curl http://127.0.0.1:9200 |
安装常见问题
在启动ES时可能会出现几种错误情况
max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
修改/etc/security/limits.conf文件,
1 | [es@localhost root]# su root |
在文件末尾添加如下:
1 | * hard nofile 65536 |
max number of threads [3818] for user [es] is too low, increase to at least [4096]
修改/etc/security/limits.d/20-nproc.conf文件,
1 | [es@localhost root]# su root |
修改内容如下:
1 | * soft nproc 4096 |
memory locking requested for elasticsearch process but memory is not locked
修改/etc/security/limits.conf文件,
1 | [es@localhost root]# su root |
在文件末尾添加如下:
1 | * hard memlock unlimited |
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
/etc/sysctl.conf文件末尾添加 vm.max_map_count = 262144
1 | [es@localhost root]# su root |
修改内容如下:
1 | # |
the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
修改 elasticsearch.yml,取消注释保留一个节点cluster.initial_master_nodes: [“node-1”]这个设置,这里的node-1是上面一个默认的记得打开就可以了重启ES
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Ther的小站!