参照:https://blog.csdn.net/CsethCRM/article/details/112221486
从5.0开始,ElasticSearch 安全级别提高了,不允许采用root帐号启动,所以我们要添加一个用户。 创建elk 用户组groupadd elk创建用户
sudo useradd -m es -d /home/es -s /bin/bash设置密码,设置自己的密码
passwd es将用户添加到用户组**
usermod -G elk es设置sudo权限
chmod +w /etc/sudoers vim /etc/sudoers
假设没有VIM 命令,请先安装:https://www.cnblogs.com/linux1836/p/10393745.html
yum -y install vim*
es ALL=(ALL:ALL) ALL切换到 新建的 es 用户, 安装配置Elasticsearch
su es定位到安装包所在的文件夹,压缩包在服务器上的位置
cd /home/soft/创建目录
sudo mkdir /home/lib/elasticsearch定位到压缩包所在的位置
cd /home/soft/解压缩到该目录
sudo tar -zxvf elasticsearch-7.6.2-linux-x86_64.tar.gz -C /home/lib/elasticsearch解压缩到该目录
sudo tar -zxvf elasticsearch-7.6.2-linux-x86_64.tar.gz -C /home/lib/elasticsearch解压后文件夹位置
cd /home/lib/elasticsearch/elasticsearch-7.6.2/配置文件修改
重要:改变ES目录拥有者账号 sudo chmod 777 /home/lib/elasticsearch/elasticsearch-7.6.2/ sudo chmod 777 /home/lib/elasticsearch/elasticsearch-7.6.2/config/ sudo chmod 777 /home/lib/elasticsearch/elasticsearch-7.6.2/配置Elasticsearch的最低内存要求,切换到root用户,在 /etc/sysctl.conf文件最后添加一行
vim /etc/sysctl.conf vm.max_map_count=655360 执行sysctl -p 让其生效 sysctl -p启动es 切换到非root用户,然后启动es 我们这里 用的 es 用户
cd /home/lib/elasticsearch/elasticsearch-7.6.2/ a) 启动 elasticsearch bin/elasticsearch b) 后台运行 elasticsearch, bin/elasticsearch -d打开:http://您的IP:9200/
看到如下内容:
{
“name” : “node-1”,
“cluster_name” : “elasticsearch”,
“cluster_uuid” : “OnOaVvbLR7irfvhvakpv8Q”,
“version” : {
“number” : “7.6.2”,
“build_flavor” : “default”,
“build_type” : “tar”,
“build_hash” : “ef48eb35cf30adf4db14086e8aabd07ef6fb113f”,
“build_date” : “2020-03-26T06:34:37.794943Z”,
“build_snapshot” : false,
“lucene_version” : “8.4.0”,
“minimum_wire_compatibility_version” : “6.8.0”,
“minimum_index_compatibility_version” : “6.0.0-beta1”
},
“tagline” : “You Know, for Search”
}
☆☆☆☆☆☆☆ 恭喜^_^ 大功告成 ☆☆☆☆☆☆☆修改后的配置
# ======================== Elasticsearch Configuration ========================= # # NOTE: Elasticsearch comes with reasonable defaults for most settings. # Before you set out to tweak and tune the configuration, make sure you # understand what are you trying to accomplish and the consequences. # # The primary way of configuring a node is via this file. This template lists # the most important settings you may want to configure for a production cluster. # # Please consult the documentation for further information on configuration options: # https://www.elastic.co/guide/en/elasticsearch/reference/index.html # # ---------------------------------- Cluster ----------------------------------- # # Use a descriptive name for your cluster: # #cluster.name: my-application # # ------------------------------------ Node ------------------------------------ # # Use a descriptive name for the node: # node.name: node-1 # # Add custom attributes to the node: # #node.attr.rack: r1 # # ----------------------------------- Paths ------------------------------------ # # Path to directory where to store the data (separate multiple locations by comma): # #path.data: /path/to/data # # Path to log files: # #path.logs: /path/to/logs # # ----------------------------------- Memory ----------------------------------- # # Lock the memory on startup: # #bootstrap.memory_lock: true # # Make sure that the heap size is set to about half the memory available # on the system and that the owner of the process is allowed to use this # limit. # # Elasticsearch performs poorly when the system is swapping the memory. # # ---------------------------------- Network ----------------------------------- # # Set the bind address to a specific IP (IPv4 or IPv6): # network.host: 0.0.0.0 # # Set a custom port for HTTP: # http.port: 9200 # # For more information, consult the network module documentation. # # --------------------------------- Discovery ---------------------------------- # # Pass an initial list of hosts to perform discovery when this node is started: # The default list of hosts is ["127.0.0.1", "[::1]"] # #discovery.seed_hosts: ["host1", "host2"] # # Bootstrap the cluster using an initial set of master-eligible nodes: # cluster.initial_master_nodes: ["node-1"] # # For more information, consult the discovery and cluster formation module documentation. # # ---------------------------------- Gateway ----------------------------------- # # Block initial recovery after a full cluster restart until N nodes are started: # #gateway.recover_after_nodes: 3 # # For more information, consult the gateway module documentation. # # ---------------------------------- Various ----------------------------------- # # Require explicit names when deleting indices: # #action.destructive_requires_name: true http.cors.enabled: true http.cors.allow-origin: "*"附录: 问题 1 :
Exception in thread “main” java.lang.RuntimeException: starting java failed with [1]
output:
error:
Unrecognized VM option ‘UseConcMarkSweepGC’
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
at org.elasticsearch.tools.launchers.JvmErgonomics.flagsFinal(JvmErgonomics.java:111)
at org.elasticsearch.tools.launchers.JvmErgonomics.finalJvmOptions(JvmErgonomics.java:79)
at org.elasticsearch.tools.launchers.JvmErgonomics.choose(JvmErgonomics.java:57)
at org.elasticsearch.tools.launchers.JvmOptionsParser.main(JvmOptionsParser.java:89)
解决方案:https://www.cnblogs.com/twfb/p/12653621.html
总体原因就是Java版本太高了,重新安装一个 jkd 11
Exception in thread “main” java.nio.file.AccessDeniedException: /usr/lib/elasticsearch/elasticsearch-7.3.1/config/jvm.options
at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:90)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116)
at java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:219)
at java.base/java.nio.file.Files.newByteChannel(Files.java:373)
at java.base/java.nio.file.Files.newByteChannel(Files.java:424)
at java.base/java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:420)
at java.base/java.nio.file.Files.newInputStream(Files.java:158)
at org.elasticsearch.tools.launchers.JvmOptionsParser.main(JvmOptionsParser.java:61)
解决方案:https://blog.csdn.net/qq_34419607/article/details/100047678 cd /home/lib/elasticsearch/ chown -R es elasticsearch-7.3.1问题 3 :
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
解决方案:https://www.cnblogs.com/yidiandhappy/p/7714489.html
问题 4 :max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
解决方案:https://blog.csdn.net/liyantianmin/article/details/81589795
问题 5:ERROR: [1] bootstrap checks failed
[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
解决方案:https://blog.csdn.net/qq_43655835/article/details/104637625
问题6:在 elasticsearch-head 中使用,不能使用,跨域问题 参照解决方案:https://blog.csdn.net/wyg1973017714/article/details/105788924
打开config目录下的elasticsearch.yml文件,然后添加:
http.cors.enabled: true
http.cors.allow-origin: “*”
netstat -alnp | grep 9200
elasticsearch-head 路径:file:///D:/05SvnLocal/SH2Group.documents/SH2Group%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/elasticsearch%20install/Windows/02%20elasticsearch/elasticsearch-head-master/index.html
其他查看防火墙状态:
systemctl status firewalld.service
停止防火墙:
systemctl stop firewalld.service
永久禁用防火墙:
systemctl disable firewalld.service



