1、开启4台服务器,都各自添加4块硬盘(重启才会生效),在开一台客户端
2、服务器规划
主机1:192.168.35.188
hostnamectl set-hostname node1
主机2:192.168.35.189
hostnamectl set-hostname node2
主机3:192.168.35.153
hostnamectl set-hostname node3
主机4:192.168.35.177
hostnamectl set-hostname node4
客户端:192.168.35.142
hostnamectl set-hostname client
3、将四台服务器上的磁盘格式化,并挂载(脚本执行)
(1)进入opt目录
[root@node1 ~]# cd /opt
(2)磁盘格式化、挂载脚本
[root@node1 opt]# vim s.sh
#! /bin/bash
echo "the disks exist list:"
fdisk -l |grep '磁盘 /dev/sd[a-z]'
echo "=================================================="
PS3="chose which disk you want to create:"
select VAR in `ls /dev/sd*|grep -o 'sd[b-z]'|uniq` quit
do
case $VAR in
sda)
fdisk -l /dev/sda
break ;;
sd[b-z])
#create partitions
echo "n
p
w" | fdisk /dev/$VAR
#make filesystem
mkfs.xfs -i size=512 /dev/${VAR}"1" &> /dev/null
#mount the system
mkdir -p /data/${VAR}"1" &> /dev/null
echo -e "/dev/${VAR}"1" /data/${VAR}"1" xfs defaults 0 0\n" >> /etc/fstab
mount -a &> /dev/null
break ;;
quit)
break;;
*)
echo "wrong disk,please check again";;
esac
done
(3)给于脚本执行权限
[root@node1 opt]# chmod +x s.sh
(4)将脚本通过scp推送到其他三台服务器上
scp s.sh root@192.168.35.189:/opt
scp s.sh root@192.168.35.153:/opt
scp s.sh root@192.168.35.177:/opt
(5)执行脚本,这里只对一台进行完整操作(四台服务器操作一样)
[root@node1 opt]# ./s.sh
the disks exist list:
==================================================
1) sdb
2) sdc
3) sdd
4) sde
5) quit
chose which disk you want to create:1 //输入序号
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x6720dc91.
Command (m for help): Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): Partition number (1-4, default 1): First sector (2048-41943039, default 2048): Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): Using default value 41943039
Partition 1 of type Linux and of size 20 GiB is set
Command (m for help): The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
the disks exist list:
==================================================
1) sdb
2) sdc
3) sdd
4) sde
5) quit
chose which disk you want to create:2 //输入序号
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xd56024e5.
Command (m for help): Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): Partition number (1-4, default 1): First sector (2048-41943039, default 2048): Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): Using default value 41943039
Partition 1 of type Linux and of size 20 GiB is set
Command (m for help): The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@node1 opt]# ./s.sh
the disks exist list:
==================================================
1) sdb
2) sdc
3) sdd
4) sde
5) quit
chose which disk you want to create:3 //输入序号
Welcome to fdisk (util