技术交流QQ群【JAVA,.NET,BigData,AI】:170933152 

这东西用来做大数据检索,可以跟hadoop一起使用。

安装准备:

1.安装jdk

2.给虚拟机配置静态ip,可以查看其它博文怎么配置

3.开始安装:在centos7上操作

我把elasticsearch,放在了/usr/elasticsearch下面,到这个目录然后:

https://www.elastic.co/downloads/elasticsearch#preview-release 先去这里地址,找到rpm包,然后复制地址

执行:wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.0.0-beta1-x86_64.rpm

开始下载,挺大的得下一会儿

4.直接解压安装,超级方便,一步到位

rpm -ivh elasticsearch-2.3.5.rpm 

systemctl daemon-reloa//这个我没有执行成功,但是也没发现有什么影响

5.启动并查看安装状态,直接下载完解压,就可以启动起来

systemctl start elasticsearch

systemctl status elasticsearch

6.启动的日志

[root@localhost elasticsearch]# systemctl status elasticsearch
● elasticsearch.service - Elasticsearch
   Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2019-03-04 01:32:11 CST; 19s ago
     Docs: http://www.elastic.co
 Main PID: 12458 (java)
   CGroup: /system.slice/elasticsearch.service
           ├─12458 /lib/jvm/bin/java -Xms1g -Xmx1g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -Des.networkaddress.cache.tt...
           └─12517 /usr/share/elasticsearch/modules/x-pack-ml/platform/linux-x86_64/bin/controller

7.然后去访问一下看看:

curl -XGET "127.0.0.1:9200" 或者运行 curl http://localhost:9200 curl http://127.0.0.1:9200 都可以

8.可以看到没问题

