tongsiying

阅读|运动|自律

0%

BlockStorage-tool

校验副本间extent、seq是否一致

extent-check.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
104
105
106
107
108
109
110
#/bin/bash
ZONE1=(
"10.238.161.1"
"10.238.161.2")
ZONE2=(
"10.238.161.3"
"10.238.161.4")
ZONE3=(
"10.238.161.5"
"10.238.161.6")

LOCAL_PATH=`pwd`
rm -rf ${LOCAL_PATH}/zone*.log ${LOCAL_PATH}/result.log ${LOCAL_PATH}/f-result.log

exec 5>>${LOCAL_PATH}/zone1.log
exec 6>>${LOCAL_PATH}/zone2.log
exec 7>>${LOCAL_PATH}/zone3.log
exec 9>>${LOCAL_PATH}/result.log

thread_num=4000

tempfifo="my_temp_fifo"
mkfifo ${tempfifo}
exec 8<>${tempfifo}
rm -f ${tempfifo}

ProgressBar()
{
local current=$1; local total=$2
local now=$((current*100/total))
local last=$(((current-1)*100/total))
[[ $((last % 2)) -eq 1 ]]&&let last++
local str=$(for i in `seq 1 $((last/2))`; do printf '#'; done)
use_time=`ps -p $$ -o etime|column -t|tail -1`
for ((i=$last;$i<=$now;i+=2));do printf "\r[%-50s]%d%%[%03d/%03d][%-5s]\r" "$str" $i $current $total ${use_time};str+='#';done
}

ex_zone1() {
curl -s -X GET "http://${ZONE1[0]}:8080/sys/debug/extentlist?pretty=y"|grep -E "extentId|tranSeq"|sed -n '{N;s/\n/ /p}'|sed 's/ //g'|sed 's/ //g'|sed 's/"extentId":"//g'|sed 's/","/:/g'|sed 's/tranSeq"://g'|sed 's/,//g' >> ZONE1.log
curl -s -X GET "http://${ZONE1[1]}:8080/sys/debug/extentlist?pretty=y"|grep -E "extentId|tranSeq"|sed -n '{N;s/\n/ /p}'|sed 's/ //g'|sed 's/ //g'|sed 's/"extentId":"//g'|sed 's/","/:/g'|sed 's/tranSeq"://g'|sed 's/,//g' >> ZONE1.log
sort -t ":" -n -k2 ZONE1.log >&5
rm -rf ZONE1.log
}

ex_zone2() {
curl -s -X GET "http://${ZONE2[0]}:8080/sys/debug/extentlist?pretty=y"|grep -E "extentId|tranSeq"|sed -n '{N;s/\n/ /p}'|sed 's/ //g'|sed 's/ //g'|sed 's/"extentId":"//g'|sed 's/","/:/g'|sed 's/tranSeq"://g'|sed 's/,//g' >> ZONE2.log
curl -s -X GET "http://${ZONE2[1]}:8080/sys/debug/extentlist?pretty=y"|grep -E "extentId|tranSeq"|sed -n '{N;s/\n/ /p}'|sed 's/ //g'|sed 's/ //g'|sed 's/"extentId":"//g'|sed 's/","/:/g'|sed 's/tranSeq"://g'|sed 's/,//g' >> ZONE2.log
sort -t ":" -n -k2 ZONE2.log >&6
rm -rf ZONE2.log
}

ex_zone3() {
curl -s -X GET "http://${ZONE3[0]}:8080/sys/debug/extentlist?pretty=y"|grep -E "extentId|tranSeq"|sed -n '{N;s/\n/ /p}'|sed 's/ //g'|sed 's/ //g'|sed 's/"extentId":"//g'|sed 's/","/:/g'|sed 's/tranSeq"://g'|sed 's/,//g' >> ZONE3.log
curl -s -X GET "http://${ZONE3[1]}:8080/sys/debug/extentlist?pretty=y"|grep -E "extentId|tranSeq"|sed -n '{N;s/\n/ /p}'|sed 's/ //g'|sed 's/ //g'|sed 's/"extentId":"//g'|sed 's/","/:/g'|sed 's/tranSeq"://g'|sed 's/,//g' >> ZONE3.log
sort -t ":" -n -k2 ZONE3.log >&7
rm -rf ZONE3.log
}

