欢迎光临
我们一直在努力

CentOS安装Elasticsearch 7详细过程

elasticsearch.jpg

环境

  • 系统:CENTOS 7;
  • Elasticsearch版本:elasticsearch-7.1.1-linux-x86_64.tar.gz;
  • 单节点部署elasticsearch;

安装JDK

详细过程参考:CentOS安装JDK

安装Elasticsearch

1.下载

地址:https://www.elastic.co/downloads/ ,这里我放在/home/inspur/elasticsearch/elasticsearch-7.1.1-linux-x86_64.tar.gz

2.解压

tar xzvf elasticsearch-7.1.1-linux-x86_64.tar.gz

3.运行

假设你没有修改任何配置:

[inspur@localhost elasticsearch]$ cd /home/inspur/elasticsearch/elasticsearch-7.1.1
[inspur@localhost elasticsearch-7.1.1]$ ./bin/elasticsearch

4.访问

没修改配置的情况下会有如下信息打印:

[inspur@localhost ~]$ curl localhost:9200
{
  "name" : "localhost.localdomain",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "Gqri13VpSCSI6RIbgkHaiA",
  "version" : {
    "number" : "7.1.1",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "7a013de",
    "build_date" : "2019-05-23T14:04:00.380842Z",
    "build_snapshot" : false,
    "lucene_version" : "8.0.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

修改配置

默认情况下,Elastic 只允许本机访问,如果需要远程访问,可以修改 Elastic 安装目录的config/elasticsearch.yml文件:

[inspur@localhost elasticsearch-7.1.1]$ vi ./config/elasticsearch.yml

取消注释下面几行:

cluster.name: www.4spaces.org
node.name: node-1
network.host: 0.0.0.0
http.port: 9200
discovery.seed_hosts: ["127.0.0.1", "[::1]"]
cluster.initial_master_nodes: ["node-1"]

# 开启跨域访问支持,默认为false
http.cors.enabled: true
# 跨域访问允许的域名地址,(允许所有域名)以上使用正则
http.cors.allow-origin: "*"

注:生产环境下请将network.host主机IP。

重新启动后访问:

{
  "name" : "node-1",
  "cluster_name" : "www.4spaces.org",
  "cluster_uuid" : "Gqri13VpSCSI6RIbgkHaiA",
  "version" : {
    "number" : "7.1.1",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "7a013de",
    "build_date" : "2019-05-23T14:04:00.380842Z",
    "build_snapshot" : false,
    "lucene_version" : "8.0.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

常见错误

1.修改配置后启动服务失败,报错:

ERROR: [3] 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]

1)对于[1],解决方式:sudo sysctl -w vm.max_map_count=262144,这样重启后会失效,永久的修改(需root用户)是:

[root@localhost elasticsearch-7.1.1]# echo "vm.max_map_count=262144" >> /etc/sysctl.conf
[root@localhost elasticsearch-7.1.1]# sysctl -p

2) 对于[2],解决方式:修改/etc/security/limits.conf,增加下面内容:

* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096 

然后注销后重新登录,使修改生效。

2.启动报错:

ERROR: [1] bootstrap checks failed
[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

修改配置文件,修改为下面内容:

cluster.name: www.4spaces.org
node.name: node-1
discovery.seed_hosts: ["127.0.0.1", "[::1]"]
cluster.initial_master_nodes: ["node-1"]

参考:

  1. 全文搜索引擎 Elasticsearch 入门教程
  2. elasticsearch 7 单机配置
  3. ElasticSearch 启动报错max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
赞(0) 打赏
未经允许不得转载:Ddmit » CentOS安装Elasticsearch 7详细过程

评论 抢沙发

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续提供更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫

登录

找回密码

注册