Tag Archive for: Memcached


Memcached is a memory object caching system specifically designed to enhance the speed of dynamic web applications by reducing the load of the database server. If we explain the usage of Memcached in simple words, it helps you to take the memory from the part of your system where it is unnecessary and assign it to that part of the memory where more memory is needed. In this way, mostly your web servers have not to deal with the cache, most developers dedicated the separate machines to deal with the cache.

In this guide, two different methods of the installation of Memcached have been discussed in detail, along with its basic configuration on Ubuntu.

How to install Memcached on Ubuntu 22.04

There are two different methods for the installation of Memcached on Ubuntu either from its default repository by using the apt package manager or by downloading its tar package from its official website.

Method 1: How to install Memcached on Ubuntu 22.04 from its default repository

The first and simple method to install Memcached on Ubuntu is by installing it from its default repository, for which we will use the apt package manager:

$ sudo apt install memcached libmemcached-tools -y

To confirm the successful execution of the above command, we will find out the installed version details of Memcached by using the command:

Using the systemctl command, we will check the status of memcached:

$ sudo systemctl status memcached

To uninstall the memcached from Ubuntu with all its configuration files, we will use the purge command with apt package manager:

$ sudo apt purge memcached libmemcached-tools -y

Method 2: Installing Memcached on Ubuntu 22.04 by downloading its tar package

Another method to install the the Memcached on Ubuntu is by downloading its zipped package from its official website using the wget command:

$ wget -c https://memcached.org/files/memcached-1.6.15.tar.gz

Unzip the zipped file to access its contents by using the command:

$ tar -zxvf memcached-1.6.15.tar.gz

List down the contents of the directory to confirm the file has been unzipped:

Navigate to the memcached-1.6.15 directory using the cd command:

Now install the libevent-dev package because it is the dependency of memcached:

$ sudo apt install libevent-dev -y

Now we will configure, compile all the files using the make command and then install all the compiled files:

$ ./configure && make && make test && sudo make install

How to configure the Memcached on Ubuntu 22.04

For configuration, we will open its config file using any text editor:

$ sudo nano /etc/memcached.conf

Now change the IP address in the configuration file with your IP address, for example, our IP address is 10.0.2.15:

Stop the Memcached service by using the systemctl command:

$ sudo systemctl stop memcached.service

Now again start the service:

$ sudo systemctl start memcached.service

Also enable the service of the Memcached on your system:

$ sudo systemctl enable memcached.service

And allow the traffic on your IP address at port 11211 using the ufw command:

$ sudo ufw allow from 10.0.2.15 to any port 11211

How Memcached as caching database

There are multiple methods to connect with Memcached.

If your application is PHP based such as WordPress, Joomla, or Drupal and you want to connect Memcached as caching database then install php-memcached through the command:

$ sudo apt install php-memcached

For Python based applications:

$ pip install pymemcache
$ pip install python-memcached

Conclusion

Memcached is an open-source application that is used to run php-based dynamic web applications by reducing the load on their databases so that it can speed the performance of those applications. In this write-up, we have explored two installation methods of Memcached on Ubuntu one by using the default repository and the other by downloading its zipped package from its website.



Source link

Memcached es un almacén de datos de clave-valor en memoria de alto rendimiento, gratuito y de código abierto. Se utiliza principalmente como sistema de almacenamiento en caché para acelerar las aplicaciones al almacenar en caché varios objetos de los resultados de las llamadas a la base de datos.

En este tutorial, explicaremos cómo instalar y configurar Memcached en CentOS 7.
Prerrequisitos

Antes de continuar con este tutorial, asegúrese de iniciar sesión como usuario con privilegios sudo.
Instalando Memcached

Los paquetes de Memcached se incluyen en los repositorios predeterminados de CentOS 7. La instalación es bastante fácil, simplemente escriba el siguiente comando:

yum install memcached libmemcached

El paquete libmemcached contiene proporciona varias herramientas de línea de comandos para administrar el servidor Memcached.

Una vez completada la instalación, inicie y habilite el servicio Memcached

systemctl start memcached y a continuacion systemctl enable memcached para activar el servicio

Eso es todo, en este punto tiene Memcached instalado y ejecutándose en su servidor CentOS 7.

Configurando Memcached

Memcached se puede configurar editando el archivo / etc / sysconfig / memcached. De forma predeterminada, Memcached está configurado para escuchar en todas las interfaces. En las siguientes secciones, le mostraremos cómo configurar el servicio para el acceso local y remoto.

Cuando se configura incorrectamente, se puede usar Memcached para realizar un ataque distribuido de denegación de servicio (DDoS).
Sólo acceso local

Si el cliente que se conecta al servidor también se está ejecutando en el mismo host, se recomienda configurar el servicio Memcached para que solo escuche localhost.

Para hacerlo, abra el archivo de configuración de memcached con su editor de texto:

nano /etc/sysconfig/memcached

En el parámetro OPCIONES agregue -l 127.0.0.1. Esto le indica a Memcached que se enlace solo a la interfaz especificada y no olvides de reiniciar el servicio para aplicar los cambios con el comando systemctl restart memcached

Configurar para acceso remoto

Si la aplicación que se conectará a Memcached está alojada en un servidor remoto, debe configurar su firewall y permitir el acceso al puerto de Memcached 11211 solo desde la dirección IP del cliente.

El siguiente ejemplo asume que desea conectarse al servidor Memcached a través de una red privada. La IP del servidor Memcached es 192.168.100.20 y la dirección IP del cliente es 192.168.100.30

CentOS viene con una herramienta de configuración de firewall FirewallD. Los comandos a continuación crearán una nueva zona llamada memcached, abrirán el puerto 11211 y permitirán el acceso solo desde la dirección IP del cliente.

firewall-cmd --new-zone=memcached --permanent
firewall-cmd --zone=memcached --add-port=11211/udp --permanent
firewall-cmd --zone=memcached --add-port=11211/tcp --permanent
firewall-cmd --zone=memcached --add-source=192.168.100.30/32 --permanent
firewall-cmd --reload

Una vez que su firewall esté configurado, el siguiente paso es editar la configuración de Memcached y configurar el servicio para que escuche en la interfaz de red privada del servidor:

Abra el archivo de configuración de memcached:

In the OPTIONS parameter add the server IP address -l 192.168.100.20 y despues reinicia el servicio systemctl restart memcached

Conectando a Memcached

Para conectarse al servidor Memcached, debe utilizar un cliente específico del idioma.
PHP

Para usar Memcached como una base de datos de almacenamiento en caché para su aplicación PHP como WordPress, Drupal o Magento, necesita instalar la extensión php-pecl-memcached:

sudo apt install php-pecl-memcache

Dupdo
Pitón

Hay varias bibliotecas de Python para interactuar con memcache. Puedes instalar tu biblioteca preferida usando pip:

pip instalar pymemcache

Dupdo

pip instalar python-memcached

Dupdo
Conclusión

Ha aprendido cómo instalar Memcached en su servidor CentOS 7. Para obtener más información sobre este tema, consulte Memcached Wiki.