linux服务器性能测试

  1 #!/bin/sh
  2 #Shell      menu.sh
  3 #Author    lipc
  4 #Date      20200818
  5 #Ps       linux系统压测,有些工具需要下载,脚本不完善,需要调试
  6 
  7 # Check if user is root
  8 [ $(id -u) != "0" ] && {
  9     echo "${CFAILURE}Error: You must be root to run this script${CEND}"
 10     exit 1
 11 }
 12 pwd=/tmp
 13 
 14 #初始化、安装跑分
 15 function Test_environment_initialization() {
 16     dir=$(pwd)
 17     cd $pwd
 18     yum -y install gcc automake autoconf libtool make perl-Time-HiRes perl wget vim screen
 19 
 20     cd $pwd
 21     if [ -s UnixBench-5.1.4.tar.gz ]; then
 22         echo "UnixBench-5.1.4.tar.gz [found]"
 23     else
 24         echo "UnixBench-5.1.4.tar.gz not found!!!download now..."
 25         if ! wget -c https://github.com/qcsuper/byte-unixbench/releases/download/v5.1.4/UnixBench-5.1.4.tar.gz; then
 26             echo "Failed to download UnixBench-5.1.4.tar.gz, please download it to ${cur_dir} directory manually and try again."
 27             exit 1
 28         fi
 29     fi
 30     tar -zxvf UnixBench-5.1.4.tar.gz && rm -f UnixBench-5.1.4.tar.gz
 31     cd UnixBench/
 32     make
 33 
 34     cd $pwd
 35     if [ -s 1.0.17]; then
 36         echo "sysbench-1.0.17.tar.gz [fonud]"
 37     else
 38         echo "sysbench-1.0.17.tar.gz not found!!!download now..."
 39         if ! wget -c https://codeload.github.com/akopytov/sysbench/tar.gz/1.0.17; then
 40             echo "Failed to download sysbench-1.0.17.tar.gz, please download it to ${cur_dir} directory manually and try again."
 41             exit 1
 42         fi
 43     fi
 44     tar -zxvf 1.0.17 -C /usr/local/ && rm -f 1.0.17
 45     cd /usr/local/sysbench-1.0.17
 46     ./autogen.sh
 47     ./configure --without-mysql
 48     make -j
 49     make install
 50 
 51     #安装获取服务器软件、硬件信息的脚本。
 52     if [ ! -e '/tmp/systeminfo.sh' ]; then
 53         echo "Installing systeminfo.sh......"
 54         dir=$(pwd)
 55         cd $pwd
 56         wget -N --no-check-certificate https://raw.githubusercontent.com/learning2016/Server-evaluation/master/systeminfo.sh >/dev/null 2>&1
 57         cd $pwd
 58         chmod a+rx /tmp/systeminfo.sh
 59     fi
 60     #安装网络延迟的脚本。
 61     if [ ! -e '/tmp/AWS-ping.py' ]; then
 62         echo "Installing AWS-ping.py......"
 63         dir=$(pwd)
 64         cd $pwd
 65         wget -N --no-check-certificate https://raw.githubusercontent.com/learning2016/Server-evaluation/master/AWS-ping.py >/dev/null 2>&1
 66         cd $pwd
 67         chmod a+rx /tmp/AWS-ping.py
 68     fi
 69 }
 70 
 71 function Get_hardware_and_software_information() {
 72     /usr/bin/bash /tmp/systeminfo.sh
 73 }
 74 
 75 function Network_delay_test() {
 76     python /tmp/AWS-ping.py
 77 }
 78 
 79 function The_CPU_test() {
 80     #printf "正在测试,请耐心等待"
 81     /usr/bin/sysbench cpu --cpu-max-prime=200000000 --threads=8 run >/tmp/cpu.log 2>&1
 82     #clear
 83     name13=CPU计算素数所需时间
 84     name14=$(cat /tmp/cpu.log | grep "total time:")
 85     str7=$name13$name14
 86     echo $str7
 87 }
 88 
 89 function The_memory_test() {
 90     #printf "正在测试,请耐心等待"
 91     /usr/local/sysbench-1.0.17/src/sysbench --test=memory --memory-block-size=8K --memory-total-size=4G --num-threads=2 run >/tmp/memory.log 2>&1
 92     name15=内存读写性能
 93     name16=$(cat /tmp/memory.log | grep "transferred")
 94     str8=$name15$name16
 95     echo $str8
 96 }
 97 
 98 function Disk_test() {
 99     #printf "正在测试,请耐心等待,大约30分钟"
100     #rndrw 混合随机读/101     /usr/local/sysbench-1.0.17/src/sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=rndrw prepare >/tmp/rndrw-prepare.log 2>&1
102     /usr/local/sysbench-1.0.17/src/sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=rndrw run >/tmp/rndrw-run.log 2>&1
103     /usr/local/sysbench-1.0.17/src/sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=rndrw cleanup >/tmp/rndrw-cleanup.log 2>&1
104 
105     #rndwr 随机写入
106     /usr/local/sysbench-1.0.17/src/sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=rndwr prepare >/tmp/rndwr-prepare.log 2>&1
107     /usr/local/sysbench-1.0.17/src/sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=rndwr run >/tmp/rndwr-run.log 2>&1
108     /usr/local/sysbench-1.0.17/src/sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=rndwr cleanup >/tmp/rndwr-cleanup.log 2>&1
109 
110     #rndrd 随机读取
111     /usr/local/sysbench-1.0.17/src/sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=rndrd prepare >/tmp/rndrd-prepare.log 2>&1
112     /usr/local/sysbench-1.0.17/src/sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=rndrd run >/tmp/rndrd-run.log 2>&1
113     /usr/local/sysbench-1.0.17/src/sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=rndrd cleanup >/tmp/rndrd-cleanup.log 2>&1
114 
115     #seqrd 顺序读取
116     /usr/local/sysbench-1.0.17/src/sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=seqrd prepare >/tmp/seqrd-prepare.log 2>&1
117     /usr/local/sysbench-1.0.17/src/sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=seqrd run >/tmp/seqrd-run.log 2>&1
118     /usr/local/sysbench-1.0.17/src/sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=seqrd cleanup >/tmp/seqrd-cleanup.log 2>&1
119 
120     #seqrewr 顺序读写
121     #/usr/local/sysbench-1.0.17/src/sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=seqrewr prepare > /tmp/seqrewr-prepare.log 2>&1
122     #/usr/local/sysbench-1.0.17/src/sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=seqrewr run > /tmp/seqrewr-run.log 2>&1
123     #/usr/local/sysbench-1.0.17/src/sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=seqrewr cleanup > /tmp/seqrewr-cleanup.log 2>&1
124 
125     #seqwr 顺序写入
126     /usr/local/sysbench-1.0.17/src/sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=seqwr prepare >/tmp/seqwr-prepare.log 2>&1
127     /usr/local/sysbench-1.0.17/src/sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=seqwr run >/tmp/seqwr-run.log 2>&1
128     /usr/local/sysbench-1.0.17/src/sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=seqwr cleanup >/tmp/seqwr-cleanup.log 2>&1
129 
130     #clear
131     name1=顺序写入速度
132     name2=$(cat /tmp/seqwr-run.log | grep "written, MiB/s:")
133     str1=$name1$name2
134     echo $str1
135 
136     #name3=顺序读写速度
137     #name4=$(cat /tmp/seqrewr-run.log |grep "written, MiB/s:")
138     #str2=$name3$name4
139     #echo $str2
140 
141     name5=顺序读取速度
142     name6=$(cat /tmp/seqrd-run.log | grep "read, MiB/s:")
143     str3=$name5$name6
144     echo $str3
145 
146     name7=随机读取速度
147     name8=$(cat /tmp/rndrd-run.log | grep "read, MiB/s:")
148     str4=$name7$name8
149     echo $str4
150 
151     name9=随机写入速度
152     name10=$(cat /tmp/rndwr-run.log | grep "written, MiB/s:")
153     str5=$name9$name10
154     echo $str5
155 
156     name11=混合随机读/157     name12=$(cat /tmp/rndrw-run.log | grep "MiB/s")
158     str6=$name11$name12
159     echo $str6
160 }
161 
162 function Grading_test() {
163     cd /tmp/UnixBench
164     ./Run >/tmp/unixbench.log 2>&1
165     name17=Unixbench评分
166     name18=$(cat /tmp/unixbench.log | grep "System Benchmarks Index Score")
167     str9=$name17$name18
168     echo $str9
169 }
170 
171 function A_key_test() {
172     screen iotest
173     Test_environment_initialization
174     Get_hardware_and_software_information
175     printf '%80s\n' | tr ' ' -
176     Network_delay_test
177     printf '%80s\n' | tr ' ' -
178     The_CPU_test
179     printf '%80s\n' | tr ' ' -
180     The_memory_test
181     printf '%80s\n' | tr ' ' -
182     Disk_test
183     printf '%80s\n' | tr ' ' -
184     Grading_test
185     printf '%80s\n' | tr ' ' -
186 }
187 
188 function menu() {
189     cat <<EOF
190 ----------------------------------------
191 |***************菜单主页***************|
192 ----------------------------------------
193 $(echo -e "\033[33m 1)测试环境初始化(必选)\033[0m")
194 $(echo -e "\033[33m 2)获取软硬件信息\033[0m")
195 $(echo -e "\033[33m 3)网络延迟测试\033[0m")
196 $(echo -e "\033[33m 4)CPU测试\033[0m")
197 $(echo -e "\033[33m 5)内存测试\033[0m")
198 $(echo -e "\033[33m 6)磁盘IO测试(预估至少30分钟)\033[0m")
199 $(echo -e "\033[33m 7)Unixbench评分测试(预估至少45分钟)\033[0m")
200 $(echo -e "\033[33m 8)一键测试(预估至少75分钟)\033[0m")
201 $(echo -e "\033[33m 9)退出\033[0m")
202 EOF
203     read -p "请输入对应产品的数字:" num1
204     case $num1 in
205     1)
206         #clear
207         Test_environment_initialization
208         menu
209         ;;
210         #获取服务器软件、硬件信息。
211     2)
212         #clear
213         Get_hardware_and_software_information
214         menu
215         ;;
216         #获取网络延迟。
217     3)
218         #clear
219         Network_delay_test
220         menu
221         ;;
222         #测试cpu。
223     4)
224         #clear
225         The_CPU_test
226         menu
227         ;;
228         #测试内存。
229     5)
230         #clear
231         The_memory_test
232         menu
233         ;;
234         #测试磁盘IO。
235     6)
236         #clear
237         Disk_test
238         menu
239         ;;
240         #服务器性能跑分。
241     7)
242         #clear
243         Grading_test
244         menu
245         ;;
246         #以上功能,一键完成。
247     8)
248         A_key_test
249         menu
250         ;;
251     9)
252         exit 0
253         ;;
254     esac
255 }
256 menu

 

posted @ 2020-08-18 18:02  Leonardo-li  阅读(492)  评论(0编辑  收藏  举报