CentOS 7 安装 ElasticSearch

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.8.1-x86_64.rpm
rpm --install elasticsearch-7.8.1-x86_64.rpm

chown -R elasticsearch /var/lib/elasticsearch/

systemctl enable elasticsearch
systemctl start elasticsearch

报错:
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x000000008a660000, 1973026816, 0) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 1973026816 bytes for committing reserved memory.
# An error report file with more information is saved as:
# /root/elasticsearch-5.6.0/hs_err_pid19703.log
vi /etc/elasticsearch/jvm.options
或
vi config/jvm.options
-Xms2g
-Xmx2g
修改为:
-Xms256m
-Xmx256m

./bin/elasticsearch

curl --proxy "" http://localhost:9200/?pretty

修改Elasticsearch的配置,使其支持外网访问:
vi /etc/elasticsearch/elasticsearch.yml
network.host: 0.0.0.0
node.name: node-1
cluster.initial_master_nodes: ["node-1"]

报错:
Exception in thread "main" java.lang.RuntimeException: don't run elasticsearch as root
添加专门的用户
useradd elastic
passwd elastic
chown -R elastic:elastic elasticsearch-5.6.0/

报错:
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
修改/etc/sysctl.conf配置文件
cat /etc/sysctl.conf | grep vm.max_map_count
vm.max_map_count=262144
如果不存在则添加
echo "vm.max_map_count=262144" >>/etc/sysctl.conf
sysctl -p

报错:
ERROR: [1] bootstrap checks failed
[1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_p... configured
ERROR: Elasticsearch did not exit normally - check the logs at /var/log/elasticsearch/elasticsearch.log
vi /etc/elasticsearch/elasticsearch.yml
取消注释保留一个节点
cluster.initial_master_nodes: ["node-1"]