linux上安裝jdk和jmeter的腳本

前幾天應工做的要求,搞起了jmeter壓力測試,由於暫時沒有多餘的linux機器,因此下面的全部操做都是在我本地安裝的虛擬機上完成的,不過,並沒有區別。java

主要實現的操做有:linux

  • 在linux上安裝jdk並設置環境變量
  • 在linux上安裝jmeter並設置環境變量

廢話也不想多說了,直接貼腳本吧。apache

#! /bin/bash
cd `dirname $0`
BASE_PATH=`pwd`
configfile=$BASE_PATH/config.ini
source $configfile
install_files=/usr/etc/installFile

# install JDK
java -version 2>&1 > /dev/null
if [ $? -ne 0 ];then
	if [ ! -d $JDK_Install_Path ];then
		mkdir $JDK_Install_Path
	fi
	cp $install_files/jdk*.gz $JDK_Install_Path
	cd $JDK_Install_Path
	aaa=`pwd`
	echo "In $aaa"
	jdk_name=`ls -l $JDK_Install_Path | awk '/^-/ {print $NF}'`
	echo "JDK name : $jdk_name"
	tar -zxf $jdk_name
	if [ $? -eq 0 ];then
		javadir=`ls -l $JDK_Install_Path | awk '/^d/ {print $NF}'`
		echo "JDK dir : $javadir"
		jdk_home="$JDK_Install_Path/$javadir"
		echo "" >> /etc/profile
		echo "JAVA_HOME=$jdk_home" >> /etc/profile
		echo 'PATH=$JAVA_HOME/bin:$PATH' >> /etc/profile
		echo 'CLASSPATH=.:$JAVA_HOME/lib/tools.jar' >> /etc/profile
		echo 'export JAVA_HOME PATH CLASSPATH' >> /etc/profile
		source /etc/profile
		sleep 1
		java -version 2>&1 > /dev/null
		if [ $? -eq 0 ];then
			echo "JDK install completed!"
		else
			echo "JDK path error!"
			echo "Please manual installation, will exit from $ip."
		fi
		rm -f $JDK_Install_Path/jdk*.gz
	else
		echo "JDK install error."
	fi
else
	echo "JDK has been installed."
fi
		
# install Jmeter
jmeter -v 2>&1 > /dev/null
if [ $? -ne 0 ];then
	if [ ! -d $Jmeter_Install_Path ];then
		mkdir $Jmeter_Install_Path
	fi
	cp $install_files/apache-jmeter*.gz $Jmeter_Install_Path
	cd $Jmeter_Install_Path
	bbb=`pwd`
	echo "In $bbb"
	jmeter_name=`ls -l $Jmeter_Install_Path | awk '/^-/ {print $NF}'`
	echo "Jmeter name : $jmeter_name"
	tar -zxf $jmeter_name
	if [ $? -eq 0 ];then
		jmeterdir=`ls -l $Jmeter_Install_Path | awk '/^d/ {print $NF}'`
		echo "Jmeter dir : $jmeterdir"
		jmeter_path=$Jmeter_Install_Path/$jmeterdir
		echo "" >> /etc/profile
		echo "JMETER_HOME=$jmeter_path" >> /etc/profile
		echo 'CLASSPATH=$JMETER_HOME/lib/ext/ApacheJMeter_core.jar:$JMETER_HOME/lib/jorphan.jar:$JMETER_HOME/lib/logkit-2.0.jar:$CLASSPATH' >> /etc/profile
		echo 'PATH=$JMETER_HOME/bin/:$PATH' >> /etc/profile
		echo 'export JMETER_HOME CLASSPATH PATH' >> /etc/profile
		source /etc/profile
		sleep 1
		jmeter -v 2>&1 > /dev/null
		if [ $? -eq 0 ];then
			echo "Jmeter install completed!"
			echo "JDK and Jmeter install completed."
		else
			echo "Jmeter path error!"
			echo "Please manual installation, will exit from $ip."
		fi
		rm -f $Jmeter_Install_Path/apache-jmeter*.gz
	else
		echo "Jmeter install error."
	fi
else
	echo "Jmeter has been installed."
fi
cd /		
rm -fr /usr/etc/installFile
rm -fr /usr/SETUP
if [ -f /usr/jmeter.log ];then
	rm -f /usr/jmeter.log
fi
if [ -f /usr/jmeter/jmeter.log ];then
	rm -f /usr/jmeter/jmeter.log
fi

以上就是安裝的腳本。bash

最近有點兒懶懶的,多多包涵。測試

轉載請標明出處,喜歡或者有用的話,就給我點個贊吧!code

相關文章
相關標籤/搜索