Unable to pass "ES_JAVA_OPTS=-Xms1g -Xmx1g" into Elasticsearch container

1,772 views
Skip to first unread message

Michael Leow

unread,
Jul 20, 2017, 10:00:29 PM7/20/17
to Nomad
Hello folks,

Need some guidance for the below:


The Docker compose doc for Elasticsearch suggests passing environment variable as per below:
```
  elasticsearch2:
    environment:
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - "discovery.zen.ping.unicast.hosts=elasticsearch1"

```

How to do the equivalent for - "ES_JAVA_OPTS=-Xms512m -Xmx512m" in Nomad as there is a key but no value?

I have tried (to no avail):
a) ES_JAVA_OPTS="-Xms512m -Xmx512m"
b) "ES_JAVA_OPTS=-Xms1g -Xmx1g" but it gets --> Error getting job struct: Error parsing job file from search.nomad: error parsing: key '"ES_JAVA_OPTS=-Xms1g -Xmx1g"' expected start of object ('{') or assignment ('=')

Any clue?  Thanks!

Regards,
Michael Leow

François Prud'homme

unread,
Jul 21, 2017, 4:32:13 AM7/21/17
to Nomad
Hello,

In my case i add an env part :
      env {
        ES_JAVA_OPTS
= "-Xms8g -Xmx8g"
     
}


For all other options, i'm using template :
      template {
        data
= <<EOH
cluster
.name: "escluster"
network
.host: {{ env "attr.unique.network.ip-address" }}
discovery
.zen.minimum_master_nodes: 2
network
.publish_host: {{ env "attr.unique.network.ip-address" }}
{{ if service "escluster-transport"}}discovery.zen.ping.unicast.hosts:{{ range service "escluster-transport" }}
 
- {{ .Address }}:{{ .Port }}{{ end }}{{ end }}
http
.port: {{ env "NOMAD_HOST_PORT_http" }}
http
.publish_port: {{ env "NOMAD_HOST_PORT_http" }}
transport
.tcp.port: {{ env "NOMAD_HOST_PORT_transport" }}
transport
.publish_port: {{ env "NOMAD_HOST_PORT_transport" }}

action
.auto_create_index: filebeat*

readonlyrest
:
  enable
: false
EOH
        destination
= "local/elasticsearch.yml"
        change_mode
= "noop"
     
}


And i mount docker this file as a docker volume :
        volumes = [
         
"local/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml",
       
]


Work pretty well... only need to build a new image with :
FROM docker.elastic.co/elasticsearch/elasticsearch:5.4.0
RUN elasticsearch
-plugin remove x-pack

Because i don't need x-pack... and many checks are failing in this configuration (maybe other variables need to be set).

Hope this can help.

Jonathan Ballet

unread,
Jul 21, 2017, 4:32:22 AM7/21/17
to nomad...@googlegroups.com

On Fri, Jul 21, 2017, at 04:00, Michael Leow wrote:
How to do the equivalent for - "ES_JAVA_OPTS=-Xms512m -Xmx512m" in Nomad as there is a key but no value?

I have tried (to no avail):
a) ES_JAVA_OPTS="-Xms512m -Xmx512m"

That should work I guess. Why do you think it doesn't?

The environment in your docker-compose file is a list of strings, and each of the item gets split on the "=" sign (see https://github.com/docker/compose/blob/d527f24ff05e1c62bc635b278f0c0928ce30dc6f/compose/container.py#L140)
You could do something similar in Docker Compose:

elasticsearch2:
  environment:
    ES_JAVA_OPTS: "-Xms512m -Xmx512m"

(that's it, using a map instead of a list).

Michael Leow

unread,
Jul 21, 2017, 3:07:02 PM7/21/17
to Nomad
Thanks for the great tip François; will try it out!

Michael Leow

unread,
Jul 21, 2017, 3:14:29 PM7/21/17
to Nomad
Jonathan,

I hit this problem when the ES container was killed by the dreaded OOM (error code 137)! :P  Which made sense if ES is requesting the default 2g (as seen in the logs) but I limit the resource to 1g and try passing in ES_JAVA_OPTS = "-Xms768m -Xmx768m".  Problem went away once I upped the resource limit >2g

I'll try out the method pointed out by François above; I probably just missed some basic step :)

Jonathan Ballet

unread,
Jul 21, 2017, 6:52:24 PM7/21/17
to nomad...@googlegroups.com
We also had some troubles with Java, memory limits and playing with the Xm* flags... We had to put them much lower than the actual limits of the container. Using `-XX:MaxRAM=` with the limits of the container was much more reliable.

But in the end, although we are not yet running Java 9, we are passing the `-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap` flags, with the last one activated by default with Java 9, which does most of the not so nice job of tuning the JVM memory limits wrt the memory limits.

 Jonathan
--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
IRC: #nomad-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Nomad" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nomad-tool+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages