跳转到主要内容
你行网

Main navigation

  • 首页
  • Drupal
  • 编程与开发
  • 数据库
  • 操作系统与应用
  • 服务器与运维
  • 社区
User account menu
  • 登录

面包屑

  1. 首页

阿里云web服务器优化配置

由 hrs, 1 三月, 2025

在你的阿里云服务器上运行 Drupal 10 CMS,并安装了 HTTPD(Apache)、MySQL 和 PHP-FPM,为了确保服务器性能优化并能够高效运行 Drupal,以下是一些优化建议:

---

### 1. 系统层面的优化
1.1 更新系统
确保系统和软件包是最新的,以修复已知漏洞并提升性能:
bash
sudo yum update


1.2 调整内核参数
优化内核参数以提高服务器性能。编辑 `/etc/sysctl.conf` 文件,添加或修改以下内容:
bash
# 增加网络性能
net.core.somaxconn = 65535
net.core.netdev_max_backlog = 65535
net.ipv4.tcp_max_syn_backlog = 65535

# 减少 TCP 连接超时
net.ipv4.tcp_fin_timeout = 15
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1

# 增加文件描述符限制
fs.file-max = 65535

# 增加内存分配
vm.swappiness = 10
vm.overcommit_memory = 1

应用更改:
bash
sudo sysctl -p


1.3 调整文件描述符限制
编辑 `/etc/security/limits.conf`,增加以下内容:
bash
* soft nofile 65535
* hard nofile 65535

然后编辑 `/etc/pam.d/common-session` 和 `/etc/pam.d/common-session-noninteractive`,添加:
bash
session required pam_limits.so


1.4 禁用不必要的服务
禁用不需要的服务以释放资源:
bash
sudo systemctl stop postfix
sudo systemctl disable postfix


---

### 2. Web 服务器(HTTPD/Apache)优化
2.1 启用压缩
启用 Gzip 压缩以减少传输数据量。编辑 `/etc/httpd/conf/httpd.conf`,确保以下内容已启用:
apache
LoadModule deflate_module modules/mod_deflate.so
LoadModule filter_module modules/mod_filter.so

<IfModule mod_deflate.c>
   AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/css text/javascript application/javascript application/x-javascript
</IfModule>


2.2 启用缓存
启用浏览器缓存以减少重复请求。编辑 `/etc/httpd/conf/httpd.conf`,添加:
apache
<IfModule mod_expires.c>
   ExpiresActive On
   ExpiresByType image/jpg "access plus 1 year"
   ExpiresByType image/jpeg "access plus 1 year"
   ExpiresByType image/gif "access plus 1 year"
   ExpiresByType image/png "access plus 1 year"
   ExpiresByType text/css "access plus 1 month"
   ExpiresByType application/pdf "access plus 1 month"
   ExpiresByType text/x-javascript "access plus 1 month"
   ExpiresByType application/x-shockwave-flash "access plus 1 month"
   ExpiresByType image/x-icon "access plus 1 year"
   ExpiresDefault "access plus 2 days"
</IfModule>


2.3 调整 Apache 配置
编辑 `/etc/httpd/conf/httpd.conf`,优化以下参数:
apache
# 减少超时时间
Timeout 60

# 增加最大连接数
MaxKeepAliveRequests 100
KeepAliveTimeout 5

# 调整进程数(根据内存调整)
StartServers 5
MinSpareServers 5
MaxSpareServers 10
ServerLimit 50
MaxRequestWorkers 50
MaxConnectionsPerChild 1000


重启 Apache:
bash
sudo systemctl restart httpd


---

### 3. PHP-FPM 优化
3.1 调整 PHP-FPM 配置
编辑 `/etc/php-fpm.d/www.conf`,优化以下参数:
ini
# 根据内存调整进程数
pm = dynamic
pm.max_children = 20
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 10

# 增加每个进程的内存限制
php_value[memory_limit] = 128M

# 增加脚本执行时间
php_value[max_execution_time] = 180


重启 PHP-FPM:
bash
sudo systemctl restart php-fpm


3.2 启用 OpCache
启用 PHP OpCache 以加速 PHP 执行。编辑 `/etc/php.d/10-opcache.ini`,确保以下内容已启用:
ini
zend_extension=opcache.so
opcache.enable=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1


---

