特性 | CentOS 6 | CentOS 7 |
---|---|---|
初始化系统 | SysV init | Systemd |
防火墙 | iptables | firewalld |
默认文件系统 | ext4 | XFS |
网络配置 | /etc/sysconfig/network-scripts/ | systemd-networkd/nmcli |
服务管理命令 | service/chkconfig | systemctl |
CentOS 6:
yum update -y
yum install -y wget curl vim
service iptables stop
chkconfig iptables off
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
CentOS 7:
yum update -y
yum install -y wget curl vim
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
CentOS 6:
yum install -y httpd
service httpd start
chkconfig httpd on
CentOS 7:
yum install -y httpd
systemctl start httpd
systemctl enable httpd
CentOS 6:
yum install -y mysql-server mysql
service mysqld start
chkconfig mysqld on
mysql_secure_installation
CentOS 7:
yum install -y mariadb-server mariadb
systemctl start mariadb
systemctl enable mariadb
mysql_secure_installation
CentOS 6:
yum install -y php php-mysql php-gd php-xml
service httpd restart
CentOS 7:
yum install -y php php-mysql php-gd php-xml
systemctl restart httpd
通用优化:
- 启用KeepAlive (KeepAlive On
in httpd.conf)
- 调整MPM模块配置 (Prefork/Worker/Event)
- 启用OPcache (PHP加速)
- 配置适当的Expires头
CentOS 7特有:
# 使用systemd优化服务启动
systemctl edit httpd.service
# 添加CPU和内存限制等参数
CentOS 6:
# 使用iptables限制访问
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
service iptables save
CentOS 7:
# 更推荐使用firewalld
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
CentOS 6:
# 使用logrotate默认配置
vim /etc/logrotate.d/httpd
CentOS 7:
# 可使用journalctl查看系统日志
journalctl -u httpd -f
# 同时仍然支持logrotate
从CentOS 6迁移到CentOS 7时需要注意:
1. 服务管理命令从service
改为systemctl
2. iptables规则需要转换为firewalld规则
3. MySQL被MariaDB替代,但基本兼容
4. 网络配置方式变化
5. 文件系统默认从ext4变为XFS
CentOS 7在Web服务器搭建和管理上提供了更现代的解决方案,特别是systemd的引入大大简化了服务管理。对于新部署,强烈建议使用CentOS 7或更高版本。对于仍在使用CentOS 6的环境,应考虑尽快升级以获得更好的性能、安全性和管理便利性。