'Unable to connect to any servers'..."Tried connecting to ... Last error: Connection refused")})

I have been getting this error since the installation of Cassandra.

[cassandra@orcl1 bin]$ ./cqlsh 192.168.1.12 9042
Connection error: ('Unable to connect to any servers', {'192.168.1.12': error(111, "Tried connecting to [('192.168.1.12', 9042)]. Last error: Connection refused")})

I came to know the issue is caused by Python 2.7.12, which I've installed. Any Python version later than 2.7.10 was giving this issue. The only resolution so far is to install Python 2.7.9 and use it.

The below section shows how we can install Python 2.7.9

Python does not office binaries to be installed. The downloaded files are sources that can be configured (ie. it needs compilation), hence, depends on the packages on the system.

Step 1

Download

Step 2

Extract the tarball

tar xvf Python.2.7.9
Step 3

Edit Modues/Setup.dist. Uncomment the lines highlighted.

[root@orcl1 Modules]# cat -n Setup.dist | grep -i zlib
464 # Andrew Kuchling's zlib module.
465 # This require zlib 1.1.3 (or later).
466 # See http://www.gzip.org/zlib/
467 zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz

216 # Socket module helper for SSL support; you must comment out the other
217 # socket line above, and possibly edit the SSL variable:
218 SSL=/usr/local/ssl
219 _ssl _ssl.c \
220             -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
221             -L$(SSL)/lib -lssl -lcrypto
222
Step 4

Install zlib-devel package

[root@orcl1 Packages]# rpm -ivh zlib-devel-1.2.3-29.el6.x86_64.rpm
warning: zlib-devel-1.2.3-29.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing... ########################################### [100%]
1:zlib-devel ########################################### [100%]

If zlib-devel package is not installed, you will get below error message

Module load path: ['/home/cassandra/apache-cassandra-3.7/bin/../lib/six-1.7.3-py2.py3-none-any.zip', '/home/cassandra/apache-cassandra-3.7/bin/../lib/futures- 2.1.6-py2.py3-none-any.zip', '/home/cassandra/apache-cassandra-3.7/bin/../lib/cassandra-driver-internal-only-3.0.0-6af642d.zip/cassandra-driver-3.0.0-6af642d', '/home/cassandra/apache-cassandra-3.7/bin', '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7', '/usr/local/lib/python2.7/plat-linux2', '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old', '/usr/local/lib/python2.7/lib-dynload', '/home/cassandra/.local/lib/python2.7/site- packages', '/usr/local/lib/python2.7/site-packages']
Error: can't decompress data; zlib not available
Step 5

Run ./configure

cd Python.2.7.9
./configure --prefix=/usr/local --enable-shared
Step 6

Execute make

make
Step 7

Execute make install

make install
Step 8

Set the LD_LIBRARY_PATH

export LD_LIBRARY_PATH=/usr/local/lib
Comments