Riak - Connection Refused while trying to connect to Riak cluster using Python client library

1.7k views Asked by At

I am a Riak newbie. I installed Riak 2.1.1 from the source on my local machine while following instructions at: https://docs.basho.com/riak/latest/ops/building/installing/mac-osx/

I then started three nodes and pinged all the three nodes and received 'pong' as the response.

I joined then joined the three nodes to create a cluster. Checking the cluster member status:

dev1/bin/riak-admin member-status
================================= Membership ==================================
Status     Ring    Pending    Node
-------------------------------------------------------------------------------
valid      34.4%      --      '[email protected]'
valid      32.8%      --      '[email protected]'
valid      32.8%      --      '[email protected]'
-------------------------------------------------------------------------------
Valid:3 / Leaving:0 / Exiting:0 / Joining:0 / Down:0

I looked at the riak.config file in rel/riak/etc/ directory and saw that the following has been set:

## listener.http.<name> is an IP address and TCP port that the Riak
## HTTP interface will bind.
## 
## Default: 127.0.0.1:8098
## 
## Acceptable values:
##   - an IP/port pair, e.g. 127.0.0.1:10011
listener.http.internal = 127.0.0.1:8098

## listener.protobuf.<name> is an IP address and TCP port that the Riak
## Protocol Buffers interface will bind.
## 
## Default: 127.0.0.1:8087
## 
## Acceptable values:
##   - an IP/port pair, e.g. 127.0.0.1:10011
listener.protobuf.internal = 127.0.0.1:8087

I then installed the Riak python client using pip. I am following the Riak python client docs at http://riak-python-client.readthedocs.org/en/2.1.0/client.html.

The following is my Python script:

import riak

client = riak.RiakClient(pb_port=8087,protocol='pbc')

print 'finished'

user_bucket = client.bucket('user')

val1 = 1
key1 = user_bucket.new('one', data=val1)
key1.store()

print 'finished2'

However, running the python script gives the following error:

/Library/Python/2.7/site-packages/riak/security.py:35: UserWarning: Found OpenSSL 0.9.8zd 8 Jan 2015 version, but expected at least OpenSSL 1.0.1g.  Security may not support TLS 1.2.
  warnings.warn(msg, UserWarning)
finished
Traceback (most recent call last):
  File "/Users/me/Documents/project/RiakDataLoader/src/DataLoader.py", line 11, in <module>
    **key1.store()**
  File "/Library/Python/2.7/site-packages/riak/riak_object.py", line 286, in store
    timeout=timeout)
  File "/Library/Python/2.7/site-packages/riak/client/transport.py", line 196, in wrapper
    return self._with_retries(pool, thunk)
  File "/Library/Python/2.7/site-packages/riak/client/transport.py", line 151, in _with_retries
    raise e.args[0]
socket.error: [Errno 61] Connection refused

All my nodes were running before I ran the python script.

I then tried the following command on the terminal using the http port:

$ curl -XPUT http://127.0.0.1:8098/buckets/welcome/keys/german  -H 'Content-Type: text/plain'  -d 'herzlich willkommen'
curl: (7) Failed to connect to 127.0.0.1 port 8098: Connection refused

What may be the cause of this connection refused error? Have been chasing this problem for hours. Any help would be greatly appreciated!

2

There are 2 answers

0
Joe On BEST ANSWER

Since you are using several dev nodes the config files will be under the dev directory, such as dev/dev1/etc/riak.conf. You'll need to check there to see which ports are being used for the protocol buffers listener for each node.. The configuration under the rel directory is only suitable for running a single node on the machine.

0
minocha On

Hi I faced a similar issue but couldn't find a solution which was straight forward.

When you do a riak stop without leaving the cluster there are files which are present in the ring directory which need to be deleted since the riak start/sudo service riak start command triggers read from the ring information.

The default location of the riak ring directory is /var/lib/riak/ring/ delete the files here and do a riak start.

Note if the node in question is a master node for the cluster you will have to -

  1. Do all of the above for the master node ( stop clean ring ) and -
  2. Remove the nodes from the cluster using the riak-admin cluster leave
  3. Stop the riak nodes using riak stop
  4. delete the ring directory as mentioned above
  5. do a riak start
  6. follow rules to set up the cluster again using riak-admin

These would be viable in non-production situations.