check_extent() {
for ((i=1;i<=${thread_num};i++))
do
{
echo
}

done >&8

num=0
len=$(wc -l ${LOCAL_PATH}/zone1.log | sed 's/^[ \t]*//g' | cut -d ' ' -f1)
mi_len=`expr $len / 2`
cat ${LOCAL_PATH}/zone1.log |awk -F ":" '{print $1}'| while read line
do
{
let num=${num}+1
if [ $(($num%4000)) = '0' ] || [ $num == $len ];then
ProgressBar $num $len
fi

read -u8
{
readzone1=`cat ${LOCAL_PATH}/zone1.log|grep ${line}`
readzone2=`cat ${LOCAL_PATH}/zone2.log|grep ${line}`
readzone3=`cat ${LOCAL_PATH}/zone3.log|grep ${line}`

if [ "${readzone1}" == "${readzone2}" ] && [ "${readzone2}" == "${readzone3}" ];then
echo >> /dev/null
else
echo A:${readzone1}"|"B:${readzone2}"|"C:${readzone3} >&9
fi
#sed -i "/$readzone1/d" ${LOCAL_PATH}/zone1.log ${LOCAL_PATH}/zone2.log ${LOCAL_PATH}/zone3.log
echo "" >&8
} &
}
done
printf "\n"
wait
exec 8>&-
}

function main()
{
a=$(date +%H%M%S)
ex_zone1
ex_zone2
ex_zone3
check_extent
exit 0
}

main

snbs版本编译脚本

sh snbs-1_10_256M_Ft_Sherman.sh -f snbs.cfg

snbs-1_10_256M_Ft_Sherman.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash
# ----------------------------------------------
# Filename: snbs-1_10.sh
# Version: 0.1
# Date: 2019/02/19
# Description: 1.add auto install. 2.modify manual install.
# ----------------------------------------------
# -------------------Variable-------------------
SCRIPTE_NAME=$(readlink -f $0)
SCRIPTE_PATH=$(cd `dirname $0`; pwd)
OS_VER="centos73"
VERSION_PATH="/mnt/data/version/${OS_VER}/snbs/Ft_Sherman/256M"
GIT="/usr/bin/git"
CP="/bin/cp -rf"
# -------------------Function-------------------
function usage()
{
echo "Usage:"
echo "sh $0 [options]"
echo "options:"
echo " -h, --help ; show this message"
echo " -f, --file=FILE ; select a specific configure file"
echo "Example:"
echo " sh $0 -f snbs.cfg"
echo ""
}

function parse()
{
RET=`getopt -o hf: \
--long help,file: \
-n "ERROR" -- "$@"`
if [ $? -ne 0 ]
then
usage
exit 1
fi

eval set -- "$RET"
while true
do
case "$1" in
-h | --help)
usage
exit 0
;;
-f | --file)
configure_file=$2
shift 2
;;
--)
shift
break
;;
*)
usage
exit 1
;;
esac
done

if [[ -n $configure_file ]] && [[ -f "${SCRIPTE_PATH}/${configure_file}" ]]
then
source ${SCRIPTE_PATH}/${configure_file}
else
usage
exit 1
fi
}

