memcachedpython-memcached

python-memcache memcached -- I installed on centos virtualbox but it get/set never seem to work


I'm using python. I did a yum install memcached followed by a easy_install python-memcached

I used the simple test program from the Help(memcache). When I wasn't getting the proper answers I threw in some print statements:

[~/test]$  cat m2.py
import memcache
mc = memcache.Client(['127.0.0.1:11211'], debug=0)

x = mc.set("some_key", "Some value")
print 'Just set a key and value into the cache (suposedly)'

value = mc.get("some_key")
print 'Just retrieved that value from the cache using the key'

print 'X %s' % x

print 'Value %s' % value    

[~/test]$  python m2.py
Just set a key and value into the cache (suposedly)
Just retrieved that value from the cache using the key
X 0
Value None
[~/test]$ 

The question now is, what have I failed to do in my installation? It appears to be working from an API perspective but it fails to put anything into the memcache share area. I'm using a virtualbox vm running centos [~]# cat /proc/version Linux version 2.6.32-358.6.2.el6.i686 (mockbuild@c6b8.bsys.dev.centos.org) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC) ) #1 SMP Thu May 16 18:12:13 UTC 2013

Is there a daemon that is supposed to be running? I don't see an obvious named one when I do a ps.

I tried to get pylibmc installed on my vm but was unable to find a working installation so for now will see if I can get the above stuff working first.

I discovered if i ran straight from the python console GUI i get a bit more output if I set debug=1

>>> mc = memcache.Client(['127.0.0.1:11211'], debug=1)
>>> mc.stats
{}
>>> mc.set('test','value')
MemCached: MemCache: inet:127.0.0.1:11211: connect: Connection     refused.  Marking dead.
0
>>> mc.get('test')
MemCached: MemCache: inet:127.0.0.1:11211: connect: Connection refused.  Marking dead.

When I try to use per the example telnet to connect to the port i get a connection refused:

[root@~]# telnet 127.0.0.1 11211
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
[root@~]# 

I tried the instructions I found on the net for configuring telnet so localhost wouldn't be disabled: vi /etc/xinetd.d/telnet service telnet { flags = REUSE socket_type = stream wait = no user = root server = /usr/sbin/in.telnetd log_on_failure += USERID disable = no }

And then ran the commands to restart the service(s):

service iptables stop
service xinetd stop
service iptables start
service xinetd start
service iptables stop

I ran with both cases (iptables started and stopped) but it has no effect. So I am out of ideas. What do I need to do to make it so the PORT will be allowed? if that is the problem? Or is there a memcached service that needs to be running that needs to open up the port ?


Solution

  • well this is what it took to get it working: ( a series of manual steps )

    1) su -
       cd /var/run
       mkdir memcached # this was missing
    

    In the memcached file I added "-l 127.0.0.1" to the OPTIONS statement. It's apparently a listen option. Do this for steps 2 & 3. I'm not certain which file is actually used at runtime.

    2) cd /etc/sysconfig
       cp memcached memcached.old
       vi memcached
    
    3) cd /etc/init.d
       cp memcached memcached.old
       vi memcached
    

    4) Try some commands to see if the server starts now

    /etc/init.d/memcached start
    /etc/init.d/memcached status
    /etc/init.d/memcached stop
    /etc/init.d/memcached restart
    

    I tried opening a browser, but it never seemed to actually display anything so I don't really know how valid this approach is. I'm not running apache or anything like this so perhaps its not relevant to my cause. Perhaps I would have to supply a ?key=blah or something.

    5)  http://127.0.0.1:11211
    

    6) Now it should be ready to go. If one runs the test shown with the following it should work. At least it did for me. doing the help(memcache) will display a simple program. just paste that in and it should work just fine.

    [~]$ python
    >>> import memcache
    >>> help(memcache)