【CentOs7/Elasticsearch7.11.0】ES单机单实例安装手顺


【目标】

1.让ES对本机9200端口提供服务,即敲入curl localhost:9200能看到

{
  "name" : "node-1",
  "cluster_name" : "hy-app322",
  "cluster_uuid" : "3uOf0MeGT06KHb1aODicpQ",
  "version" : {
    "number" : "7.11.0",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "8ced7813d6f16d2ef30792e2fcde3e755795ee04",
    "build_date" : "2021-02-08T22:44:01.320463Z",
    "build_snapshot" : false,
    "lucene_version" : "8.7.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

这样的反馈内容;

2.让ES对ip:9200端口提供服务,如虚拟机ip为192.168.32.130,那么主机上浏览器通过192.168.32.130:9200端口可以得到上面这段反馈。

3.在本机或是主机上 能创建、查询和删除文档。

以上三条中,头两条较容易实现,但不保证实现后第三条也能顺利出来。

网上类似文档多如牛毛,但基本只满足了目标1和2,但这是不完全的。

ES能否实用,还得以第三条为检验标准。

【准备安装的软件】

elasticsearch-7.11.0-linux-x86_64.tar.gz

因为该版本自带jdk,就不需另装一个了。 

【系统版本及内核】

CentOS Linux release 7.9.2009 (Core)

3.10.0-1160.el7.x86_64

【es解压过程】

因为es不能以root执行,故创建用户hy,然后以这个用户来解压

$tar -xvzf elasticsearch-7.11.0-linux-x86_64.tar.gz

解压之后会出现目录elasticsearch-7.11.0,

配置文件是elasticsearch-7.11.0/config/elasticsearch.yml,

执行文件是elasticsearch-7.11.0/bin/elasticsearch

【elasticsearch.yml的修改点】

cluster.name: hy-app322                             # 集群名,多节点时节点扎堆就靠它,所以最好给个不易重复能独立标识该群的名字

node.name: node-1                                     # 放开此节点即可

network.host: 0.0.0.0                                  # 改写成0.0.0.0是让本机和外网都能访问

http.port: 9200                                            # 默认的服务端口 放开此节点即可

cluster.initial_master_nodes: ["node-1"]     # 放开后,去掉其中的node-2,只留下node-1

【/etc/security/limits.conf的修改点】

切换到root用户
vi /etc/security/limits.conf

在文件末尾,#End of file下书写

* soft nofile 65535

* hard nofile 131072

* soft nproc 4096

* hard nproc 4096

保存退出

此项修改在再度切换为hy用户才有效,因此不要一个普通账户hy开个窗口等着,一个root在另一个窗口改。

【/etc/sysctl.conf的修改点】

vi /etc/sysctl.conf
添加

vm.max_map_count=655360

保存后执行
sysctl -p

【系统防火墙的设置】

放开9200端口或是直接了当停止防火墙

#systemctl stop firewalld 

【执行es】

切回hy账户,执行elasticsearch-7.11.0/bin/elasticsearch

【目标1的检验】 

[hy@localhost ~]$ curl localhost:9200
{
  "name" : "node-1",
  "cluster_name" : "hy-app130",
  "cluster_uuid" : "OHQmV0p8QUCLutfepnipqQ",
  "version" : {
    "number" : "7.11.0",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "8ced7813d6f16d2ef30792e2fcde3e755795ee04",
    "build_date" : "2021-02-08T22:44:01.320463Z",
    "build_snapshot" : false,
    "lucene_version" : "8.7.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}
[hy@localhost ~]$

【目标2的检验】

【目标3的检验】

 待执行的语句:

# 创建两条文档
curl -H "Content-Type: application/json" -XPUT 'localhost:9200/google/emp/1?pretty' -d' {"name":"Andy","age":"21","salary":"30k","hdate":"2020-1-1T12:12:12"}'

curl -H "Content-Type: application/json" -XPUT 'localhost:9200/google/emp/2?pretty' -d' {"name":"Bill","age":"22","salary":"60k","hdate":"2021-1-1T12:12:12"}'

# 按ID查找
curl -XGET 'localhost:9200/google/emp/2?pretty'

# 删除
curl -XDELETE 'localhost:9200/google/emp/2?pretty'

# 看是否删掉了
curl -XGET 'localhost:9200/google/emp/2?pretty'

执行结果:

[hy@localhost ~]$ curl -H "Content-Type: application/json" -XPUT 'localhost:9200/google/emp/1?pretty' -d' {"name":"Andy","age":"21","salary":"30k","hdate":"2020-1-1T12:12:12"}'
{
  "_index" : "google",
  "_type" : "emp",
  "_id" : "1",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 0,
  "_primary_term" : 1
}
[hy@localhost ~]$ curl -H "Content-Type: application/json" -XPUT 'localhost:9200/google/emp/2?pretty' -d' {"name":"Bill","age":"22","salary":"60k","hdate":"2021-1-1T12:12:12"}'
{
  "_index" : "google",
  "_type" : "emp",
  "_id" : "2",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 1,
  "_primary_term" : 1
}
[hy@localhost ~]$ url -XGET 'localhost:9200/google/emp/2?pretty'
bash: url: command not found...
[hy@localhost ~]$ curl -XGET 'localhost:9200/google/emp/2?pretty'
{
  "_index" : "google",
  "_type" : "emp",
  "_id" : "2",
  "_version" : 1,
  "_seq_no" : 1,
  "_primary_term" : 1,
  "found" : true,
  "_source" : {
    "name" : "Bill",
    "age" : "22",
    "salary" : "60k",
    "hdate" : "2021-1-1T12:12:12"
  }
}
[hy@localhost ~]$ curl -XDELETE 'localhost:9200/google/emp/2?pretty'
{
  "_index" : "google",
  "_type" : "emp",
  "_id" : "2",
  "_version" : 2,
  "result" : "deleted",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 2,
  "_primary_term" : 1
}
[hy@localhost ~]$ curl -XGET 'localhost:9200/google/emp/2?pretty'
{
  "_index" : "google",
  "_type" : "emp",
  "_id" : "2",
  "found" : false
}
[hy@localhost ~]$

如果执行和预期一致,则说明安装成功。

END

相关