Otu esi etinye & hazie Memcached na AlmaLinux 8

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 nkuzi, ị ga-ama otu esi etinye na hazie Memcached na sistemụ arụmọrụ Almalinux 8 gị.

Prerequisites

  • OS akwadoro: AlmaLinux 8.
  • 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 AlmaLinux Sistemụ arụmọrụ iji hụ na ngwugwu niile dị adị adịla ugbu a:

sudo dnf upgrade --refresh -y

Nkuzi a ga-eji ya sudo iwu na na-eche na ị nwere ọnọdụ sudo.

Iji nyochaa ọkwa sudo na akaụntụ gị:

sudo whoami

Ihe atụ na-egosi ọkwa sudo:

[joshua@localhost ~]$ sudo whoami
root

Ka ịtọlite ​​akaụntụ sudo dị adị ma ọ bụ ọhụrụ, gaa na nkuzi anyị na Otu esi etinye onye ọrụ na Sudoers na AlmaLinux.

Iji mgbọrọgwụ akaụntụ, jiri iwu na-esonụ na paswọọdụ mgbọrọgwụ banye.

su

Advertisement


Wụnye Memcached

Site na ndabara, AlmaLinux enweela Memcached na iyi ngwa ya. Iji tinye Memcached, tinye iwu a:

sudo dnf install memcached libmemcached

Ihe atụ mmepụta:

Otu esi etinye & hazie Memcached na AlmaLinux 8

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

Rịba ama, nhọrọ nrụnye nke abụọ, "libmemcached” 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 nyochaa ụdị ya wee wuo ya

memcached --version

Ihe atụ mmepụta:

memcached 1.5.22

Ọrụ ahụ, na ndabara, agaghị arụ ọrụ. Ka ịmalite Memcached site na iji iwu a:

sudo systemctl enable memcached --now

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 & hazie Memcached na AlmaLinux 8

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:

memcach+   27220       1  0 22:24 ?        00:00:00 /usr/bin/memcached -p 11211 -u memcached -m 2000 -c 2000 -l 127.0.0.1 -U 0
joshua     29536   25923  0 22:52 pts/0    00:00:00 grep --color=auto memcached

Hazie Memcached

Memcached ga-abụrịrị na-ege ntị 127.0.0.1. Mepee ntọala ndabara na faịlụ nhazi dị na "/etc/sysconfig/memcached".

sudo nano /etc/sysconfig/memcached

Nhọrọ nke mbụ bụ ịgbanwe nọmba ọdụ ụgbọ mmiri ọdịnala maka Memcached.

11211

Ọ bụrụ na ị nwere nọmba ọdụ ụgbọ mmiri a ma nwee iwu firewall dị adị, ha ga-achọ ka emelite ha. Dị ka o kwesịrị, enwere ike ịhapụ nke a dị ka ndabara.

Nhọrọ nke abụọ bụ ịgbanwe njikọ max ka ọ bụrụ ihe dị elu karịa ma ọ bụrụ na sistemụ gị nwere ike ijikwa ya.

MAXCONN="2000"

Ekwesịrị ịbawanye njikọ kacha nwayọ nwayọ wee nwalee. Edola oke elu.

Na-esote, gbanwee nha cache 64MB ndabara ka ọ bụrụ nha ị kwenyere na cache gị ga-enwe ọnụ ụlọ iku ume.

Ọmụmaatụ nke ịgbanwe gaa na 2GB:

CACHESIZE="2000"

Ọ bụrụ na ihe nkesa gị nwere ọtụtụ ihe onwunwe, ọnụọgụ ọ bụla ga-eme, mana kpachara anya ma debe n'ime oke gị ma ọ bụrụ na ị nọ na onye na-elekọta ego.

Ugbu a gbadaa ala wee chọta ahịrị ndị a wee lelee ya "-l" paramita dị.

Site ebe a, ị nwere ike ịhapụ localhost ma ọ bụ kọwaa adreesị IP nke ime ma ọ bụ mpụga. Ọzọkwa, ị nwere ike itinye mgbakwunye nhọrọ nke a ga-akọwa n'okpuru.

