重启后 RAID 阵列不会重新组装

重启后 RAID 阵列不会重新组装

重启后 RAID 阵列未组装。

我有一块用于启动系统的 SSD,以及三块属于阵列的 HDD。系统是 Ubuntu 16.04。

我所遵循的步骤主要基于本指南:

https://www.digitalocean.com/community/tutorials/how-to-create-raid-arrays-with-mdadm-on-ubuntu-16-04#creating-a-raid-5-array

  1. 确认我是否可以出发。

    lsblk -o NAME,SIZE,FSTYPE,TYPE,MOUNTPOINT
    

输出结果显示除了 SSD 分区之外,还有 sda、sdb 和 sdc 设备。我通过查看以下输出验证了这些设备是否确实代表 HDD:

hwinfo --disk

一切都匹配。

  1. 組織阵列。

    sudo mdadm --create --verbose /dev/md0 --level=5 --raid-devices=3 /dev/sda /dev/sdb /dev/sdc
    

我通过输入以下内容来验证它是否正常:cat /proc/mdstat

输出如下所示:

Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md0 : active raid5 sdc[3] sdb[1] sda[0]
      7813774336 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/2] [UU_]
      [=======>.............]  recovery = 37.1% (1449842680/3906887168) finish=273.8min speed=149549K/sec
      bitmap: 0/30 pages [0KB], 65536KB chunk

unused devices: <none>

我等到这个过程结束。

Personalities : [raid1] [linear] [multipath] [raid0] [raid6] [raid5] [raid4] [raid10] 
md0 : active raid5 sdc[3] sdb[1] sda[0]
      209584128 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]

unused devices: <none>
  1. 创建并安装文件系统。

    sudo mkfs.ext4 -F /dev/md0
    
    sudo mkdir -p /mnt/md0
    
    sudo mount /dev/md0 /mnt/md0
    
    df -h -x devtmpfs -x tmpfs
    

我输入了一些数据,输出如下所示:

Filesystem      Size  Used Avail Use% Mounted on
/dev/nvme0n1p2  406G  191G  196G  50% /
/dev/nvme0n1p1  511M  3.6M  508M   1% /boot/efi
/dev/md0        7.3T  904G  6.0T  13% /mnt/md0
  1. 保存阵列布局。

    sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf
    
    sudo update-initramfs -u
    
    echo '/dev/md0 /mnt/md0 ext4 defaults,nofail,discard 0 0' | sudo tee -a /etc/fstab
    
  2. 重新启动并验证一切是否正常工作。

重启后我尝试:cat /proc/mdstat
它没有显示任何活动的 raid 设备。

ls /mnt/md0 

是空的。

以下命令不会打印任何内容并且也不起作用:

mdadm --assemble --scan -v

仅以下操作可恢复包含数据的阵列:

sudo mdadm --create --verbose /dev/md0 --level=5 --raid-devices=3 /dev/sda /dev/sdb /dev/sdc

应该做哪些不同的事情?

其他可能有用的信息:

sudo dpkg-reconfigure mdadm

输出显示:

update-initramfs: deferring update (trigger activated)
Generating grub configuration file ...
Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
Found linux image: /boot/vmlinuz-4.4.0-51-generic
Found initrd image: /boot/initrd.img-4.4.0-51-generic
Found linux image: /boot/vmlinuz-4.4.0-31-generic
Found initrd image: /boot/initrd.img-4.4.0-31-generic
Adding boot menu entry for EFI firmware configuration
done
update-rc.d: warning: start and stop actions are no longer supported; falling back to defaults
Processing triggers for initramfs-tools (0.122ubuntu8.5) ...
update-initramfs: Generating /boot/initrd.img-4.4.0-51-generic

对我来说最有趣的部分是“启动和停止操作不再受支持;恢复为默认设置”

此外,/usr/share/mdadm/mkconf 的输出最后不会打印任何数组。

# mdadm.conf
#
# Please refer to mdadm.conf(5) for information about this file.
#

# by default (built-in), scan all partitions (/proc/partitions) and all
# containers for MD superblocks. alternatively, specify devices to scan, using
# wildcards if desired.
#DEVICE partitions containers

# auto-create devices with Debian standard permissions
CREATE owner=root group=disk mode=0660 auto=yes

# automatically tag new arrays as belonging to the local system
HOMEHOST <system>

# instruct the monitoring daemon where to send mail alerts
MAILADDR [email protected]

# definitions of existing MD arrays

而 cat /etc/mdadm/mdadm.conf 的输出却是这样的。

# mdadm.conf
#
# Please refer to mdadm.conf(5) for information about this file.
#

