完整记录安装elasticsearch的过程

1.修改config/elsatcisearch.yml配置

cluster.name: my-application
node.name: node-1
network.host: 0.0.0.0
http.port: 9200
cluster.initial_master_nodes: ["node-1"]

2.如果直接运行./bin/elsaticsearch,报错

[o.e.b.ElasticsearchUncaughtExceptionHandler] [node-1] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root

3. 添加一个用来运行es的用户

useradd zen
passwd zen

4.把/opt/elasticsearch-7.13.1目录以及子目录拥有者和组改为zen这个用户

chown -R zen:zen /opt/elasticsearch-7.13.1

5.切换到zen用户,运行elsaticsearch报错:

max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
bootstrap check failure [2] of [2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

su zen
./bin/elasticsearch

 6. 解决上面的问题

1#解决文件创建限制问题,#切换到root用户
su root
#修改最大可创建文件大小限制
vim /etc/security/limits.conf
#在文件末尾添加下面两项
zen soft nofile 65536
zen hard nofile 65536

#==
vim /etc/security/limits.d/20-nproc.conf
#在末尾添加
zen soft nofile 65536
zen hard nofile 65536
* hard nproc 4096
# * 代表所有linux用户名称

2# 解决虚拟内存太小问题
vim /etc/sysctl.conf
#添加如下内容
vm.max_map_count=655360
# 重新加载
sysctl -p

 7.切换zen用户,运行

su zen
./elasticsearch

 8.输入http://192.168.135.100:9200/访问不到,因为centos7没有打开9200端口,开启9200端口

firewall-cmd --add-port=9200/tcp --zone=public --permanent
firewall-cmd --reload

9.http://192.168.135.100:9200/正常打开

{
"name": "node-1",
"cluster_name": "my-application",
"cluster_uuid": "mzOq-NcVS_2SwVH3G2kV9w",
"version": {
"number": "7.13.1",
"build_flavor": "default",
"build_type": "tar",
"build_hash": "9a7758028e4ea59bcab41c12004603c5a7dd84a9",
"build_date": "2021-05-28T17:40:59.346932922Z",
"build_snapshot": false,
"lucene_version": "8.8.2",
"minimum_wire_compatibility_version": "6.8.0",
"minimum_index_compatibility_version": "6.0.0-beta1"
},
"tagline": "You Know, for Search"
}
原文地址:https://www.cnblogs.com/powerbear/p/14879649.html