Otu esi etinye Memcached na Debian 11 Bullseye

Debara aha A na-eji mee ka weebụsaịtị webụsaịtị na-akwalite nchekwa data ngwa ngwa site na ịchekwa data na ihe dị na RAM. Nke a na-ebelata ugboro ole a ga-agụrịrị isi iyi data mpụga, nke na-ewetu oke ego ma na-agba ọsọ oge nzaghachi. Akụrụngwa nchekwa nchekwa bụ ọrụ n'efu, mepere emepe nke onye ọ bụla nwere ike iji.

Na njedebe nke ntuziaka, ị ga-ama otu esi etinye na hazie Memcached na Debian 11 Bullseye gị sistemụ nrụọrụ.

Prerequisites

  • OS akwadoro: Nnenna 11 Bullseye
  • Akaụntụ onye ọrụ: Akaụntụ onye ọrụ nwere sudo ihe ùgwù or ohere mgbọrọgwụ (su Command).

Na-emelite Sistemụ Ọrụ

Melite gi Debian 11 Sistemụ arụmọrụ iji hụ na ngwugwu niile dị adị adịla ugbu a:

sudo apt update && sudo apt upgrade

Mgbọrọgwụ ma ọ bụ Sudo Access

Site na ndabara, mgbe ị mepụtara akaụntụ gị na mmalite na Debian ma e jiri ya tụnyere nkesa ndị ọzọ, ọ naghị enweta ọkwa sudoers ozugbo. Ị ga-enwerịrị ike ịnweta ya mgbọrọgwụ paswọọdụ iji iwu su ma ọ bụ gaa na nkuzi nkuzi anyị Otu esi etinye onye ọrụ na Sudoers na Debian.


Advertisement


Wụnye Memcached

Site na ndabara, Debian 11 enwetala Memcached na ebe nchekwa ya. Iji tinye Memcached, tinye iwu a:

sudo apt install memcached libmemcached-tools

Ihe atụ mmepụta:

Otu esi etinye Memcached na Debian 11 Bullseye

ụdị Y, wee pịa Tinye igodo ịga n'ihu na nwụnye.

Rịba ama, nhọrọ nrụnye nke abụọ, "libmemcached-ngwaọrụ” ngwugwu, na-enye ndị ọzọ iwu iji weta mmezi mmekọrịta na mebie ikike na Memcached.

Na-esote, gosi na etinyere Memcached nke ọma site na iji nyocha iwu amụma apt-cache:

sudo apt-cache policy memcached

Ihe atụ mmepụta:

Otu esi etinye Memcached na Debian 11 Bullseye

Ekwesịrị ịgbalite Memcached na ndabara. Iji nyochaa nke a, jiri systemctl iwu iwu dị ka ndị a:

systemctl status memcached

Ihe atụ mmepụta:

Otu esi etinye Memcached na Debian 11 Bullseye

Ọ bụrụ na arụghị ọrụ a, malite Memcached site na iji iwu a:

sudo systemctl start memcached

Iwu ndị ọzọ bara uru maka ijikwa ọrụ Memcached bụ ndị a:

Iji mee ka ọrụ Memcached dị na buut sistemụ:

sudo systemctl enable Memcached

Ka ịkwụsị ọrụ Memcached:

sudo systemctl stop memcached

Iji gbanyụọ ọrụ Memcached na buut sistemụ:

sudo systemctl disable memcached

Ka ịmalitegharịa ọrụ Memcached:

sudo systemctl restart memcached

Na-esote, nyochaa Memcached na-ege ntị nke ọma na localhost na ndabara ọdụ ụgbọ mmiri 11211. Iji kwado ụdị a, ihe ndị a:

ps -ef | grep memcached

Ihe atụ mmepụta:

memcache    5934       1  0 09:36 ?        00:00:00 /usr/bin/memcached -m 64 -p 11211 -u memcache -l 127.0.0.1 -P /var/run/memcached/memcached.pid
root        6591    3653  0 09:55 pts/0    00:00:00 grep memcached

Hazie Memcached

Memcached ga-abụrịrị na-ege ntị 127.0.0.1. Ọzọ, mepee ntọala ndabara na faịlụ nhazi dị na "/etc/memcached.conf".

sudo nano /etc/memcached.conf

