雷达智富

首页 > 内容 > 程序笔记 > 正文

程序笔记

如何在 Hetzner 根服务器上安装 Debian 12

2024-07-09 52

Debian 12(Bookworm) 是 Debian 的最新稳定版本,比其前身 Bullseye 附带了更多的软件。如果您对在 Hetzner 根服务器上安装 Debian 12 感兴趣,那么本文就是为您准备的。 Hetzner Cloud 提供专用服务器产品,让您能够完全访问和控制以根据自己的喜好配置服务器。请访问 Hetzner Online GmbH,查看专用服务器硬件的服务器拍卖,每月支付的价格极具竞争力。

我们有一台具有以下硬件规格的专用服务器。

CPU: Intel(R) Xeon(R) CPU E5-1650 v3 @ 3.50GHz (Cores 12)
Memory: 256GB RAM
Disk: 2 x 480GB SSD
Network: 1Gbit
IPV4 Addresses: 1 x IPV4 public address

您从 Hetzner 订购的每台根服务器都附带一个 IPv4 公共 IP 地址。但可按需提供额外的公共 IP 地址。

1) 订购专用服务器

访问 https://www.hetzner.com/sb 并搜索服务器。您可以按价格、位置、CPU、内存、驱动器等过滤搜索结果

2) 进入救援模式

订单完成后,登录并访问 Hetzner 根服务器控制台,然后导航至主要功能 > 服务器 > 服务器标签 > 救援部分,以救援模式启动服务器。

选择 Linux 操作系统和适合您的 CPU 的架构。选择公钥或密码身份验证方法,然后激活救援系统

在“重置”部分下重新启动服务器以使用救援系统。

3)为installimage创建安装配置

服务器重新启动后,使用 root 用户名和密码/密钥身份验证选项通过 ssh 连接到服务器。

$ ssh root@ServerIP
Linux rescue 6.5.5 #1 SMP Mon Sep 25 03:07:50 UTC 2023 x86_64

-------------------------------------------------------------------------------------------------------------------------

  Welcome to the Hetzner Rescue System.

  This Rescue System is based on Debian GNU/Linux 12 (bookworm) with a custom kernel.
  You can install software like you would in a normal system.

  To install a new operating system from one of our prebuilt images, run 'installimage' and follow the instructions.

  Important note: Any data that was not written to the disks will be lost during a reboot.

  For additional information, check the following resources:
    Rescue System:           https://docs.hetzner.com/robot/dedicated-server/troubleshooting/hetzner-rescue-system
    Installimage:            https://docs.hetzner.com/robot/dedicated-server/operating-systems/installimage
    Install custom software: https://docs.hetzner.com/robot/dedicated-server/operating-systems/installing-custom-images
    other articles:          https://docs.hetzner.com/robot

-------------------------------------------------------------------------------------------------------------------------

Rescue System up since 2023-10-09 11:21 +02:00

Hardware data:

   CPU1: Intel(R) Xeon(R) CPU E5-1650 v3 @ 3.50GHz (Cores 12)
   Memory:  257647 MB
   Disk /dev/sda: 480 GB (=> 447 GiB) doesn't contain a valid partition table
   Disk /dev/sdb: 480 GB (=> 447 GiB) doesn't contain a valid partition table
   Total capacity 894 GiB with 2 Disks

Network data:
   eth0  LINK: yes
         MAC:  xxxxxx
         IP:   yyyyyy
         IPv6: zzzzzz
         Intel(R) Gigabit Ethernet Network Driver

从输出中我们可以确认服务器有两个磁盘@480GB

Disk /dev/sda: 480 GB (=> 447 GiB) doesn't contain a valid partition table
Disk /dev/sdb: 480 GB (=> 447 GiB) doesn't contain a valid partition table

我们将在非冗余 RAID 0 配置中配置它们。首先创建安装程序配置文件。

vim install-config.txt

修改下面提供的示例配置参数以满足您的安装要求。

# Define disks to be used
DRIVE1 /dev/sda
DRIVE2 /dev/sdb

# Enable Raid 0
SWRAID 1
SWRAIDLEVEL 0 # Use 1 for Raid 1
BOOTLOADER grub
HOSTNAME deb12.example.com # Set correct hostname
PART /boot ext4 512M
PART lvm vg0 all
LV vg0 root / ext4 50G
LV vg0 swap swap swap 8G
LV vg0 var /var  ext4  300G
# List images with ls /root/.oldroot/nfs/install/../images
IMAGE /root/images/Debian-1202-bookworm-amd64-base.tar.gz

根据存储硬件和可用空间配置您自己的分区方案。

4) 在 Hetzner 根服务器上安装 Debian 12 (Bookworm)

创建自定义配置后,适用于安装 Debian 12 Linux 系统。

# installimage -a -c install-config.txt

应立即开始安装。

Found AUTOSETUP file '/autosetup'
Running unattended installimage installation ...

DRIVE1 /dev/sda
DRIVE2 /dev/sdb
SWRAID 1
SWRAIDLEVEL 0 # Use 1 for Raid 1
BOOTLOADER grub
HOSTNAME myrootserver.computingforgeeks.com
PART /boot ext3 512M
PART lvm vg0 all
LV vg0 root / ext4 50G
LV vg0 swap swap swap 8G
LV vg0 var /var  ext4  300G
IMAGE /root/.oldroot/nfs/install/../images/Debian-1201-bookworm-amd64-base.tar.gz