function main()
{
VERSION="SNBS_${GITBRANCH##*_}"
VERSION_FUSE="SNBSFUSE_${GITBRANCH##*_}"
rm -rf ${SCRIPTE_PATH}/snbs_git

$GIT clone $GITURL 2>&1 >/dev/null
cd ${SCRIPTE_PATH}/snbs_git
$GIT checkout $GITBRANCH 2>&1 >/dev/null
$GIT checkout $GITCOMMIT 2>&1 >/dev/null

if [ $? -ne 0 ]
then
exit 1
fi

export GOROOT="${SCRIPTE_PATH}/go1.10"
export PATH=$PATH:$GOROOT/bin
export GOPATH="${SCRIPTE_PATH}/snbs_git/go/snbs"
LD_FLAG="-X code.suning.com/util.VERSION=${VERSION}-CentOS7.3-${GITNUM}-256M"
LD_FLAG_FUSE="-X code.suning.com/util.VERSION=${VERSION_FUSE}-CentOS7.3-${GITNUM}-256M"
go install -tags "256MB" -ldflags "$LD_FLAG" code.suning.com/server
go install -tags "256MB" -ldflags "$LD_FLAG_FUSE" code.suning.com/snbsfuse
#go build /opt/compile/snbs/snbs_git/go/snbs/src/code.suning.com/test/mastertool.go
if [ $? -ne 0 ]
then
echo "[Error] compile ${VERSION} fail, exit!"
exit
else
echo "[INFO] compile ${VERSION} success!"
fi
cd ..
echo "[`date +'%F %T'`]" >> compile.log
echo "-------" >> compile.log
cat $configure_file >> compile.log
echo "-------" >> compile.log
mkdir -p ${VERSION_PATH}/${GITNUM}/ETCD
$CP ./snbs_git/go/snbs/bin/* ${VERSION_PATH}/${GITNUM}
cd ${SCRIPTE_PATH}/snbs_git/c/
tar -zcvf tgt-1.0.73.tar.gz tgt-1.0.73 >> /dev/null
cd ${SCRIPTE_PATH}
$CP ./snbs_git/c/tgt-1.0.73.tar.gz ${VERSION_PATH}/${GITNUM}
$CP ./snbs_git/c/*.rpm ${VERSION_PATH}/${GITNUM}
$CP ./snbs_git/thirdparty/etcd/etcd-v3.3.12-linux-amd64.tar.gz ${VERSION_PATH}/${GITNUM}/ETCD/
$CP ./snbs_git/thirdparty/etcd/run-etcd.sh ${VERSION_PATH}/${GITNUM}/ETCD/
$CP -r ./snbs_git/snbs_supervisor/ ${VERSION_PATH}/${GITNUM}
$CP -r ./snbs_git/thirdparty/nrpe/CentOS7.3/SNBS-Deps ${VERSION_PATH}/${GITNUM}
cd ${VERSION_PATH}/${GITNUM}
tar -zcvf snbs_supervisor.tar.gz snbs_supervisor >> /dev/null
mv SNBS-Deps SNBS-nrpe
tar -zcvf SNBS-nrpe.tar.gz SNBS-nrpe >> /dev/null
rm -rf snbs_supervisor SNBS-nrpe
#chmod +x ${VERSION_PATH}/${GITNUM}/*.sh
echo "VERSION PATH: ${VERSION_PATH}/${GITNUM}"
}
# -------------------Main-----------------------
parse $@ && main

snbs.cfg.Ft_Sherman

1
2
3
4
5
GITURL="git@git.cnsuning.com:snbs/snbs_git.git"
#GITURL="http://git.cnsuning.com/snbs/snbs_git.git"
GITBRANCH="origin/Ft_Sherman"
GITCOMMIT="5c36def146e1497cdfd5ad1824dbda03af58c73e"
GITNUM="191115a"

snbs筛选错误日志

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
LOG="server.INFO-`date  +"%Y%m%d".gz`"
LOG_PATH="/mnt/snbslog/snbs"
KEYWORDeyword="false|fail|err|no"
IP=(
"10.238.161.1"
"10.238.161.2"
"10.238.161.3"
"10.238.161.4"
"10.238.161.5"
"10.238.161.6")


rm -rf /tmp/log
mkdir -p /tmp/log
for ip in ${IP[@]}
do
for i in Master ChunkServer TgtMaster DiskCheck Iscsiserver
do
echo ${ip} >> /tmp/log/${i}.log
echo "=======================================" >>/tmp/log/${i}.log
ssh root@${ip} "cd ${LOG_PATH}/${i};gunzip -c stackfile-20191116.gz |grep -iE '${KEYWORDeyword}'" >> /tmp/log/${i}.log
done
done

echo "cd /tmp/log/;ls"

启动脚本

sh start-fuse.sh –start/restart/status

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
#!/bin/bash
##------------------Variable------------------
MntDir="/mnt/data/" #fuse mount dir
LOG="/home/snbs/snbsfuse/log" #log dir for snbsfuse
WEED="/home/snbs/snbsfuse/snbsfuse" #snbsfuse exe file path
GATEWAYPORT="8686" #gateway http port
GATEWAYTCPPORT="8585" #gateway tcp port scsi
TGTMASTERIP="10.244.25.49"
TGTTMASTERPORT="8888"


##------------------Function------------------
function _init()
{
mkdir -p $LOG
sysctl -w net.ipv4.tcp_tw_reuse=1 >/dev/null
sysctl -w net.ipv4.tcp_tw_recycle=0 >/dev/null
sysctl -w vm.overcommit_memory=1 >/dev/null
export OMP_NUM_THREADS=1
export GOGC=20
export OMP_NUM_THREADS=2
ulimit -SHn 51200
ulimit -c unlimited
export GOTRACEBACK=crash
sysctl -w kernel.core_pattern=/home/snbs/snbsfuse/core.%e.%p.%t
}

function _start()
{
ps -ef |grep "$WEED" |grep -v grep >/dev/null
if [ $? -ne 0 ]
then
$WEED -v=0 -http=true -log_dir=$LOG snbsfuse \
-mountpoint=$MntDir \
-maxvolumelist=1 \
-debug=false \
-tgtmasterIp=$TGTMASTERIP \
-tgtmasterPort=$TGTTMASTERPORT \
-gatewayPort=$GATEWAYPORT \
-gatewayTcpPort=$GATEWAYTCPPORT \
>/dev/null 2>>${LOG}/stackfile &
fi
}

function _stop()
{
pid=`ps -ef |grep "$WEED" |grep -v grep |awk '{print $2}'`
if [ -n $pid ]
then
kill $pid
fi
}

function _restart()
{
_stop
sleep 2
_start
}

function main()
{
if [[ "$*" == "--start" ]]
then
_init && _start
elif [[ "$*" == "--stop" ]]
then
_stop
elif [[ "$*" == "--restart" ]]
then
_init && _restart
else
echo "*** excute volume script param error! ***"
fi
}
##--------------------Main--------------------
main $@

创建镜像卷

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
current=`pwd`
serverlist=`cat $current/serverlist.txt`
for SERVER in $serverlist
do
TAB1=`curl -s -X PUT "http://127.0.0.1:8686/region/pool/vol/fullclone?volname=${SERVER}"|awk -F \" '{print $4}'`
set i=0
set j=0
for((i=0;i<10;))
do
let "j=j+1"
TAB2=`curl -s -X GET "http://127.0.0.1:8686/region/pool/vol/snapshot?volname=${SERVER}&newname=${TAB1}&type=fullclone"|awk -F \" '{print $4}'`
if [ "$TAB2" = "newname exist" ];then
break;
fi
done
done

openstack安装脚本

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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#CRIPTION: copy image from ftp to os controller.
# ORGANIZATION: Suning
# CREATED: 2016/09/01
# AUTHOR: linan
#=========================================================

# return code返回码
NORMAL=0
ERROR_NO_PARAMETER_INCORRECT=100
ERROR_NO_GET_FTP_FILE_FAILED=101
ERROR_NO_IMPORT_IMAGE_BY_GLANCE_FAILED=102
ERROR_NO_OTHERS=200

#全局变量
SCRTIP_NAME="cp_image.sh" #脚本名
exec 5>>/tmp/${SCRTIP_NAME/.sh/}.log #带>&5都输出到这个日志

#--- FUNCTION 函数-------------------------------------------
# NAME: echolog
# DESCRIPTION: Echo log information to stdout.
#-------------------------------------------------------------
echolog() {
printf "[`date "+%Y/%m/%d %H:%M:%S"`]: %s\n" "$@"; #输出当前时间格式:[2019/11/10 15:43:01]:
}

#--- FUNCTION -------------------------------------------
# NAME: usage
# DESCRIPTION: Display usage information.
#----------------------------------------------------------
usage() {
cat << EOT

Usage : cp_image.sh -U <ftpAddress> -P <filePath> -N <fileName> -R <openstackRelease>

Examples:
- cp_image.sh -U "ftp://10.27.97.1" -P "/rh63/x86_64/mirror/1.0.4/" -N "RHEL6U3_64bit_75G_20150804_APP.qcow2" -I "redhat6.3_X64_20G" -R "JUNO" -Q "LOCALLVM"

Options:
-h Display this message
-U ftp image file address.
-P image file path
-N image file name
-I image file name recorded in glance
-R the openstack releases "ICEHOUSE" "JUNO" "OCATA"
-Q the openstack imageBackendType "LOCALLVM" "SNBS"
EOT
} # ---------- end of function usage ----------


function main()
{
echolog "${SCRTIP_NAME} START." >&5
while getopts ":hU:P:N:I:R:Q:" opt
do
case "${opt}" in

h ) usage; exit 0 ;;
U ) FTP_URL=$OPTARG ;;
P ) FILE_PATH=$OPTARG ;;
N ) FILE_NAME=$OPTARG ;;
I ) IMAGE_NAME=$OPTARG ;;
R ) OPENSTACK_RELEASE=$OPTARG ;;
Q ) imageBackendType=$OPTARG ;;
\?) echo
echolog "Option does not exist : $OPTARG"
usage
exit 1
;;

esac # --- end of case ---
done

if [ ${OPENSTACK_RELEASE} == "OCATA" ] && [ ${imageBackendType} == "SNBS" ];then
gluster_glance=`df -Ph | grep -E '/gluster_glance' | awk '{print $5}'| sed -n 1p | sed 's/%//g'`
if [ $gluster_glance -gt 90 ];then
echo "echolog "failed, out of disk space." >&5"
else
WORK_PATH="/gluster_glance/"
cd ${WORK_PATH}
wget -qP ${WORK_PATH} ${FTP_URL}${FILE_PATH}${FILE_NAME}
fi
else
os_gluster_glance=`df -Ph | grep -E '/os_gluster_glance' | awk '{print $5}'| sed -n 1p | sed 's/%//g'`
if [ $os_gluster_glance -gt 90 ];then
echo "echolog "failed, out of disk space." >&5"
else
WORK_PATH="/os_gluster_glance/"
cd ${WORK_PATH}
wget -qP ${WORK_PATH} ${FTP_URL}${FILE_PATH}${FILE_NAME}
fi
fi

ls ${WORK_PATH}${FILE_NAME} >/dev/null 2>&1
if [ $? -eq 0 ];then
echolog "OK, Get image file from ftp" >&5
#3.Create image by glance cmd
source /root/openrc
if [ ${OPENSTACK_RELEASE} == "ICEHOUSE" -o ${OPENSTACK_RELEASE} == "JUNO" ];then
glance image-create --name=${IMAGE_NAME} --disk-format=qcow2 --container-format=bare --is-public=true --file=./${FILE_NAME} | grep '| id ' | awk -F'|' '{print $3}' | sed 's/ //g'
fi
if [ ${OPENSTACK_RELEASE} == "OCATA" ] && [ ${imageBackendType} == "LOCALLVM" ];then
openstack image create --container-format bare --disk-format qcow2 --public --file ./${FILE_NAME} ${IMAGE_NAME} |grep '| id ' | awk -F'|' '{print $3}' | sed 's/ //g'
fi
if [ ${OPENSTACK_RELEASE} == "OCATA" ] && [ ${imageBackendType} == "SNBS" ];then
glanceConf=/etc/glance/glance-api.conf
#imageDesPath="/mnt/snbsfuse/snpool001"
imageDesPath="/mnt/snbsfuse/pool-openstack"
imageId=`glance image-create --name ${IMAGE_NAME} --container-format bare --disk-format raw --tag snbs|grep id | awk -F '|' '{print $3}'`
imageId=`echo $imageId`
res=`qemu-img convert -S 8k -f qcow2 -O raw ${WORK_PATH}${FILE_NAME} ${imageDesPath}/${imageId}`
if [ $? -ne 0 ];then
echolog "error convert img to snbs error!" >&5
exit ${ERROR_NO_IMPORT_IMAGE_BY_GLANCE_FAILED}
fi
imageSize=`qemu-img info ${WORK_PATH}${FILE_NAME} |grep 'virtual size'|awk -F '(' '{print $2}'|awk -F ' ' '{print $1}'`
dbUser=`cat $glanceConf|grep mysql|grep connection|awk -F '@' '{print $1}'|awk -F '//' '{print $2}'|awk -F ':' '{print $1}'`
dbPass=`cat $glanceConf|grep mysql|grep connection|awk -F '@' '{print $1}'|awk -F '//' '{print $2}'|awk -F ':' '{print $2}'`
dbHost=`cat $glanceConf|grep mysql|grep connection|awk -F '@' '{print $2}'|awk -F '/' '{print $1}'`
insertLocation="INSERT INTO image_locations(image_id,value,created_at,deleted) VALUES('${imageId}','snbsfuse://${imageId}',NOW(),0)"
mysql -u${dbUser} -p${dbPass} -h${dbHost} -Dglance -e "${insertLocation}"
updateImage="UPDATE images SET status='active',size='${imageSize}' WHERE id='${imageId}'"
mysql -u${dbUser} -p${dbPass} -h${dbHost} -Dglance -e "${updateImage}"
echo "${imageId}"

fi
if [ -z "$FILE_NAME" ];then
echolog "FAIL,Input parameter is empty" >&5
else
glance image-list | grep ${IMAGE_NAME} >/dev/null 2>&1
if [ $? -eq 0 ];then
echolog "OK, Import image to glance" >&5
rm -rf ${WORK_PATH}${FILE_NAME}
echolog "OK, Deleted the image file." >&5
else
rm -rf ./${FILE_NAME}
echolog "Error, Delete the image file failed!" >&5
exit ${ERROR_NO_IMPORT_IMAGE_BY_GLANCE_FAILED}
fi
fi
else
echolog "Error, Get image file from ftp failed!"
exit ${ERROR_NO_GET_FTP_FILE_FAILED}
fi
echolog "${SCRTIP_NAME} END." >&5
}
##--------------------Main--------------------
main $@
exit ${NORMAL} #退出的时候返回NORMAL,脚本开头

snbs功能集合脚本

sh tool.sh -t checkRepair -f tool.conf
sh tool.sh -t checkExtent -f tool.conf

tool.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#/bin/bash
usage() {
cat << EOT
Usage : sh tool.sh -T <TYPE> -F <CONFIG_FILE>

Examples:
- sh tool.sh -t checkRepair -f tool.conf
- sh tool.sh -t checkExtent -f tool.conf

Options:
-h Display this message.
-t TYPE.
-f Config file.

<TYPE> :
checkExtent#以zone1为基准,校验三个zone之间相同extent的seq是否一致
checkRepair#需要在任意etcd节点执行,查看集群repair任务
EOT
}

function parse()
{
RET=`getopt -o h,t:,f: \
-n "ERROR" -- "$@"`

if [ $? -ne 0 ]
then
usage
exit 0
fi

CLEANUP=1
eval set -- "$RET"
while true
do
case "$1" in
-h)
usage
exit 0
;;
-t)
TYPE=$2
shift 2
;;
-f)
CONFIG_FILE=$2
shift 2
;;
--)
shift
break
;;
*)
usage
exit 0
;;
esac
done
}

LOCAL_PATH=$(cd `dirname $0`; pwd)
rm -rf ${LOCAL_PATH}/zone*.log ${LOCAL_PATH}/result.log ${LOCAL_PATH}/rol.log

exec 5>>${LOCAL_PATH}/zone1.log
exec 6>>${LOCAL_PATH}/zone2.log
exec 7>>${LOCAL_PATH}/zone3.log
exec 9>>${LOCAL_PATH}/result.log
exec 3>>${LOCAL_PATH}/rol.log

#thread_num=1000

tempfifo="my_temp_fifo"
mkfifo ${tempfifo}
exec 8<>${tempfifo}
rm -f ${tempfifo}

ProgressBar()
{
local current=$1; local total=$2
local now=$((current*100/total))
local last=$(((current-1)*100/total))
[[ $((last % 2)) -eq 1 ]]&&let last++
local str=$(for i in `seq 1 $((last/2))`; do printf '#'; done)
use_time=`ps -p $$ -o etime|column -t|tail -1`
for ((i=$last;$i<=$now;i+=2));do printf "\r[%-50s]%d%%[%03d/%03d][%-5s]\r" "$str" $i $current $total ${use_time};str+='#';done
}

ex_zone1() {
curl -s -X GET "http://${ZONE1[0]}:8080/sys/debug/extentlist?pretty=y"|grep -E "extentId|tranSeq"|sed -n '{N;s/\n/ /p}'|sed 's/ //g'|sed 's/ //g'|sed 's/"extentId":"//g'|sed 's/","/:/g'|sed 's/tranSeq"://g'|sed 's/,//g' >> ZONE1.log
curl -s -X GET "http://${ZONE1[1]}:8080/sys/debug/extentlist?pretty=y"|grep -E "extentId|tranSeq"|sed -n '{N;s/\n/ /p}'|sed 's/ //g'|sed 's/ //g'|sed 's/"extentId":"//g'|sed 's/","/:/g'|sed 's/tranSeq"://g'|sed 's/,//g' >> ZONE1.log
sort -t ":" -n -k2 ZONE1.log >&5
rm -rf ZONE1.log
}

ex_zone2() {
curl -s -X GET "http://${ZONE2[0]}:8080/sys/debug/extentlist?pretty=y"|grep -E "extentId|tranSeq"|sed -n '{N;s/\n/ /p}'|sed 's/ //g'|sed 's/ //g'|sed 's/"extentId":"//g'|sed 's/","/:/g'|sed 's/tranSeq"://g'|sed 's/,//g' >> ZONE2.log
curl -s -X GET "http://${ZONE2[1]}:8080/sys/debug/extentlist?pretty=y"|grep -E "extentId|tranSeq"|sed -n '{N;s/\n/ /p}'|sed 's/ //g'|sed 's/ //g'|sed 's/"extentId":"//g'|sed 's/","/:/g'|sed 's/tranSeq"://g'|sed 's/,//g' >> ZONE2.log
sort -t ":" -n -k2 ZONE2.log >&6
rm -rf ZONE2.log
}

ex_zone3() {
curl -s -X GET "http://${ZONE3[0]}:8080/sys/debug/extentlist?pretty=y"|grep -E "extentId|tranSeq"|sed -n '{N;s/\n/ /p}'|sed 's/ //g'|sed 's/ //g'|sed 's/"extentId":"//g'|sed 's/","/:/g'|sed 's/tranSeq"://g'|sed 's/,//g' >> ZONE3.log
curl -s -X GET "http://${ZONE3[1]}:8080/sys/debug/extentlist?pretty=y"|grep -E "extentId|tranSeq"|sed -n '{N;s/\n/ /p}'|sed 's/ //g'|sed 's/ //g'|sed 's/"extentId":"//g'|sed 's/","/:/g'|sed 's/tranSeq"://g'|sed 's/,//g' >> ZONE3.log
sort -t ":" -n -k2 ZONE3.log >&7
rm -rf ZONE3.log
}
check_extent() {
for ((i=1;i<=${thread_num};i++))
do
{
echo
}

done >&8

num=0
len=$(wc -l ${LOCAL_PATH}/zone1.log | sed 's/^[ \t]*//g' | cut -d ' ' -f1)
mi_len=`expr $len / 2`
cat ${LOCAL_PATH}/zone1.log |awk -F ":" '{print $1}'| while read line
do
{
let num=${num}+1
if [ $(($num%4000)) = '0' ] || [ $num == $len ];then
ProgressBar $num $len
fi

read -u8
{
readzone1=`cat ${LOCAL_PATH}/zone1.log|grep ${line}`
readzone2=`cat ${LOCAL_PATH}/zone2.log|grep ${line}`
readzone3=`cat ${LOCAL_PATH}/zone3.log|grep ${line}`
if [ "${readzone1}" == "${readzone2}" ] && [ "${readzone2}" == "${readzone3}" ];then
echo >> /dev/null
else
num1=`echo ${readzone1}|sed 's/'"${line}:"'//g'`
num2=`echo ${readzone2}|sed 's/'"${line}:"'//g'`
num3=`echo ${readzone3}|sed 's/'"${line}:"'//g'`
echo A:${readzone1}"|"B:${readzone2}"|"C:${readzone3} >&9
if [[ $num1 -gt $num2 ]];then
tmp=$num1
num1=$num2
num2=$tmp
fi
if [[ $num1 -gt $num3 ]];then
tmp=$num1
num1=$num3
num3=$tmp
fi
if [[ $num2 -gt $num3 ]];then
tmp=$num2
num2=$num3
num3=$tmp
fi
if [[ $num1 -eq $num2 ]];then
echo A:${readzone1}"|"B:${readzone2}"|"C:${readzone3} >&3
fi
fi
echo "" >&8
} &
}
done
printf "\n"
wait
exec 8>&-
}
check_repair() {
#etcdctl get repair --prefix|sed '/^\s*$/d'
ETCDCTL_API=3 etcdctl --endpoints="http://${MASTER}:2379" get repair --prefix|sed '/^\s*$/d'
}

