Discover Centmin Mod today
Register Now

Memcached Memcached Socket on Centmin Mod

Discussion in 'Other Centmin Mod Installed software' started by BamaStangGuy, Feb 8, 2017.

  1. BamaStangGuy

    BamaStangGuy Active Member

    470
    137
    43
    May 25, 2014
    Ratings:
    +180
    Local Time:
    12:00 AM
    Has anyone gotten Memcached to work with a socket rather than via tcp? I have not been able to get XenForo to connect to memcached via socket.
     
  2. eva2000

    eva2000 Administrator Staff Member

    30,168
    6,784
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    3:00 PM
    Nginx 1.13.x
    MariaDB 5.5
  3. BamaStangGuy

    BamaStangGuy Active Member

    470
    137
    43
    May 25, 2014
    Ratings:
    +180
    Local Time:
    12:00 AM
    Nope. I will get you exact config I am using here in a few.
     
  4. BamaStangGuy

    BamaStangGuy Active Member

    470
    137
    43
    May 25, 2014
    Ratings:
    +180
    Local Time:
    12:00 AM
    PHP:
    $config['cache']['enabled'] = true;
    $config['cache']['frontend'] = 'Core';
    $config['cache']['frontendOptions']['cache_id_prefix'] = 'cf_';
    $config['cache']['cacheSessions'] = true;

    $config['cache']['backend'] = 'Libmemcached';
    $config['cache']['backendOptions'] = array(
            
    'compression' => false,
            
    'servers' => array(
                    array(
                              
    // your memcached server IP /address
                            
    'host' => '/var/run/memcached/memcached1.sock',
                            
                               
    // memcached port
                            
    'port' => 0,
                    )
            )
    );
     
  5. Matt

    Matt Moderator Staff Member

    691
    319
    63
    May 25, 2014
    Sheffield, UK
    Ratings:
    +444
    Local Time:
    6:00 AM
    1.7.1
    MariaDB 10
    Your host value is incorrect. You are missing the unix:// part.

    PHP:
    'host' => 'unix:///var/run/memcached/memcached1.sock',
     
  6. eva2000

    eva2000 Administrator Staff Member

    30,168
    6,784
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    3:00 PM
    Nginx 1.13.x
    MariaDB 5.5
    @Matt actually unix:// only needed for memcache, libmemcached/memcached uses without unix:// from my experience unless different for zend framework /xenforo ?

    @BamaStangGuy Did you switch Centmin Mod memcached over to using unix sockets via /etc/init.d/memcached variable SOCKET_ENABLE=y ?

    default is TCP on port 11211 with SOCKET_ENABLE=n
    Code (Text):
    /usr/local/bin/memcached -d -m 8 -l 127.0.0.1 -p 11211 -c 2048 -b 2048 -R 200 -t 4 -n 72 -f 1.25 -u nobody -o modern -P /var/run/memcached/memcached1.pid
    

    with SOCKET_ENABLE=y uses Unix socket
    Code (Text):
    usr/local/bin/memcached -d -m 8 -s /var/run/memcached/memcached1.sock -a 0755 -c 2048 -b 2048 -R 200 -t 4 -n 72 -f 1.25 -u nobody -o modern -P /var/run/memcached/memcached1.pid
    


    Bug fix update



    Seems I found some bugs in memcached server config for Unix sockets due to permissions of Unix socket which I have now fixed and update 123.09beta01 https://community.centminmod.com/th...ort-for-php-in-123-09beta01.10377/#post-44505. To apply fix:
    1. update centmin mod 123.09beta01 via centmin.sh menu option 23 submenu option 2
    2. then exit centmin.sh via menu option 24, change into directory /usr/local/src/centminmod again
      Code (Text):
      cd /usr/local/src/centminmod
    3. re-run centmin.sh to apply the automatic fix which will create a memcached user/group and change /etc/init.d/memcached reference from USER=nobody to USER=memcached and setup proper unix file permissions for memcached user including adding memcached user to nginx group
    4. then set SOCKET_ENABLE=y in /etc/init.d/memcached to enable unix socket and restart memcached server
    5. then edit your memcached.php file at /usr/local/nginx/html/memcache_XXXX.php where XXXX is randomly generated alphanumeric set of characters and change
      Code (Text):
      $MEMCACHE_SERVERS[] = 'localhost:11211'; //
      to
      Code (Text):
      $MEMCACHE_SERVERS[] = 'unix:///var/run/memcached/memcached1.sock';
    6. restart nginx + php-fpm services too
      Code (Text):
      nprestart


    for memcache.php need to use unix:// prefix only

    upload_2017-2-8_12-21-6.png

    Note this may break default ngx_pagespeed's memcached usage as it's looking for memcached TCP connection on port 11211 if you switch to memcached Unix sockets
     
    Last edited: Feb 8, 2017
  7. Matt

    Matt Moderator Staff Member

    691
    319
    63
    May 25, 2014
    Sheffield, UK
    Ratings:
    +444
    Local Time:
    6:00 AM
    1.7.1
    MariaDB 10
    I had to use it for Redis as well
    PHP:
    $config['cache']['backendOptions'] = array(
    'server' => 'unix:///tmp/redis.sock',
    'port' => '6379',
    'connect_retries' => 2,
    'use_lua' => true,
    );
     
  8. eva2000

    eva2000 Administrator Staff Member

    30,168
    6,784
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    3:00 PM
    Nginx 1.13.x
    MariaDB 5.5
  9. eva2000

    eva2000 Administrator Staff Member

    30,168
    6,784
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    3:00 PM
    Nginx 1.13.x
    MariaDB 5.5
    @Matt for libmemcached/memcached unix socket seems to look for path without unix:// PHP: Memcached::addServer - Manual

    while memcache needs unix:// PHP: Memcache::connect - Manual
     
  10. BamaStangGuy

    BamaStangGuy Active Member

    470
    137
    43
    May 25, 2014
    Ratings:
    +180
    Local Time:
    12:00 AM
    Followed those instructions and I get: Cant connect to:unix:///var/run/memcached/memcached1.sock:0 for the memcache_xxxxx file.

    Screen Shot 2017-02-07 at 9.52.50 PM.png

    Neither XF or Railgun will connect via socket either.

    Code:
    #!/bin/sh
    # chkconfig: - 80 12
    # description:  The memcached daemon is a network memory cache service.
    # processname: memcached
    BINNAME=memcached
    BIN=/usr/local/bin/memcached
    USER=memcached
    LOGGING='n'
    LOGFILE="/var/log/memcached.log"
    LOGFILEB="/var/log/memcached2.log"
    CON=2048
    BACKLOG=2048
    MAXREQ=200
    THREADS=4
    MINSP=72
    CHUNKF=1.25
    PORT1=11211
    PORT2=11212
    SOCKET_ENABLE=y
    SOCKETA='-s /var/run/memcached/memcached1.sock -a 0755'
    SOCKETB='-s /var/run/memcached/memcached2.sock -a 0755'
    MEMSIZE=2048
    SERVERCOUNT=1
    SERVERIP='127.0.0.1'
    OPTIONS='-o slab_reassign,slab_automove'
    PIDA='/var/run/memcached/memcached1.pid'
    PIDB='/var/run/memcached/memcached2.pid'
    Code:
    $config['cache']['enabled'] = true;
    $config['cache']['frontend'] = 'Core';
    $config['cache']['frontendOptions']['cache_id_prefix'] = 'cf_';
    $config['cache']['cacheSessions'] = true;
    
    $config['cache']['backend'] = 'Libmemcached';
    $config['cache']['backendOptions'] = array(
            'compression' => false,
            'servers' => array(
                    array(
                              // your memcached server IP /address
                            'host' => '/var/run/memcached/memcached1.sock',
                          
                               // memcached port
                            'port' => 0,
                    )
            )
    );
     
  11. eva2000

    eva2000 Administrator Staff Member

    30,168
    6,784
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    3:00 PM
    Nginx 1.13.x
    MariaDB 5.5
    restart nginx + php-fpm services too
    Code (Text):
    nprestart
     
  12. BamaStangGuy

    BamaStangGuy Active Member

    470
    137
    43
    May 25, 2014
    Ratings:
    +180
    Local Time:
    12:00 AM
    I did as well.
     
  13. BamaStangGuy

    BamaStangGuy Active Member

    470
    137
    43
    May 25, 2014
    Ratings:
    +180
    Local Time:
    12:00 AM
    Memcached is showing as running via the socket and the log file shows the following:

    Code:
    slab class   1: chunk size     120 perslab    8738
    slab class   2: chunk size     152 perslab    6898
    slab class   3: chunk size     192 perslab    5461
    slab class   4: chunk size     240 perslab    4369
    slab class   5: chunk size     304 perslab    3449
    slab class   6: chunk size     384 perslab    2730
    slab class   7: chunk size     480 perslab    2184
    slab class   8: chunk size     600 perslab    1747
    slab class   9: chunk size     752 perslab    1394
    slab class  10: chunk size     944 perslab    1110
    slab class  11: chunk size    1184 perslab     885
    slab class  12: chunk size    1480 perslab     708
    slab class  13: chunk size    1856 perslab     564
    slab class  14: chunk size    2320 perslab     451
    slab class  15: chunk size    2904 perslab     361
    slab class  16: chunk size    3632 perslab     288
    slab class  17: chunk size    4544 perslab     230
    slab class  18: chunk size    5680 perslab     184
    slab class  19: chunk size    7104 perslab     147
    slab class  20: chunk size    8880 perslab     118
    slab class  21: chunk size     11104 perslab      94
    slab class  22: chunk size     13880 perslab      75
    slab class  23: chunk size     17352 perslab      60
    slab class  24: chunk size     21696 perslab      48
    slab class  25: chunk size     27120 perslab      38
    slab class  26: chunk size     33904 perslab      30
    slab class  27: chunk size     42384 perslab      24
    slab class  28: chunk size     52984 perslab      19
    slab class  29: chunk size     66232 perslab      15
    slab class  30: chunk size     82792 perslab      12
    slab class  31: chunk size    103496 perslab      10
    slab class  32: chunk size    129376 perslab       8
    slab class  33: chunk size    161720 perslab       6
    slab class  34: chunk size    202152 perslab       5
    slab class  35: chunk size    252696 perslab       4
    slab class  36: chunk size    315872 perslab       3
    slab class  37: chunk size    394840 perslab       2
    slab class  38: chunk size    524288 perslab       2
    <26 server listening (auto-negotiate)
     
  14. eva2000

    eva2000 Administrator Staff Member

    30,168
    6,784
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    3:00 PM
    Nginx 1.13.x
    MariaDB 5.5
    the init.d/memcached file you posted is pre-patch updated one so you didn't apply the patch properly probably due to not exiting centmin.sh for re-run ?

    do
    Code (Text):
    cd /usr/local/src/centminmod
    ./centmin.sh
    

    exit centmin.sh then restart memcached service
     
  15. BamaStangGuy

    BamaStangGuy Active Member

    470
    137
    43
    May 25, 2014
    Ratings:
    +180
    Local Time:
    12:00 AM
    Something didn't get updated right then because when I did it the first time I saw this:

    Code:
    [21:35][root@christianforums.whippmedia.com centminmod]# ./centmin.sh
    
    Update memcached server setup
    Adding memcached user/group and adding to nginx group
    uid=1001(memcached) gid=1001(memcached) groups=1001(memcached),1000(nginx)
    Changing memcached server user from nobody to memcached
    USER=memcached
    /usr/local/src/centminmod/config/memcached/memcached-socketfix.patch
    /etc/init.d /usr/local/src/centminmod
    /usr/local/src/centminmod
    --------------------------------------------------------
         Centmin Mod Menu 123.09beta01 centminmod.com   
     
  16. BamaStangGuy

    BamaStangGuy Active Member

    470
    137
    43
    May 25, 2014
    Ratings:
    +180
    Local Time:
    12:00 AM
    Rerunning it doesn't do anything.
     
  17. eva2000

    eva2000 Administrator Staff Member

    30,168
    6,784
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    3:00 PM
    Nginx 1.13.x
    MariaDB 5.5
    strange then just tested both fresh 123.09beta01 install and updated 123.09beta01 and memcached with unix socket is working for memcache.php file at least
     
  18. BamaStangGuy

    BamaStangGuy Active Member

    470
    137
    43
    May 25, 2014
    Ratings:
    +180
    Local Time:
    12:00 AM
    I copied the new memcached from /usr/local/src/centminmod/config and still can not get anything to connect via socket. With or without the unix://
     
  19. eva2000

    eva2000 Administrator Staff Member

    30,168
    6,784
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    3:00 PM
    Nginx 1.13.x
    MariaDB 5.5
  20. eva2000

    eva2000 Administrator Staff Member

    30,168
    6,784
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    3:00 PM
    Nginx 1.13.x
    MariaDB 5.5
    did you set SOCKET_ENABLE=y in /etc/init.d/memcached it's not set by default

    restart memcached, nginx and php-fpm services as well