Ubuntu LAMP(Linux, Apache, MySQL, PHP)系统的调优可以从多个方面进行,包括硬件优化、操作系统优化、Apache优化、MySQL优化和PHP优化。以下是一些基本的调优步骤:
sudo apt update && sudo apt upgrade
/etc/security/limits.conf 文件,增加以下内容:* soft nofile 65535
* hard nofile 65535
/etc/sysctl.conf 文件,添加或修改以下内容:net.core.somaxconn = 65535
net.ipv4.tcp_max_syn_backlog = 65535
net.ipv4.ip_local_port_range = 1024 65535
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_fin_timeout = 30
然后运行 sudo sysctl -p 使更改生效。/etc/apache2/apache2.conf 或 /etc/apache2/mods-enabled/mpm_prefork.conf 文件,根据服务器内存调整 MaxRequestWorkers 参数。<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxRequestWorkers 150
MaxConnectionsPerChild 0
</IfModule>
/etc/apache2/apache2.conf 中启用 KeepAlive 和 MaxKeepAliveRequests:KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
/etc/mysql/my.cnf 或 /etc/mysql/mysql.conf.d/mysqld.cnf 文件,增加以下参数:[mysqld]
innodb_buffer_pool_size = 1G
key_buffer_size = 256M
max_allowed_packet = 64M
table_open_cache = 2000
sort_buffer_size = 2M
join_buffer_size = 2M
query_cache_size 和 query_cache_type。/etc/php/7.x/apache2/php.ini 文件,增加 memory_limit:memory_limit = 256M
max_execution_time:max_execution_time = 300
opcache 扩展已启用,并根据需要调整其参数。htop, iotop, nmon 等来监控系统资源使用情况。通过以上步骤,你可以显著提高Ubuntu LAMP系统的性能和稳定性。不过,具体的调优策略应根据实际应用场景和硬件配置进行调整。