LNMP是指Linux、Nginx、MySQL(MariaDB)和PHP這四種軟件的組合,常用于搭建動態網站或服務器。在Ubuntu上配置和測試LNMP環境,可以按照以下步驟進行:
sudo apt update
sudo apt install nginx
sudo apt install mysql-server
在安裝過程中,系統會提示設置MySQL的root用戶密碼,請務必記住該密碼,以便日后使用。
sudo apt install php-fpm php-mysql
/etc/nginx/sites-available/default
。在 location ~ \.php$
塊中,添加以下內容:fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
注意:根據你的PHP版本,fastcgi_pass
行中的路徑可能會有所不同。
sudo systemctl restart nginx
sudo systemctl restart php7.4-fpm
sudo apt install apache2-utils
ab -n 1000 -c 10 http://your-domain.com/
這個命令會對你的網站進行1000次請求,每次請求10個并發連接,以測試服務器的性能。
在進行性能測試之前,建議先對服務器資源(如內存、CPU)進行監控,以確保測試結果的準確性??梢允褂霉ぞ呷?top
或 htop
來實時查看資源使用情況。
worker_processes auto;
worker_cpu_affinity auto;
worker_rlimit_nofile 65535;
http {
sendfile on;
sendfile_max_chunk 512k;
gzip off;
fastcgi_read_timeout 300000;
tcp_nodelay on;
keepalive_timeout 65;
keepalive_requests 100000;
error_log /var/log/nginx/error.log;
access_log off;
server {
proxy_socket_keepalive on;
keepalive_requests 100000;
}
}
opcache.enable=1;
opcache.interned_strings_buffer=64;
opcache.max_accelerated_files=10000;
opcache.memory_consumption=256;
opcache.save_comments=1;
opcache.fast_shutdown=1;
opcache.jit=on;
opcache.jit_buffer_size=128M;
ulimit -n 65535
sysctl -w net.core.somaxconn=65535
sysctl -w net.ipv4.ip_local_port_range="1024 65535"
sysctl -w net.ipv4.tcp_fin_timeout=30
sysctl -w net.ipv4.tcp_slow_start_after_idle=0
sysctl -w net.ipv4.tcp_fastopen=3
sysctl -w net.ipv4.tcp_syncookies=1
sysctl -w net.core.netdev_max_backlog=65535
sysctl -w net.nf_conntrack_max=2097152
sysctl -w net.netfilter.nf_conntrack_max=2097152
sysctl -w net.netfilter.nf_conntrack_tcp_timeout_fin_wait=60
sysctl -w net.netfilter.nf_conntrack_tcp_timeout_time_wait=60
通過以上步驟和優化,你可以對Debian LNMP環境進行壓力測試,并根據測試結果進行相應的調優,以確保服務器在高并發情況下的穩定性和性能。