Centos7上安装ElasticSearch

  • 我这里选择的版本是Elasticsearch 7.17.6,下载链接为Elasticsearch 7.17.6 | Elastic

  • 下载完毕后解压到想要安装的文件夹,我这里是/data/elasticsearch-7.17.6

  • 由于我的服务器内存比较小,所以需要配置一下启动内存

    vim /data/elasticsearch-7.17.6/config/jvm.options
    

image

打开之后发现配置文件注释内容大致为ES会根据当前系统的可用内存自动分配内存,如果需要配置的话,需要在当前配置文件目录下的jvm.options.d文件夹中创建一个文件进行配置,就类似于Nginx的配置方式,现在Es可以引用其他的配置文件了

  • 看到这个内容后,我没有更改Jvm的堆内存大小,发现还是无法启动的,报错内容确实为内存的问题,所以我就在Es指定的文件夹中创建了一个文件,并指定内存,学习使用,内存设置的比较小

    • -Xms512m
    • -Xmx512m
  • 尝试重新启动,还是报同样的错误,我猜测是配置文件名称,所以我将自定义的配置文件的名称也改为jvm.options,注释中并没有写文件的命名格式,所以也只是尝试一下,启动之后发现报错信息变成不能以root用户启动Es,这个报错信息是比较常见的,说明刚才启动失败确实是配置文件命名的问题

    • 后来发现这个配置文件是要求拓展名为options,这一点在配置文件的注释中是没有要求的,需要格外注意
  • 那么现在的问题是root用户无法启动的问题,很容易解决,就是创建一个用户,用这个用户启动Es

##先创建一个用户组,名称可以自己指定
groupadd elastic

##在这个组里面创建用户 useradd 用户名 -g(将其分配到elastic用户组) -p (指定密码)
useradd elastic -g elastic -p ******

##更改 /data/elasticsearch-7.17.6 文件夹及内部文件的所属用户及组为elastic
chown -R elastic:elastic /data/elasticsearch-7.17.6
  • 继续尝试启动,发现启动到一半进程自动被Kill掉了,并没有任何报错,网上查询资料后,大家给的原因是还是内存不足,查看系统剩余内存
free -m
							total       	used        free      	shared  	buff/cache   available
Mem:           1734         836         753           0         144         757

此时还剩下700M内存,我配置的jvm堆内存为512M,确实是有可能内存不足,我的服务器内存只有2G,看到 Swap

功能没有开启,我的理解是将硬盘的一部分的容量当做内存使用,就像现在的某些智能手机一样。尝试开启Swap

CentOS7上配置Swap交换空间-阿里云开发者社区 (aliyun.com)

  • 配置完成后
free -m
							total       	used        free      	shared  	buff/cache   available
Mem:           1734         836         753           0         144         757
Swap:          4095          28        4067
  • 继续尝试启动,还是报错
ERROR: [2] bootstrap checks failed. You must address the points described in the following [2] lines before starting Elasticsearch.
bootstrap check failure [1] of [2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
bootstrap check failure [2] of [2]: 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

这个问题也是比较常见的问题

系统虚拟内存默认最大映射数为65530,无法满足ES系统要求,需要调整为262144以上。

#修改文件
sudo vim /etc/sysctl.conf
 
#添加参数
vm.max_map_count = 262144

#重新加载配置
sysctl -p
  • 还是报错😞
ERROR: [1] bootstrap checks failed. You must address the points described in the following [1] lines before starting Elasticsearch.
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

搜索发现是没有更改配置,编辑config目录下的elasticsearch.yml文件,修改配置

#允许远程连接的配置
network.host: 0.0.0.0 

#指定当前节点的名称
node.name: node-1

#大概也是集群相关的配置,不懂干啥的
cluster.initial_master_nodes: ["node-1"]

经过上面的配置,Es顺利启动,

[2022-09-25T15:31:35,174][INFO ][o.e.i.g.GeoIpDownloader  ] [node-1] successfully downloaded geoip database [GeoLite2-City.mmdb]
[2022-09-25T15:31:38,366][INFO ][o.e.i.g.DatabaseNodeService] [node-1] successfully reloaded changed geoip database file [/tmp/elasticsearch-16699838870076211366/geoip-databases/KPty4tFHSUiOJv0NGuYIpQ/GeoLite2-City.mmdb]
[2022-09-25T15:31:38,378][INFO ][o.e.i.g.DatabaseNodeService] [node-1] retrieve geoip database [GeoLite2-Country.mmdb] from [.geoip_databases] to [/tmp/elasticsearch-16699838870076211366/geoip-databases/KPty4tFHSUiOJv0NGuYIpQ/GeoLite2-Country.mmdb.tmp.gz]
[2022-09-25T15:31:38,671][INFO ][o.e.i.g.GeoIpDownloader  ] [node-1] successfully downloaded geoip database [GeoLite2-Country.mmdb]
[2022-09-25T15:31:38,724][INFO ][o.e.i.g.DatabaseNodeService] [node-1] successfully reloaded changed geoip database file [/tmp/elasticsearch-16699838870076211366/geoip-databases/KPty4tFHSUiOJv0NGuYIpQ/GeoLite2-Country.mmdb]

请求es的默认端口,正确响应

[root@iZbp17plnodbhxyytyd8rhZ config]# curl localhost:9200
{
  "name" : "node-1",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "96XuP0lTSVKBpr58rMGlQw",
  "version" : {
    "number" : "7.17.6",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "f65e9d338dc1d07b642e14a27f338990148ee5b6",
    "build_date" : "2022-08-23T11:08:48.893373482Z",
    "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"
}
posted @   _fun_ny  阅读(295)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示
主题色彩