Views: 17865
Last Modified: 04.09.2024

Attention!
  1. For operations, described in this chapter, knowledge of *nix-systems administration is required. Prior to start of these operations, it is recommended to perform full backup of Bitrix Virtual Appliance.
  2. Provided settings are listed outside the scope of the Virtual Appliance menu. This means that the details below are provided for informational purposes only and should be used with clear understanding of your actions and under your own liability. Bitrix24 technical support reviews the questions related to Virtual Appliance menu items only.

Attention!

Incorrectly configured Memcached (available for third-parties) can be used for for malicious purposes for site hacking. Check the option -l <ip> in its settings. Querying Memcached must be permitted only from your site.

  Memcached settings

If memcached is planned to be used in the project, it is necessary to configure it in accordance with anticipated load.

For this, it is required:

  1. To specify the following parameters in the /etc/sysconfig/memcached file:
    • MAXCONN = "1024" - quantity of simultaneous connections (1024 by default);
    • CACHESIZE="1024" - volume of memory, allocated for cache (64MB by default);
    • OPTIONS="t 8" - quantity of memcached flows (4 by default).

    Note: MAXCONN, CACHESIZE and OPTIONS parameters are selected experimentally depending on the type of load and on the available resources.

    The volume of memory required for caching (parameter CACHESIZE) can be evaluated according to the size of your file cache. If file cache occupies 3GB in your project, then the use of memcached with 256MB memory will not be effective due to frequent preemption.

  2. After configuring is competed, it is necessary to restart memchached via the command:

    CentOS 7:

    systemctl restart memcached.service
    
  3. Next, connect it into /bitrix/php_interface/dbconn.php:

    define("BX_CACHE_TYPE", "memcache");
    define("BX_CACHE_SID", $_SERVER["DOCUMENT_ROOT"]."#01");
    define("BX_MEMCACHE_HOST", "127.0.0.1");
    define("BX_MEMCACHE_PORT", "11211");
    

    and in the file /bitrix/.settings_extra.php (create it, if unavailable):

    <?php
    return array(
      'cache' => array(
        'value' => array(
          'type' => 'memcache',
          'memcache' => array(
            'host' => '127.0.0.1',
            'port' => '11211',
          ),
          'sid' => $_SERVER["DOCUMENT_ROOT"]."#01"
        ),
      ),
    );
    ?>
    

  Handling memcached via socket

If one more server is used, you can configure the operation with memcached via socket to improve the productivity:

  1. Set parameters in the file /etc/sysconfig/memcached:

    • USER="bitrix" - user from which memcached will be launched;
    • OPTIONS="-t 8 -s /tmp/memcached.sock" - quantity of flows and path to socket.

  2. Restart memcached via command:

    CentOS 7:

    systemctl restart memcached.service
    
  3. After that, it is necessary to modify settings in /bitrix/php_interface/dbconn.php:

    define("BX_CACHE_TYPE", "memcache");
    define("BX_CACHE_SID", $_SERVER["DOCUMENT_ROOT"]."#01");
    define("BX_MEMCACHE_HOST", "unix:///tmp/memcached.sock");
    define("BX_MEMCACHE_PORT", "0");
    

    and in the file /bitrix/.settings_extra.php (create it, if unavailable):

    <?php
    return array(
      'cache' => array(
        'value' => array(
          'type' => 'memcache',
          'memcache' => array(
            'host' => 'unix:///tmp/memcached.sock',
            'port' => '0',
          ),
          'sid' => $_SERVER["DOCUMENT_ROOT"]."#01"
        ),
      ),
    );
    ?>
    

Note: When using multiple sites, the example must contain static sid Site ID, an ID field in settings site config parameters , without $_SERVER["DOCUMENT_ROOT"]. Otherwise, cache will be different for two sites, because site folders are different.





Courses developed by Bitrix24