ES运行需要JDK支持,安装jdk请参考Linux下rpm安装jdk17,本文以elasticsearch-7.17.1为例。虽然下载的是源码,其实只需要将下载的tar.gz包解压缩即可。
下载
elasticsearch的下载地址https://www.elastic.co/guide/en/elasticsearch/reference/7.17/targz.html,
选择版本7.17
,接着选择Install Elasticsearch from archive on Linux or MacOS
,页面左边就会给出具体的下载地址:elasticsearch-7.17.1-darwin-x86_64.tar.gz 。
配置
下载完成后,使用tar -zxvf elasticsearch-7.17.1-darwin-x86_64.tar.gz
进行解压,解压完成后目录结构如下:
[xupeng@instance-1apocjsh elasticsearch-7.17.1]$ ls
bin config data jdk lib LICENSE.txt logs modules NOTICE.txt plugins README.asciidoc
bin目录下是可执行程序,经常使用的是elasticsearch
,config目录下是配置文件,经常使用的是elasticsearch.yml
。
1 vim编辑config/elasticsearch.yml
,network.host
: 修改为0.0.0.0
,即:
network.host: 0.0.0.0(原来是注释掉的,解开注释然后修改为0.0.0.0)
这样外网也可以访问。(默认只能本地访问)
2 继续编辑config/elasticsearch.yml
,添加如下内容:
node.name: node-1(原来是注释掉的,解开注释即可)
cluster.initial_master_nodes: [“node-1”]
用来解决报错:
bootstrap check failure [1] of [2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
3 vim编辑/etc/sysctl.conf
,添加vm.max_map_count
等于262144。
vm.max_map_count=262144
然后再执行命令sysctl -p
。
用来解决报错:
bootstrap check failure [1] of [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
运行
注意,较新版本的elasticsearch
不能直接使用root启动,必须使用其他账户才行。(使用root账户执行useradd、passwd创建账户
)
运行elasticsearch
,运行时的打印信息比较多,当出现如下信息后,便是启动成功,
[2022-03-22T15:44:18,693][INFO ][o.e.i.g.DatabaseNodeService] [node-1] successfully reloaded changed geoip database file [/tmp/elasticsearch-2108482673908586040/geoip-databases/j6bbwvGmS72FB83s0lmORw/GeoLite2-ASN.mmdb]
[2022-03-22T15:44:20,625][INFO ][o.e.i.g.GeoIpDownloader ] [node-1] geoip database [GeoLite2-ASN.mmdb] is up to date, updated timestamp
[2022-03-22T15:44:20,787][INFO ][o.e.i.g.GeoIpDownloader ] [node-1] updating geoip database [GeoLite2-City.mmdb]
如果需要让其后台运行,可以使用(./bin/elasticsearch&)
验证
elasticsearch
的默认端口为9200
,可以在外网使用浏览器直接访问地址:https://ip地址:9200
,
访问成功返回如下内容:
{
"name" : "node-1",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "akM08BOmRXq4iK_zEnlI0Q",
"version" : {
"number" : "7.17.1",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "e5acb99f822233d62d6444ce45a4543dc1c8059a",
"build_date" : "2022-02-23T22:20:54.153567231Z",
"build_snapshot" : false,
"lucene_version" : "8.11.1",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}