• 周五. 11 月 13th, 2026

CentOS7安装ElasticSearch7

由root

7 月 9, 2020 #elastic, #elasticsearch, #es
  1. 下载es
    https://www.elastic.co/cn/downloads/elasticsearch
  2. CentOS创建es用户
useradd es  //添加用户
passwd es   //设置密码

3. 安装jdk(如果没有装) ,JDK需要11版本以上
CentOS安装jdk14

4. 解压缩下载好的es包

tar -zxvf elasticsearch-7.8.0-linux-x86_64.tar.gz

5. 将解压后的目录移动到/usr/local/下

mv elasticsearch-7.8.0 /usr/local/elasticsearch

6. 修改/usr/local/elasticsearch/config/elasticsearch.yml配置文件,

node.name: node-1 //指定当前节点名称
network.host: 0.0.0.0     //其他服务器可通过IP访问
cluster.initial_master_nodes: ["node-1"]  //指定主节点名称

7. 启动ES

查看/usr/local/elasticsearch目录的权限。 这里需要改所属用户和组

chown -R es.es /usr/local/elasticsearch

如果当前你在root用户下,请切换到es用户,否则es会提示你不能用root启动

su es

8. 后台启动es

cd /usr/local/elasticsearch/
./bin/elasticsearch -d

9. 查看启动日志

[es@VM_0_3_centos elasticsearch]$ tail -f logs/elasticsearch.log 
[2020-07-09T14:21:06,717][INFO ][o.e.x.m.p.NativeController] [VM_0_3_centos] Native controller process has stopped - no new native processes can be started
[2020-07-09T14:21:06,745][INFO ][o.e.n.Node               ] [VM_0_3_centos] stopping ...
[2020-07-09T14:21:06,762][INFO ][o.e.x.w.WatcherService   ] [VM_0_3_centos] stopping watch service, reason [shutdown initiated]
[2020-07-09T14:21:06,765][INFO ][o.e.x.w.WatcherLifeCycleService] [VM_0_3_centos] watcher has stopped and shutdown
[2020-07-09T14:21:06,864][INFO ][o.e.n.Node               ] [VM_0_3_centos] stopped
[2020-07-09T14:21:06,866][INFO ][o.e.n.Node               ] [VM_0_3_centos] closing ...
1] bootstrap checks failed
[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
ERROR: [1] bootstrap checks failed
[1]: 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/logs/elasticsearch.log

可以看到有ERROR 大概意思是需要提高vm.max_map_count的值,切回root

[root@VM_0_3_centos elasticsearch]# sysctl -w vm.max_map_count=262144   //设置
vm.max_map_count = 262144
[root@VM_0_3_centos elasticsearch]# sysctl -a | grep  vm.max_map_count   //查看生效没
sysctl: reading key "net.ipv6.conf.all.stable_secret"
sysctl: reading key "net.ipv6.conf.default.stable_secret"
sysctl: reading key "net.ipv6.conf.eth0.stable_secret"
sysctl: reading key "net.ipv6.conf.lo.stable_secret"
vm.max_map_count = 262144

//设置永久生效
vim /etc/sysctl.conf
在文件尾加入
vm.max_map_count = 262144

10. 如果日志中看不出错误,即可验证

[es@VM_0_3_centos elasticsearch]$ curl http://localhost:9200
{
  "name" : "VM_0_3_centos",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "2SsGoLt1RA2upOQ-sO8d5Q",
  "version" : {
    "number" : "7.8.0",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "757314695644ea9a1dc2fecd26d1a43856725e65",
    "build_date" : "2020-06-14T19:35:50.234439Z",
    "build_snapshot" : false,
    "lucene_version" : "8.5.1",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

常见问题

max number of threads [3818] for user [es] is too low, increase to at least [4096]
最大线程个数太低。修改配置文件etc/security/limits.conf,增加配置
* soft nproc 4096
* hard nproc 4096

注意这里的*号要带上,不可以删除

由 root

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注