Memcached – Cannot Listen on Port Different from 11211 in Alma Linux 8.8

centos8linuxmemcachedport

I installed successfully Memcached in Alma Linux 8.8 (a Red Hat 8.8 clone) but, when I changed the port number from 11211 to 11212 in the config file at /etc/sysconfig/memcached and restarted the service, I got the following message:

failed to listen on TCP port 11212: Permission denied

Other port numbers (11213, 11214, etc.) don't work either!

I am running a Vagrant machine (downloaded from the official repository of Alma Linux) on VirtualBox 7.0.8

Updates: after reading asktyagi note, I changed the port number to 11213 and restarted the service. I've got this on cockpit:

SELinux access control errors

SELinux is preventing /usr/bin/memcached from name_bind access on the
tcp_socket port 11213.

Solution: If you want to allow /usr/bin/memcached to bind to network port 11213
you need to modify the port type.

Solution details: semanage port -a -t memcache_port_t -p tcp 11213

Audit log:

type=AVC msg=audit(1690420222.524:28): avc: denied { name_bind } for pid=778 comm="memcached" src=11213 scontext=system_u:system_r:memcached_t:s0 tcontext=system_u:object_r:unreserved_port_t:s0 tclass=tcp_socket permissive=0

Best Answer

SELinux is preventing port to bind. Execute below command to allow it from selinux side.

semanage port -a -t memcache_port_t -p tcp 11213

Other way is disable selinux, relabel it and retry.

Related Topic