This is an old revision of the document!


How to use memcached in UNIX socket?

Memcached can also run in UNIX socket which provides better performance than TCP connection.

Please use root privilege to the following instructions, and SELinux needs to be disabled

1. Stop memcached

systemctl stop memcached

2. Copy file service file

cp /usr/lib/systemd/system/memcached.service /etc/systemd/system/memcached.service

3. Add following content to /etc/systemd/system/memcached.service ,after [Service], please change username to php user

User=username
Group=username

the file should be like this:

4. Edit /etc/sysconfig/memcached , please change path to your desired location. change from

OPTIONS=""

to

OPTIONS="-s /path/to/memcached.sock -a 0770"

and change username to the same user name in step 3. change from

USER="memcached"

to

USER="username"

5. Now start memcached again

systemctl start memcached

6. Check if it started successfully ,

systemctl status memcached

7. Check if everything goes well.

nc -U /path/to/memcached.sock

and then type

stats

1. Stop memcached

service memcached stop

2. Edit /etc/sysconfig/memcached change

OPTIONS=""

to

OPTIONS="-s /path/to/memcached.sock -a 0770"

change

USER=""

to

USER="username"

the same user runs php

3.

4. Start memcached

service memcached start

5. Check if everything goes well.

nc -U /path/to/memcached.sock

and then type

stats

1. Stop memcached

systemctl stop memcached

2. Edit

/etc/memcached.conf

comment out host and port , add socket path and permission.

-s /tmp/memcached.sock
-a 755

3. Start memcached again

systemctl start memcached

4. Check if everything goes well.

nc -U /tmp/memcached.sock

and then type

stats

1. Stop memcached

service memcached stop

2. Edit

/etc/memcached.conf

comment out host and port , add socket path and permission.

-s /tmp/memcached.sock
-a 755

Add additional line on Ubuntu 14.04

-u root

3. Start memcached again

service memcached start

4. Check if everything goes well.

nc -U /tmp/memcached.sock

and then type

stats

sources:

https://www.orangecoat.com/how-to/run-memcached-as-a-socket-under-systemd-in-centos-or-rhel-7

https://chirale.org/2015/09/04/installing-and-configure-memcache-on-centos-7/

https://guides.wp-bullet.com/install-latest-memcached-object-cache-wordpress-php5-debian/

  • Admin
  • Last modified: 2018/01/17 21:10
  • by qtwrk