总结一些常用脚本

白昼怎懂夜的黑 提交于 2020-01-28 08:20:18

1、替换ceph.conf配置文件
if [ -n "`/usr/bin/grep -w paxos_min /etc/ceph/ceph.conf`" ]; then sed -i '/paxos_min/c\paxos_min = 5000' /etc/ceph/ceph.conf; else sed -i '/auth_client_required/a\paxos_min = 5000' /etc/ceph/ceph.conf; fi

2、删除一个root
pool_name=xxxx;for i in `ceph osd crush ls "$pool_name"_host_group`;do ceph osd crush rm `ceph osd crush ls "$i"` $i ; done;for i in `ceph osd crush ls "$pool_name"_host_group`;do ceph osd crush rm $i ;done;ceph osd crush rm "$pool_name"_host_group
3、统计所有慢op
原型

ceph daemon osd.1 dump_historic_slow_ops|egrep -w "initiated_at|duration|time|event"|sed -e 's/"//g' -e 's/:/,/' -e 's/ //g' -e 's/:/,/g'|awk '
    BEGIN{FS=",";count_flag=0}
    {
        if($0~"initiated_at"){date1=$2;date2=$3;date3=$4}
        if($0~"duration"){duration=$2}
        if($0~"time"){time[count_flag]=$4}
        if($0~"event"){event[count_flag]=$2;count_flag=count_flag+1}
        
        if($0~"done"){
            printf("\n\n time:%s%s%s duration:%s io_block:",date1,date2,date3,duration);
            for(i=1;i<count_flag;i++)
            {
                tmp_time=time[i]-time[i-1]
                if(tmp_time<0)
                {
                    tmp_time += 60
                }
                
                if (tmp_time>0.5)
                {
                    printf("<%s--->%s:%s> ",event[i-1],event[i],tmp_time);
                }
            }
            count_flag=0
        }
    }
    END{printf("\n")}'

简写
ceph daemon osd.1 dump_historic_slow_ops|egrep -w "initiated_at|duration|time|event"|sed -e 's/"//g' -e 's/:/,/' -e 's/ //g' -e 's/:/,/g'|awk 'BEGIN{FS=",";count_flag=0}{if($0~"initiated_at"){date1=$2;date2=$3;date3=$4};if($0~"duration"){duration=$2};if($0~"time"){time[count_flag]=$4};if($0~"event"){event[count_flag]=$2;count_flag=count_flag+1};if($0~"done"){printf("\n\n time:%s%s%s duration:%s io_block:",date1,date2,date3,duration);for(i=1;i<count_flag;i++){tmp_time=time[i]-time[i-1];if(tmp_time<0){tmp_time += 60};if (tmp_time>static_time){printf("<%s--->%s:%s> ",event[i-1],event[i],tmp_time)};}count_flag=0;}}END{printf("\n")}' static_time=1
统计本节点所有慢op
for i in `lsblk|grep /var/lib/ceph/osd|awk 'BEGIN{FS="-"}{print $2}'`;do echo ----------------$i--------------; ceph daemon osd.$i dump_historic_slow_ops|egrep -w "initiated_at|duration|time|event"|sed -e 's/"//g' -e 's/:/,/' -e 's/ //g' -e 's/:/,/g'|awk 'BEGIN{FS=",";count_flag=0}{if($0~"initiated_at"){date1=$2;date2=$3;date3=$4};if($0~"duration"){duration=$2};if($0~"time"){time[count_flag]=$4};if($0~"event"){event[count_flag]=$2;count_flag=count_flag+1};if($0~"done"){printf("\n\n time:%s%s%s duration:%s io_block:",date1,date2,date3,duration);for(i=1;i<count_flag;i++){tmp_time=time[i]-time[i-1];if(tmp_time<0){tmp_time += 60};if (tmp_time>static_time){printf("<%s--->%s:%s> ",event[i-1],event[i],tmp_time)};}count_flag=0;}}END{printf("\n")}' static_time=1; done

4、统计init到queue for pg op
for i in `lsblk|grep /var/lib|awk 'BEGIN{FS="-"}{print $2}'`;do echo -------$i------------;ceph daemon osd.$i dump_historic_slow_ops | grep -C 4 -w initiated ;done |egrep -v "flag_point|events|\{|\}"|awk 'BEGIN{FS="[:|\"]"}{if($0~"----------")print $0;if($0~"initiated"){B=A};if($0~"queued_for_pg"){C=A;if(C-B>1){printf("%s %f\n",D,(C-B))}};A=$7;D=$0}'
5、打印某个时间点的慢op
for i in `lsblk|grep /var/lib/|awk 'BEGIN{FS="-"}{print $2}'`;do echo "-----------$i----------"; ceph daemon osd."$i" dump_historic_slow_ops;done|egrep "2019-08-20 14:16:46.353085|----"
6、一键设置所有块设备参数
for i in `lsblk|grep sd*|grep disk|grep -v hda|awk '{print $1}'`;do echo "255" > /sys/block/"$i"/device/device_sync_ctrl;done
7、一键查看所有块设备参数
for i in `lsblk|grep sd*|grep disk|grep -v hda|awk '{print $1}'`;do echo "---------------$i------------";cat /sys/block/"$i"/device/device_sync_ctrl;done
8、获取一个group下的所有osd id
for i in `ceph osd crush ls small_1_host_group`;do ceph osd crush ls $i ;done|sed 's/osd.//'|awk '{printf("%s,",$1)}END{printf("\n")}'
9、性能测试

rados bench 3000000 -b 2M -t 1 write --no-cleanup -p pool0 | awk '{ printf "%s\t",$0; system("date +\"[%F %T\"]"); }' 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!