Seislab 管理脚本备份

机器新装

新机系统设置脚本 setting.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash

set -e

yeah='\033[32mYeah\033[39m'
warn='\033[33mWarning\033[39m'
error='\033[31mERROR\033[39m'

function finishprint() {
if [ ${1} -eq 0 ]; then
echo -e "${yeah}: Finish ${2} when setting ${3}"
else
echo -e ">> ${error}: Fail ${2} when setting ${3}"
fi
}

# no-password login
operation="no-password loging"
echo "==========================================================================="
echo "Set ${operation}:"

systemctl stop firewalld.service
finishprint $? "1/4" ${operation}

systemctl disable firewalld.service
finishprint $? "2/4" ${operation}

setenforce 0
finishprint $? "3/4" ${operation}

echo " > please edit /etc/selinux/config: SELINUX=... => SELINUX=disabled"
read -p " > press any key to edit:"
vi /etc/selinux/config
finishprint $? "4/4" ${operation}

# EPEL source
operation="EPEL source"
echo "==========================================================================="
echo "Set ${operation}:"

yum -y install epel-release
finishprint $? "1/2" ${operation}

yum clean all && yum makecache
finishprint $? "2/2" ${operation}

# ELRepo source
operation="ELRepo source"
read -p "> Do you want to configure ELRepo source? (Y/n):" ELRepo
if [ "${ELRepo}" == "Y" ]; then
echo "==========================================================================="
echo "Set ${operation}:"

rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
finishprint $? "1/2" ${operation}

read -p " > please enter version number (x.x-x):" ver
rpm -Uvh http://www.elrepo.org/elrepo-release-${ver}.e17.elrepo.noarch.rpm
finishprint $? "2/2" ${operation}
fi

# rename host
operation="hostname"
echo "==========================================================================="
echo "Set ${operation}:"

read -p " > please enter a new hostname:" host
hostnamectl set-hostname ${host}
finishprint $? "1/1" ${operation}

# modify timezone
operation="timezone"
echo "==========================================================================="
echo "Set ${operation}:"

timedatectl set-timezone Asia/Shanghai && timedatectl set-local-rtc 1
finishprint $? "1/1" ${operation}

# some soft-link
operation="soft-links"
echo "==========================================================================="
echo "Set ${operation}:"

mkdir -p /opt/intel/licenses
finishprint $? "1/3" ${operation}

ln -s /home/data/system/software/intel_compiler.lic /opt/intel/licenses/intel_compiler.lic
finishprint $? "2/3" ${operation}

ln -s /home/data/system/motd.sh /etc/profile.d/
finishprint $? "3/3" ${operation}

echo "==========================================================================="
echo "> Finish all auto-config \\(^.^)/"
echo "> Next you should (optional):"
echo " 1) install more basic softwares (software.sh);"
echo " 2) setup font library;"
echo " 3) install and configure InfiniBand;"
echo " 4) mount local disk and remote directory (mount.all.sh);"
echo " 5) install and configure PBS Pro;"
echo " 6) install and configure NVIDIA driver and cuda library;"
echo " 7) copy user information files (cpusr.all.sh)."
echo

新机软件安装脚本 software.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash

set -e

read -p "Ensure to install these softwares [-y/ ]:" YorN

# compiler
yum ${YorN} install gcc-gfortran gcc-c++.x86_64

# shell
yum ${YorN} install zsh

# minitool
yum ${YorN} install vim htop tmux mlocate mkfontscale
yum ${YorN} install autojump && yum ${YorN} install autojump-zsh.noarch

# for remote mount
yum ${YorN} install nfs-utils rpcbind

# library
yum ${YorN} install hdf5-devel

新机用户拷贝脚本 cpusr.first.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash

blacklist="asc sccp hym01"

backdir=/root/backup
userdir=/home/data/system/user
ftemp1=/tmp/cpusr.1.$$
ftemp2=/tmp/cpusr.2.$$

mkdir -p ${backdir}

function copy_info() {
cp /etc/${1} ${backdir}/
cp ${userdir}/${1} ${ftemp1}

for i in ${blacklist}
do
cp ${ftemp1} ${ftemp2}
cat ${ftemp2} | grep -v ${i} > ${ftemp1}
done

cp ${ftemp1} /etc/${1}
}

copy_info passwd
copy_info group
copy_info shadow
copy_info gshadow

rm -f ${ftemp1} ${ftemp2}

日常维护

单机操作

单机新增用户拷贝脚本 cpusr.indv.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash

username=${1}
RED='\033[01;31m'
STA='\033[00m'

function copy_info() {
# backup the info.-file
cp /etc/${3} /root/backup/

# append the user-info. to file
cat ${1}/${3} | awk -F: '{if($1 == "'${username}'") print $0}' >> ${2}/${3}

# check the info.-file
echo "GREP <${2}/${3}>: " `grep ${username} ${2}/${3}`

echo
}

function copy_user() {
if [ ${username} ]; then
yon=${3}
if [ -z ${yon} ]; then
echo -en "Ensure to copy user info. for ${RED}${username}${STA} [Y/n]: "
read yon
fi
if [ "${yon}" == "Y" ]; then
# for /etc/passwd
copy_info ${1} ${2} passwd

# for /etc/group
copy_info ${1} ${2} group

# for /etc/shadow
copy_info ${1} ${2} shadow

# for /etc/gshadow
copy_info ${1} ${2} gshadow
fi
else
echo "No user to copy!"
fi
}

