Elasticsearch学习笔记(三)—在centos7上搭建环境

时间:2022-11-02 21:58:09

1 系统环境

  • 操作系统:CentOS Linux release 7.5.1804 (Core)

  • Java 1.8.0_181

2 Elastic安装

2.1 安装的简单说明

按照官网的说明,安装步骤如下:

  1. 下载和解压安装包

  2. 启动程序

  3. 检查是否启动成功

2.2 下载安装包

打开官网,点击【下载】,选择Elasticsearch,再选择ZIP安装包

Elasticsearch学习笔记(三)—在centos7上搭建环境

2.3启动服务

  1. 解压tar -xvf elasticsearch-6.5.4.tar.gz

  2. 进入下载的目录$ cd elasticsearch-6.5.4/bin

  3. 执行启动指令$ ./elasticsearch

    [2018-12-28T15:36:18,278][INFO ][o.e.e.NodeEnvironment    ] [kdektch] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [32.2gb], net total_space [49.9gb], types [rootfs]
    [2018-12-28T15:36:18,281][INFO ][o.e.e.NodeEnvironment    ] [kdektch] heap size [999mb], compressed ordinary object pointers [true]
    ······
    ······
    ······
    [2018-12-28T15:36:32,269][INFO ][o.e.c.m.MetaDataIndexTemplateService] [kdektch] adding template [.monitoring-alerts] for index patterns [.monitoring-alerts-6]
    [2018-12-28T15:36:32,291][INFO ][o.e.c.m.MetaDataIndexTemplateService] [kdektch] adding template [.monitoring-kibana] for index patterns [.monitoring-kibana-6-*]
    [2018-12-28T15:36:32,380][INFO ][o.e.l.LicenseService     ] [kdektch] license [da80144f-ad52-444f-adea-181efb360f16] mode [basic] - valid

2.4 获取版本信息

  1. 另开一个标签页

  2. 执行指令$ curl localhost:9200

    控制台打印信息如下:

    # curl localhost:9200
    {
      "name" : "kdektch",
      "cluster_name" : "elasticsearch",
      "cluster_uuid" : "KLu4TCvUQN6USdx0yA1MpQ",
      "version" : {
        "number" : "6.5.4",
        "build_flavor" : "default",
        "build_type" : "tar",
        "build_hash" : "d2ef93d",
        "build_date" : "2018-12-17T21:17:40.758843Z",
        "build_snapshot" : false,
        "lucene_version" : "7.5.0",
        "minimum_wire_compatibility_version" : "5.6.0",
        "minimum_index_compatibility_version" : "5.0.0"
      },
      "tagline" : "You Know, for Search"
    }

2.5 备注

  • 停止Elastic,在启动选项卡中直接control+c即可停止。

  • 如果你想把 Elasticsearch 作为一个守护进程在后台运行,那么可以在后面添加参数 -d

  • 默认情况下,Elastics只允许本机访问,如果需要远程访问,可以修改 Elastic 安装目录的config/elasticsearch.yml文件,去掉network.host的注释,将它的值改成0.0.0.0,然后重新启动 Elastic。

    #network.host: 192.168.0.1
    network.host: 0.0.0.0
  • 安装中文插件

    在安装目录下,运行指令:$ ./elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.5.4/elasticsearch-analysis-ik-6.5.4.zip

    注意版本要一致。

    安装完成后,重启。

    # ./elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.5.4/elasticsearch-analysis-ik-6.5.4.zip
    -> Downloading https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.5.4/elasticsearch-analysis-ik-6.5.4.zip
    [=================================================] 100%   
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    @     WARNING: plugin requires additional permissions     @
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    * java.net.SocketPermission * connect,resolve
    See http://docs.oracle.com/javase/8/docs/technotes/guides/security/permissions.html
    for descriptions of what these permissions allow and the associated risks.
    
    Continue with installation? [y/N]y
    -> Installed analysis-ik
    

3 Kibana安装

3.1 安装的简单说明

按照官网给出的资料(链接),安装步骤顺序如下:

  1. 下载Kibana安装包

  2. 打开config/kibana.yml配置文件,并进行设置

  3. 运行指令启动Kibana

  4. 打开浏览器访问http://localhost:5601

3.2 下载安装包

打开官网,点击【下载】,选择Kibana,再选择LINUX 64-BIT安装包。

Elasticsearch学习笔记(三)—在centos7上搭建环境

3.3 修改配置文件

  1. 将下载的安装包进行解压# tar -zvxf kibana-6.5.4-linux-x86_64.tar.gz

  2. 进入解压后目录的config目录下# cd kibana-6.5.4-linux-x86_64/config/

  3. 找到kibana.yml文件,进行编辑$ vim kibana.yml

  4. 找到elasticsearch.url,去掉前面的注释,并且将值设置为Elasticsearch的实例。更改如下图

    Elasticsearch学习笔记(三)—在centos7上搭建环境

3.4 启动服务

进入安装目录的config文件夹下,执行指令$ ./kibana

Elasticsearch学习笔记(三)—在centos7上搭建环境

3.5 打开浏览器访问

打开浏览器,输入地址http://localhost:5601

Elasticsearch学习笔记(三)—在centos7上搭建环境

4 安装遇到的问题

4.1 启动失败(一)

  • 错误日志

    [2018-12-28T15:30:59,095][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [unknown] uncaught exception in thread [main]
    org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
      at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:140) ~[elasticsearch-6.5.4.jar:6.5.4]
      at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:127) ~[elasticsearch-6.5.4.jar:6.5.4]
      at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.5.4.jar:6.5.4]
      at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.5.4.jar:6.5.4]
      at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.5.4.jar:6.5.4]
      at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.5.4.jar:6.5.4]
      at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86) ~[elasticsearch-6.5.4.jar:6.5.4]
    Caused by: java.lang.RuntimeException: can not run elasticsearch as root
      at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:103) ~[elasticsearch-6.5.4.jar:6.5.4]
      at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:170) ~[elasticsearch-6.5.4.jar:6.5.4]
      at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:333) ~[elasticsearch-6.5.4.jar:6.5.4]
      at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-6.5.4.jar:6.5.4]
      ... 6 more
  • 错误原因

    不能使用root账户启动elasticsearch

  • 解决思路

    创建一个新用户elastic来启动

  • 解决步骤

    [root@localhost local]# adduser elastic     --创建用户elastic
    [root@localhost local]# passwd elastic      --更改用户密码
    更改用户 elastic 的密码 。
    新的 密码:
    无效的密码: 密码少于 8 个字符
    重新输入新的 密码:
    passwd:所有的身份验证令牌已经成功更新。
    [root@localhost local]# chown -R elastic:elastic elasticsearch-6.5.4   --elastic赋权
    [root@localhost local]# su elastic      --切换elastic用户
    [elastic@localhost local]$ pwd
    /usr/local
    [elastic@localhost local]$ cd elasticsearch-6.5.4/bin/   --进入安装目录
    [elastic@localhost bin]$ ./elasticsearch   --启动

4.2 启动失败(二)

  • 错误日志

    max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]
  • 解决步骤

    root用户修改配置文件/etc/sysctl.conf,添加配置vm.max_map_count=655360。修改完毕后执行执行sysctl -p

4.3 启动失败(三)

  • 错误日志

    max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
  • 解决步骤

    root用户修改配置文件/etc/security/limits.conf,添加配置

    *               soft    nofile          65536
    *               hard    nofile          65536

    文件修改完毕后,需要重新打开新的terminal才会生效。

5 参考资料

elastic官网

Elasticsearch5.0 安装问题集锦

elasticsearch启动常见错误