Ugbu a gbadaa ala wee chọta ahịrị ndị a wee lelee ya "-l" paramita dị. Hapụ dị ka ndabara ọ gwụla ma ị nwere IP dị n'ime na netwọk mpaghara ma ọ bụ IP mpụga site n'èzí; ị ga-agbanwe adreesị IP ndabara site na 127.0.0.1 gaa na adreesị IP ọhụrụ.

-l 127.0.0.1

A na-atụ aro ka ị gbanyụọ UDP. Ọ gwụla ma ịchọrọ ka agbanyere ọrụ a, gbakwunye ahịrị na-esote iji gbanyụọ ya.

-U 0

Tupu ịmechaa, a na-atụ aro ka ị gbanwee ebe nchekwa 64MB ndabara n'ihi na nke a abụghị nke ukwuu maka weebụsaịtị buru ibu, ị gaghị ahụkwa nnukwu uru site na iji Memcached.

Ịkwesịrị ịtọ nke a ka ọ bụrụ ihe ezi uche dị na ya maka ihe nkesa gị. Ọ bụrụ na ị nwere 3 ruo 6 GB nke RAM a na-ejikarị eme ihe, tinye ya na 1GB ma ọ bụ 2GB. Nke a bụ ntọala ị ga-ekpebi nke ga-akacha mma maka ihe nkesa gị. Ihe nkesa nke ntuziaka na-agba na 8GB, yabụ anyị meziri cache anyị ka ọ bụrụ 2GB dịka ọmụmaatụ naanị.

-m 2000

Ugbu a, chekwaa faịlụ ahụ CTRL + O ma tie "Y," mgbe ahụ CTRL + X pụọ wee malitegharịa ihe atụ Memcached gị.

sudo systemctl restart memcached

Advertisement


Nhọrọ – Kwe ka Memcached Iwu UFW

Ọ bụrụ na etinyere UFW, ịkwesịrị ịmepụta iwu ikike UFW na iwu TCP ọdụ ụgbọ mmiri 11211. Dabere na nrụnye na ihe achọrọ ma ọ bụrụ na ị na-eji otu netwọkụ ma ọ bụ na netwọkụ ụyọkọ, ọmụmaatụ ụfọdụ dị n'okpuru:

Otu ihe atụ njikọ netwọk IP:

sudo ufw allow proto tcp from <ip address> to any port 11211

Njikọ netwọkụ ụyọkọ IP nwere ọtụtụ ihe atụ:

sudo ufw allow proto tcp from <ip address>/24 to any port 11211

Mara, iwu UFW nke abụọ bụ iwu subnet. Mara, gbaa mbọ hụ na netwọkụ dị n'ime nwere nchekwa yana ntụkwasị obi tupu ikwe ya.

Wụnye ọba akwụkwọ PHP Memcached

Memcached na-abịa na ndọtị dị iche iche maka asụsụ mmemme, mana a na-eji ya maka PHP. Iji wụnye ọbá akwụkwọ PHP tinye ihe ndị a.

sudo apt install php-memcached apache2 libapache2-mod-php php php-cli php-memcached php-memcached

Server Apache HTTP

Ndị ọrụ Apache nwere ike mebe koodu ndị a iji mee Memcached na sistemụ ha.

phpenmod memcached && sudo service apache2 restart

Nginx HTTP sava

A ga-eme Memcached maka Nginx na ngọngọ PHP gị ozugbo etinyere ya.


Advertisement


Wụnye ọba akwụkwọ ndị ọzọ

Ị nwere ike iwunye Python na ma ọ bụ nkwado Perl site na ime iwu ndị a.

Nkwado Python:

sudo apt install python3-pymemcache

Nkwado Perl:

sudo apt install libcache-memcached-libmemcached-perl

Ịnweta Memcached site na Line Command

Enwere ike ikpokọta stats memcached site na ọtụtụ sọftụwia na WEB UI nke ọ na-arụ ọrụ na njikọ. Agbanyeghị, ụzọ ka mma iji lelee bụ iso Memcached na-emekọrịta ihe ozugbo site na iji ahịrị iwu.

Akpa, TELET banye n'ọrụ gị:

telnet localhost 11211

Ihe atụ mmepụta:

Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.

Na-esote, ị nwere ike nweta nkọwapụta nke ọrụ Memcached gị site na iji iwu a:

stats

Ihe atụ mmepụta:

