Ts'ebetso ea HestiaCP php-fpm e nka lisebelisoa tse ngata tsa CPU Nka e ntlafatsa joang?

HestiaCP Sebapali se matla sa CPU? Tataiso e felletseng ea ho ntlafatsa ts'ebetso ea PHP-FPM!

Ts'ebetso ea HestiaCP php-fpm e nka lisebelisoa tse ngata tsa CPU Nka e ntlafatsa joang?

Na CPU ea seva e lula e le 100%? Fane e ntse e bilika hampe? Na lebelo la ho bula sebaka sa marang-rang le fokotseha?Molato e ka ba php-fpm!

Ke sa tsoa sibolla chenweiliang.com Letamo lena la PHP php-fpm Ts'ebetso e ile ea ja CPU joalo ka bohlanya, 'me seva ea senyeha!

E le ho tsosolosa seva, ke lekile letoto la mekhoa ea ho ntlafatsa 'me qetellong ka atleha ho fokotsa tšebeliso ea CPU.

Jwale, ha re arolelaneng sena Tataiso e Sebetsang ea Ntlafatso! 🚀

1. Fokotsa palo ea mekhoa ea php-fpm

php-fpm litlhophiso tsa kamehla li kase nang moeliTs'ebetso e entsoe ka mokhoa o sa laoleheng, e etsang hore seva sa CPU se jale haholo.

Ho e ntlafatsa, re ka fetola liparamente tsa taolo ea ts'ebetso.

bulela php-fpm Lifaele tsa Tlhophiso:

sudo nano /etc/php/*/fpm/pool.d/www.conf
  • *Fetolela mofuta oa hau oa PHP, joalo ka PHP8.3, 'me u e fetole ho sena:/etc/php/8.3/fpm/pool.d/www.conf

Botsa mofuta oa PHP o behiloeng ke HestiaCP

v-list-web-domain user domain.com

Moq:

v-list-web-domain abc chenweiliang.com

Ka sephetho, u tla bona ntho e kang:

PHP SUPPORT      yes
PHP MODE        php-fpm
PHP VERSION     8.3

Sena se bolela hore webosaete e sebetsa PHP 8.3.

Fumana le ho fetola liparamente tse latelang:

pm = dynamic
pm.max_children = 16  ; 根据服务器资源调整,建议值:CPU 核心数 × 2
pm.start_servers = 4   ; 初始进程数,建议设为 max_children × 25%
pm.min_spare_servers = 2  ; 最小空闲进程数
pm.max_spare_servers = 7  ; 最大空闲进程数
pm.max_requests = 3000    ; 每个子进程处理完 3000 个请求后自动重启
pm.process_idle_timeout = 10s  ; 空闲进程 10s 后自动退出

Ebe o qala hape php-fpm Ho etsa hore e atlehe:

sudo systemctl restart php-fpm

Phello: Fokotsa palo ea lits'ebetso ho thibela php-fpm ho sebelisa lisebelisoa tsa CPU ho feta tekano.

2. Numella OPCache (ho ntlafatsa ts'ebetso ea PHP)

PHP e fetola khoutu nako le nako ha e etsoa, ​​​​e leng tšenyo ea lisebelisoa.
Tharollo? Numella OPCache le ho boloka khoutu ea hau ea PHP!

hlophisa php.ini tokomane:

sudo nano /etc/php/*/fpm/php.ini

Kenya kapa fetola tse latelang:

opcache.enable=1
opcache.memory_consumption=128
opcache.max_accelerated_files=10000
opcache.validate_timestamps=0  # 禁用实时检测,提高性能

Kamora ho boloka, qala ts'ebetso ea PHP bocha:

sudo systemctl restart php8.3-fpm

Phello: Fokotsa ho arola khafetsa khoutu ea PHP, fokotsa moroalo oa CPU, 'me u ntlafatse ts'ebetso ea ts'ebetso.

3. Fokotsa nako e telele ea ho phethahatsa ea mangolo a PHP

Haeba sengoloa sa PHP se sebetsa nako e telele haholo, lisebelisoa tsa CPU li tla lula li lula.
Ho beha nako e loketseng ea ho qeta nako ho ka thibela lits'ebetso tse "manganga" ho lula ho seva nako e telele.

bulela php.ini tokomane:

