CentOS Stream 9云主机系统安装与环境配置
在 CentOS Stream 9 云主机上进行系统安装与环境配置,可以按照以下步骤进行。这里假设你已经通过云服务提供商(如 AWS、阿里云等)创建了一台 CentOS Stream 9 的实例,或者通过本地虚拟化工具(如 VirtualBox、VMware)安装了该系统。一、系统安装后初始配置
[*]登录系统
[*]使用 SSH 客户端(如 PuTTY、OpenSSH)连接到你的云主机。
[*]输入用户名(通常是 root 或你创建的用户)和密码进行登录。
[*]更新系统
[*]运行以下命令更新系统到最新版本:
sudo dnf update -y
[*]设置时区和时间
[*]使用 timedatectl 命令设置时区,例如设置为上海时区:
sudo timedatectl set-timezone Asia/Shanghai
[*]启用 NTP 同步:
sudo timedatectl set-ntp true
[*]配置网络
[*]确保网络连接正常,可以使用 ping 命令测试外网连通性。
[*]如果需要配置静态 IP,编辑 /etc/sysconfig/network-scripts/ifcfg-eth0(或对应的网卡配置文件),设置 BOOTPROTO=static,并指定 IPADDR、NETMASK、GATEWAY 和 DNS1。
[*]创建新用户并配置 sudo 权限
[*]创建一个新用户:
sudo adduser yourusername
[*]为新用户设置密码:
sudo passwd yourusername
[*]将新用户添加到 wheel 组以获得 sudo 权限:
sudo usermod -aG wheel yourusername
二、环境配置
[*]安装常用工具
[*]安装一些常用的系统工具和开发工具:
sudo dnf groupinstall "Development Tools" -y
sudo dnf install -y vim wget curl git net-tools
[*]配置防火墙
[*]CentOS Stream 9 默认使用 firewalld 作为防火墙。
[*]开放常用端口,例如 HTTP (80)、HTTPS (443)、SSH (22):
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --reload
[*]安装和配置 Web 服务器(可选)
[*]例如安装 Nginx:
sudo dnf install -y nginx
sudo systemctl start nginx
sudo systemctl enable nginx
[*]安装数据库(可选)
[*]例如安装 MariaDB:
sudo dnf install -y mariadb-server
sudo systemctl start mariadb
sudo systemctl enable mariadb
# 运行安全脚本
sudo mysql_secure_installation
[*]安装编程语言环境(可选)
[*]例如安装 Python 3:
sudo dnf install -y python3
[*]或者安装 Node.js:
# 添加 NodeSource 仓库
curl -fsSL https://rpm.nodesource.com/setup_18.x | sudo bash -
sudo dnf install -y nodejs
三、安全配置
[*]SSH 安全
[*]编辑 /etc/ssh/sshd_config,禁用 root 登录和密码认证,使用密钥认证:
PermitRootLogin no
PasswordAuthentication no
[*]重启 SSH 服务:
sudo systemctl restart sshd
[*]定期更新系统
[*]设置定期更新任务,可以使用 cron 或 dnf-automatic。
[*]安装和配置 Fail2Ban(可选)
[*]防止暴力破解:
sudo dnf install -y fail2ban
sudo systemctl start fail2ban
sudo systemctl enable fail2ban
四、监控与日志
[*]安装监控工具
[*]例如安装 htop、glances:
sudo dnf install -y htop glances
[*]配置日志管理
[*]使用 journalctl 查看系统日志,或配置 rsyslog 发送日志到远程服务器。
五、备份与恢复
[*]定期备份重要数据
[*]使用 rsync、tar 或云服务商提供的备份工具。
[*]测试恢复流程
[*]确保在需要时能够快速恢复系统或数据。
总结
以上步骤涵盖了 CentOS Stream 9 云主机的基本安装与环境配置。根据你的具体需求,可能还需要安装其他软件或进行更详细的配置。始终记得在修改系统配置前备份重要数据,并在生产环境中谨慎操作。
页:
[1]