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.

If memcached failed to start , it is usually due to permission and user problem , please check the socket path is writable to designated user.

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 the same user that runs PHP

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 that runs PHP

3. Start memcached

service memcached start

4. 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 /path/to/memcached.sock
-a 0770

and change

-u memcache

to

-u username

the same user that runs PHP

3. Start memcached again

systemctl start memcached

4. Check if everything goes well.

nc -U /path/to/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 /path/to/memcached.sock
-a 0770

and change

-u memcache

to

-u username

the same user that runs PHP

3. Start memcached again

service memcached start

4. Check if everything goes well.

nc -U /path/to/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 22:38
  • by qtwrk