以下是CentOS LAMP网络配置的核心步骤,涵盖IP设置、服务优化及安全配置:
ip addr show # 确认网卡名称(如eth0、ens33)
vi /etc/sysconfig/network-scripts/ifcfg-<网卡名>
关键参数(静态IP示例):BOOTPROTO=static # 静态IP
IPADDR=192.168.1.100 # IP地址
NETMASK=255.255.255.0 # 子网掩码
GATEWAY=192.168.1.1 # 网关
DNS1=8.8.8.8 # DNS服务器
ONBOOT=yes # 开机自启
systemctl restart network
ip addr show <网卡名> # 检查IP是否生效
ping www.baidu.com # 测试网络连通性
/etc/httpd/conf/httpd.conf,确认Listen 80(HTTP)和Listen 443(HTTPS)。mod_rewrite(URL重写)和mod_ssl(HTTPS支持)已启用。/etc/my.cnf,将bind-address设为0.0.0.0,并重启MySQL。/etc/php.d/opcache.ini),调整memory_limit和max_execution_time。firewall-cmd --permanent --add-service=http --add-service=https # 放行HTTP/HTTPS
firewall-cmd --reload
firewall-cmd --permanent --add-rich-rule='rule source address="192.168.1.0/24" port protocol=tcp port=3306 accept'
setsebool -P httpd_can_network_connect=1 # 允许Apache访问网络
/var/www/html/info.php,内容为<?php phpinfo(); ?>,通过浏览器访问http://IP/info.php。mysql -h <服务器IP> -u root -p
注意:根据实际网络环境调整IP、网关等参数,生产环境需额外加强安全策略,如限制SSH访问、定期更新系统补丁等。