Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
memcached_unix_socket [2018/01/17 22:45] qtwrk [for Ubuntu 14.04 and Debian 7] |
memcached_unix_socket [2018/01/18 15:56] (current) Lisa Clarke [How to use Memcached in a UNIX socket] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ======How to use memcached in UNIX socket?====== | + | ======How to use Memcached in a UNIX Socket====== |
- | Memcached can also run in UNIX socket which provides better performance than TCP connection. | + | Memcached can run in a UNIX socket, which provides better performance than a TCP connection. |
+ | **Note**: If Memcached fails to start, it is usually due to permission and user problems. Please use root privilege to execute the following instructions, and verify that the socket path is writable to the designated user. | ||
+ | =====For Centos7.X===== | ||
- | =====Note===== | + | - Stop Memcached <code>systemctl stop memcached</code> |
- | Please use root privilege to the following instructions. | + | - Copy the service file <code>cp /usr/lib/systemd/system/memcached.service /etc/systemd/system/memcached.service</code> |
- | + | - Add the following content to ''/etc/systemd/system/memcached.service''. After ''[Service]'', please change username to the same user that runs PHP: <code>User=username | |
- | If memcached failed to start , it is usually due to permission and user problem , please check the socket path is writable to designated user. | + | |
- | =====for Centos7.X===== | + | |
- | + | ||
- | 1. Stop memcached <code>systemctl stop memcached</code> | + | |
- | + | ||
- | 2. Copy file service file <code>cp /usr/lib/systemd/system/memcached.service /etc/systemd/system/memcached.service</code> | + | |
- | + | ||
- | 3. Add following content to /etc/systemd/system/memcached.service ,after [Service], please change username to the same user that runs PHP | + | |
- | <code>User=username | + | |
Group=username | Group=username | ||
- | </code> | + | </code> The contents of the file should look like this: {{ :litespeed_wiki:cache:lscwp:configuration:object-cache3.jpg?direct |}} |
- | + | - Edit ''/etc/sysconfig/memcached'', changing the path to your desired location, and the username to the same one used in Step 3: <code>OPTIONS="" | |
- | the file should be like this: | + | USER="memcached"</code> becomes <code>OPTIONS="-s /path/to/memcached.sock -a 0770" |
- | {{ :litespeed_wiki:cache:lscwp:configuration:object-cache3.jpg?direct |}} | + | USER="username"</code> |
- | + | - Start Memcached again: <code>systemctl start memcached</code> | |
- | 4. Edit /etc/sysconfig/memcached , please change path to your desired location. | + | - Verify it started successfully: <code>systemctl status memcached</code> |
- | change from <code>OPTIONS=""</code> to <code>OPTIONS="-s /path/to/memcached.sock -a 0770"</code> | + | - Check if everything is working well: <code>nc -U /path/to/memcached.sock |
- | and change username to the same user name in step 3. | + | stats</code> |
- | change from <code>USER="memcached"</code> to <code>USER="username"</code> | + | |
- | + | ||
- | 5. Now start memcached again<code>systemctl start memcached</code> | + | |
- | + | ||
- | 6. Check if it started successfully , | + | |
- | <code>systemctl status memcached</code> | + | |
- | + | ||
- | 7. Check if everything goes well. | + | |
- | <code>nc -U /path/to/memcached.sock</code> | + | |
- | and then type <code>stats</code> | + | |
=====for Centos6.X===== | =====for Centos6.X===== | ||
- | 1. Stop memcached <code>service memcached stop</code> | + | - Stop Memcached <code>systemctl stop memcached</code> |
+ | - Edit ''/etc/sysconfig/memcached'' and change <code>OPTIONS="" | ||
+ | USER=""</code> to <code>OPTIONS="-s /path/to/memcached.sock -a 0770" | ||
+ | USER="username"</code> where ''userid'' is the same user that runs PHP. | ||
+ | - Start Memcached <code>service memcached start</code> | ||
+ | - Check if everything is working well: <code>nc -U /path/to/memcached.sock | ||
+ | stats</code> | ||
- | 2. Edit /etc/sysconfig/memcached | + | =====For Ubuntu 17.10, Ubuntu 16.04, Debian 8 and Debian 9===== |
- | change <code>OPTIONS=""</code> to <code>OPTIONS="-s /path/to/memcached.sock -a 0770"</code> | + | |
- | change <code>USER=""</code> to <code>USER="username"</code>, the same user that runs PHP | + | |
- | + | ||
- | 3. Start memcached <code>service memcached start</code> | + | |
- | + | ||
- | 4. Check if everything goes well. | + | |
- | <code>nc -U /path/to/memcached.sock</code> | + | |
- | and then type <code>stats</code> | + | |
- | =====for Ubuntu 17.10, Ubuntu 16.04, Debian 8 and Debian 9===== | + | |
- | + | ||
- | 1. Stop memcached <code>systemctl stop memcached</code> | + | |
- | + | ||
- | 2. Edit <code>/etc/memcached.conf</code>comment out host and port , add socket path and permission. | + | |
- | <code>-s /path/to/memcached.sock | + | |
- | -a 0770</code> | + | |
- | and change <code>-u memcache</code> to <code>-u username</code> | + | |
- | the same user that runs PHP | + | |
- | + | ||
- | + | ||
- | + | ||
- | 3. Start memcached again <code>systemctl start memcached</code> | + | |
- | + | ||
- | 4. Check if everything goes well. | + | |
- | <code>nc -U /path/to/memcached.sock</code> | + | |
- | and then type <code>stats</code> | + | |
+ | - Stop Memcached <code>systemctl stop memcached</code> | ||
+ | - Edit ''/etc/memcached.conf'', comment out host and port, add socket path and permission <code>-s /path/to/memcached.sock | ||
+ | -a 0770</code> and change ''-u memcache'' to ''-u username'' where ''username'' is the same user that runs PHP. | ||
+ | - Start Memcached again <code>systemctl start memcached</code> | ||
+ | - Check if everything is working well: <code>nc -U /path/to/memcached.sock | ||
+ | stats</code> | ||
=====for Ubuntu 14.04 and Debian 7===== | =====for Ubuntu 14.04 and Debian 7===== | ||
- | 1. Stop memcached <code>service memcached stop</code> | + | - Stop Memcached <code>service memcached stop</code> |
- | + | - Edit ''/etc/memcached.conf'', comment out host and port, add socket path and permission <code>-s /path/to/memcached.sock | |
- | 2. Edit <code>/etc/memcached.conf</code>comment out host and port , add socket path and permission. | + | -a 0770</code> and change ''-u memcache'' to ''-u username'' where ''username'' is the same user that runs PHP. |
- | <code>-s /path/to/memcached.sock | + | - Start Memcached again <code>service memcached start</code> |
- | -a 0770</code> | + | - Check if everything is working well: <code>nc -U /path/to/memcached.sock |
- | and change <code>-u memcache</code> to <code>-u username</code> | + | stats</code> |
- | the same user that runs PHP | + | |
- | + | ||
- | 3. Start memcached again <code>service memcached start</code> | + | |
- | + | ||
- | 4. Check if everything goes well. | + | |
- | <code>nc -U /path/to/memcached.sock</code> | + | |
- | and then type <code>stats</code> | + |