Memcached

記憶體記憶體基本配置

  • October 9, 2015

我已經為 Drupal 站點安裝了 memcache,它帶有 memcached pecl 擴展。一切都執行良好,但我仍在為配置設置而苦苦掙扎。

例如,遵循 drupal.org 上的建議

You should probably lock down the memcache server so that it only listens for 
connections from the hosts that need to be served, as the default is that 
memcache listens to connections from all addresses. 
So, to close that hole, edit /etc/sysconfig/memcached with:

OPTIONS="-l ${HOSTIP}"

問題是我的伺服器上沒有這個文件,無論如何不在這個位置。其他一些文章提到了 /etc/memcached.conf 但我也找不到這個文件。

考慮到 /etc/sysconfig/memcached 或 /etc/memcached.conf 不會在我的伺服器上退出,我可以安全地創建它們嗎?這些文件是否有可能位於其他地方,在這種情況下我應該在哪裡查看或者有什麼方法可以找到該資訊?

最後,任何資源、教程或文件連結將不勝感激。我瀏覽過 memcache 的站點 Wiki,只能找到一些針對初學者的相關文章。

您沒有告訴我們您的作業系統/發行版。另外,您沒有告訴我們您是如何安裝 memcached 的。

通常,當您在基於 debian 的系統和或在 redhat、fedora 或 centos 下/etc/安裝 memcached 時,您會得到一個範例配置文件。apt-get``rpm``yum

如果你從原始碼安裝它,你可能不會得到一個範例文件/etc/(我自己沒有從原始碼安裝 memcached)。但是,您可以在解壓縮的源文件夾中查找範例配置文件。

無論如何,您可以使用locate memcached.conf在您的系統中尋找一個。您需要在sudo updatedb此之前更新搜尋記憶體。

這是我係統中的配置文件。你可以使用它:

# Run memcached as a daemon. This command is implied, and is not needed for the
# daemon to run. See the README.Debian that comes with this package for more
# information.
-d

# Log memcached's output to /var/log/memcached
logfile /var/log/memcached.log

# Be verbose
# -v

# Be even more verbose (print client commands as well)
# -vv

# Start with a cap of 64 megs of memory. It's reasonable, and the daemon default
# Note that the daemon will grow to this size, but does not start out holding this much
# memory
-m 64

# Default connection port is 11211
-p 11211
# Run the daemon as root. The start-memcached will default to running as root if no
# -u command is present in this config file
-u memcache

# Specify which IP address to listen on. The default is to listen on all IP addresses
# This parameter is one of the only security measures that memcached has, so make sure
# it's listening on a firewalled interface.
-l 127.0.0.1

# Limit the number of simultaneous incoming connections. The daemon default is 1024
# -c 1024

# Lock down all paged memory. Consult with the README and homepage before you do this
# -k

# Return error when memory is exhausted (rather than removing items)
-M

# Maximize core file limit
# -r

您也可以從命令行傳遞相同的選項。

引用自:https://serverfault.com/questions/347621