温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎样配置linux服务器

发布时间:2026-09-11 06:24:09 来源:亿速云 阅读:102 作者:小樊 栏目:系统运维

配置 Linux 服务器是一个比较宽泛的话题,具体步骤取决于你用什么发行版(如 Ubuntu、CentOS、Debian)以及服务器用途(Web 服务器、数据库、开发环境等)。

下面我给你一个通用、实用的 Linux 服务器基础配置流程,适合新手和常见生产环境。


一、前期准备

  1. 选择发行版
    • 新手推荐:Ubuntu 22.04 / 24.04
    • 企业常用:CentOS Stream / Rocky Linux / AlmaLinux
  2. 登录服务器
    ssh root@服务器IP
    

二、基础系统配置

1. 更新系统

# Ubuntu / Debian
apt update && apt upgrade -y

# CentOS / Rocky
dnf update -y

2. 创建普通用户(安全第一)

adduser deploy
usermod -aG sudo deploy   # Ubuntu
# CentOS 用 wheel 组

3. 配置 SSH 安全

编辑配置文件:

vim /etc/ssh/sshd_config

建议修改:

PermitRootLogin no
PasswordAuthentication no

然后重启:

systemctl restart sshd

4. 配置防火墙

# Ubuntu
ufw allow 22
ufw allow 80
ufw allow 443
ufw enable

# CentOS
firewall-cmd --add-service=ssh --permanent
firewall-cmd --add-service=http --permanent
firewall-cmd --reload

三、常用环境配置

1. 安装基础工具

apt install -y curl wget git vim unzip

2. 配置时间同步

timedatectl set-timezone Asia/Shanghai

3. 安装 Nginx(Web 服务示例)

apt install nginx -y
systemctl enable nginx

4. 安装 Docker(可选)

curl -fsSL https://get.docker.com | sh
systemctl enable docker

四、安全增强(推荐)

1. 禁用不必要的服务

systemctl disable bluetooth

2. 安装 fail2ban

apt install fail2ban -y

3. 定期备份

  • 数据库:mysqldump
  • 文件:rsync / 云备份

五、监控与维护

  • htop 查看资源
  • journalctl 查看日志
  • df -h 查看磁盘

六、示例:一台 Web 服务器最小配置清单

✅ 非 root 用户
✅ SSH 密钥登录
✅ 防火墙开启
✅ Nginx + 域名
✅ 自动更新或定期更新


如果你能告诉我:

  • 使用的 Linux 发行版
  • 服务器 用途(网站 / API / 数据库 / 游戏等)

我可以给你更精确的一步一步配置方案。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI
助
手