在Ubuntu中設置Apache并發連接,需修改配置文件并調整MPM模塊參數,具體步驟如下:
選擇MPM模塊
sudo nano /etc/apache2/mods-available/mpm_*.conf(如mpm_event.conf)。event或worker模塊(多線程處理,資源占用低),非線程安全應用選prefork。核心參數調整
MaxClients):設置最大并發連接數,需結合服務器內存計算(建議不超過內存支持的最大進程數)。<IfModule mpm_event_module>
MaxRequestWorkers 150 # 根據服務器資源調整
</IfModule>
worker/event模塊):每個子進程的線程數,影響并發處理能力。ThreadsPerChild 25 # 每個子進程25個線程
其他優化參數
KeepAlive On
KeepAliveTimeout 5
MaxKeepAliveRequests 100 # 單個連接最大請求數
重啟服務并驗證
sudo systemctl restart apache2
sudo apachectl configtest # 檢查配置語法
注意:修改后需通過htop或ab(Apache Benchmark)工具監控服務器負載,避免參數設置過高導致資源耗盡。
參考來源: