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
#!/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 _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
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
#testif 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
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是原卷/本地卷