如何在Hetzner根服务器上安装CentOS 7

时间:2020-02-23 14:30:37  来源:igfitidea点击:

在本文中,我们将重点介绍在Hetzner根服务器上安装CentOS 7. Hetzner是一家云托管,提供按月计费模式的极具竞争力的价格拍卖物理服务器硬件。

我们将在具有以下规格的Hetzner根服务器上进行此安装。

CPU: Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz (12 cores)
Memory: 64GB RAM
Disk: 2 x 1024GB NVMe SSDs
Network: 1Gbit
IPV4 Adresses: 1 x IPV4 public address

请注意,使用Hetzner Root服务器,我们将获得一个IPv4公用IP地址,但是我们可以请求使用其他IP或者子网。

启动救援模式

登录到根服务器的Hetzner控制台,然后导航到"主要功能"下的"服务器"部分。

主要功能>服务器>服务器标签>救援

选择要在救援模式下使用的操作系统,CPU体系结构和公共密钥,然后单击"激活救援系统"。

在"重置服务器"部分下重新引导服务器。

创建根服务器配置。

使用Rescue激活期间显示的root用户和密码,以抢救模式SSH到服务器。

$ssh theitroad@localhost

 Welcome to the Hetzner Rescue System.
 This Rescue System is based on Debian 9 (stretch) with a newer
   kernel. You can install software as in a normal system.
 To install a new operating system from one of our prebuilt
   images, run 'installimage' and follow the instructions.
 More information at http://wiki.hetzner.de
 
 Rescue System up since 2019-07-04 23:34 +02:00
 Last login: Sat May  6 09:03:05 2019 from 41.90.217.125
 Hardware data:
 CPU1: Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz (Cores 12)
    Memory:  64339 MB
    Disk /dev/nvme0n1: 1024 GB (=> 953 GiB) 
    Disk /dev/nvme1n1: 1024 GB (=> 953 GiB) 
    Total capacity 1907 GiB with 2 Disks
 Network data:
    eth0  LINK: yes
          MAC:  b4:2e:99:47:fa:5c
          IP:   xxxxxxxxxxxxxxxxxx
          IPv6: xxxxxxxxxxxxxxxxxx
          Intel(R) PRO/1000 Network Driver
 theitroad@localhost ~ #

我的根服务器有两个磁盘@ 512GB。将它们配置为非冗余RAID 1(剥离)配置。让我们从预先构建的镜像之一创建Hetzner服务器配置,以供installimage用于新操作系统。

$vim  install-config.txt
DRIVE1 /dev/nvme0n1
DRIVE2 /dev/nvme1n1
SWRAID 1
SWRAIDLEVEL 0
BOOTLOADER grub
HOSTNAME myrootserver.theitroad.local
PART /boot ext3 512M
PART lvm vg0 200G
#PART lvm vg0 all

LV vg0 root/xfs 50G
LV vg0 swap swap swap 16G
LV vg0 var /var  xfs  100G
LV vg0 tmp /tmp  xfs  30G

IMAGE /root/.oldroot/nfs/install/../images/CentOS-76-64-minimal.tar.gz

配置完成后,安装镜像并创建分区。

# installimage -a -c install-config.txt

安装应该开始。

安装过程。

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 centos 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 ext3                done 
         :    formatting /dev/vg0/root with xfs             done 
         :    formatting /dev/vg0/swap with swap            done 
         :    formatting /dev/vg0/var with xfs              done 
         :    formatting /dev/vg0/tmp with xfs              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 centos 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 password as you logged in to the rescue system.

安装完成后,重新启动服务器。

# shutdown -r now

登录并确认服务器安装。

[theitroad@localhost ~]# cat /etc/os-release 
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

更新CentOS并安装基本软件包。

sudo yum -y update
sudo yum -y install vim wget curl bash-completion epel-release telnet

我们现在已经在Hetzner根服务器上成功安装了CentOS 7.