if [ `hostname` == "seislab1" ]; then
copy_user /etc /home/data/system/user ${2}
else
copy_user /home/data/system/user /etc ${2}
fi

单机普通目录远程挂载脚本 mount.indv.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash

#set -e

host=`hostname`
yeah='\033[32mYeah\033[39m'
warn='\033[33mWarning\033[39m'
error='\033[31mERROR\033[39m'

if [ "${host}" == "seislab2" -o "${host}" == "garray2" ]; then
# for NO infiniband hosts: seislab2 and garray2
list="seislab1:xx.xx.xx.xxx:/public: \
seislab2:seislab2:/shdisk/lab2:/dev/sda2 \
seislab5:seislab5:/shdisk/lab5:/dev/sdb \
seislab6:seislab6:/shdisk/lab6:/dev/sdb \
seislab0:seislab0:/data:/dev/sda1 \
garray3:garray3:/shdisk/ary3:/dev/sda \
garray4:garray4:/shdisk/ary4:/dev/sdb \
remdata1:remdata1:/shdisk/rem1: "
else
# for other hosts:
list="seislab1:192.18.1.101:/public: \
seislab2:seislab2:/shdisk/lab2:/dev/sda2 \
seislab5:seislab5:/shdisk/lab5:/dev/sdb \
seislab6:seislab6:/shdisk/lab6:/dev/sdb \
seislab0:seislab0:/data:/dev/sda1 \
garray3:garray3:/shdisk/ary3:/dev/sda \
garray4:garray4:/shdisk/ary4:/dev/sdb \
remdata1:remdata1:/shdisk/rem1: "
fi

function print_help() {
echo
echo "/home/data/system/scripts/mount.sh <option>"
echo " option list:"
echo " local - local mount its own devices on one host."
echo " remote - remote mount other host directories on one host."
echo " unload - umount all mounted directories on one host."
echo
exit ${1}
}

function print_return_code() {
if [ ${1} -eq 0 ]; then
echo -e "${yeah}: Finished for ${2} @${3}"
else
echo -e ">> ${warn}: Failed for ${2} @${3}"
fi
}

function mount_list() {
for i in ${list}
do
hs=`echo ${i} | awk -F ":" '{print $1}'`
ip=`echo ${i} | awk -F ":" '{print $2}'`
mp=`echo ${i} | awk -F ":" '{print $3}'`
dv=`echo ${i} | awk -F ":" '{print $4}'`

if [ "${1}" == "local" ]; then
if [ "${host}" == "${hs}" ]; then
if ! grep -qs "${mp}" /proc/mounts; then
if [[ -n ${dv} ]]; then
mount ${dv} ${mp}
print_return_code $? ${mp} ${hs}
ls ${mp}
fi
fi
fi
fi

if [ "${1}" == "remote" ]; then
if [ "${host}" != "${hs}" ]; then
if ! grep -qs "${mp}" /proc/mounts; then
mount -t nfs ${ip}:${mp} ${mp}
print_return_code $? ${mp} ${hs}
fi
fi
fi

if [ "${1}" == "unload" ]; then
if grep -qs "${mp}" /proc/mounts; then
umount -l ${mp}
print_return_code $? ${mp} ${hs}
fi
fi

done
}

if [ $# -ne 1 ]; then
print_help 1
else
if [ ${1} == "-h" -o ${1} == "--help" ]; then
print_help 0
elif [ ${1} == "local" -o ${1} == "remote" -o ${1} == "unload" ]; then
mount_list ${1}
else
print_help 2
fi
fi

集群操作

集群新增用户拷贝脚本 cpusr.all.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/bash

set -e
RED='\033[01;31m'
STA='\033[00m'

cmdcpusr=/home/data/system/scripts/cpusr.indv.sh
nodelist="seislab1 seislab2 seislab3 seislab4 seislab5 seislab6 \
seislab0 garray1 garray2 garray3 garray4"

username=${1}
yon=${2}
if [ -z ${yon} ]; then
echo -en "Ensure to copy user info. for ${RED}${username}${STA} [Y/n]: "
read yon
fi

if [ "${yon}" == "Y" ]; then
for i in ${nodelist}
do
echo ">> prepare to cpusr on ${i} ..."
ssh ${i} "${cmdcpusr} ${username} ${yon}"
done
else
echo "No user to copy!"
fi

集群 home 目录远程挂载脚本 mount.home.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# !/bin/bash

set -e

# for normal nodes:
nodelist="seislab3 seislab4 seislab5 seislab6 \
seislab0 garray1 garray3 garray4"

for i in ${nodelist}
do
ssh ${i} "grep /home /proc/mounts | grep -qs seislab1 || \
mount -t nfs 192.18.1.101:/home /home"
done

# for NO-infiniband nodes:
noiblist="seislab2 garray2"

for i in ${noiblist}
do
ssh ${i} "grep /home /proc/mounts | grep -qs seislab1 || \
mount -t nfs xx.xx.xx.xxx:/home /home"
done

集群普通目录远程挂载脚本 mount.all.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/bash

set -e

cmdmount=/home/data/system/scripts/mount.indv.sh
nodelist="seislab1 seislab2 seislab3 seislab4 seislab5 seislab6 \
seislab0 garray1 garray2 garray3 garray4"

for i in ${nodelist}
do
echo ">> prepare to mount local on ${i} ..."
ssh ${i} "${cmdmount} local"
done

for i in ${nodelist}
do
echo ">> prepare to mount remote on ${i} ..."
ssh ${i} "${cmdmount} remote"
done
---------- 文结至此 静待下章 ----------