sudo nano /etc/php/*/fpm/php.ini

Fetola li-parameter tse latelang:

max_execution_time = 30  # PHP 脚本最多执行 30max_input_time = 30  # 处理输入数据最多 30memory_limit = 256M  # 限制单个 PHP 进程的内存占用

Ebe u qala ts'ebetso ea PHP hape:

sudo systemctl restart php-fpm

Phello: Thibela lits'ebetso tsa PHP ho sebetsa nako e telele le ho fokotsa litšila tsa lisebelisoa tsa CPU.

4. Hlahloba MySQL Potso butle

PHP-FPM e na le mojaro o phahameng,E kanna ea bakoa ke potso ea SQL butle!
Bulela MySQL Potso e liehang, fumana lipolelo tsa SQL tse itšoereng morao.

Fetola faele ea tlhophiso ea MySQL:

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

Kenyeletsa ho:

slow_query_log = 1
slow_query_log_file = /var/log/mysql-slow.log
long_query_time = 1  # 超过 1 秒的查询会被记录

Ka mor'a ho boloka, qala hape MySQL:

sudo systemctl restart mysql

Ebe u sebelisa mysqldumpslow Sekaseka lipotso tse liehang:

mysqldumpslow -s c -t 10 /var/log/mysql-slow.log

Phello: Fumana lipotso tsa SQL tse jang nako, ntlafatsa ts'ebetso ea database, 'me ka tsela e sa tobang u fokotse mojaro oa PHP.

5. Fokotsa tšebeliso ea lisebelisoa tsa Memcached

Ha ke sheba lenane la ts'ebetso, ke le fumane Ts'ebeliso ea Memcached CPU ke 24.8%!
Ho ka etsahala hore kabo ea cache e kholo haholo, e leng se etsang hore CPU e sebetse palo e kholo ea data.

Phetoho memcached Tlhophiso:

sudo nano /etc/memcached.conf

Hlahloba:

-m 32  # 限制 Memcached 内存使用 32MB

Ebe o qala hape:

sudo systemctl restart memcached

Phello: Fokotsa moroalo oa CPU oa ts'ebetso ea Memcached le ho ntlafatsa ts'ebetso ea cache.

6. Numella Nginx ho boloka lisebelisoa tse tsitsitseng

Hangata, PHP e sebetsa likopo tse nang le palo e kholo ea CSS, JS, litšoantšo, empa lifaele tsena ha li hloke hore PHP e aroloe ho hang!
Tharollo? Sebelisa Nginx ho boloka lisebelisoa tse tsitsitseng!

Fetola tlhophiso ea Nginx:

sudo nano /etc/nginx/nginx.conf

Kenyeletsa ho:

location ~* \.(jpg|jpeg|png|gif|css|js|ico|xml)$ {
    expires max;
    log_not_found off;
}

Ka mor'a ho boloka, qala Nginx hape:

sudo systemctl restart nginx

Phello: Fokotsa palo ea makhetlo a PHP e sebetsanang le lifaele tse tsitsitseng le ho fokotsa ts'ebeliso ea CPU.

7. Fumana mongolo oa PHP o sebelisang CPU ka ho fetisisa

Haeba CPU e ntse e phahame haholo kamora ho ntlafatsoa, ​​​​e kanna ea ba hore mangolo a mang a PHP a sebetsa hampe.
Sebelisa taelo e latelang ho fumana ts'ebetso ea PHP ka ts'ebeliso e phahameng ka ho fetisisa ea CPU:

ps -eo pid,user,pcpu,pmem,args --sort=-pcpu | grep php

Haeba u fumana hore mongolo oa PHP o nka CPU e ngata haholo, u ka e bolaea ka kotloloho:

kill -9 PID

Phello: Tseba ka nepo "liapole tse mpe" 'me u thibele ts'ebetso ea PHP ho nka CPU nako e telele.

Kakaretso: Mekhoa e 7 ea ho ntlafatsa PHP-FPM

Fokotsa palo ea lits'ebetso tsa PHP-FPM, ho thibela ho tlala ha CPU
Numella OPCache, fokotsa ho aroloa khafetsa ha khoutu ea PHP
Ho beha nako ea PHP, ho thibela ts'ebetso ea nako e telele
Ho hlahloba lipotso tse liehang tsa MySQL, ntlafatsa ts'ebetso ea potso ea database
Fetola Memcached Memori, ho fokotsa moroalo oa CPU
Numella Nginx static cache, ho fokotsa moroalo oa ho arola PHP
Fumana lingoloa tsa PHP tsa tšebeliso e phahameng ea CPU, optimization e nepahetseng

ha re phethela

Ntlafatso ea seva e tšoana le boikoetliso, o hloka ho etsa liphetoho tse nepahetseng 'me u se ke oa senya!
Kamora letoto la lintlafatso, mojaro oa seva sa ka oa CPU o theohile ho tloha 80% ho ea ho 15%, sebaka sa marang-rang se bula habeli ka potlako!
Haeba seva sa hau se na le mathata a tšoanang, leka mekhoa ena! 💪

???? Nka bohato hona joale! Ntlafatsa PHP-FPM ea hau 'me u boloke seva ea hau! 🚀

Comments

Aterese ea hau ea lengolo-tsoibila e ke ke ea phatlalatsoa. Ho sebelisoa masimo a hlokahalang * Letšoao

Sengoli sa Lingoloa
Scroll ho Top