elasticsearch基础----->elasticsearch环境的搭建

  这里面我们主要是在ubuntu系统上对elasticsearch进行一个环境的搭建,记录一下这个过程中遇到的一些问题以及解决方案。我总是躲在梦与季节的深处,听花与黑夜唱尽梦魇,唱尽繁华,唱断所有记忆的来路。

elasticsearch的下载安装

我们用的测试系统是ubuntu16.0.4,首先是下载最新的elasticsearch。地址:https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.1.0.tar.gz

一、在/home/huhx/apache/server目录下,用wget下载

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.1.0.tar.gz

使用tar对其进行解压:

tar -xf elasticsearch-6.1.0.tar.gz

cd到elasticsearch-6.1.0目录下面,可以看到如下的结构:

elasticsearch的启动命令:加-d参数可以作为一个后台进程支行。

./bin/elasticsearch -d

我们访问地址: localhost:9200/。可以看到如下的页面信息:

{
  "name" : "1zXRuwV",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "2It6zBz5R62uV48XM0UsJw",
  "version" : {
    "number" : "6.1.0",
    "build_hash" : "c0c1ba0",
    "build_date" : "2017-12-12T12:32:54.550Z",
    "build_snapshot" : false,
    "lucene_version" : "7.1.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

但是在本地机器却不能正常的访问服务器192.168.1.112的9200端口的服务,这是因为elasticsearch默认只能本机访问elasticsearch的服务。我们修改config下面的elasticsearch.yml文件:添加内容

network.host: 0.0.0.0

重启elasticsearch服务,就可以要本地机器访问服务器上的elasticsearch服务了。注意:elasticsearch6.1.0好像没有停止elasticsearch的服务了,我们可以kill pid杀掉进程。

二、为了方便查看我们可以安装插件elasticsearch-head

  在elasticsearch安装目录之外,我们新建立目录去安装/elasticsearch-head。如果把/elasticsearch-head安装到elasticsearch下面的plugins目录下面,启动会报错。

在~/apache/plugins目录下面,我们下载:elasticsearch-head。

wget https://github.com/mobz/elasticsearch-head/archive/master.zip

解压master.zip文件:

unzip master.zip

elasticsearch-head的运行需要nodejs的支持,所以首先需要安装nodejs,这里就不做介绍。执行npm install,下载必要的依赖。下载完成之后,执行npm run start启动elasticsearch-head,打印的日志如下:

huhx@huhx:~/apache/plugins/elasticsearch-head-master$ npm run start

> elasticsearch-head@0.0.0 start /home/huhx/apache/plugins/elasticsearch-head-master
> grunt server

(node:24860) ExperimentalWarning: The http2 module is an experimental API.
Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:9100

为了解决访问跨域的问题,我们需要修改elasticsearch的配置文件。地址:/home/huhx/apache/server/elasticsearch-6.1.0/config/elasticsearch.yml。在结尾添加内容:

http.cors.enabled: true
http.cors.allow-origin: "*"

现在我们启动elasticsearch和elasticsearch-head,在本地机器访问:http://192.168.1.112:9100/。截图如下:

三、安装一些问题的整理

  • es-head插件的安装:之前好像可以通过进入elasticsearch/bin目录,输入命令./plugin –install mobz/elasticsearch-head 安装head插件。现在bin目录下面有一个elasticsearch-plugin,但是也不能通过这种方式去安装插件。
  • elasticsearch的启动不能使用root用法,否则会报can not run elasticsearch as root的异常。
  • 运行elasticsearch报错:max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]。下面是解决方案:
切换到root用户修改配置sysctl.conf: vi /etc/sysctl.conf 
添加下面配置:vm.max_map_count
=655360
并执行命令:sysctl -p

友情链接

原文地址:https://www.cnblogs.com/huhx/p/bauseelasticsearchenv.html