#!/bin/bash
sttya=`tty`
if [[ "$sttya" =~ "pts" ]];then
stty erase ^?
fi
if [ $UID -ne 0 ]; then
echo "当前用户不是root用户,请以root用户身份执行此脚本!"
echo "The current user is not root,please execute this script as the root user!"
exit
fi
multipah -l > /dev/null 2>&1
if [ $? == 0 ];then
ifuse=`multipath -F`
if [[ "$ifuse" =~ "use" ]];then
echo -e "\e[94m当前主机已有存储正在使用!请先卸载存储卷!\e[0m"
echo -e "\e[94mCurrent host already has storage in use!Please unmount the storage volume first!\e[0m"
exit
fi
fi
echo -e "\e[94m###################################################################\e[0m"
echo -e "\e[94m# 1.中文 #\e[0m"
echo -e "\e[94m# 2.English #\e[0m"
echo -e "\e[94m###################################################################\e[0m"
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
echo -e "\e[94m请选择运行脚本所用的语言: \e[0m"
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
echo -e "\e[94mPlease select a language to run the script: \e[0m"
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
while true
do
read -p "Enter the number: " language
if [[ $language == 1 ]];then
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
echo -e "\e[94m已选择中文!\e[0m"
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
language=1
export LANG="zh_CN.UTF-8"
sleep 1
break;
elif [[ $language == 2 ]];then
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
echo -e "\e[94mEnglish selected!\e[0m"
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
language=2
export LANG="en_US.UTF-8"
sleep 1
break;
else
echo -e "\e[94m请选择语言!\e[0m"
echo -e "\e[94mPlease select a language!\e[0m"
fi
done
if [ $language == 1 ];then
echo -e "\e[94m###################################################################\e[0m"
echo -e "\e[94m# 1.多路径辅助配置脚本适用于FC-SAN和IP-SAN #\e[0m"
echo -e "\e[94m# 2.支持联想 DM、DE系列、DS系列、Storwize V系列 #\e[0m"
echo -e "\e[94m# 3.支持NetApp FAS、E系列,IBM Storwize V系列、FS系列 #\e[0m"
echo -e "\e[94m# 4.支持华为OceanStor系列,浪潮G2系列 #\e[0m"
echo -e "\e[94m# 5.支持戴尔 MD系列、SC系列,宏杉MS系列 #\e[0m"
echo -e "\e[94m# 6.支持惠普 3PAR系列、MSA 1040、1050、2040、2050系列 #\e[0m"
echo -e "\e[94m# 7.其他品牌和型号,使用操作系统生成的默认多路径参数 #\e[0m"
echo -e "\e[94m# 8.支持CentOS 6.x/7.x/8.x RedHat 6.x/7.x/8.x #\e[0m"
echo -e "\e[94m# 9.作者:猫先生 #\e[0m"
echo -e "\e[94m# 10.编写时间:2020年4月16日 #\e[0m"
echo -e "\e[94m# 11.更多内容访问 https://www.mr-mao.cn #\e[0m"
echo -e "\e[94m###################################################################\e[0m"
echo -e "\033[1;m提示:如按Backspace键无法正常删除内容时,可按 Ctrl+Backspace\e[0m"
sleep 1
oskernel=`uname -r | awk -F"-" '{print $1}'`
osrealease=`cat /etc/redhat-release`
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
echo -e "\e[94m当前操作系统为$osrealease\e[0m"
if [ "$oskernel" = "2.6.32" ]; then
echo -e "\e[94m内核版本为2.6.32系列\e[0m"
elif [ "$oskernel" = "3.10.0" ]; then
echo -e "\e[94m内核版本为3.10.0系列\e[0m"
elif [ "$oskernel" = "4.18.0" ]; then
echo -e "\e[94m内核版本为4.18.0系列\e[0m"
echo -e "\033[1;m因存储厂家目前未做适配,当前系统默认使用系统生成的多路径参数!\e[0m"
else
echo -e "\e[94m此脚本不支持当前操作系统!\e[0m"
exit
fi
multipathpack=`rpm -qa | grep device-mapper-multipath |wc -l`
if [ "$multipathpack" -ge 2 ];
then
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
echo -e "\e[94m操作系统多路径软件已安装\e[0m"
elif [ "$multipathpack" -lt 2 ];
then
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
echo -e "\e[94m系统多路径软件安装不完整,如yum正常,执行下面的命令安装\e[0m"
echo yum install -y device-mapper-multipath
echo -e "\e[94m如果yum未配置,则进入系统盘/Packages文件夹下执行\e[0m"
echo rpm -ivh device-mapper-multipath-*.rpm
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
exit
else
exit
fi
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
initpack=`rpm -qa |grep iscsi-initiator-utils |wc -l`
lspci > /dev/null 2>&1
if [[ $? == 0 ]];then
hba=`lspci |grep -i fibre`
fi
oslabel=`df -h |grep boot |head -n1 |awk -F " " '{print$1}' |grep [a-z]d[a-z] -o`
echo -e "\e[94m###################################################################\e[0m"
echo -e "\e[94m# 1.FC #\e[0m"
echo -e "\e[94m# 2.ISCSI #\e[0m"
echo -e "\e[94m###################################################################\e[0m"
while true
do
read -p "选择存储连接方式,输入数字即可: " mode
if [ "$mode" == 1 ];then
echo -e "\e[94m当前选择的连接方式为:FC\e[0m"
mode=1
break;
elif [ "$mode" == 2 ]; then
echo -e "\e[94m当前选择的连接方式为:ISCSI\e[0m"
mode=2
break;
else
echo -e "\e[94m选择正确的连接方式!\e[0m"
fi
done
if [ "$mode" == 1 ]; then
if [ -z "$hba" ]; then
lspci > /dev/null 2>&1
if [[ $? != 0 ]];then
echo -e "\e[94m当前操作系统缺少查看硬件的组件,请自行确定HBA卡是否已识别
或输入下面的命令安装。\e[0m"
echo -e "\e[94m如yum正常,则可以执行下面的命令安装\e[0m"
echo yum -y install pciutils
echo -e "\e[94m如果未配置yum,则进入系统盘/Packages文件夹下执行\e[0m"
echo rpm -ivh pciutils-*.rpm
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
fi
echo -e "\e[94m未检测到HBA卡,请检查驱动是否安装合适!\e[0m"
exit
fi
echo -e "\e[94m已检测到当前系统盘为 $oslabel \e[0m"
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
sleep 1
echo -e "\e[94m当前主机HBA卡的WWPN如下:\e[0m"
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
cat /sys/class/fc_host/host*/port_name |awk -F "0x" '{print $2}'
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
sleep 1
fi
if [ "$mode" == 2 ]; then
if [ "$initpack" == 0 ]; then
echo -e "\e[94m当前系统未安装iSCSI,请先安装!\e[0m"
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
echo -e "\e[94m如yum正常,则可以执行下面的命令安装\e[0m"
echo yum -y install iscsi-initiator-utils
echo -e "\e[94m如果未配置yum,则进入系统盘/Packages文件夹下执行\e[0m"
echo rpm -ivh iscsi-initiator-utils-*.rpm
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
exit
fi
echo -e "\e[94m当前主机的iSCSI发起名称是:\e[0m"
echo
iscsiadm -m node --logoutall=all > /dev/null 2>&1
cat /etc/iscsi/initiatorname.iscsi |awk -F "=" '{print$2}'
echo
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
sleep 1
ip a | grep -E "^[0-9]" | grep -vE ": lo|: virbr" |awk -F ": <" '{print$1}' |awk -F ": " '{print$2}' > /tmp/nic
echo -e "\e[94m当前主机所有网卡如下:\e[0m"
echo -e "\e[94m-------------------------\e[0m"
cat /tmp/nic |awk '{print NR,$1}'
echo -e "\e[94m-------------------------\e[0m"
while true
do
read -p "选择用来连接存储的网卡,输入数字即可,如使用多个网卡,用空格隔开: " nicnum
selectnum=`echo $nicnum |awk -F " " '{print NF}'`
if [ $selectnum -lt 1 ];then
echo -e "\e[94m最少选择1块网卡,请重新选择!\e[0m"
else
break;
fi
done
for num in $nicnum;
do
nicx=`cat /tmp/nic |awk "NR==$num" |awk -F " " '{print$1}'`
if [[ "$nicx" == "" ]];then
echo -e "\e[94m选择正确的网卡!\e[0m"
exit
fi
done
for num in $nicnum;
do
selectnic=`cat /tmp/nic |awk "NR==$num"`
selectnicip=`ip a s $selectnic | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+' | head -n1`
if [ -z "$selectnicip" ];then
echo -e "\e[94m当前网卡 $selectnic 无IP地址,请先配置!\e[0m"
exit
else
echo -e "\e[94m已选择 $selectnic\e[0m"
echo -e "\e[94m-------------------------\e[0m"
echo -e "\e[94m网卡 $selectnic IP地址:
$selectnicip\e[0m"
echo -e "\e[94m-------------------------\e[0m"
sleep 1
fi
done
read -p "请输入存储target IP地址,如有多个IP,使用空格隔开: " targetip
for tip in $targetip;
do
echo -e "\e[94m正在检查网络连通性,请稍候!\e[0m"
ping=`ping -c 5 $tip |awk 'NR==9 {print $4}'`
if [[ $ping -eq 0 ]];then
echo -e "\e[94m当前主机无法ping通存储 $tip,请检查网络配置!\e[0m"
exit
else
echo -e "\e[94m当前主机与存储 $tip 通信正常,正在配置iSCSI连接。。。\e[0m"
iscsiadm -m discovery -t st -p $targetip > /dev/null 2>&1
if [[ "$?" == 0 ]]; then
iscsiadm -m node -p $tip -l > /dev/null 2>&1
echo -e "\e[94miSCSI已连接,请在存储端映射卷。\e[0m"
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
sleep 1
else
echo -e "\e[94m当前主机无法登录iSCSI存储!请检查配置!\e[0m"
exit
fi
fi
done
fi
read -p "存储端是否完成映射?按n退出,按其他按键表示已映射:" answer1
answer1lower=`echo $answer1 | tr [A-Z] [a-z]`
if [ "$answer1lower" == "n" ]; then
echo -e "\e[94m请在存储端完成映射后,重新执行此脚本!\e[0m"
else
sleep 1
fi
if [[ -z "$oslabel" ]]; then
while true
do
read -p "输入操作系统所在磁盘,比如 sda: " osdisk
if [[ -z "$osdisk" ]]; then
echo -e "\e[94m系统盘不能为空!\e[0m"
else
echo -e "\e[94m当前系统所在磁盘为 $osdisk\e[0m"
break;
sleep 1
fi
done
else
osdisk=$oslabel
fi
if [ "$oskernel" = "2.6.32" ]; then
wwid=`/sbin/scsi_id -g -u /dev/$osdisk`
fi
if [[ "$oskernel" = "3.10.0" ]]; then
wwid=`/usr/lib/udev/scsi_id -g -u /dev/$osdisk`
fi
if [[ "$oskernel" = "4.18.0" ]]; then
wwid=`/usr/lib/udev/scsi_id -g -u /dev/$osdisk`
fi
sleep 1
if [ "$mode" == 1 ]; then
for x in `ls /sys/class/fc_host`; do echo "- - -" > /sys/class/scsi_host/$x/scan; done
fi
if [ "$mode" == 2 ]; then
for x in `ls /sys/class/iscsi_host`; do echo "- - -" > /sys/class/scsi_host/$x/scan; done
fi
echo -e "\e[94m正在检测存储.....\e[0m"
sleep 1
rm -f /etc/multipath.conf
if [ "$oskernel" = "2.6.32" ]; then
mpathconf --enable --find_multipaths y --user_friendly_names y --with_module y --with_chkconfig y
sleep 1
service multipathd restart > /dev/null 2>&1
sleep 3
multipath -F
multipath -v2 > /dev/null 2>&1
multipath -l
fi
if [[ "$oskernel" = "3.10.0" ]]; then
mpathconf --enable --find_multipaths y --with_module y --with_multipathd y --user_friendly_names y
sleep 1
systemctl restart multipathd > /dev/null 2>&1
sleep 3
multipath -F
multipath -v2 > /dev/null 2>&1
multipath -l
fi
if [[ "$oskernel" = "4.18.0" ]]; then
mpathconf --enable --find_multipaths y --with_module y --with_multipathd y --user_friendly_names y
sleep 1
systemctl restart multipathd > /dev/null 2>&1
sleep 3
multipath -F
multipath -v2 > /dev/null 2>&1
multipath -l
fi
dev=`multipath -l`
if [[ -z "$dev" ]]; then
echo -e "\e[94m未检测到存储!请检查是否已映射或链路是否为多链路!\e[0m"
exit
fi
echo
if [ "$wwid" == "" ]; then
echo -e "\e[94m未检测到系统盘 $osdisk 的wwid,当前主机可能是虚拟机,已在多路径配置文件中使用 $osdisk 做为黑名单设备\e[0m"
backlist=$osdisk
cat > /tmp/multipath.conf << EOF
blacklist{
devnode "$backlist"
}
defaults {
user_friendly_names yes
find_multipaths yes
}
multipaths {
EOF
else
backlist=$wwid
echo -e "\e[94m已检测到系统盘WWID为 $wwid,已在多路径配置文件中使用wwid为黑名单设备\e[0m"
echo
cat > /tmp/multipath.conf << EOF
blacklist{
wwid "$backlist"
}
defaults {
user_friendly_names yes
find_multipaths yes
}
multipaths {
EOF
fi
multipath=`multipath -l |grep dm- |grep [0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z] -o`
if [[ "$multipath" == "" ]];then
echo -e "\e[94m此脚本不支持当前存储!\e[0m"
exit
fi
for dev in $multipath;
do
size=`multipath -l $dev |grep size= |awk -F " " '{print$1}'`
dm=`multipath -l |grep $dev |grep dm-"[0-9]\{1,3\}" -o`
vendor=`multipath -l |grep $dev |awk -F "$dm" '{print$2}' |sed s/[[:space:]]//g`
multipath -l |grep $dev |awk -F "$dm" '{print$2}' |sed s/[[:space:]]//g > /tmp/vendor
multipath -l |grep $dev |awk -F "$dm" '{print$2}' |sed s/[[:space:]]//g >> /tmp/vendors
if [[ "$vendor" =~ "NETAPP,LUNC-Mode" ]]; then
echo -e "\e[94m已检测到NETAPP品牌FAS系列存储\e[0m"
elif [[ "$vendor" =~ "LENOVO,DE_Series" ]]; then
echo -e "\e[94m已检测到联想品牌DE系列存储\e[0m"
elif [[ "$vendor" =~ "NETAPP,INF-01-00" ]]; then
echo -e "\e[94m已检测到NETAPP品牌E系列存储\e[0m"
elif [[ "$vendor" =~ "LSI,INF-01-00" ]]; then
echo -e "\e[94m已检测到NETAPP品牌E系列存储\e[0m"
elif [[ "$vendor" =~ "Lenovo,DS2200" ]]; then
echo -e "\e[94m已检测到联想品牌DS2200存储\e[0m"
elif [[ "$vendor" =~ "Lenovo,DS4200" ]]; then
echo -e "\e[94m已检测到联想品牌DS4200存储\e[0m"
elif [[ "$vendor" =~ "Lenovo,DS6200" ]]; then
echo -e "\e[94m已检测到联想品牌DS6200存储\e[0m"
elif [[ "$vendor" =~ "IBM,2145" ]]; then
echo -e "\e[94m已检测到IBM品牌V或者FS系列存储\e[0m"
elif [[ "$vendor" =~ "HUAWEI,XSG1" ]]; then
echo -e "\e[94m已检测到华为品牌OceanStor系列存储\e[0m"
elif [[ "$vendor" =~ "INSPUR,MCS" ]]; then
echo -e "\e[94m已检测到浪潮品牌G2系列存储\e[0m"
elif [[ "$vendor" =~ "COMPELNT,CompellentVol" ]]; then
echo -e "\e[94m已检测到戴尔品牌SC系列存储\e[0m"
elif [[ "$vendor" =~ "DELL,MD34xx" ]]; then
echo -e "\e[94m已检测到戴尔品牌MD34系列存储\e[0m"
elif [[ "$vendor" =~ "DELL,MD32xx" ]]; then
echo -e "\e[94m已检测到戴尔品牌MD32系列存储\e[0m"
elif [[ "$vendor" =~ "DELL,MD36xx" ]]; then
echo -e "\e[94m已检测到戴尔品牌MD36系列存储\e[0m"
elif [[ "$vendor" =~ "DELL,MD38xx" ]]; then
echo -e "\e[94m已检测到戴尔品牌MD38系列存储\e[0m"
elif [[ "$vendor" =~ "HP,MSA1040SAN" ]]; then
echo -e "\e[94m已检测到惠普品牌MSA 1040系列存储\e[0m"
elif [[ "$vendor" =~ "HP,MSA1050SAN" ]]; then
echo -e "\e[94m已检测到惠普品牌MSA 1050系列存储\e[0m"
elif [[ "$vendor" =~ "HP,MSA2040SAN" ]]; then
echo -e "\e[94m已检测到惠普品牌MSA 2040系列存储\e[0m"
elif [[ "$vendor" =~ "HP,MSA2050SAN" ]]; then
echo -e "\e[94m已检测到惠普品牌MSA 2050系列存储\e[0m"
elif [[ "$vendor" =~ "MacroSAN,LU" ]]; then
echo -e "\e[94m已检测到宏杉品牌MS系列存储\e[0m"
elif [[ "$vendor" =~ "3PARdata,VV" ]]; then
echo -e "\e[94m已检测到惠普品牌3PAR系列存储\e[0m"
elif [[ "$vendor" =~ "UniversalXport" ]]; then
echo -e "\e[94m已检测到存储带内管理分区\e[0m"
else
echo -e "\e[94m已检测到$vendor存储,当前存储将使用操作系统默认多路径参数!\e[0m"
fi
echo WWID为 $dev
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
while true
do
if [[ "$vendor" =~ "UniversalXport" ]]; then
echo -e "\e[94m此分区为存储厂商实现带内管理而自动分配,已将其屏蔽!\e[0m"
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
break;
else
echo -e "\e[94m为 [ wwid为 $dev $size DM为 $dm ] 的存储卷定义别名\e[0m"
read -p "输入存储卷的别名: " dmname1
dmname=`echo ${dmname1,,}`
if [ "$dmname" == "" ]; then
echo -e "\e[94m别名不能为空,请重新输入!\e[0m"
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
else
echo -e "\e[94m已配置别名为 $dmname \e[0m"
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
break;
fi
fi
done
if [ "$dmname" != "" ];then
cat >> /tmp/multipath.conf << EOF
multipath {
wwid $dev
alias $dmname
}
EOF
fi
done
sleep 1
echo > /tmp/vendor
if [[ "$oskernel" != "4.18.0" ]]; then
cat >> /tmp/multipath.conf << EOF
}
devices{
EOF
echo -e "\e[94m根据存储品牌,正在写入当前存储厂商推荐的多路径参数.................\e[0m"
for dev in $multipath;
do
dm=`multipath -l |grep $dev |grep dm-"[0-9]\{1,3\}" -o`
vendor1=`multipath -l |grep $dev |awk -F "$dm" '{print$2}' |sed s/[[:space:]]//g`
vendor2=`cat /tmp/vendor`
if [[ "$vendor1" == "$vendor2" ]];then
echo .
else
vendor=$vendor1
multipath -l |grep $dev |awk -F "$dm" '{print$2}' |sed s/[[:space:]]//g > /tmp/vendor
if [[ "$vendor" =~ "NETAPP,LUNC-Mode" ]]; then
cat >> /tmp/multipath.conf << EOF
device {
vendor "NETAPP"
product "LUN"
flush_on_last_del yes
dev_loss_tmo infinity
fast_io_fail_tmo 5
failback immediate
features "3 queue_if_no_path pg_init_retries 50"
hardware_handler "1 alua"
path_checker tur
path_grouping_policy group_by_prio
path_selector "round-robin 0"
prio alua
rr_min_io 1000
rr_weight uniform
}
EOF
elif [[ "$vendor" =~ "NETAPP,INF-01-00" ]]; then
cat >> /tmp/multipath.conf << EOF
device {
vendor "NETAPP"
product "INF-01-00"
path_grouping_policy "group_by_prio"
features "2 pg_init_retries 50"
path_checker "rdac"
path_selector "round-robin 0"
hardware_handler "1 rdac"
prio "rdac"
failback "immediate"
no_path_retry 30
detect_prio yes
rr_weight priorities
}
EOF
elif [[ "$vendor" =~ "LSI,INF-01-00" ]]; then
cat >> /tmp/multipath.conf << EOF
device {
vendor "LSI"
product "INF-01-00"
path_grouping_policy "group_by_prio"
features "2 pg_init_retries 50"
path_checker "rdac"
path_selector "round-robin 0"
hardware_handler "1 rdac"
prio "rdac"
failback "immediate"
no_path_retry 30
detect_prio yes
rr_weight priorities
}
EOF
elif [[ "$vendor" =~ "LENOVO,DE_Series" ]]; then
cat >> /tmp/multipath.conf << EOF
device {
vendor "LENOVO"
product "DE_Series"
path_grouping_policy "group_by_prio"
features "2 pg_init_retries 50"
path_checker "rdac"
path_selector "round-robin 0"
hardware_handler "1 rdac"
prio "rdac"
failback "immediate"
no_path_retry 30
detect_prio yes
rr_weight priorities
}
EOF
elif [[ "$vendor" =~ "Lenovo,DS2200" ]]; then
cat >> /tmp/multipath.conf << EOF
device {
vendor "Lenovo"
product "DS2200"
failback immediate
prio alua
}
EOF
elif [[ "$vendor" =~ "Lenovo,DS4200" ]]; then
cat >> /tmp/multipath.conf << EOF
device {
vendor "Lenovo"
product "DS4200"
failback immediate
prio alua
}
EOF
elif [[ "$vendor" =~ "Lenovo,DS6200" ]]; then
cat >> /tmp/multipath.conf << EOF
device {
vendor "Lenovo"
product "DS6200"
failback immediate
prio alua
}
EOF
elif [[ "$vendor" =~ "IBM,2145" ]]; then
cat >> /tmp/multipath.conf << EOF
device {
vendor "IBM"
product "2145"
path_grouping_policy "group_by_prio"
path_selector "service-time 0"
prio "alua"
path_checker "tur"
failback "immediate"
no_path_retry 5
rr_weight uniform
rr_min_io_rq "1"
dev_loss_tmo 120
}
EOF
elif [[ "$vendor" =~ "HUAWEI,XSG1" ]]; then
cat >> /tmp/multipath.conf << EOF
device {
vendor "HUAWEI"
product "XSG1"
path_grouping_policy "group_by_prio"
path_checker "tur"
path_selector "round-robin 0"
prio alua
failback "immediate"
dev_loss_tmo 30
fast_io_fail_tmo 5
}
EOF
elif [[ "$vendor" =~ "INSPUR,MCS" ]]; then
cat >> /tmp/multipath.conf << EOF
device {
vendor "INSPUR"
product "MCS"
path_grouping_policy group_by_prio
path_selector "service-time 0"
features "1 queue_if_no_path"
path_checker tur
prio alua
failback immediate
}
EOF
elif [[ "$vendor" =~ "COMPELNT,CompellentVol" ]]; then
cat >> /tmp/multipath.conf << EOF
device {
vendor "COMPELNT"
product "Compellent Vol"
features 0
no_path_retry fail
}
EOF
elif [[ "$vendor" =~ "DELL,MD34xx" ]]; then
cat >> /tmp/multipath.conf << EOF
device {
vendor "DELL"
product "MD34xx"
path_grouping_policy "group_by_prio"
features "2 pg_init_retries 50"
path_checker "rdac"
path_selector "round-robin 0"
hardware_handler "1 rdac"
prio "rdac"
failback "immediate"
no_path_retry 30
detect_prio yes
rr_weight priorities
}
EOF
elif [[ "$vendor" =~ "DELL,MD32xxi" ]]; then
cat >> /tmp/multipath.conf << EOF
device {
vendor "DELL"
product "MD32xxi"
path_grouping_policy "group_by_prio"
features "2 pg_init_retries 50"
path_checker "rdac"
path_selector "round-robin 0"
hardware_handler "1 rdac"
prio "rdac"
polling_interval 5
failback "immediate"
no_path_retry 30
detect_prio yes
rr_weight priorities
}
EOF
elif [[ "$vendor" =~ "DELL,MD32xx" ]]; then
cat >> /tmp/multipath.conf << EOF
device {
vendor "DELL"
product "MD32xx"
path_grouping_policy "group_by_prio"
features "2 pg_init_retries 50"
path_checker "rdac"
path_selector "round-robin 0"
hardware_handler "1 rdac"
prio "rdac"
polling_interval 5
failback "immediate"
no_path_retry 30
detect_prio yes
rr_min_io 100
}
EOF
elif [[ "$vendor" =~ "DELL,MD36xxi" ]]; then
cat >> /tmp/multipath.conf << EOF
device {
vendor "DELL"
product "MD36xxi"
path_grouping_policy "group_by_prio"
features "2 pg_init_retries 50"
path_checker "rdac"
path_selector "round-robin 0"
hardware_handler "1 rdac"
prio "rdac"
polling_interval 5
failback "immediate"
no_path_retry 30
detect_prio yes
rr_min_io 100
}
EOF
elif [[ "$vendor" =~ "DELL,MD36xxf" ]]; then
cat >> /tmp/multipath.conf << EOF
device {
vendor "DELL"
product "MD36xxf"
path_grouping_policy "group_by_prio"
features "2 pg_init_retries 50"
path_checker "rdac"
path_selector "round-robin 0"
hardware_handler "1 rdac"
prio "rdac"
polling_interval 5
failback "immediate"
no_path_retry 30
detect_prio yes
rr_min_io 100
}
EOF
elif [[ "$vendor" =~ "DELL,MD38xx" ]]; then
cat >> /tmp/multipath.conf << EOF
device {
vendor "DELL"
product "MD38xx"
path_grouping_policy "group_by_prio"
features "2 pg_init_retries 50"
path_checker "rdac"
path_selector "round-robin 0"
hardware_handler "1 rdac"
prio "rdac"
failback "immediate"
no_path_retry 30
detect_prio yes
rr_weight priorities
}
EOF
elif [[ "$vendor" =~ "HP,MSA1040SAN" ]]; then
cat >> /tmp/multipath.conf << EOF
device{
vendor "HP”
product "MSA 1040 SAN"
path_grouping_policy "group_by_prio"
path_selector "round-robin 0"
rr_weight uniform
path_checker tur
hardware_handler "0"
failback immediate
no_path_retry 18
rr_min_io 100
}
EOF
elif [[ "$vendor" =~ "HP,MSA1050SAN" ]]; then
cat >> /tmp/multipath.conf << EOF
device{
vendor "HP”
product "MSA 1050 SAN"
path_grouping_policy "group_by_prio"
path_selector "round-robin 0"
rr_weight uniform
path_checker tur
hardware_handler "0"
failback immediate
no_path_retry 18
rr_min_io 100
}
EOF
elif [[ "$vendor" =~ "HP,MSA2040SAN" ]]; then
cat >> /tmp/multipath.conf << EOF
device{
vendor "HP”
product "MSA 2040 SAN"
path_grouping_policy "group_by_prio"
path_selector "round-robin 0"
rr_weight uniform
path_checker tur
hardware_handler "0"
failback immediate
no_path_retry 18
rr_min_io 100
}
EOF
elif [[ "$vendor" =~ "HP,MSA2050SAN" ]]; then
cat >> /tmp/multipath.conf << EOF
device{
vendor "HP”
product "MSA 2050 SAN"
path_grouping_policy "group_by_prio"
path_selector "round-robin 0"
rr_weight uniform
path_checker tur
hardware_handler "0"
failback immediate
no_path_retry 18
rr_min_io 100
}
EOF
elif [[ "$vendor" =~ "MacroSAN,LU" ]]; then
cat >> /tmp/multipath.conf << EOF
device{
vendor "MacroSAN"
product "LU"
path_grouping_policy group_by_prio
path_selector "round-robin 0"
path_checker tur
prio alua
no_path_retry 30
hardware_handler "0"
failback 15
}
EOF
elif [[ "$vendor" =~ "3PARdata,VV" ]]; then
cat >> /tmp/multipath.conf << EOF
device{
vendor "3PARdata"
product "VV"
path_grouping_policy group_by_prio
path_selector "round-robin 0"
path_checker tur
features "0"
hardware_handler "1 alua"
prio alua
failback immediate
rr_weight uniform
no_path_retry 18
rr_min_io_rq 1
detect_prio yes
fast_io_fail_tmo 10
dev_loss_tmo 14
}
EOF
fi
fi
done
fi
cat >> /tmp/multipath.conf << EOF
}
EOF
xport=`cat /tmp/vendors`
if [[ "$xport" =~ "UniversalXport" ]];then
sed -i 's/blacklist{/&\ndevice{\nvendor "*"\nproduct "Universal Xport"\n}/' /tmp/multipath.conf
fi
if [[ "$vendor" =~ "IBM,2145" && "$oskernel" = "2.6.32" ]];then
sed -i '/path_selector/s/service-time 0/round-robin 0/' /tmp/multipath.conf
fi
hpe3par=`cat /tmp/vendors`
if [[ "$hpe3par" =~ "3PARdata,VV" && "$oskernel" = "2.6.32" ]];then
echo -e "\e[94m当前存储为HPE 3PAR系列,官方推荐使用【Generic-ALUA 角色2】,linux7.x
系统默认使用【Generic-ALUA 角色2】,鉴于当前系统是6.x,请选择你创建主机的角色定义\e[0m"
echo -e "\e[94m###################################################################\e[0m"
echo -e "\e[94m# 1.【Generic 角色 1】 #\e[0m"
echo -e "\e[94m# 2.【Generic-ALUA 角色 2】 #\e[0m"
echo -e "\e[94m###################################################################\e[0m"
while true
do
read -p "选择主机角色定义,输入数字即可:" hostnum
if [[ "$hostnum" == 1 ]];then
echo -e "\e[94m已选择【Generic 角色 1】\e[0m"
break;
elif [[ "$hostnum" == 2 ]];then
echo -e "\e[94m已选择【Generic 角色 1】\e[0m"
break;
else
echo -e "\e[94m选择正确的主机定义!\e[0m"
fi
done
fi
if [[ "$hostnum" == 1 ]];then
sed -i '/path_grouping_policy/s/group_by_prio/multibus/' /tmp/multipath.conf
sed -i '/prio/d' /tmp/multipath.conf
echo -e "\e[94m已适配【Generic 角色 1】的多路径参数!\e[0m"
fi
cat /tmp/multipath.conf > /etc/multipath.conf
sleep 1
echo -e "\e[94m正在配置多路径.............................\e[0m"
if [ "$oskernel" = "2.6.32" ]; then
service multipathd restart > /dev/null 2>&1
sleep 3
multipath -F
multipath -v2 > /dev/null 2>&1
multipath -ll
fi
if [[ "$oskernel" = "3.10.0" ]]; then
systemctl restart multipathd
sleep 3
multipath -F
multipath -v2 > /dev/null 2>&1
multipath -ll
fi
if [[ "$oskernel" = "4.18.0" ]]; then
sleep 1
systemctl restart multipathd > /dev/null 2>&1
sleep 3
multipath -F
multipath -v2 > /dev/null 2>&1
multipath -ll
fi
rm -f /tmp/multipath.conf
rm -f /tmp/nic
rm -f /tmp/vendor
rm -f /tmp/vendors
echo -e "\e[94m多路径配置已完成!\e[0m"
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
fi
if [[ "$language" == 2 ]];then
echo -e "\e[94m###################################################################\e[0m"
echo -e "\e[94m# 1.Multipath configuration script for FC-SAN and IP-SAN #\e[0m"
echo -e "\e[94m# 2.Support Lenovo DM/DE Series,DS Series,Storwize V Series #\e[0m"
echo -e "\e[94m# 3.Support NetApp FAS/E Series,IBM Storwize V Series,FS Series #\e[0m"
echo -e "\e[94m# 4.Support HuaWei OceanStor Series,Inspur G2 Series #\e[0m"
echo -e "\e[94m# 5.Support DELL MD/SC Series, MacroSAN MS Series #\e[0m"
echo -e "\e[94m# 6.Support HPE 3PAR Series,MSA 1040/1050/2040/2050 Series #\e[0m"
echo -e "\e[94m# 7.Others,use default multipath parameters generated by OS #\e[0m"
echo -e "\e[94m# 8.Support CentOS 6.x/7.x/8.x RedHat 6.x/7.x/8.x #\e[0m"
echo -e "\e[94m# 9.Author: Mr.Mao #\e[0m"
echo -e "\e[94m# 10.Compiled: April 16,2020 #\e[0m"
echo -e "\e[94m# 11.More View https://www.mr-mao.cn #\e[0m"
echo -e "\e[94m###################################################################\e[0m"
echo -e "\033[1;mTip:If the Backspace key does not work,press Ctrl+Backspace\e[0m"
sleep 1
oskernel=`uname -r | awk -F"-" '{print $1}'`
osrealease=`cat /etc/redhat-release`
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
echo -e "\e[94mThe current OS is $osrealease\e[0m"
if [ "$oskernel" = "2.6.32" ]; then
echo -e "\e[94mThe kernel version is 2.6.32 Series\e[0m"
elif [ "$oskernel" = "3.10.0" ]; then
echo -e "\e[94mThe kernel version is 3.10.0 Series\e[0m"
elif [ "$oskernel" = "4.18.0" ]; then
echo -e "\e[94mThe kernel version is4.18.0 Series\e[0m"
echo -e "\033[1;mBecause the storage manufacturer has not made adaptations, the current system uses the multipath parameters generated by the system by default!\e[0m"
else
echo -e "\e[94mThis script does not support the current OS\e[0m"
exit
fi
multipathpack=`rpm -qa | grep device-mapper-multipath |wc -l`
if [ "$multipathpack" -ge 2 ];
then
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
echo -e "\e[94mMultipath software is installed!\e[0m"
elif [ "$multipathpack" -lt 2 ];
then
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
echo -e "\e[94mMultipath software is not installed,if you have yum,then execute\e[0m"
echo yum install -y device-mapper-multipath
echo -e "\e[94melse,Go to the /Packages folder of the installation source,execute\e[0m"
echo rpm -ivh device-mapper-multipath-*.rpm
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
exit
else
exit
fi
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
initpack=`rpm -qa |grep iscsi-initiator-utils |wc -l`
lspci > /dev/null 2>&1
if [[ $? == 0 ]];then
hba=`lspci |grep -i fibre`
fi
oslabel=`df -h |grep boot |head -n1 |awk -F " " '{print$1}' |grep [a-z]d[a-z] -o`
echo -e "\e[94m###################################################################\e[0m"
echo -e "\e[94m# 1.FC #\e[0m"
echo -e "\e[94m# 2.ISCSI #\e[0m"
echo -e "\e[94m###################################################################\e[0m"
while true
do
read -p "Select the storage connection method and enter the number: " mode
if [ "$mode" == 1 ];then
echo -e "\e[94mThe selected connection method is: FC\e[0m"
mode=1
break;
elif [ "$mode" == 2 ]; then
echo -e "\e[94mThe selected connection method is: ISCSI\e[0m"
mode=2
break;
else
echo -e "\e[94m选择正确的连接方式!\e[0m"
fi
done
if [ "$mode" == 1 ]; then
if [ -z "$hba" ]; then
lspci > /dev/null 2>&1
if [[ $? != 0 ]];then
echo -e "\e[94mThe current operating system is missing a component to view the hardware, please determine whether the HBA card has been recognized by yourself,Or enter the following command to install.\e[0m"
echo -e "\e[94mif you have yum,then execute\e[0m"
echo yum -y install pciutils
echo -e "\e[94melse,Go to the /Packages folder of the installation source,execute\e[0m"
echo rpm -ivh pciutils-*.rpm
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
fi
echo -e "\e[94mNo HBA card detected,please check if the driver is installed properly!\e[0m"
exit
fi
echo -e "\e[94mThe current OS disk has been detected as $oslabel\e[0m"
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
sleep 1
echo -e "\e[94mThe WWPN of the current host HBA card is as follows:\e[0m"
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
cat /sys/class/fc_host/host*/port_name |awk -F "0x" '{print $2}'
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
sleep 1
fi
if [ "$mode" == 2 ];
then
if [ "$initpack" == 0 ]; then
echo -e "\e[94mISCSI software is not installed,please install it first!\e[0m"
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
echo -e "\e[94mif you have yum,then execute\e[0m"
echo yum -y install iscsi-initiator-utils
echo -e "\e[94melse,Go to the /Packages folder of the installation source,execute\e[0m"
echo rpm -ivh iscsi-initiator-utils-*.rpm
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
exit
fi
echo -e "\e[94mThe iSCSI initiator name of the current host is: \e[0m"
echo
iscsiadm -m node --logoutall=all > /dev/null 2>&1
cat /etc/iscsi/initiatorname.iscsi |awk -F "=" '{print$2}'
echo
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
sleep 1
ip a | grep -E "^[0-9]" | grep -vE ": lo|: virbr" |awk -F ": <" '{print$1}' |awk -F ": " '{print$2}' > /tmp/nic
echo -e "\e[94mAll NICs of the current host are as follows: \e[0m"
echo -e "\e[94m-------------------------\e[0m"
cat /tmp/nic |awk '{print NR,$1}'
echo -e "\e[94m-------------------------\e[0m"
while true
do
read -p "Select the NIC used for storage,enter the number.multiple NICs,separated by spaces: " nicnum
selectnum=`echo $nicnum |awk -F " " '{print NF}'`
if [ $selectnum -lt 1 ];then
echo -e "\e[94mSelect at least one NIC,please choose again!\e[0m"
else
break;
fi
done
for num in $nicnum;
do
nicx=`cat /tmp/nic |awk "NR==$num" |awk -F " " '{print$1}'`
if [[ "$nicx" == "" ]];then
echo -e "\e[94mPlease select correct NIC!\e[0m"
exit
fi
done
for num in $nicnum;
do
selectnic=`cat /tmp/nic |awk "NR==$num"`
selectnicip=`ip a s $selectnic | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+' | head -n1`
if [ -z "$selectnicip" ];then
echo -e "\e[94mThe NIC $selectnic has no IP address,please configure it first!\e[0m"
exit
else
echo -e "\e[94mChosen $selectnic\e[0m"
echo -e "\e[94m-------------------------\e[0m"
echo -e "\e[94mNIC $selectnic IP address:
$selectnicip\e[0m"
echo -e "\e[94m-------------------------\e[0m"
sleep 1
fi
done
read -p "Please enter the storage target IP address.If there are multiple IPs,separate them with spaces: " targetip
for tip in $targetip;
do
echo -e "\e[94mChecking network connectivity,please wait!\e[0m"
ping=`ping -c 5 $tip |awk 'NR==9 {print $4}'`
if [[ $ping -eq 0 ]];then
echo -e "\e[94mCurrent host and storage cannot communicate,please check the network configuration!\e[0m"
exit
else
echo -e "\e[94mCurrent host and storage $tip communication is normal,iSCSI connection is being configuring......\e[0m"
iscsiadm -m discovery -t st -p $targetip > /dev/null 2>&1
if [[ "$?" == 0 ]]; then
iscsiadm -m node -p $tip -l > /dev/null 2>&1
echo -e "\e[94miSCSI is connected,please map the volume on the storage side!\e[0m"
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
sleep 1
else
echo -e "\e[94mCurrent host cannot login to the iSCSI storage! Please check the configuration!\e[0m"
exit
fi
fi
done
fi
read -p "Is the mapping done on the storage side? Press n to exit,press other keys to continue: " answer1
answer1lower=`echo $answer1 | tr [A-Z] [a-z]`
if [ "$answer1lower" == "n" ]; then
echo -e "\e[94mPlease re-execute this script after the mapping is done on the storage side!\e[0m"
else
sleep 1
fi
if [[ -z "$oslabel" ]]; then
while true
do
read -p "Enter the disk where the OS is located,such as sda: " osdisk
if [[ -z "$osdisk" ]]; then
echo -e "\e[94mThe OS disk cannot be empty!\e[0m"
else
echo -e "\e[94mThe current OS disk is $osdisk\e[0m"
break;
sleep 1
fi
done
else
osdisk=$oslabel
fi
if [ "$oskernel" = "2.6.32" ]; then
wwid=`/sbin/scsi_id -g -u /dev/$osdisk`
fi
if [[ "$oskernel" = "3.10.0" ]]; then
wwid=`/usr/lib/udev/scsi_id -g -u /dev/$osdisk`
fi
if [[ "$oskernel" = "4.18.0" ]]; then
wwid=`/usr/lib/udev/scsi_id -g -u /dev/$osdisk`
fi
sleep 1
if [ "$mode" == 1 ];
then
for x in `ls /sys/class/fc_host`; do echo "- - -" > /sys/class/scsi_host/$x/scan; done
elif [ "$mode" == 2 ];
then
for x in `ls /sys/class/iscsi_host`; do echo "- - -" > /sys/class/scsi_host/$x/scan; done
else
exit
fi
echo -e "\e[94mDetecting the storage....\e[0m"
sleep 1
rm -f /etc/multipath.conf
if [ "$oskernel" = "2.6.32" ]; then
mpathconf --enable --find_multipaths y --user_friendly_names y --with_module y --with_chkconfig y
sleep 2
service multipathd restart > /dev/null 2>&1
sleep 2
multipath -F
multipath -v2 > /dev/null 2>&1
multipath -l
fi
if [[ "$oskernel" = "3.10.0" ]]; then
mpathconf --enable --find_multipaths y --with_module y --with_multipathd y --user_friendly_names y
sleep 2
systemctl restart multipathd
sleep 2
multipath -F
multipath -v2 > /dev/null 2>&1
multipath -l
fi
if [[ "$oskernel" = "4.18.0" ]]; then
mpathconf --enable --find_multipaths y --with_module y --with_multipathd y --user_friendly_names y
sleep 1
systemctl restart multipathd > /dev/null 2>&1
sleep 3
multipath -F
multipath -v2 > /dev/null 2>&1
multipath -l
fi
dev=`multipath -l`
if [[ -z "$dev" ]]; then
echo -e "\e[94mNo storage detected!Please check if it is mapped or if the link is multi-link!\e[0m"
exit
fi
echo
if [ "$wwid" == "" ]; then
echo -e "\e[94mThe wwid of the system disk $osdisk is not detected,the current host may be a virtual machine,and $osdisk has been used as a blacklisted device in the multipath configuration file!\e[0m"
backlist=$osdisk
cat > /tmp/multipath.conf << EOF
blacklist{
devnode "$backlist"
}
defaults {
user_friendly_names yes
find_multipaths yes
}
multipaths {
EOF
else
backlist=$wwid
echo -e "\e[94mThe WWID of OS disk is detected as $wwid,and wwid has been used as a blacklisted device in the multipath configuration file!\e[0m"
echo
cat > /tmp/multipath.conf << EOF
blacklist{
wwid "$backlist"
}
defaults {
user_friendly_names yes
find_multipaths yes
}
multipaths {
EOF
fi
multipath=`multipath -l |grep dm- |grep [0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z] -o`
if [[ "$multipath" == "" ]];then
echo -e "\e[94mThis script does not support current storage!\e[0m"
exit
fi
for dev in $multipath;
do
size=`multipath -l $dev |grep size= |awk -F " " '{print$1}'`
dm=`multipath -l |grep $dev |grep dm-"[0-9]\{1,3\}" -o`
vendor=`multipath -l |grep $dev |awk -F "$dm" '{print$2}' |sed s/[[:space:]]//g`
multipath -l |grep $dev |awk -F "$dm" '{print$2}' |sed s/[[:space:]]//g > /tmp/vendor
multipath -l |grep $dev |awk -F "$dm" '{print$2}' |sed s/[[:space:]]//g >> /tmp/vendors
if [[ "$vendor" =~ "NETAPP,LUNC-Mode" ]]; then
echo -e "\e[94mDetected NETAPP brand FAS series storage!\e[0m"
elif [[ "$vendor" =~ "NETAPP,INF-01-00" ]]; then
echo -e "\e[94mDetected NETAPP brand E series storage!\e[0m"
elif [[ "$vendor" =~ "LSI,INF-01-00" ]]; then
echo -e "\e[94metected NETAPP brand E series storage!\e[0m"
elif [[ "$vendor" =~ "LENOVO,DE_Series" ]]; then
echo -e "\e[94mDetected LENOVO brand DE series storage!\e[0m"
elif [[ "$vendor" =~ "Lenovo,DS2200" ]]; then
echo -e "\e[94mDetected LENOVO brand DS2200 storage!\e[0m"
elif [[ "$vendor" =~ "Lenovo,DS4200" ]]; then
echo -e "\e[94mDetected LENOVO brand DS4200 storage!\e[0m"
elif [[ "$vendor" =~ "Lenovo,DS6200" ]]; then
echo -e "\e[94mDetected LENOVO brand DS6200 storage!\e[0m"
elif [[ "$vendor" =~ "IBM,2145" ]]; then
echo -e "\e[94mDetected IBM brand V or FS series storage!\e[0m"
elif [[ "$vendor" =~ "HUAWEI,XSG1" ]]; then
echo -e "\e[94mDetected HUAWEI brand OceanStor series storage!\e[0m"
elif [[ "$vendor" =~ "INSPUR,MCS" ]]; then
echo -e "\e[94mDetected INSPUR brand G2 series storage!\e[0m"
elif [[ "$vendor" =~ "COMPELNT,CompellentVol" ]]; then
echo -e "\e[94mDetected DELL brand SC series storage!\e[0m"
elif [[ "$vendor" =~ "DELL,MD34xx" ]]; then
echo -e "\e[94mDetected DELL brand MD34xx series storage!\e[0m"
elif [[ "$vendor" =~ "DELL,MD32xx" ]]; then
echo -e "\e[94mDetected DELL brand MD32xx series storage!\e[0m"
elif [[ "$vendor" =~ "DELL,MD36xx" ]]; then
echo -e "\e[94mDetected DELL brand MD36xx series storage!\e[0m"
elif [[ "$vendor" =~ "DELL,MD38xx" ]]; then
echo -e "\e[94mDetected DELL brand MD38xx series storage!\e[0m"
elif [[ "$vendor" =~ "HP,MSA1040SAN" ]]; then
echo -e "\e[94mDetected HPE brand MSA 1040 series storage!\e[0m"
elif [[ "$vendor" =~ "HP,MSA1050SAN" ]]; then
echo -e "\e[94mDetected HPE brand MSA 1050 series storage!\e[0m"
elif [[ "$vendor" =~ "HP,MSA2040SAN" ]]; then
echo -e "\e[94mDetected HPE brand MSA 2040 series storage!\e[0m"
elif [[ "$vendor" =~ "HP,MSA2050SAN" ]]; then
echo -e "\e[94mDetected HPE brand MSA 2050 series storage!\e[0m"
elif [[ "$vendor" =~ "MacroSAN,LU" ]]; then
echo -e "\e[94mDetected MacroSAN brand MS series storage!\e[0m"
elif [[ "$vendor" =~ "3PARdata,VV" ]]; then
echo -e "\e[94mDetected HPE brand 3PAR series storage!\e[0m"
elif [[ "$vendor" =~ "UniversalXport" ]]; then
echo -e "\e[94mIn-storage management partition detected\e[0m"
else
echo -e "\e[94mDetected $vendor brand storage!Current storage will use OS default multipath parameters!\e[0m"
fi
echo WWID is $dev
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
while true
do
if [[ "$vendor" =~ "UniversalXport" ]]; then
echo -e "\e[94mThis partition is automatically mapped for storage vendors to implement in-band management and has been blocked!\e[0m"
break;
else
echo -e "\e[94mDefine alias for storage volume [wwid is $dev $size DM is $dm]\e[0m"
read -p "Enter alias for storage volume: " dmname1
dmname=`echo ${dmname1,,}`
if [ "$dmname" == "" ]; then
echo -e "\e[94mAlias cannot be empty,please re-enter!\e[0m"
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
else
echo -e "\e[94mConfigured volume alias as: $dmname\e[0m"
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
break;
fi
fi
done
if [ "$dmname" != "" ];then
cat >> /tmp/multipath.conf << EOF
multipath {
wwid $dev
alias $dmname
}
EOF
fi
done
sleep 1
echo > /tmp/vendor
if [[ "$oskernel" != "4.18.0" ]]; then
cat >> /tmp/multipath.conf << EOF
}
devices{
EOF
echo -e "\e[94mAccording to storage brand,multipath parameters recommended by storage vendors are being written.................\e[0m"
for dev in $multipath;
do
dm=`multipath -l |grep $dev |grep dm-"[0-9]\{1,3\}" -o`
vendor1=`multipath -l |grep $dev |awk -F "$dm" '{print$2}' |sed s/[[:space:]]//g`
vendor2=`cat /tmp/vendor`
if [[ "$vendor1" == "$vendor2" ]];then
echo .
else
vendor=$vendor1
multipath -l |grep $dev |awk -F "$dm" '{print$2}' |sed s/[[:space:]]//g > /tmp/vendor
if [[ "$vendor" =~ "NETAPP,LUNC-Mode" ]]; then
cat >> /tmp/multipath.conf << EOF
device {
vendor "NETAPP"
product "LUN"
flush_on_last_del yes
dev_loss_tmo infinity
fast_io_fail_tmo 5
failback immediate
features "3 queue_if_no_path pg_init_retries 50"
hardware_handler "1 alua"
path_checker tur
path_grouping_policy group_by_prio
path_selector "round-robin 0"
prio alua
rr_min_io 1000
rr_weight uniform
}
EOF
elif [[ "$vendor" =~ "NETAPP,INF-01-00" ]]; then
cat >> /tmp/multipath.conf << EOF
device {
vendor "NETAPP"
product "INF-01-00"
path_grouping_policy "group_by_prio"
features "2 pg_init_retries 50"
path_checker "rdac"
path_selector "round-robin 0"
hardware_handler "1 rdac"
prio "rdac"
failback "immediate"
no_path_retry 30
detect_prio yes
rr_weight priorities
}
EOF
elif [[ "$vendor" =~ "LSI,INF-01-00" ]]; then
cat >> /tmp/multipath.conf << EOF
device {
vendor "LSI"
product "INF-01-00"
path_grouping_policy "group_by_prio"
features "2 pg_init_retries 50"
path_checker "rdac"
path_selector "round-robin 0"
hardware_handler "1 rdac"
prio "rdac"
failback "immediate"
no_path_retry 30
detect_prio yes
rr_weight priorities
}
EOF
elif [[ "$vendor" =~ "LENOVO,DE_Series" ]]; then
cat >> /tmp/multipath.conf << EOF
device {
vendor "LENOVO"
product "DE_Series"
path_grouping_policy "group_by_prio"
features "2 pg_init_retries 50"
path_checker "rdac"
path_selector "round-robin 0"
hardware_handler "1 rdac"
prio "rdac"
failback "immediate"
no_path_retry 30
detect_prio yes
rr_weight priorities
}
EOF
elif [[ "$vendor" =~ "Lenovo,DS2200" ]]; then
cat >> /tmp/multipath.conf << EOF
device {
vendor "Lenovo"
product "DS2200"
failback immediate
prio alua
}
EOF
elif [[ "$vendor" =~ "Lenovo,DS4200" ]]; then
cat >> /tmp/multipath.conf << EOF
device {
vendor "Lenovo"
product "DS4200"
failback immediate
prio alua
}
EOF
elif [[ "$vendor" =~ "Lenovo,DS6200" ]]; then
cat >> /tmp/multipath.conf << EOF
device {
vendor "Lenovo"
product "DS6200"
failback immediate
prio alua
}
EOF
elif [[ "$vendor" =~ "IBM,2145" ]]; then
cat >> /tmp/multipath.conf << EOF
device {
vendor "IBM"
product "2145"
path_grouping_policy "group_by_prio"
path_selector "service-time 0"
prio "alua"
path_checker "tur"
failback "immediate"
no_path_retry 5
rr_weight uniform
rr_min_io_rq "1"
dev_loss_tmo 120
}
EOF
elif [[ "$vendor" =~ "HUAWEI,XSG1" ]]; then
cat >> /tmp/multipath.conf << EOF
device {
vendor "HUAWEI"
product "XSG1"
path_grouping_policy "group_by_prio"
path_checker "tur"
path_selector "round-robin 0"
prio alua
failback "immediate"
dev_loss_tmo 30
fast_io_fail_tmo 5
}
EOF
elif [[ "$vendor" =~ "INSPUR,MCS" ]]; then
cat >> /tmp/multipath.conf << EOF
device {
vendor "INSPUR"
product "MCS"
path_grouping_policy group_by_prio
path_selector "service-time 0"
features "1 queue_if_no_path"
path_checker tur
prio alua
failback immediate
}
EOF
elif [[ "$vendor" =~ "COMPELNT,CompellentVol" ]]; then
cat >> /tmp/multipath.conf << EOF
device {
vendor "COMPELNT"
product "Compellent Vol"
features 0
no_path_retry fail
}
EOF
elif [[ "$vendor" =~ "DELL,MD34xx" ]]; then
cat >> /tmp/multipath.conf << EOF
device {
vendor "DELL"
product "MD34xx"
path_grouping_policy "group_by_prio"
features "2 pg_init_retries 50"
path_checker "rdac"
path_selector "round-robin 0"
hardware_handler "1 rdac"
prio "rdac"
failback "immediate"
no_path_retry 30
detect_prio yes
rr_weight priorities
}
EOF
elif [[ "$vendor" =~ "DELL,MD32xxi" ]]; then
cat >> /tmp/multipath.conf << EOF
device {
vendor "DELL"
product "MD32xxi"
path_grouping_policy "group_by_prio"
features "2 pg_init_retries 50"
path_checker "rdac"
path_selector "round-robin 0"
hardware_handler "1 rdac"
prio "rdac"
polling_interval 5
failback "immediate"
no_path_retry 30
detect_prio yes
rr_weight priorities
}
EOF
elif [[ "$vendor" =~ "DELL,MD32xx" ]]; then
cat >> /tmp/multipath.conf << EOF
device {
vendor "DELL"
product "MD32xx"
path_grouping_policy "group_by_prio"
features "2 pg_init_retries 50"
path_checker "rdac"
path_selector "round-robin 0"
hardware_handler "1 rdac"
prio "rdac"
polling_interval 5
failback "immediate"
no_path_retry 30
detect_prio yes
rr_min_io 100
}
EOF
elif [[ "$vendor" =~ "DELL,MD36xxi" ]]; then
cat >> /tmp/multipath.conf << EOF
device {
vendor "DELL"
product "MD36xxi"
path_grouping_policy "group_by_prio"
features "2 pg_init_retries 50"
path_checker "rdac"
path_selector "round-robin 0"
hardware_handler "1 rdac"
prio "rdac"
polling_interval 5
failback "immediate"
no_path_retry 30
detect_prio yes
rr_min_io 100
}
EOF
elif [[ "$vendor" =~ "DELL,MD36xxf" ]]; then
cat >> /tmp/multipath.conf << EOF
device {
vendor "DELL"
product "MD36xxf"
path_grouping_policy "group_by_prio"
features "2 pg_init_retries 50"
path_checker "rdac"
path_selector "round-robin 0"
hardware_handler "1 rdac"
prio "rdac"
polling_interval 5
failback "immediate"
no_path_retry 30
detect_prio yes
rr_min_io 100
}
EOF
elif [[ "$vendor" =~ "DELL,MD38xx" ]]; then
cat >> /tmp/multipath.conf << EOF
device {
vendor "DELL"
product "MD38xx"
path_grouping_policy "group_by_prio"
features "2 pg_init_retries 50"
path_checker "rdac"
path_selector "round-robin 0"
hardware_handler "1 rdac"
prio "rdac"
failback "immediate"
no_path_retry 30
detect_prio yes
rr_weight priorities
}
EOF
elif [[ "$vendor" =~ "HP,MSA1040SAN" ]]; then
cat >> /tmp/multipath.conf << EOF
device{
vendor "HP”
product "MSA 1040 SAN"
path_grouping_policy "group_by_prio"
path_selector "round-robin 0"
rr_weight uniform
path_checker tur
hardware_handler "0"
failback immediate
no_path_retry 18
rr_min_io 100
}
EOF
elif [[ "$vendor" =~ "HP,MSA1050SAN" ]]; then
cat >> /tmp/multipath.conf << EOF
device{
vendor "HP”
product "MSA 1050 SAN"
path_grouping_policy "group_by_prio"
path_selector "round-robin 0"
rr_weight uniform
path_checker tur
hardware_handler "0"
failback immediate
no_path_retry 18
rr_min_io 100
}
EOF
elif [[ "$vendor" =~ "HP,MSA2040SAN" ]]; then
cat >> /tmp/multipath.conf << EOF
device{
vendor "HP”
product "MSA 2040 SAN"
path_grouping_policy "group_by_prio"
path_selector "round-robin 0"
rr_weight uniform
path_checker tur
hardware_handler "0"
failback immediate
no_path_retry 18
rr_min_io 100
}
EOF
elif [[ "$vendor" =~ "HP,MSA2050SAN" ]]; then
cat >> /tmp/multipath.conf << EOF
device{
vendor "HP”
product "MSA 2050 SAN"
path_grouping_policy "group_by_prio"
path_selector "round-robin 0"
rr_weight uniform
path_checker tur
hardware_handler "0"
failback immediate
no_path_retry 18
rr_min_io 100
}
EOF
elif [[ "$vendor" =~ "HP,MSA2050SAN" ]]; then
cat >> /tmp/multipath.conf << EOF
device{
vendor "HP”
product "MSA 2050 SAN"
path_grouping_policy "group_by_prio"
path_selector "round-robin 0"
rr_weight uniform
path_checker tur
hardware_handler "0"
failback immediate
no_path_retry 18
rr_min_io 100
}
EOF
elif [[ "$vendor" =~ "MacroSAN,LU" ]]; then
cat >> /tmp/multipath.conf << EOF
device{
vendor "MacroSAN"
product "LU"
path_grouping_policy group_by_prio
path_selector "round-robin 0"
path_checker tur
prio alua
no_path_retry 30
hardware_handler "0"
failback 15
}
EOF
elif [[ "$vendor" =~ "3PARdata,VV" ]]; then
cat >> /tmp/multipath.conf << EOF
device{
vendor "3PARdata"
product "VV"
path_grouping_policy group_by_prio
path_selector "round-robin 0"
path_checker tur
features "0"
hardware_handler "1 alua"
prio alua
failback immediate
rr_weight uniform
no_path_retry 18
rr_min_io_rq 1
detect_prio yes
fast_io_fail_tmo 10
dev_loss_tmo 14
}
EOF
fi
fi
done
fi
cat >> /tmp/multipath.conf << EOF
}
EOF
xport=`cat /tmp/vendors`
if [[ "$xport" =~ "UniversalXport" ]];then
sed -i 's/blacklist{/&\ndevice{\nvendor "*"\nproduct "Universal Xport"\n}/' /tmp/multipath.conf
fi
if [[ "$vendor" =~ "IBM,2145" && "$oskernel" = "2.6.32" ]];then
sed -i '/path_selector/s/service-time 0/round-robin 0/' /tmp/multipath.conf
fi
hpe3par=`cat /tmp/vendors`
if [[ "$hpe3par" =~ "3PARdata,VV" && "$oskernel" = "2.6.32" ]];then
echo -e "\e[94mThe Detected storage is HPE 3PAR series,officially recommended to use
[Generic-ALUA role 2], linux7.x series use [Generic-ALUA role 2] by default.In view of
the fact that OS is 6.x series,please select the role definition of the host you created\e[0m"
echo -e "\e[94m###################################################################\e[0m"
echo -e "\e[94m# 1.[Generic Persona 1] #\e[0m"
echo -e "\e[94m# 2.[Generic-ALUA Persona 2] #\e[0m"
echo -e "\e[94m###################################################################\e[0m"
while true
do
read -p "Select the host role definition and enter the numbers: " hostnum
if [[ "$hostnum" == 1 ]];then
echo -e "\e[94mChosen [Generic Persona 1]\e[0m"
break;
elif [[ "$hostnum" == 2 ]];then
echo -e "\e[94mChosen [Generic-ALUA Persona 2]\e[0m"
break;
else
echo -e "\e[94mChoose the correct host definition!\e[0m"
fi
done
fi
if [[ "$hostnum" == 1 ]];then
sed -i '/path_grouping_policy/s/group_by_prio/multibus/' /tmp/multipath.conf
sed -i '/prio/d' /tmp/multipath.conf
echo -e "\e[94mThe multipath parameters of [Generic Persona 1] have been adapted!\e[0m"
fi
cat /tmp/multipath.conf > /etc/multipath.conf
sleep 1
echo -e "\e[94mConfiguring multipath..........................\e[0m"
if [ "$oskernel" = "2.6.32" ]; then
service multipathd restart > /dev/null 2>&1
sleep 3
multipath -F
multipath -v2 > /dev/null 2>&1
multipath -ll
fi
if [[ "$oskernel" = "3.10.0" ]]; then
systemctl restart multipathd
sleep 3
multipath -F
multipath -v2 > /dev/null 2>&1
multipath -ll
fi
if [[ "$oskernel" = "4.18.0" ]]; then
sleep 1
systemctl restart multipathd > /dev/null 2>&1
sleep 3
multipath -F
multipath -v2 > /dev/null 2>&1
multipath -ll
fi
rm -f /tmp/multipath.conf
rm -f /tmp/nic
rm -f /tmp/vendor
rm -f /tmp/vendors
echo -e "\e[94mMultipath configuration is completed!\e[0m"
echo -e "\e[94m-------------------------------------------------------------------\e[0m"
fi