CentOS配置指南
系统初始化
网络配置

- 编辑
/etc/sysconfig/network-scripts/ifcfg-ens33(根据实际网卡名称修改)。 - 设置
ONBOOT=yes确保开机启动。 - 设置
BOOTPROTO=static使用静态IP地址。 - 添加
IPADDR=192.168.1.100、NETMASK=255.255.255.0、GATEWAY=192.168.1.1分别配置IP地址、子网掩码和网关。
- 编辑
主机名配置
- 编辑
/etc/hostname。 - 设置主机名为
centos-server。 - 编辑
/etc/hosts,添加0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4和:1 localhost localhost.localdomain localhost6 localhost6.localdomain6。
- 编辑
基础环境配置
更新系统
- 运行
sudo yum update -y更新所有系统包。
- 运行
安装基本工具
- 运行
sudo yum install -y net-tools openssh-server openssh-clients安装网络工具和SSH服务。
- 运行
SSH服务配置

- 编辑
/etc/ssh/sshd_config。 - 设置
PermitRootLogin no禁止root用户登录。 - 设置
PasswordAuthentication yes允许密码登录。 - 重启SSH服务
sudo systemctl restart sshd。
- 编辑
安全设置
关闭不必要的端口
- 使用
sudo iptables -A INPUT -p tcp --dport 22 -j DROP关闭SSH端口。 - 使用
sudo iptables -A INPUT -p tcp --dport 80 -j DROP关闭HTTP端口。
- 使用
设置防火墙
- 编辑
/etc/sysconfig/iptables。 - 添加规则允许SSH和SSH端口。
- 重启防火墙
sudo systemctl restart iptables。
- 编辑
常用软件安装
安装MySQL
- 运行
sudo yum install -y mysql-community-server。 - 启动MySQL服务
sudo systemctl start mysqld。 - 设置开机自启
sudo systemctl enable mysqld。
- 运行
安装Apache

- 运行
sudo yum install -y httpd。 - 启动Apache服务
sudo systemctl start httpd。 - 设置开机自启
sudo systemctl enable httpd。
- 运行
FAQs
Q1:如何查看CentOS的版本信息?
A1:在终端运行 cat /etc/redhat-release 命令即可查看CentOS的版本信息。
Q2:如何修改CentOS的默认密码?
A2:登录到系统,然后运行 passwd root 命令,根据提示输入新密码即可。
【版权声明】:本站所有内容均来自网络,若无意侵犯到您的权利,请及时与我们联系将尽快删除相关内容!
发表回复