-l 127.0.0.1

Ọkọlọtọ agbakwunyere nke mbụ bụ iji gbanyụọ UDP ma ọ bụrụ na achọrọghị ya.

-U 0

Nchịkọta nke nkuzi maka ihe ntọlite ​​gị nwere ike ịdị ka ozugbo emechara.

Ọmụmaatụ naanị:

Otu esi etinye & hazie Memcached na AlmaLinux 8

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


Hazie Firewalld maka Memcached

Site na ndabara, ọ nweghị iwu edobere maka Memcached. Nke a pụtara na ị ga-achọ ịmepụta iwu ndị dị mkpa iji kwụsị ọgụ. Ọdịda n'ichekwa Memcached ga-ebute nsogbu na egwu ahụ, yabụ awụla nke a ma ọ bụrụ na ị nweghị ụzọ ọzọ iji chebe nrụnye gị.

Nke mbụ, tinye mpaghara raara onwe ya nye maka iwu Memcached firewalld:

sudo firewall-cmd --permanent --new-zone=memcached

Na-esote, kọwapụta adreesị IP anabatara nke enyere ikike ịnweta Memcached.

sudo firewall-cmd --permanent --zone=memcached --add-source=1.2.3.4

Dochie 1.2.3.4 na IP adreesị nke a ga-agbakwunye na ndepụta ikike.

Ozugbo itinyechara adreesị IP, mepee ọdụ ụgbọ mmiri Memcached.

Site na ndabara, nke a bụ TCP ọdụ ụgbọ mmiri 11211.

sudo firewall-cmd --permanent --zone=memcached --add-port=11211/tcp

Mara, ị nwere ike ịgbanwe ọdụ ụgbọ mmiri ndabara na faịlụ nhazi gị ma ọ bụrụ na ịgbanwee ọdụ ụgbọ mmiri firewall na-emeghe iwu n'elu na uru ọhụrụ.

Mgbe ịmechara iwu ndị ahụ, bugharịa firewall iji mejuputa iwu ọhụrụ:

sudo firewall-cmd --reload

Mwepụta ihe atụ ma ọ bụrụ na ọ ga nke ọma:

success

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. Agbanyeghị, Almalinux chọrọ ụfọdụ ebe nchekwa agbakwunyere arụnyere iji dọpụta ngwungwu ndị a n'ihi na ha anaghị egosipụta na iyi ngwa ngwa ndabara.

Nke mbụ, wụnye ebe nchekwa EPEL na Remi PHP.

sudo dnf install epel-release -y
sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm -y

Na-esote, mee ka modul PHP ị na-eji ugbu a. Ụfọdụ ihe atụ dị n'okpuru.

PHP 8.0:

sudo dnf module enable php:remi-8.0 -y

PHP 7.4:

sudo dnf module enable php:remi-7.4 -y

Na-esote, tinye nkwado PHP Memcached site na iji iwu na-esonụ.

sudo dnf install php-pecl-memcache php-pecl-memcached

Ihe atụ mmepụta:

Otu esi etinye & hazie Memcached na AlmaLinux 8

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

Na mgbakwunye, maka nkwado Memcached na Python, ị nwere ike iwunye ngwugwu ndị a site na iji ọba akwụkwọ PIP.

pip3 install pymemcache --user
pip3 install python-memcached --user

Advertisement


Ị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 '^]'.

Mara, ọ bụrụ na arụnyeghị Telnet, mee iwu a ka ịwụnye.

sudo dnf install telnet -y

Mara, TELNET ekwesịghị ikwe ka ọ kparịta ụka na netwọk ọha yana machibido ya na gburugburu netwọkụ nkeonwe.

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

Otu esi ewepu (wepụ) Memcached

Iji wepu Memcached, jiri iwu na-esonụ na ọdụ gị.

sudo dnf autoremove memcached libmemcached

Nke a ga-ewepụ Memcached na sistemụ gị ozugbo.


Advertisement


Okwu na mmechi

Nkuzi ahụ egosila gị otu esi etinye Memcached na sistemụ arụmọrụ Almalinux 8 gị, wụnye ọ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