集群部署脚本
#!/bin/bash
. /etc/init.d/functions
#定义主机清单
export MASTER_IP=192.168.31.160
export NODE_IP=(192.168.31.161
192.168.31.163
192.168.31.164
)
export SUBNET=192.168.31.0
export Domainname="ginpie.com"
export PASSWORD="123456"
datename=$(date +%Y%m%d-%H%M%S)
#安装OHPC源
yum -y install http://build.openhpc.community/OpenHPC:/1.3/CentOS_7/x86_64/ohpc-release-1.3-1.el7.x86_64.rpm
yum -y install --skip-broken ohpc-base ohpc-warewulf
echo "------------------------------------------------"
if [ `echo $?` -eq 0 ];then
action "安装ohpc-base ohpc-warewulf" /bin/true
else
action "安装ohpc-base ohpc-warewulf" /bin/false
exit 1
fi
echo "-------------------------------------------------"
sleep 5
yum install -y pdsh-ohpc
echo "------------------------------------------------"
if [ `echo $?` -eq 0 ];then
action "安装pdsh" /bin/true
else
action "安装pdsh" /bin/false
exit 2
fi
echo "-------------------------------------------------"
sleep 5
#第二阶段
#bash
###############################################################################################
#配置免密登录
if [ -f /root/.ssh/cluster.pub ]
then
for i in ${NODE_IP[@]}
do
expect send-sshkey.exp /root/.ssh/cluster.pub $i $PASSWORD
done
else
echo -e "\e[1;31m请检查ohpc是否按照完成\e[0m"
echo -e "\e[1;31m使用bash命令后,再次执行\e[0m"
exit 4
fi
#配置主机名
hostnamectl set-hostname mgt
[ -n `hostname |grep mgt` ] || exit 5
#配置hosts文件并分发给其他节点
c=`grep mgt /etc/hosts | wc -l`
if [ ${c} -gt 0 ];then
sed -i '3,$'d /etc/hosts
fi
echo "$MASTER_IP mgt">>/etc/hosts
count=1
for i in ${NODE_IP[@]};do
pdsh -w $i "hostnamectl set-hostname cn${count}"
echo "$i cn${count}">>/etc/hosts
count=$((count+=1))
done
sed -i "s@cn\([0-9]\{1,\}\)@cn\1 cn\1.${Domainname}@g" /etc/hosts
sed -i "s@mgt@mgt mgt.${Domainname}@g" /etc/hosts
for i in ${NODE_IP[@]};do
pdsh -w ${i} 'rm -rf /etc/hosts'
scp /etc/hosts ${i}:/etc/
done
yum -y install ypserv rpcbind
echo "-------------------------------------------------"
if [ `echo $?` -eq 0 ];then
action "安装ypserv rpcbind" /bin/true
else
action "安装ypserv rpcbind" /bin/false
exit 1
fi
echo "-------------------------------------------------"
ypdomainname ${Domainname}
grep $SUBNET /usr/share/doc/ypserv-2.31/securenets || echo "255.255.255.0 $SUBNET" >>/usr/share/doc/ypserv-2.31/securenets
grep ${Domainname} /etc/sysconfig/network || echo "NISDOMAIN=${Domainname}" >> /etc/sysconfig/network
systemctl restart rpcbind ypserv ypxfrd yppasswdd
systemctl enable rpcbind ypserv ypxfrd yppasswdd
if [ `systemctl status rpcbind ypserv ypxfrd yppasswdd|grep Active|awk '{print $2}'|wc -l` -eq 4 ];then
action "启动rpcbind ypserv ypxfrd yppasswdd" /bin/true
else
action "启动rpcbind ypserv ypxfrd yppasswdd" /bin/false
exit 6
fi
/usr/lib64/yp/ypinit -m
for i in ${NODE_IP[@]}
do
pdsh -w $i 'yum -y install rpcbind ypbind'
pdsh -w $i ypdomainname $Domainname
pdsh -w $i "grep ${Domainname} /etc/sysconfig/network || echo "NISDOMAIN=${Domainname}" >> /etc/sysconfig/network"
pdsh -w $i "authconfig --enablenis --nisdomain=$Domainname --nisserver=mgt.${Domainname} --enablemkhomedir --update"
if [ `echo $?` -eq 0 ];then
action "计算节点authconfig" /bin/true
else
action "计算节点authconfig" /bin/false
exit 1
fi
pdsh -w $i 'systemctl enable rpcbind ypbind'
pdsh -w $i 'systemctl restart rpcbind ypbind'
done
#配置NTP
systemctl enable ntpd.service
c=`grep aliyun /etc/ntp.conf | wc -l`
if [ ${c} -gt 0 ];then
sed -i '59,$'d /etc/ntp.conf
fi
echo "server ntp1.aliyun.com">>/etc/ntp.conf
systemctl restart ntpd
systemctl enable ntpd
for i in ${NODE_IP[@]};do
pdsh -w $i 'yum -y install ntp'
#pdsh -w $i 'rm -rf /etc/ntp.conf'
#scp /etc/ntp.conf $i:/etc/ntp.conf
pdsh -w $i 'echo "server mgt">>/etc/ntp.conf'
pdsh -w $i 'systemctl enable ntpd'
pdsh -w $i 'systemctl restart ntpd'
done
#配置limit
c=`grep 65535 /etc/security/limits.conf | wc -l`
if [ ${c} -gt 0 ];then
sed -i '62,$'d /etc/security/limits.conf
fi
echo "* soft nofile 65535">>/etc/security/limits.conf
echo "* hard nofile 65535">>/etc/security/limits.conf
echo "* soft memlock unlimited">>/etc/security/limits.conf
echo "* hard memlock unlimited">>/etc/security/limits.conf
echo "* soft stack unlimited">>/etc/security/limits.conf
echo "* hard stack unlimited">>/etc/security/limits.conf
for i in ${NODE_IP[@]} ;do
pdsh -w $i 'cp -a /etc/security/limits.conf /etc/security/limits.conf.bak${datename}'
scp /etc/security/limits.conf $i:/etc/security/
done
#配置PBS
yum -y install pbspro-server-19.1.1-0.x86_64.rpm
c=`grep -E '\-s' /opt/pbs/lib/init.d/limits.pbs_mom|wc -l`
if [ ${c} -gt 2 ];then
sed -i '12,$'d /opt/pbs/lib/init.d/limits.pbs_mom
echo "ulimit -s unlimited">>/opt/pbs/lib/init.d/limits.pbs_mom
else
echo "ulimit -s unlimited">>/opt/pbs/lib/init.d/limits.pbs_mom
fi
systemctl enable pbs
systemctl restart pbs
count=1
for i in ${NODE_IP[@]}
do
/opt/pbs/bin/qmgr -c "create node cn${count}"
count=$((count+=1))
done
/opt/pbs/bin/qmgr -c 'set server flatuid=true'
/opt/pbs/bin/qmgr -c "set server job_history_enable=True"
for i in ${NODE_IP[@]}
do
scp pbspro-execution-19.1.1-0.x86_64.rpm $i:/root/
pdsh -w $i 'yum install -y pbspro-execution-19.1.1-0.x86_64.rpm'
pdsh -w $i "sed -i 's@CHANGE_THIS_TO_PBS_PRO_SERVER_HOSTNAME@mgt@g' /var/spool/pbs/mom_priv/config"
pdsh -w $i "sed -i 's@CHANGE_THIS_TO_PBS_PRO_SERVER_HOSTNAME@mgt@g' /etc/pbs.conf"
#######c=`grep -E '\-s' /opt/pbs/lib/init.d/limits.pbs_mom|wc -l`
#######if [ ${c} -gt 2 ];then
####### sed -i '12,$'d /opt/pbs/lib/init.d/limits.pbs_mom
####### echo "ulimit -s unlimited">>/opt/pbs/lib/init.d/limits.pbs_mom
#######else
####### echo "ulimit -s unlimited">>/opt/pbs/lib/init.d/limits.pbs_mom
####### fi
pdsh -w $i 'cp -a /opt/pbs/lib/init.d/limits.pbs_mom /opt/pbs/lib/init.d/limits.pbs_mom.bak${datename}'
scp /opt/pbs/lib/init.d/limits.pbs_mom $i:/opt/pbs/lib/init.d/
pdsh -w $i 'systemctl enable pbs'
pdsh -w $i 'systemctl restart pbs'
done
#配置NFS
yum install -y nfs-utils
grep '/home' /etc/exports || echo "/home *(rw,no_subtree_check,fsid=10,no_root_squash)" >> /etc/exports
grep '/opt/ohpc/pub' /etc/exports || echo "/opt/ohpc/pub *(rw,no_subtree_check,fsid=11,no_root_squash)" >> /etc/exports
grep '/data' /etc/exports || echo "/data *(rw,no_subtree_check,fsid=12,no_root_squash)" >> /etc/exports
systemctl enable nfs
systemctl enable rpcbind
systemctl restart rpcbind
systemctl restart nfs
for i in ${NODE_IP[@]}
do
pdsh -w $i 'yum install -y nfs-utils'
pdsh -w $i 'systemctl restart nfs'
pdsh -w $i 'systemctl enable nfs'
pdsh -w $i 'mkdir -pv /data /opt/ohpc/pub'
pdsh -w $i "grep /home /etc/fstab || echo $MASTER_IP:/home /home nfs nfsvers=4,nodev,nosuid,noatime,_netdev 0 0 >> /etc/fstab"
pdsh -w $i "grep /opt/ohpc/pub /etc/fstab || echo $MASTER_IP:/opt/ohpc/pub /opt/ohpc/pub nfs nfsvers=4,nodev,noatime,_netdev 0 0 >> /etc/fstab"
pdsh -w $i "grep /data /etc/fstab || echo $MASTER_IP:/data /data nfs nfsvers=4,nodev,nosuid,noatime,_netdev 0 0 >> /etc/fstab"
pdsh -w $i "mount -a"
done