# by default (built-in), scan all partitions (/proc/partitions) and all
# containers for MD superblocks. alternatively, specify devices to scan, using
# wildcards if desired.
#DEVICE partitions containers

# DEVICE /dev/sda /dev/sdb /dev/sdc

# auto-create devices with Debian standard permissions
CREATE owner=root group=disk mode=0660 auto=yes

# automatically tag new arrays as belonging to the local system
HOMEHOST <system>

# instruct the monitoring daemon where to send mail alerts
MAILADDR [email protected]

# definitions of existing MD arrays

# This file was auto-generated on Sun, 04 Dec 2016 18:56:42 +0100
# by mkconf $Id$

ARRAY /dev/md0 metadata=1.2 spares=1 name=hinton:0 UUID=616991f1:dc03795b:8d09b1d4:8393060a

有什么解决办法?我浏览了半个互联网,似乎没有人遇到同样的问题。

几天前我也在 serverfault 上添加了完全相同的问题(没有答案)。如果我这样做违反了 stack exchange 的社区规则,我深表歉意。

答案1

我遇到了同样的问题,我不确定,但我发现的解决方法是在 LINUX Raid 类型的 raid 成员上创建新的分区,然后在创建阵列时我使用该分区而不是使用该设备。

答案2

看起来这是使用时相当常见的问题整个磁盘在一个数组中。

这篇文章给出了该问题的最新总结以及我如何解决这个问题:重启后,mdadm RAID 底层的 LVM 消失

这篇文章帮助我理解并解决了我的问题:使用分区或直接使用整个磁盘创建 mdadm 阵列有什么区别

答案3

我无法重现您的确切问题,但我认为我找到了系统行为的可能原因:

当您使用以下命令创建 3 磁盘 RAID5 阵列时:

sudo mdadm --create --verbose /dev/md0 --level=5 --raid-devices=3 /dev/sda /dev/sdb /dev/sdc

当 RAID 设备处于恢复状态时,mdadm scan 命令显示:

sudo mdadm --detail --scan
ARRAY /dev/md0 metadata=1.2 spares=1 name=desktop:0 UUID=da60c69a:1cbe4f2e:e83d0971:0520ac89

恢复过程完成后,该spares=1参数就消失了:

sudo mdadm --detail --scan
ARRAY /dev/md0 metadata=1.2 name=desktop:0 UUID=da60c69a:1cbe4f2e:e83d0971:0520ac89

我假设,在完全恢复的软件 RAID5 上,使用该参数重新组装 3 个磁盘读取spares=1会失败,因为您没有更多备用磁盘。如果您尝试使用以下命令组装 RAID,则会失败:

sudo mdadm --create --verbose /dev/md0 --level=5 --raid-devices=3 --spare-devices=1 /dev/sda /dev/sdb /dev/sdc

下一个命令将创建不同的 RAID 布局:

sudo mdadm --create --verbose /dev/md0 --level=5 --raid-devices=2 --spare-devices=1 /dev/sda /dev/sdb /dev/sdc

另外需要注意的是:如果您不需要从 RAID5 启动,则无需将配置添加到文件中/etc/mdadm/mdadm.conf。Ubuntu 将自动启动 RAID,因为配置在 RAID 超级块中可用。

答案4

解决方案如下:扫描所有未安装操作系统的驱动器。然后从中选择要选择的驱动器。在创建任何 RAID 之前,您需要将驱动器格式化为兼容格式,如 ext4。请参阅我的示例 bash 代码,从租用的计算机中选择除操作系统驱动器之外的所有驱动器,并构建 RAID0 以获得最大速度,以便稍后形成快速数据库节点。

