Memcached 通過以服務器更容易讀取的格式在服務器內存中保存常用腳本元素的副本來提高性能,從而減少時間。 此對象緩存的另一個功能是它能夠減少與數據庫的連接數。 在本教程中,我們將指導如何安裝 Memcached,但需要注意的是,在應用程序中使用 Memcache 時,必須對應用程序進行特殊編碼或配置以存儲和檢索緩存數據。
注意:注意:從我們的專門文章中了解有關緩存的更多信息,或訪問我們的數據庫優化系列。
以前的要求
- 我們以 root 身份登錄Ubuntu16.04 VPS 採用 Liquid Web 技術!
- 安裝並運行 Apache 和 PHP 7。
內存緩存安裝
步驟1:
按照最佳實踐,我們將使用以下命令進行快速包更新。
apt-get update
第2步:
使用此命令安裝 memcached 守護程序。
apt-get install memcached -y
第 3 步:
安裝用於 PHP 功能的內存緩存模塊。
apt-get install php-memcached -y
驗證 Memcached 安裝
使用 php -m 標誌顯示已編譯的模塊,同時通過專門查找 memcached 對它們進行排序。
php -m | grep memcached
memcached
可選配置
在某些時候,您可能需要更改 Memcached 的默認設置。 其中包括調整端口號、緩存內存和偵聽 IP 地址。
vim /etc/memcached.conf
通過保持相同的標誌(-m、-p、-u、-l)調整這些設置,調整標誌後的字母或數字,並通過鍵入 :wq 保存文件。
# 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 few security measures that memcached has, so make sure
# it's listening on a firewalled interface.
-l 127.0.0.1
重新啟動 Memcached 服務以識別對此文件的更改:
systemctl restart memcached
致電 800.580.4985 或打開一個聊天或票我們與我們經驗豐富的託管或解決方案顧問之一交談,以了解有關我們的 VPS 服務器的更多信息以及您今天如何利用這些優惠。