我有一个问题与systemd配置ElasticSearch。

[Unit]
Description=platform-elasticsearch
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
User={{ app_user }}
Group={{ app_group }}
Environment=ES_PATH_CONF=/platform/opt/elasticsearch-{{ elasticsearch.version }}/config
Environment=JAVA_HOME=/platform/opt/jdk{{ jdk.major_version }}_{{ jdk.minor_version }}
LimitAS=infinity
LimitRSS=infinity
LimitCORE=infinity
LimitNOFILE=100000
LimitMEMLOCK=100000
StandardOutput=syslog
StandardError=syslog
WorkingDirectory=/platform/var/app/elasticsearch
ExecStart=/platform/opt/elasticsearch-{{ elasticsearch.version }}/bin/elasticsearch
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s -TERM $MAINPID
TimeoutStopSec=60
# When a JVM receives a SIGTERM signal it exits with code 143
SuccessExitStatus=143 0
Type=simple
Restart=on-failure
RestartSec=10
PIDFile=/platform/var/run/elasticsearch.pid

[Install]
WantedBy=multi-user.target

这似乎不让我配置虚拟机。max_map_count设置。

Jul 20 14:53:46 scratchpad elasticsearch: [2018-07-20T14:53:46,359][INFO ][o.e.b.BootstrapChecks    ] [1oQJNUK] bound or publishing to a non-loopback     address, enforcing bootstrap checks
Jul 20 14:53:46 scratchpad elasticsearch: ERROR: [1] bootstrap checks failed
Jul 20 14:53:46 scratchpad elasticsearch: [1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
Jul 20 14:53:46 scratchpad elasticsearch: [2018-07-20T14:53:46,376][INFO ][o.e.n.Node               ] [1oQJNUK] stopping ...
Jul 20 14:53:46 scratchpad elasticsearch: [2018-07-20T14:53:46,414][INFO ][o.e.n.Node               ] [1oQJNUK] stopped
Jul 20 14:53:46 scratchpad elasticsearch: [2018-07-20T14:53:46,414][INFO ][o.e.n.Node               ] [1oQJNUK] closing ...
Jul 20 14:53:46 scratchpad elasticsearch: [2018-07-20T14:53:46,445][INFO ][o.e.n.Node               ] [1oQJNUK] closed
Jul 20 14:53:46 scratchpad systemd: platform-elasticsearch.service: main process exited, code=exited, status=78/n/a

具体问题如下:

Jul 20 14:53:46 scratchpad elasticsearch: [1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

我已经能够在命令行上使用以下命令启动弹性搜索:

sudo su -c 'echo 262144 > "/proc/sys/vm/max_map_count"' && \ 
export JAVA_HOME=/platform/opt/jdk1.8.0_181 && \
export ES_PATH_CONF=/platform/opt/elasticsearch-6.3.1/config && \
/platform/opt/elasticsearch-6.3.1/bin/elasticsearch 

谁能告诉我为什么LimitMEMLOCK=100000不工作,以及我如何有效地设置max_map_count从systemd。

我还尝试设置了以下内容:

cat /etc/security/limits.d/30_elastic_limits.conf

vagrant       hard    nofile     500000
vagrant       hard    memlock     262144

但systemd似乎完全忽略了这一点。


当前回答

我在单节点弹性搜索集群中遇到了同样的问题。作为perelastic-search文档,对于运行单个节点,您必须使用“发现”。在docker run命令中输入Type =single-node。

docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.13.3

在docker-compose。Yml,您可以具体如下:

version: '3.1'
services:
 elastic_search:
  image: docker.elastic.co/elasticsearch/elasticsearch:7.13.3
  container_name: es01
  environment:
   - discovery.type=single-node
   - node.name=es01
   - bootstrap.memory_lock=true
   - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
  ports:
   - 9200:9200
  networks:
   - elastic
networks:
 elastic:

其他回答

对于MS Windows用户,使用wsl子系统

打开powershell,运行

wsl -d docker-desktop

then

sysctl -w vm.max_map_count=262144

如果您使用的是yml文件

apiVersion: elasticsearch.k8s.elastic.co/v1
kind: Elasticsearch
metadata:
  name: prod
spec:
  version: 8.6.0
  nodeSets:
    - name: master-nodes
      count: 3
      config:
        node.roles: ["master"]
      podTemplate:
        spec:
          initContainers:
            - name: sysctl
              securityContext:
                privileged: true
                runAsUser: 0
              command: ["sh", "-c", "sysctl -w vm.max_map_count=262144"]
      volumeClaimTemplates:
        - metadata:
            name: elasticsearch-data
          spec:
            accessModes:
              - ReadWriteOnce
            resources:
              requests:
                storage: 10Gi
            storageClassName: standard
    - name: data-nodes
      count: 10
      config:
        node.roles: ["data"]
      podTemplate:
        spec:
          initContainers:
            - name: sysctl
              securityContext:
                privileged: true
                runAsUser: 0
              command: ["sh", "-c", "sysctl -w vm.max_map_count=262144"]
      volumeClaimTemplates:
        - metadata:
            name: elasticsearch-data
          spec:
            accessModes:
              - ReadWriteOnce
            resources:
              requests:
                storage: 100Gi
            storageClassName: standard

你也可以设置node.store。allow_mmap:假的。

但是,如本文所述,此设置对生产工作负载有内存影响。它帮助我在minikube kubernetes集群中使用elastic操作符部署Elasticsearch 8.4.0。

vm.max_map_count = 262144

将这一行添加到下面的路径中

我知道 /etc/sysctl.conf

或者访问这个链接https://www.elastic.co/guide/en/elasticsearch/reference/current/vm-max-map-count.html

sysctl -w vm. sh执行以下命令。max_map_count=262144,增加Elasticsearch使用的默认虚拟内存。

注意:当您运行上述命令时,您的问题将得到解决,但这将是一个临时解决方案,因为节点/系统/容器重新启动,您的更改将继续执行。所以如果你想永久地设置这个,你需要编辑/etc/sysctl.conf并设置vm。Max_map_count到262144。

更多详情请点击这里。