WARNING:
  Starting installation in 20 seconds ...
  Press X to continue immediately ...
  Installation will DELETE ALL DATA ON DISK(s)!
  Press CTRL-C to abort now!

安装完全自动化,生成配置后无需用户输入。

Hetzner Online GmbH - installimage

  Your server will be installed now, this will take some minutes
             You can abort at any time with CTRL+C ...

         :  Reading configuration                           done
         :  Loading image file variables                    done
         :  Loading debian specific functions               done
   1/17  :  Deleting partitions                             done
   2/17  :  Test partition size                             done
   3/17  :  Creating partitions and /etc/fstab              done
   4/17  :  Creating software RAID level 0                  done
   5/17  :  Creating LVM volumes                            done
   6/17  :  Formatting partitions
         :    formatting /dev/md/0 with ext4                done
         :    formatting /dev/vg0/root with ext4            done
         :    formatting /dev/vg0/swap with swap            done
         :    formatting /dev/vg0/var with ext4             done
   7/17  :  Mounting partitions                             done
   8/17  :  Sync time via ntp                               done
         :  Importing public key for image validation       done
   9/17  :  Validating image before starting extraction     done
  10/17  :  Extracting image (local)                        done
  11/17  :  Setting up network config                       done
  12/17  :  Executing additional commands
         :    Setting hostname                              done
         :    Generating new SSH keys                       done
         :    Generating mdadm config                       done
         :    Generating ramdisk                            done
         :    Generating ntp config                         done
  13/17  :  Setting up miscellaneous files                  done
  14/17  :  Configuring authentication
         :    Fetching SSH keys                             done
         :    Disabling root password                       done
         :    Disabling SSH root login without password     done
         :    Copying SSH keys                              done
  15/17  :  Installing bootloader grub                      done
  16/17  :  Running some debian specific functions          done
  17/17  :  Clearing log files                              done

                  INSTALLATION COMPLETE
   You can now reboot and log in to your new system with the
 same credentials that you used to log into the rescue system.

安装 Debian 12 后,请重新启动服务器以开始使用它。

# shutdown -r now

使用为服务器配置的公共 IP 地址可以通过 SSH 进行远程访问。

$ ssh root@serverip
Enter passphrase for key '/Users/jmutai/.ssh/id_rsa':
Linux pve01 6.2.16-15-pve #1 SMP PREEMPT_DYNAMIC PMX 6.2.16-15 (2023-09-28T13:53Z) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.

可以使用下面共享的命令检查磁盘分区方案和 LVM 分区。

# lsblk
NAME           MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
sda              8:0    0 447.1G  0 disk
├─sda1           8:1    0   512M  0 part
│ └─md0          9:0    0   511M  0 raid1 /boot
└─sda2           8:2    0 446.6G  0 part
  └─md1          9:1    0   893G  0 raid0
    ├─vg0-root 253:0    0    50G  0 lvm   /
    ├─vg0-swap 253:1    0     8G  0 lvm   [SWAP]
    └─vg0-var  253:2    0   300G  0 lvm   /var
sdb              8:16   0 447.1G  0 disk
├─sdb1           8:17   0   512M  0 part
│ └─md0          9:0    0   511M  0 raid1 /boot
└─sdb2           8:18   0 446.6G  0 part
  └─md1          9:1    0   893G  0 raid0
    ├─vg0-root 253:0    0    50G  0 lvm   /
    ├─vg0-swap 253:1    0     8G  0 lvm   [SWAP]
    └─vg0-var  253:2    0   300G  0 lvm   /var

# pvs
  PV         VG  Fmt  Attr PSize   PFree
  /dev/md1   vg0 lvm2 a--  893.00g 535.00g

# vgs
  VG  #PV #LV #SN Attr   VSize   VFree
  vg0   1   3   0 wz--n- 893.00g 535.00g

# lvs
  LV   VG  Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root vg0 -wi-ao----  50.00g
  swap vg0 -wi-ao----   8.00g
  var  vg0 -wi-ao---- 300.00g

从卷组中的可用空间扩展 LVM 很容易。在此示例中,我们将额外的 50GB 添加到 /dev/vg0/var 逻辑卷。

# lvextend -r -L +50G /dev/vg0/vg0

通过查询操作系统版本信息确认 Debian 安装成功:

root@proxmox ~ # cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/";
SUPPORT_URL="https://www.debian.org/support";
BUG_REPORT_URL="https://bugs.debian.org/";

阻止默认启用的 rpcbind 端口 111

iptables -A INPUT -p tcp -m tcp --dport 111 -j DROP
iptables -A INPUT -p udp -m udp --dport 111 -j DROP
sudo /sbin/iptables-save

您可以选择完全禁用该服务。

sudo systemctl disable --now rpcbind rpcbind.socket

升级您的系统并更新所有已安装的软件包。

apt update && apt -y full-upgrade
apt install wget vim sudo bash-completion
[ -f /var/run/reboot-required ] && reboot -f

如果您需要安装 Proxmox VE,请查看以下文章。

  • 如何在 Debian 12 上安装 Proxmox VE 8 (Bookworm)

更新于:2个月前
赞一波!2

文章评论

全部评论