Cassandra tmpdir change location

Cassandra is failing to start if /tmp is set as noexec, which is pretty much default these days:

java.lang.NoClassDefFoundError: Could not initialize class com.sun.jna.Native
        at org.apache.cassandra.utils.memory.MemoryUtil.allocate( ~[apache-cassandra-2.2.2.jar:2.2.2]
        at<init>( ~[apache-cassandra-2.2.2.jar:2.2.2]
        at ~[apache-cassandra-2.2.2.jar:2.2.2]
        at$IndexSummarySerializer.deserialize( ~[apache-cassandra-2.2.2.jar:2.2.2]
        at ~[apache-cassandra-2.2.2.jar:2.2.2]
        at ~[apache-cassandra-2.2.2.jar:2.2.2]
        at ~[apache-cassandra-2.2.2.jar:2.2.2]
        at ~[apache-cassandra-2.2.2.jar:2.2.2]
        at ~[apache-cassandra-2.2.2.jar:2.2.2]
        at$ ~[apache-cassandra-2.2.2.jar:2.2.2]
        at java.util.concurrent.Executors$ ~[na:1.8.0_102]
        at ~[na:1.8.0_102]
        at java.util.concurrent.ThreadPoolExecutor.runWorker( ~[na:1.8.0_102]
        at java.util.concurrent.ThreadPoolExecutor$ [na:1.8.0_102]
        at [na:1.8.0_102]

If I remove the noexec flag from the /var/tmp mount Cassandra starts up properly. I’ve tried a number of methods to change the location of the tmpdir in the file:

JVM_OPTS="$JVM_OPTS -Djna.tmpdir=/home/cassandra/tmp"
JVM_OPTS="$JVM_OPTS -Dorg.xerial.snappy.tempdir=/home/cassandra/tmp"

I haven’t used these all at once, of course, these are solutions I’ve found on the internet, but none seem to work. I even tried exporting TMPDIR at the start of the file, but to no avail. It always fails with the same message.

I think it’s a bad idea to leave /tmp without the noexec flag, security-wise. I’m obviously missing something basic here. How do I set the tmpdir to be /home/cassandra/tmp or something similar?


Leave a Reply