Search code examples
cassandraloopbackccm

ccm start Address already in use; a cluster may already be running or you may need to add the loopback alias


I'm struggling starting Cassandra cluster with 'ccm start' command.

I created a cluster named Gdelt, with 3 nodes, as follow: ccm status gives:

Cluster: 'Gdelt' 
-------------------
node1: DOWN (Not initialized)
node3: DOWN (Not initialized)
node2: DOWN (Not initialized)
node4: DOWN (Not initialized)

but ccm start raises the following error:

Traceback (most recent call last):
  File "/usr/local/bin/ccm", line 112, in <module>
    cmd.run()
  File "/usr/local/lib/python2.7/dist-packages/ccmlib/cmds/cluster_cmds.py", line 510, in run
    allow_root=self.options.allow_root) is None:
  File "/usr/local/lib/python2.7/dist-packages/ccmlib/cluster.py", line 390, in start
    common.assert_socket_available(itf)
  File "/usr/local/lib/python2.7/dist-packages/ccmlib/common.py", line 521, in assert_socket_available
    raise UnavailableSocketError("Inet address %s:%s is not available: %s; a cluster may already be running or you may need to add the loopback alias" % (addr, port, msg))
ccmlib.common.UnavailableSocketError: Inet address 127.0.0.1:9042 is not available: [Errno 98] Address already in use; a cluster may already be running or you may need to add the loopback alias
Traceback (most recent call last):
  File "/usr/local/bin/ccm", line 112, in <module>
    cmd.run()
  File "/usr/local/lib/python2.7/dist-packages/ccmlib/cmds/cluster_cmds.py", line 510, in run
    allow_root=self.options.allow_root) is None:
  File "/usr/local/lib/python2.7/dist-packages/ccmlib/cluster.py", line 390, in start
    common.assert_socket_available(itf)
  File "/usr/local/lib/python2.7/dist-packages/ccmlib/common.py", line 521, in assert_socket_available
    raise UnavailableSocketError("Inet address %s:%s is not available: %s; a cluster may already be running or you may need to add the loopback alias" % (addr, port, msg))
ccmlib.common.UnavailableSocketError: Inet address 127.0.0.1:9042 is not available: [Errno 98] Address already in use; a cluster may already be running or you may need to add the loopback alias

I've tried creating loopback aliases, with bash script as following, and executing it:

#!/bin/bash

sudo ifconfig lo0 alias 127.0.0.2 up
sudo ifconfig lo0 alias 127.0.0.3 up
sudo ifconfig lo0 alias 127.0.0.4 up
sudo ifconfig lo0 alias 127.0.0.5 up
sudo ifconfig lo0 alias 127.0.0.6 up

which raises the following error upon bash script execution:

alias: Host name lookup failure
ifconfig: `--help' gives usage information.

I've tried the ifconfig directly in the command line as following:

sudo ifconfig lo:0 127.0.0.1 up

which gives the following error:

SIOCSIFADDR: File exists
SIOCSIFFLAGS: Cannot assign requested address
SIOCSIFFLAGS: Cannot assign requested address

Is this clear, tell me please if not, so that I clarify more

I don't know finally how to run my cluster in Cassandra. Thank you very much for your help. Habib


Solution

  • So Cassandra users port 9042 by default. However, as your output shows, something appears to be using that port already when you try to start you node. That is evident from the following message:

    Inet address 127.0.0.1:9042 is not available: [Errno 98] Address already in use
    

    In this scenario you have a couple of options:

    1. Find the process using port 9042 and kill it (assuming it's something unimportant)
    2. Use a different port to start the node

    For (1), you can use:

    netstat -nap | grep 9042 | grep LISTEN
    

    You may need to be the "root" user to find the process as netstat will only display things that your current user "owns". If you're root, you'll see all processes.

    For (2), you can simply change the port in the cassandra.yaml file (native_transport_port). You should also change the "listen_address" parameter and the "native_transport_broadcast_address" to your host IP address so you're not using the loopback address (You can use "hostname -i" to find your IP address of your local host) - and set your "native_transport_address" to "0.0.0.0" if you want it to listen on all interfaces. That's what we do. Hopefully that will get you node up and running.