{
  #database here
  cd "/home/$1/UltiHash/"
  cwd=$(pwd)
  sudo systemctl start postgresql.service
  sudo service postgresql restart
  if ! [[ $(sudo -u postgres psql --command='SHOW data_directory') == *"/mnt/md0/postgresql/13/main"* ]]; then
    sudo chown -R ${mainuser} /home/${mainuser}/
    echo "${passwd}\n${passwd}\n" | sudo passwd postgres
    echo "postgres password set!"
    sudo usermod -aG sudo postgres
    echo "Configured postgres as a root user"
    sudo postgres -D /usr/local/pgsql/data > logfile 2>&1 &
    version=$(psql --version)
    cutter="$(cut -d ' ' -f 3- <<< "$version" )" && tmpcut="${cutter%% *}"
    folver="${tmpcut%%.*}"
    cd /etc/postgresql/${folver}/main
    sudo -u postgres psql --command="ALTER USER postgres WITH PASSWORD '${passwd}';"
    sudo -u postgres psql --command="CREATE USER admin WITH PASSWORD '${passwd}';"
    sudo -u postgres psql --command="ALTER USER admin WITH SUPERUSER;"
    sudo -u postgres psql --command="ALTER USER admin CREATEDB;"
    sudo service postgresql restart
    sudo systemctl stop postgresql
    cd ~/

    #unmask cinnamon
    if [[ $(file /lib/systemd/system/x11-common.service) == "/lib/systemd/system/x11-common.service: symbolic link to /dev/null" ]]; then
      sudo rm /lib/systemd/system/x11-common.service
      sudo apt-get install --reinstall x11-common
      sudo systemctl daemon-reload
      #systemctl status x11-common
    fi

    #scan drives except OS drive
    drivelist=""
    count=0
    os_drive_path="$(df -hT | grep /$ | awk -F " " '{print $1}')"
    os_drive=${os_drive_path%p*}
    no_dev=${os_drive#*/dev/}
    NL=$'\n'
    while read line; do
      if [[ ($line == *nvme* || $line == sd*) && ! ( $line == *"${no_dev}"* ) ]]; then
        drivelist="${drivelist}/dev/${line}${NL}"
        count=$((count+1))
      fi
    done <<< "$(lsblk -f)"

    #create partitions on the free drives directly in ext4 format
    drivelist_overrideable=""
    while read line; do
      drivename=$(echo "$line" | awk -F " " '{print $1}')
      drivelist_overrideable="${drivelist_overrideable}${drivename}${NL}"
      if [[ $drivename == *nvme* ]]; then
        sudo mkfs.ext4 -b 1024 -m 0 -F "$drivename"
      else
        sudo mkfs.ext4 -m 0 -F "$drivename"
      fi
    done <<< "${drivelist}"

    #now we know what has been formatted, so we know the hardware name, now we must scan again and mount the partition to the files created
    #create RAID0
    printf "Y\n" | sudo mdadm --create --verbose /dev/md0 --level=0 --raid-devices="${count}" ${drivelist_overrideable}
    cat /proc/mdstat
    sudo mkfs.ext4 -b 1024 -m 0 -F /dev/md0
    sudo mkdir -p /mnt/md0
    sudo chown -R benjamin-elias /mnt/md0
    sudo chmod -R 777 /mnt/md0
    sudo mount /dev/md0 /mnt/md0
    df -h -x devtmpfs -x tmpfs
    hardware_uid_string=$(sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf)
    sudo update-initramfs -u
    echo "$(echo "${hardware_uid_string}" | awk -F " " '{print $5}') /mnt/md0 ext4 defaults,nofail,discard 0 0" | sudo tee -a /etc/fstab
    sudo update-initramfs -u

    #safely move database
    sudo rsync -av /var/lib/postgresql /mnt/md0
    sudo mv /var/lib/postgresql/${folver}/main /var/lib/postgresql/${folver}/main.bak
    sudo chown -R postgres /mnt/md0/

    postgresconf="/etc/postgresql/${folver}/main/postgresql.conf"
    sudo cp -f ${postgresconf} ${postgresconf}.bak

    while read line; do
        if [[ $line == data_directory* ]]; then
          echo "data_directory = '/mnt/md0/postgresql/${folver}/main'" | sudo tee -a "${postgresconf}"
        else
          echo "${line}" | sudo tee -a "${postgresconf}"
        fi
    done <<< $(cat ${postgresconf}.bak)

    #setup ports
    sudo sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/" ${postgresconf}

    postgresconf="/etc/postgresql/${folver}/main/pg_hba.conf"

    while read line; do
      echo "${line}" | sudo tee -a "${postgresconf}"
      ipadress=$(echo "${line}" | awk -F " " '{print $4}')
      echo $ipadress
      ipfilter=${ipadress%%/*}
      echo $ipfilter
      sudo iptables -A INPUT -p tcp -s 0/0 --sport 1024:65535 -d ${ipfilter} --dport 5432 -m state --state NEW,ESTABLISHED -j ACCEPT
      sudo iptables -A OUTPUT -p tcp -s ${ipfilter} --sport 5432 -d 0/0 --dport 1024:65535 -m state --state ESTABLISHED -j ACCEPT
    done <<< $(cat /home/${mainuser}/UltiHash/trust_host.txt)
    #restart to load changes
    sudo systemctl start postgresql
    sudo systemctl status postgresql
    #setup firewall
    echo "$(sudo -u postgres psql --command="SHOW data_directory;")"
    sudo rm -Rf /var/lib/postgresql/${folver}/main.bak
    sudo ufw allow 5432/tcp
    sudo systemctl restart postgresql
    sudo systemctl status postgresql
  fi
}||{
  echo "Could not configure database!"
}

相关内容