function checkExtent_main()
{
ex_zone1
ex_zone2
ex_zone3
check_extent
exit 0
}

function checkRepair_main()
{
check_repair
exit 0
}

function main()
{
source ${LOCAL_PATH}/${CONFIG_FILE} 2> /dev/null
case "${TYPE}" in
checkExtent)
checkExtent_main
exit 0
;;
checkRepair)
checkRepair_main
exit 0
;;
*)
usage
exit 0
;;
esac
}

tool.conf

1
2
3
4
5
6
7
8
9
10
11
thread_num=4000
MASTER="10.238.161.1"
ZONE1=(
"10.238.161.1"
"10.238.161.2")
ZONE2=(
"10.238.161.3"
"10.238.161.4")
ZONE3=(
"10.238.161.5"
"10.238.161.6")

判断设备是否正常

1
2
3
4
5
6
7
8
9
10
11
12
#https://blog.csdn.net/xzx208/article/details/82707344
#https://www.cnblogs.com/Kinge/p/9844783.html

ssh -o ConnectTimeout=1 -o NumberOfPasswordPrompts=0 -o StrictHostKeyChecking=no ${siteip}


#!/bin/bash
for siteip in `cat ip-bad.txt`
do
site="${siteip}"
echo ${siteip}
ssh -o

