CentOS7安装ElasticSearch

    技术2026-06-15  9

    CentOS7 ElasticSearch7.8 官网下载,https://www.elastic.co/cn/downloads/ 上传到 解压 cd /soft/elastic tar -zxvf elasticsearch-7.8.0-linux-x86_64.tar.gz mv elasticsearch-7.8.0-linux-x86_64 /home/elasticsearch adduser news cd /home mkdir -p elastic/data mkdir -p elastic/logs chown -R news elasticsearch chown -R news elastic 接下来非常重要 cd /home/elasticsearch/conf/ vim elasticsearch.yml 自己认真对着下面的改,不懂的百度一下。

    #======================== 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.data: /home/elastic/data # # Path to log files: # #path.logs: /path/to/logs path.logs: /home/elastic/logs # ----------------------------------- Memory ----------------------------------- # # Lock the memory on startup: bootstrap.memory_lock: false bootstrap.system_call_filter: false # 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: 192.168.0.1 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"] discovery.zen.ping.unicast.hosts: ["host1", "host2"] # # Bootstrap the cluster using an initial set of master-eligible nodes: # #cluster.initial_master_nodes: ["node-1", "node-2"] 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: 1 # # For more information, consult the gateway module documentation. # # ---------------------------------- Various ----------------------------------- # # Require explicit names when deleting indices: #my action.destructive_requires_name: true xpack.ml.enabled: false

    接下来配置一些内核参数

    vim /etc/security/limits.conf

    到文件末尾添加如下内容

    esuser hard nofile 65536 esuser soft nofile 65536 esuser soft memlock unlimited esuser hard memlock unlimited

    为了防止报错[65530] is too low, increase to at least [262144] 修改vim /etc/sysctl.conf 文件,在末尾添加 vm.max_map_count 使生效:sysctl -p vim /etc/security/limits.d/def.conf文件尾添加

    soft nofile 204800hard nofile 204800 让news用户具有和root一样的权限,visudo,添加如下,保存并退出。

    错误:JVM is using the client VM [Java HotSpot™ Client VM] but should be using a server VM for the best performance

    修改文件 JAVA_HOME\jre\lib\i386\jvm.cfg -server KNOWN //原来在第二行 -client IF_SERVER_CLASS -server -minimal KNOWN

    错误 unable to load JNA native support library, native methods will be disabled. java.lang.UnsatisfiedLinkError: Native library (com/sun/jna/linux-x86/libjnidispatch.so) not found

    解决办法 直接删除或备份Elasticsearch-a.b.c/lib目录下面的jna文件: mv jna-4.5.1.jar jna-4.5.1.jar.bak 在lib目录下载: wget http://repo1.maven.org/maven2/net/java/dev/jna/jna/5.0.0/jna-5.0.0.jar 执行如下命令

    没有报错,如果报错,要去找到日志,拖到windows下查看,效果明显。 日志目录 /home/elastic/logs

    打开浏览器

    Processed: 0.013, SQL: 9