採用LSMCD作為物件快取的安裝流程
一般網站可能採用Redis和Memcached這些記憶體內部資料結構存放區做物件快取
由於我這邊就不加詳述Redis 和 Memcached的差異性以及誰比較優異評論,我這邊就單純以「LSMCD」(LiteSpeed版本的Memcached)的安裝流程為主軸,至於效能部分感想嘛…留待其他人能夠測試探討囉,畢竟個人希望整套以LiteSpeed相關做高度整合
以下為整個安裝流程
Step 01:停用先前安裝的Memcached(若有安裝時)
如果在當初安裝OpenLiteSpeed或是LiteSpeed Server的話,有的人在安裝時就也順便安裝了Memcached和Redis,若是有安裝的話,最好先將Memcached的服務先關掉,以防有任何衝突的地方;下方指令請從終端機或是利用PuTTY登入root帳戶後輸入相關指令(單一行輸入)後停止服務
systemctl stop memcached.service
systemctl disable memcached.service
Step 02:編譯並下載LSMCD
由於我本身是使用CentOS,所以我這邊以CentOS的指令為例,其餘的Linux可以參照Getting Started | LSMCD | Products | LiteSpeed Documentation (litespeedtech.com)
yum groupinstall "Development Tools"
yum install autoconf automake zlib-devel openssl-devel expat-devel pcre-devel libmemcached-devel cyrus-sasl*
之後再輸入下列指令
git clone https://github.com/litespeedtech/lsmcd.git
接著輸入指令對LSMCD編譯(同樣各行分別輸入)
cd lsmcd
./fixtimestamp.sh
./configure CFLAGS=" -O3" CXXFLAGS=" -O3"
make
Step 03:安裝LSMCD並設定防火牆規則
輸入下面指令後就會開始安裝LSMCD
sudo make install
然後對/usr/local/lsmcd/conf/node.conf做調整,同樣需要編輯時按下<kbd>A鍵</kbd>,要讓編輯結束時先按下<kbd>ESC鍵</kbd>後,再輸入:wq儲存變更
vi /usr/local/lsmcd/conf/node.conf
以下為個人的狀況,需依據你個人需求更改,我當時的/usr/local/lsmcd/conf/node.conf內容為下
Repl.HeartBeatReq=30
Repl.HeartBeatRetry=3000
Repl.MaxTidPacket=2048000
Repl.GzipStream=YES
Repl.LbAddrs=127.0.0.1:12340
Repl.ListenSvrAddr=127.0.0.1:12340
REPL.DispatchAddr=127.0.0.1:5501
RepldSockPath=/tmp/repld.usock
CACHED.PRIADDR=127.0.0.1:11000
CACHED.ADDR=127.0.0.1:11211
#CACHED.ADDR=UDS:///tmp/lsmcd.sock
#default is 8, it can be bigger depending on cache data amount
Cached.Slices=8
Cached.Slice.Priority.0=100
Cached.Slice.Priority.1=100
Cached.Slice.Priority.2=100
Cached.Slice.Priority.3=100
Cached.Slice.Priority.4=100
Cached.Slice.Priority.5=100
Cached.Slice.Priority.6=100
Cached.Slice.Priority.7=100
Cached.ShmDir=/dev/shm/lsmcd
Cached.UseSasl=false
Cached.DataByUser=true
Cached.Anonymous=true
#Cached.SaslDB=/etc/sasllsmcd
##this is the global setting, no need to have per slice configuration.
User=nobody
Group=nobody
#depends CPU core
CachedProcCnt=1
CachedSockPath=/tmp/cached.usock.
TmpDir=/tmp/lsmcd
LogLevel=notice
#LogLevel=dbg_medium
LogFile=/tmp/lsmcd.log
上面唯一有修改到的地方僅為CachedProcCnt=1這一行(原本為CachedProcCnt=8),這裡代表你所使用的處理器數量(由於基本數量為一個處理器,所以我這邊填入1,可以依據你使用的機器狀況作修正)
由於這邊有多出其他服務需要開啟12340、5501以及11000的連接埠(Port),所以我們可以到CyberPanel內部做設定
![](https://assets.matters.news/embed/528a55e4-85ea-4241-a4e9-10624dc2385c.png)
![](https://assets.matters.news/embed/d2eb0786-e9bf-4a0d-afde-c4b91023f16f.png)
![](https://assets.matters.news/embed/a5950e2d-802e-465e-b41c-6a82fde92ea4.png)
![](https://assets.matters.news/embed/23ae98cc-28d3-4ba0-a691-167b07814d2e.png)
Step 04:LSMCD啟用以及確認
輸入下面指令使LSMCD啟動
sudo systemctl start lsmcd
sudo systemctl enable lsmcd
接著輸入下面指令確認啟動狀態
systemctl status lsmcd
然後我的狀態顯示如下
lsmcd.service - LSB: lsmcd
Loaded: loaded (/etc/rc.d/init.d/lsmcd; generated)
Active: active (running) since Sun 2021-06-27 07:57:00 UTC; 3h 44min ago
Docs: man:systemd-sysv-generator(8)
Tasks: 3 (limit: 5794)
Memory: 5.3M
CGroup: /system.slice/lsmcd.service
├─1273 /usr/local/lsmcd/bin/lsmcd -f /usr/local/lsmcd/conf/node.conf
├─1280 /usr/local/lsmcd/bin/lsmcd
└─2736 /usr/local/lsmcd/bin/lsmcd
Jun 27 07:56:58 hwsrv-888106.hostwindsdns.com systemd[1]: Starting LSB: lsmcd...
Jun 27 07:57:00 hwsrv-888106.hostwindsdns.com lsmcd[1231]: start lsmcd >
Jun 27 07:57:00 hwsrv-888106.hostwindsdns.com systemd[1]: Started LSB: lsmcd.
從畫面得知已經啟動後,接著輸入telnet 127.0.0.1 11211可得下面結果
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
之後接著再輸入stats可得下面結果(每個人狀態不同,僅供參考)
STAT pid 1300
STAT version 1.0.0
STAT pointer_size 64
STAT rusage_user 0.024294
STAT rusage_system 0.053357
STAT cmd_get 0
STAT cmd_set 0
STAT cmd_flush 0
STAT cmd_touch 0
STAT get_hits 0
STAT get_misses 0
STAT delete_misses 0
STAT delete_hits 0
STAT incr_misses 0
STAT incr_hits 0
STAT decr_misses 0
STAT decr_hits 0
STAT cas_misses 0
STAT cas_hits 0
STAT cas_badval 0
STAT touch_hits 0
STAT touch_misses 0
STAT auth_cmds 0
STAT auth_errors 0
END
需要離開時鍵盤輸入Ctrl+C(沒錯,就是複製的快捷鍵)後輸入quit便會跳出
最後輸入下列命令,可以確認目前LSMCD的版本
/usr/local/lsmcd/bin/lsmcd -vLSMCD
可以得知我的版本是1.4.24(但因為被我發現到有Bug後回報,現在應該已經進號就是)
lsmcd server 1.4.24
沒什麼問題的話,基本上LSMCD的安裝就到此結束
然後之後在LiteSpeed Cache的快取選項裡,確認相關選項設定
![](https://assets.matters.news/embed/34e43427-0f6c-41b2-bffb-c0e7cbea96eb.png)
![](https://assets.matters.news/embed/70b58831-077e-4ca5-825f-ab272a7f0a6b.png)
Step 05:其他問題排除
由於我本身有遇到,但可能其他人安裝順利,只不過以防萬一,我還是把這問題提出
或許會有人遇到這個問題,就是用systemctl status lsmcd確認動作狀態時,有可能會有類似下面訊息報錯
auxpropfunc error no mechanism available
auxpropfunc error invalid parameter supplied
解決方式就是把LDAP移除掉就解決了
方法如下:
![](https://assets.matters.news/embed/4d60214e-cb7c-4906-bfb4-be30198936ef.png)
![](https://assets.matters.news/embed/e00a42bf-fb84-4334-898b-fc6812fbdbc1.png)
![](https://assets.matters.news/embed/29cc8170-dd34-4702-a1d8-7c6ccc3d0d1e.png)
這時再到命令列輸入systemctl status lsmcd,應該就不會有警告的狀況發生了
以上為「採用LSMCD作為物件快取的安裝流程」,希望能夠幫助你
參考資料:
Getting Started | LSMCD | Products | LiteSpeed Documentation (litespeedtech.com)
安装OpenLiteSpeed官方LSMCD对象缓存替换Memcached详细图文教程 – 搬主题 (banzhuti.com)
[解]处理auxpropfunc error no mechanism available错误 – linuxの飘扬 – Power by www.linuxfly.org