关闭redhatswap

disableswap.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
#!/bin/bash

#test if system's freemem fit with swapped pages
#disbale swap by: swapoff -a
#disbale swap on booting by: commenting swap entry in /etc/fstab
#disableswap.sh -d to test only

cg="\033[32m"
cr="\033[31m"
cn="\033[0m"

function info
{
echo -e "$cg""$*"$cn
}
function warn
{
echo -e "$cr""$*"$cn
}
function rmswap
{
file=$1
cp $file $file.bak
sed -i '/swap/s/.*/#&/' $file
}

function isok
{
freemem=`cat /proc/meminfo|egrep "MemFree|Cached|Buffers"|awk '{sum += $2} END {print sum }'`
echo freemem : `expr $freemem / 1024` mb
swapused=`cat /proc/meminfo|egrep "SwapTotal|SwapFree"|awk 'BEGIN{sum=0} {if(NR==1) {sum += $2} else {sum -= $2} fi}END {print sum}'`
echo swapused: `expr $swapused / 1024` mb

total=`cat /proc/meminfo |egrep "MemTotal"|awk '{print $2}'`
threshhold=`expr $total / 50`

tmp=`expr $swapused + $threshhold`
echo reserved: `expr $tmp / 1024` mb
if [ "$freemem" -ge "$tmp" ];
then
return 0
else
return 1
fi
}
function swapdisabled
{
swaptotal=`cat /proc/meminfo|egrep "SwapTotal"|awk '{print $2}'`
if [ "$swaptotal" == 0 ];
then
return 0
else
return 1
fi
}
if [ "$1" == "-d" ];
then
isok
if [ "$?" == 0 ]
then
info "ok to disableswap"
else
warn "not ready!!"
fi
exit
fi

isok
if [ "$?" == 0 ]
then
info "disabling swap..."
swapoff -a
sleep 2
swapdisabled
if [ "$?" == 0 ]
then
info "disabled swap"
else
exit
fi

info "rm swap from fstab"
rmswap /etc/fstab
fi

数据一致性:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
1. 有时间复现一下磁盘损坏的问题

2. 文件在 全闪.6 /root/verify,本地没测。。。。 运行案例:python gw_rw_test2.py -t dev0 -s dev160 -T origin -g 10.37.2.20 -n 2 -v crc32 -b 4096 -k 400 -c 40000

3. 各个参数
p. add_option('--gw','-g')# gateway IP
p. add_option('--target','-t")# target volume
p. add_option('--source','-s')# source volume
p. add_option("--type','-T', default="origin")# source volume type(origin/local)
p. add_option('--blocksize','-b', default=4194304)# blocksize
p. add_option('--skip','-k", default=e)# skip k of blocksize, begin offset=blocksize* skip
p. add_option('--count','-c', default=-1)# block count
p. add_option('--verify','-v', default="crc32")# verify hash method, crc32 only now
p. add option('--num','-n', default=4)# number of process

-t是克隆卷/上传卷
-s是原卷/本地卷
赞赏一下吧~