LoginSignup
22
18

More than 5 years have passed since last update.

AWSでJmeter分散負荷試験環境構築めも

Last updated at Posted at 2015-01-23

AWSでJmeter分散負荷試験環境構築

目的:

汎用的なJmeter負荷試験環境
AWSのAutoscale機能を利用し、試験必要なときのみJmeterSlaveサーバを自動作成し、Masterへの登録も自動化させる。

構成:

コントローラ : Windows2012 R2 64bit 1台(m3.medium以上)
Slaveサーバ: AmazonLinux 64bit Autoscaleグループで自動作成(m3.medium以上)

手順:

1、Slaveサーバ作成用AMI構築

①AmazonLinux最新版
②Javas64ビット最新版
③Jmeter最新版ダウンロードし、/opt/opt/apache-jmeter配下配置
④システムパラメータチューニング
/etc/security/limits.conf


root soft nofile 65535
root hard nofile 65535

⑤Jmeter起動パラメータチューニング
HEAP="-Xms2048m -Xmx2048m" <-インスタンスタイプによる調整
以下の行をコメントアウト
DUMP="-XX:+HeapDumpOnOutOfMemoryError"
⑥jmeterブート時自動起動
/etc/rc.localに以下を設定:

 #rmiサーバ設定(java.rmi.server.hostname=自身のPrivateIP)
 PIV_IP=$(curl http://169.254.169.254/latest/meta-data/local-ipv4/)
 sed -i -e "s/^RMI_HOST_DEF=-Djava.rmi.server.hostname=.*/RMI_HOST_DEF=-Djava.rmi.server.hostname=${PIV_IP}/" /opt/apache-jmeter/bin/jmeter-server
/bin/bash -l /opt/apache-jmeter/bin/jmeter-server &

⑦AMI作成(略)

2、Autoscaleグループ作成

AWSコンソールで作成(略)
例:asg01-jmeter-common

3、Jmeterマスタの構築

Windwos2012 R2 64bit
* AutoscaleのDescribe権限、EC2のDescribe権限、Slaveサーバをマスタで自動作成する場合、Autoscaleのupdate権限をIAMRoleで付与

①AWSCLIダウンロードしインストール
https://s3.amazonaws.com/aws-cli/AWSCLI64.msi
②jqのインストール
 ダウンロードしてからWindowsのシステムディレクトリに配置
③Javaのインストール(64bit, Slaveと同じバージョン)
④Jmeterのダウンロード&配置(Slaveと同じバージョン)
 Jmeterのインストール先:
 UserProfile配下の\Documents\apache-jmeter
⑤Jmeterパラメータチューニング

Powershellスクリプト作成し配置:
AWSCLIを利用してJmeterSlaveサーバのIP一覧を取得し、Jmeterの設定ファイルに自動設定


Param ([string] $strRegion = "ap-northeast-1", `
    [string] $strJmeterAsgGroupName = "asg01-jmeter", `
    [int] $intInstanceCount = 2, `
    [string] $strJmeterConfig)


#default values of parameters
$strJmeterConfig = [environment]::getenvironmentvariable("userprofile") + "\Documents\apache-jmeter\bin\jmeter.properties"
$LOG_ENCODE = "Ascii"


# create jmeter slaves (update autoscale group)
function func_CreateSlaves()
{
    try {
        aws autoscaling update-auto-scaling-group --auto-scaling-group-name $strJmeterAsgGroupName  `
            --min-size $intInstanceCount --desired-capacity $intInstanceCount --region $strRegion
    } catch [Exception] {
        $strErr = "Failed to create jmeter slaves"
        throw $strErr
    }
}

# set ip of jmeter slvaes into config file of jmeter
function func_UpdataSlaveIP()
{
    try {
        # get ip list of jmeter slvaes
        $items = @(aws ec2 describe-instances --filters `
        "Name=tag:aws:autoscaling:groupName,Values=$strJmeterAsgGroupName" "Name=instance-state-name,Values=running"  --region $strRegion `
        | jq '.Reservations[].Instances[].PrivateIpAddress')

        $strIPList = ""
        foreach($item in $items)
        {
            if($strIPList.CompareTo("") -eq 0) {
                $strIPList  += $item
            } else {
                $strIPList  += "," + $item
            }
        }

        $strIPList = $strIPList -replace "`"", ""
        $date = get-date -format yyyyMMdd
        $time = get-date -format HHmmss

        $strJmeterConfigBackup = $strJmeterConfig + $date + $time
        # backup the config file
        copy $strJmeterConfig $strJmeterConfigBackup

        # replace ips of slave server (^remote_hosts=.* -> remote_hosts=$strIPList)
        $strContent = $(Get-Content $strJmeterConfigBackup) -replace "^remote_hosts=.*","remote_hosts=$strIPList"
        Set-Content -path $strJmeterConfig -value $strContent -encoding String

    } catch [Exception] {
        $strErr = "Failed to update jmeter config"
        throw $strErr
    }
}


#func_CreateSlaves
func_UpdataSlaveIP

22
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
22
18