{
  "name" : "node-1",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "1QcPN8ZvQWKmeP-nP7UvkQ",
  "version" : {
    "number" : "7.0.0-beta1",
    "build_flavor" : "default",
    "build_type" : "rpm",
    "build_hash" : "15bb494",
    "build_date" : "2019-02-13T12:30:14.432234Z",
    "build_snapshot" : false,
    "lucene_version" : "8.0.0",
    "minimum_wire_compatibility_version" : "6.7.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

 

9.但是这个时候从外面的浏览器访问,访问不了,这个时候这样配置,进入到下面的目录,然后编辑

elasticsearch.yml文件

node.name: node-1 前面的#打开

#network.host: 192.168.0.1
network.host: 192.168.136.110
#network.host: 0.0.0.0
#network.host: localhost
#network.host: 127.0.0.1  这里把network.host 设置为自己的ip地址 网上有设置成0.0.0.0的应该也可以自己设置一下试试

cluster.initial_master_nodes: ["node-1"] 这里一定要这样设置,我就是这里没有这样设置出问题的,弄了好久

在最后加上这两句,要不然,外面浏览器就访问不了哈

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

[root@localhost elasticsearch]# cd /etc/elasticsearch/
[root@localhost elasticsearch]# ll
total 48
-rw-r--r-- 1 root elasticsearch  5123 Mar  4 00:20 df
-rw-rw---- 1 root elasticsearch   207 Mar  3 21:28 elasticsearch.keystore
-rw-rw---- 1 root elasticsearch  3101 Mar  4 01:32 elasticsearch.yml
-rw-rw---- 1 root elasticsearch  3685 Feb 13 20:37 jvm.options
-rw-rw---- 1 root elasticsearch 17170 Feb 13 20:37 log4j2.properties
-rw-rw---- 1 root elasticsearch   473 Feb 13 20:37 role_mapping.yml
-rw-rw---- 1 root elasticsearch   197 Feb 13 20:37 roles.yml
-rw-rw---- 1 root elasticsearch     0 Feb 13 20:37 users
-rw-rw---- 1 root elasticsearch     0 Feb 13 20:37 users_roles
[root@localhost elasticsearch]# vi elasticsearch.yml

# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
#cluster.name: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /var/lib/elasticsearch
#
# Path to log files:
#
path.logs: /var/log/elasticsearch
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
"elasticsearch.yml" 98L, 3101C
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
#network.host: 192.168.0.1
network.host: 192.168.136.110
#network.host: 0.0.0.0
#network.host: localhost
#network.host: 127.0.0.1
#
# Set a custom port for HTTP:
#
#http.port: 9200
#http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.seed_hosts: ["host1", "host2"]
#discovery.seed_hosts:["my-application"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
#cluster.initial_master_nodes: ["node-1", "node-2"]
cluster.initial_master_nodes: ["node-1"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
http.cors.enabled: true
http.cors.allow-origin: "*"

出了一些错误,具体是下面这几个

就是因上面的配置之前不对造成的,按照上面的配置完,再启动,就没有问题了

记录一下问题:
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.initial_master_nodes: ["node-1", "node-2"]
cluster.initial_master_nodes: ["node-1"] 这个的话,这里的node-1是上面一个默认的记得打开就可以了
 

[2019-03-04T00:52:55,299][DEBUG][o.e.a.ActionModule       ] [localhost.localdomain] Using REST wrapper from plugin org.elasticsearch.xpack.security.Security
[2019-03-04T00:52:55,869][INFO ][o.e.d.DiscoveryModule    ] [localhost.localdomain] using discovery type [zen] and seed hosts providers [settings]
[2019-03-04T00:52:58,023][INFO ][o.e.n.Node               ] [localhost.localdomain] initialized
[2019-03-04T00:52:58,023][INFO ][o.e.n.Node               ] [localhost.localdomain] starting ...
[2019-03-04T00:52:58,317][INFO ][o.e.t.TransportService   ] [localhost.localdomain] publish_address {192.168.136.110:9300}, bound_addresses {[::]:9300}
[2019-03-04T00:52:58,336][INFO ][o.e.b.BootstrapChecks    ] [localhost.localdomain] bound or publishing to a non-loopback address, enforcing bootstrap checks
[2019-03-04T00:52:58,427][ERROR][o.e.b.Bootstrap          ] [localhost.localdomain] node validation exception
[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

网上还有说ES启动不能用Root用户的,我跟着也新建了一个用户,但是最终发现,不用这个新建的 用户也行,所以应该是不用新建用户,直接用root用户就可以的

成功后可以试试:

[root@localhost elasticsearch]# curl http://192.168.136.110:9200
{
  "name" : "node-1",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "1QcPN8ZvQWKmeP-nP7UvkQ",
  "version" : {
    "number" : "7.0.0-beta1",
    "build_flavor" : "default",
    "build_type" : "rpm",
    "build_hash" : "15bb494",
    "build_date" : "2019-02-13T12:30:14.432234Z",
    "build_snapshot" : false,
    "lucene_version" : "8.0.0",
    "minimum_wire_compatibility_version" : "6.7.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

然后在浏览器上同样:http://192.168.136.110:9200/试一试就可以了.

 

想起来还有个地方,如果有问题,可以把下面的这个地方配置上,

etc/sysctl.conf 中添加上

vm.max_map_count=655360

保存

然后执行

sysctl -p

然后再重启一下elasticsearch

[root@localhost etc]# vi sysctl.conf

# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
vm.max_map_count=655360

 

 下面找的详细点的:

elasticsearch修改config目录下的 yml文件后network.host: 0.0.0.0后,报bootstrap checks failed问题解决

修改次配置,是为了可以完成外网访问,但修改后,es启动失败了,

需要首先切换到root账户下,vim /etc/sysctl.conf

进入后,点击 键盘‘i’键,进入到编辑模式

添加此句话: vm.max_map_count=655360

当然,这一句前面要顶格写的,前面如果有#号,需要去掉

然后,点击 esc 键 ,退出编辑模式

在点击键盘 shift+:   冒号键,再输入  wq,敲回车,才算保存成功,这个是vim编辑模式的保存退出

在输入命令: sysctl -p      这句一定要再root账户下完成

之后切换回到 我们自己的账户下,启动es: ./elasticsearch 或者加上 -d, 已守护线程方式启动,

查看进程是否启动: ps -ef|grep elasticsearch

关闭es和关闭他的线程方式一样: kill -9 '进程号'

 

 

 

 

 

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