### 4. MySQL 优化
4.1 调整 MySQL 配置
编辑 `/etc/my.cnf`,优化以下参数:
ini
[mysqld]
# 根据内存调整
innodb_buffer_pool_size = 512M
innodb_log_file_size = 64M
innodb_flush_log_at_trx_commit = 2
innodb_flush_method = O_DIRECT
query_cache_type = 1
query_cache_size = 64M
max_connections = 100
key_buffer_size = 64M
tmp_table_size = 64M
max_heap_table_size = 64M


重启 MySQL:
bash
sudo systemctl restart mysqld


4.2 优化数据库表
定期优化 Drupal 数据库表:
bash
mysqlcheck -o -u root -p drupal_database_name


---

### 5. Drupal 优化
5.1 启用缓存
在 Drupal 后台启用页面缓存和区块缓存:
- 进入 Configuration > Performance,启用缓存并设置缓存时间。

5.2 使用 CDN
将静态文件(如图片、CSS、JS)托管到 CDN,以减少服务器负载。

5.3 清理日志
定期清理 Drupal 日志表:
sql
TRUNCATE TABLE watchdog;


---

### 6. 监控与维护
- 使用 `htop` 或 `glances` 监控服务器资源。
- 定期备份数据库和文件。
- 使用日志分析工具(如 GoAccess)分析访问日志。

通过以上优化,你的服务器应该能够更高效地运行 Drupal 10 CMS。如果流量增加,可以考虑升级服务器配置或使用负载均衡。

  • 登录或注册以发表评论
  • 35 次浏览
内容类型分类
技术文章
文章归类
服务器与运维

文章标签

  • httpd

评论

最新文章

  • 内容审核通知 content_moderation_notifications 模块简介
  • 调度程序 scheduler 模块简介
  • 工作流当中的草稿,已发布,很好理解,已归档是怎么理解。
  • 你行网 https://www.dwoke.com seo 关键词
  • brew 是什么命令
  • drupal 9 或 drpal 10 国内内容分享模块 Will Nice social share
  • Views Slideshow - Views Vanilla JavaScript Slideshow (VVJS) 简介和安装方法
  • drupal 11 安装statistics 统计模块
  • drupal11 扩展中找不到Statistics模块
  • drupal11 设置中的“总结摘要”和“切边的” 有什么区别

标签云

adsenseAIapacheaptbadblocksbreadcrumbbrewcentoscertbotckeditorcommandcomposercookiecsharpCSScurlC语言DDEVdiffdnsdockerDreamweaverDrupaldrupal 7drupal 8drupal 9drupal10drupal 11drushExcelfirewalldfirmwareflameshotformgimpgitgzipHTMLHTML5httpdhttp验证inputipjavaJavaScriptJavaSrciptkernelKVMLinuxmavenmbstringmod_expires 模块Mysqlnerdtreenetstatnetworknginxnpmpasswordphpphpmyadminphp扩展RFIDRSSselinuxSEOsharesimple_adsensesshsslStatisticssuperfishsurroundtagcloudstitleubuntuuploadprogressvimVPNVUEWireGuardwpsxdebugyoutubeyumzip主题(theme)二进制五笔分类术语压缩解压哈希值声音字段密码工作流快捷键摄影权限果树种植标签优化模块(module)源地址版本号电子秤电脑基础电脑技巧短信验证端口简介算法网站备份网站运营翻译英语表单视图(views)计算机基础赚钱超五类线网线邮件验证重定向重定向,301错误颜色

相关文章

  • 因权限问题导致drupal cms 无法正常安装,那么该如何解决这个问题
  • kvm虚拟机启动失败:default网络未激活
  • ubuntu 安装kvm 虚拟机
  • foreach 是 PHP 循环语句使用方法
  • implode() 函数的定义和用法
  • Drupal 11 主题制作教程
  • 检查 Composer 是否为官方源
  • 在 Drupal 中权重(Weight)是怎样排序的
  • 解决 Drupal 主题缺失问题
  • 为什么学习php 会一边学,一边忘
RSS源

关于我们

  • 你行网简介
  • 关于我们
  • 版权声明

网站相关

  • 社区论坛
  • 网址导航
  • 网站地图
  • 联系我们

友情链接

  • 英文学习

友情链接2

  • drupal 大学
  • 水滴间
  • 爱码网
  • Apache

友情链接3

  • MySQL
  • php
  • drupalcode

友情链接4

  • Drupal 中国
  • Drupal 老葛
  • 宁浩网
  • drupal 台湾
Copyright © 2019 - 2021 你行网 版权所有  粤ICP备19072650号-1