STAT pid 5934
STAT uptime 1275
STAT time 1631930242
STAT version 1.6.9
STAT libevent 2.1.12-stable
STAT pointer_size 64
STAT rusage_user 0.113635
STAT rusage_system 0.000000
STAT max_connections 1024
STAT curr_connections 1
STAT total_connections 2
STAT rejected_connections 0
STAT connection_structures 2
STAT response_obj_oom 0
STAT response_obj_count 1
STAT response_obj_bytes 16384
STAT read_buf_count 2
STAT read_buf_bytes 32768
STAT read_buf_bytes_free 0
STAT read_buf_oom 0
STAT reserved_fds 20
STAT cmd_get 0
STAT cmd_set 0
STAT cmd_flush 0
STAT cmd_touch 0
STAT cmd_meta 0
STAT get_hits 0
STAT get_misses 0
STAT get_expired 0
STAT get_flushed 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
STAT bytes_read 7
STAT bytes_written 0
STAT limit_maxbytes 67108864
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT time_in_listen_disabled_us 0
STAT threads 4
STAT conn_yields 0
STAT hash_power_level 16
STAT hash_bytes 524288
STAT hash_is_expanding 0
STAT slab_reassign_rescues 0
STAT slab_reassign_chunk_rescues 0
STAT slab_reassign_evictions_nomem 0
STAT slab_reassign_inline_reclaim 0
STAT slab_reassign_busy_items 0
STAT slab_reassign_busy_deletes 0
STAT slab_reassign_running 0
STAT slabs_moved 0
STAT lru_crawler_running 0
STAT lru_crawler_starts 6
STAT lru_maintainer_juggles 1325
STAT malloc_fails 0
STAT log_worker_dropped 0
STAT log_worker_written 0
STAT log_watcher_skipped 0
STAT log_watcher_sent 0
STAT unexpected_napi_ids 0
STAT round_robin_fallback 0
STAT bytes 0
STAT curr_items 0
STAT total_items 0
STAT slab_global_page_pool 0
STAT expired_unfetched 0
STAT evicted_unfetched 0
STAT evicted_active 0
STAT evictions 0
STAT reclaimed 0
STAT crawler_reclaimed 0
STAT crawler_items_checked 0
STAT lrutail_reflocked 0
STAT moves_to_cold 0
STAT moves_to_warm 0
STAT moves_within_lru 0
STAT direct_reclaims 0
STAT lru_bumps_dropped 0
END

Dị ka n'elu, nke a na-egosi ụfọdụ ihe dị mkpa ị nwere ike ịhụ, dị ka oge nkwụsị, ọnụ ọgụgụ nke ihe dị na cache, na ọnụ ọgụgụ nke njikọ ndị ahịa na ihe atụ.

Ị nwere ike imezi ọchụchọ ahụ site na ilele anya na ebe nchekwa dị iche iche Memcached slabs (nkebi) iji weghachi rịzọlt.

Ọmụmaatụ n'okpuru:

Depụta mbadamba nkume ndị dị na ihe atụ ejikọrọ:

stats slabs

Ndepụta slabs nke gụnyere ngụkọ nke ihe echekwara n'ime slab ọ bụla:

stats items

Na-esote, ị nwere ike ịnweta ma hichapụ data site na iji iwu cachedump iji depụta igodo.

Mbụ, mee ihe iwu cachedump:

stats cachedump [slab ID] [number of items, 0 for all items]

Ọmụmaatụ n'omume:

stats cachedump 1 0

Ihe atụ mmepụta:

ITEM testkey [9 b; 1296857316 s]
END

Dịka n'elu, SLAB 1 nwere otu ihe nwere igodo "Testkey." Iji nweta ezigbo uru, ị nwere ike iji "nweta igodo" nye iwu dika ndi a:

get testkey

Ihe atụ mmepụta:

VALUE testkey 0 9
test data
END

N'ikpeazụ, ka ihichapụ ihe echekwara, na nke a, a "igodo ule" jiri iwu a:

delete testkey

Ihe atụ mmepụta:

DELETED

Advertisement


Okwu na mmechi

Nkuzi ahụ egosila gị otu esi etinye Memcached na sistemụ arụmọrụ Debian 11 Bullseye gị, na-etinye ọba akwụkwọ ndị ọzọ yana otu esi enweta ndepụta iwu ọnụ.

Maka akwụkwọ ndị ọzọ, ọrụ ahụ bụ Github Wiki ibe na-akọwa n'ihu n'ụzọ zuru oke maka ndị nchịkwa ihe nkesa nkọwa ma ọ bụ ozi ọ bụla ha chọrọ.

Ahapụ a Comment