CentOS 系统设置指南

系统初始化配置
1 设置主机名
在终端输入以下命令,设置主机名为“centos-server”:
hostnamectl set-hostname centos-server
2 设置时区
使用以下命令设置时区为“Asia/Shanghai”:
timedatectl set-timezone Asia/Shanghai
3 设置网络配置
编辑网络配置文件 /etc/sysconfig/network-scripts/ifcfg-ens33(根据实际网卡名称修改),设置以下参数:
BOOTPROTO=static ONBOOT=yes IPADDR=192.168.1.100 NETMASK=255.255.255.0 GATEWAY=192.168.1.1 DNS1=8.8.8.8 DNS2=8.8.4.4
重启网络服务:
systemctl restart network
系统安全设置
1 设置防火墙
安装firewalld:
yum install firewalld
设置防火墙允许SSH服务:
firewall-cmd --permanent --add-service=ssh firewall-cmd --reload
2 设置SELinux

关闭SELinux:
setenforce 0
编辑 /etc/selinux/config 文件,将 SELINUX=enforcing 改为 SELINUX=disabled。
系统优化设置
1 关闭不需要的服务
关闭并禁用不必要的服务,如:
systemctl stop cups systemctl disable cups
2 优化内核参数
编辑 /etc/sysctl.conf 文件,添加以下内容:
net.ipv4.tcp_fin_timeout = 30 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_tw_recycle = 1 net.ipv4.tcp_keepalive_time = 600
重启网络服务:
systemctl restart network
软件安装与配置
1 安装Apache
安装Apache:
yum install httpd
启动Apache服务:
systemctl start httpd
设置Apache服务开机自启:

systemctl enable httpd
2 安装MySQL
安装MySQL:
yum install mysql-server
启动MySQL服务:
systemctl start mysqld
设置MySQL服务开机自启:
systemctl enable mysqld
FAQs
Q1:如何查看系统版本?
A1:在终端输入以下命令:
cat /etc/redhat-release
Q2:如何查看系统CPU信息?
A2:在终端输入以下命令:
cat /proc/cpuinfo
是CentOS系统设置的基本步骤,希望对您有所帮助,在实际操作过程中,请根据实际情况进行调整。
