- Use ssh-keygen to create private/public key-pair for vagrant
$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (PATH_TO_FILE/id_rsa): vagrant
- Setup Vagrant
- Use VagrantFile in gist
- Update VagrantFile ssh setting
subconfig.ssh.private_key_path = ["~/.ssh/vagrant", "~/.vagrant.d/insecure_private_key"] ⇒ Confirm "~/.vagrant.d/insecure_private_key" points to the vagrant root folder in host machine, typically in C:/<USER> subconfig.vm.provision "file", source: "~/.ssh/vagrant.pub", destination: "~/.ssh/authorized_keys" ⇒ Change pub file to the path of public key file created in step 1
- Update sync folder (if necessary)
config.vm.synced_folder "<HOST_MACHINE_PATH>", "/home/vagrant/jmeter", type:"virtualbox", :mount_options => ['dmode=774','fmode=775']
- Run vagrant (vagrant up)
- Run Xming to forward application in vagrant to host machine display
-
Install if not installed already https://sourceforge.net/projects/xming/
-
Run Xming first
-
Then run XLaunch a. Select 'multiple windows', then next b. Select 'start a program' c. Select 'Run Remote using Putty (plink.exe)'
Connect to computer: 127.0.0.1 Login as user: vagrant Password: <blank>
d. Just go next on 'Additional parameters' window e. Finish configuration
-
- Configure Putty to connect to vagrant
Reference: https://medium.com/@jcook0017/how-to-enable-x11-forwarding-in-windows-10-on-a-vagrant-virtual-box-running-ubuntu-d5a7b34363f
- Get info of vagrant we want to connect to
- From ssh-config result, enter IP address and port to Putty Note: Every time vagrant up is run, port might change so always double check with ssh-config
- Connection > Data
Auto-login username: vagrant
- Connection > SSH > Auth Browse the private key created in step 1
- Connection > SSH > Auth > X11 Check 'Enable X11 forwarding'
- Save session
- Connect to vagrant via putty Note: First time connecting, '/home/vagrant/. Xauthority” does not exist' might appear. This is OK
- Run JMeter in vagrant window opened in step 5
[vagrant@jmeter ~]$ /opt/apache-jmeter-2.13/bin/jmeter.sh
- DONE! Now you can see JMeter GUI running in host machine (windows)
Last active
March 10, 2022 21:02
-
-
Save carthegian/eeac70d5f4bdcc8767e1b0b5374d7d1a to your computer and use it in GitHub Desktop.
A quick gist for JMeter stress testing using Vagrant with Amazon Linux 2 (X11 forwarding enabled for JMeter GUI in host machine)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
# All Vagrant configuration is done below. The "2" in Vagrant.configure | |
# configures the configuration version (we support older styles for | |
# backwards compatibility). Please don't change it unless you know what | |
# you're doing. | |
BOX_IMAGE = "gbailey/amzn2" | |
@scriptApp = <<SCRIPT | |
// Cleanup & update | |
sudo rm -rf /var/cache/yum | |
sudo yum clean all | |
sudo yum -y update | |
sudo rm -f /var/run/yum.pid | |
# Install Java | |
sudo yum install -y java-1.8.0-openjdk-devel.x86_64 | |
# Install JMeter | |
cd /opt/ | |
sudo wget https://ftp.jaist.ac.jp/pub/apache//jmeter/binaries/apache-jmeter-5.3.tgz | |
sudo tar xvzf apache-jmeter-5.3.tgz | |
sudo chown -R vagrant:vagrant /opt/apache-jmeter-5.3 | |
sleep 5 | |
# Set JMeter path to bashrc using full path since provisioner runs as root so that ~ refers to /root | |
# https://stackoverflow.com/questions/27026015/update-bashrc-from-provisioning-shell-script-with-vagrant | |
sudo echo $'\n# Jmeter' >> /home/vagrant/.bashrc | |
sudo echo 'PATH=$PATH:$HOME/bin:/opt/apache-jmeter-5.3/bin' >> /home/vagrant/.bashrc | |
tail -2 ~/.bashrc | |
source ~/.bashrc | |
# Install JMeter plugin manager and http2 sampler | |
wget https://repo1.maven.org/maven2/kg/apc/jmeter-plugins-manager/1.6/jmeter-plugins-manager-1.6.jar -P /opt/apache-jmeter-5.3/lib/ext | |
wget http://search.maven.org/remotecontent?filepath=kg/apc/cmdrunner/2.2/cmdrunner-2.2.jar -O /opt/apache-jmeter-5.3/lib/cmdrunner-2.2.jar | |
java -cp /opt/apache-jmeter-5.3/lib/ext/jmeter-plugins-manager-1.6.jar org.jmeterplugins.repository.PluginManagerCMDInstaller | |
ls -l /opt/apache-jmeter-5.3/bin/PluginsManagerCMD.sh | |
/opt/apache-jmeter-5.3/bin/PluginsManagerCMD.sh install bzm-http2 | |
# JMeter setting | |
sudo sed -i 's|HEAP="-Xms512m -Xmx512m"|HEAP="-Xms512m -Xmx4096m"|' /opt/apache-jmeter-5.3/bin/jmeter | |
which jmeter | |
jmeter --version | |
# Install xauth and xclock for x11 forwarding | |
sudo yum install -y xorg-x11-xauth | |
sudo yum install -y xorg-x11-apps | |
SCRIPT | |
@scriptSshConfig = <<SCRIPT | |
# Create .ssh/config file | |
touch /home/vagrant/.ssh/config | |
sudo echo 'Host *' >> /home/vagrant/.ssh/config | |
sudo echo 'ForwardX11 yes' >> /home/vagrant/.ssh/config | |
sudo chown vagrant:vagrant /home/vagrant/.ssh/config | |
SCRIPT | |
Vagrant.configure("2") do |config| | |
config.vm.define "app" do |subconfig| | |
subconfig.vm.box = BOX_IMAGE | |
subconfig.vm.hostname = "app" | |
subconfig.vm.network :private_network, ip: "10.0.0.10" | |
# Make vagrant ssh use our defined key-pair instead of random key during 'vagrant up' | |
subconfig.ssh.insert_key = false | |
subconfig.ssh.private_key_path = ["~/.ssh/vagrant", "~/.vagrant.d/insecure_private_key"] | |
subconfig.vm.provision "file", source: "~/.ssh/vagrant.pub", destination: "~/.ssh/authorized_keys" | |
subconfig.vm.provision :shell, :inline => "sudo rm /etc/localtime && sudo ln -s /usr/share/zoneinfo/Asia/Tokyo /etc/localtime", run: "always" | |
subconfig.vm.provider 'virtualbox' do |vb| | |
vb.customize ["modifyvm", :id, "--name", "amazonlinux2-app"] | |
vb.customize ["guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 1000] | |
end | |
end | |
config.vm.define "jmeter" do |subconfig| | |
subconfig.vm.box = BOX_IMAGE | |
subconfig.vm.hostname = "jmeter" | |
subconfig.vm.network "private_network", ip: "10.0.0.11" | |
subconfig.vm.provider 'virtualbox' do |vb| | |
vb.customize ["modifyvm", :id, "--name", "amazonlinux2-jmeter"] | |
vb.customize ["modifyvm", :id, "--memory", "2048"] | |
vb.customize ["guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 1000] | |
end | |
# Make vagrant ssh use our defined key-pair instead of random key during 'vagrant up' | |
subconfig.ssh.insert_key = false | |
# Need to generate private/public key using ssh-keygen | |
subconfig.ssh.private_key_path = ["~/.ssh/vagrant", "~/.vagrant.d/insecure_private_key"] | |
subconfig.vm.provision "file", source: "~/.ssh/vagrant.pub", destination: "~/.ssh/authorized_keys" | |
# To run JMeter GUI, need to set X11 forwarding so we can use GUI interface of host machine | |
# Set SSH settings here | |
subconfig.ssh.forward_agent = true | |
subconfig.ssh.forward_x11 = true | |
# Install JMeter and required applications | |
subconfig.vm.provision "shell", | |
inline: @scriptApp | |
# Create .ssh/config file and defined forwarding settings | |
subconfig.vm.provision "shell", | |
inline: @scriptSshConfig | |
subconfig.vm.provision "shell", | |
inline: "sudo rm /etc/localtime && sudo ln -s /usr/share/zoneinfo/Asia/Tokyo /etc/localtime", | |
run: "always" | |
#Synced folders | |
# Fill <HOST_MACHINE_PATH> according to your need | |
#config.vm.synced_folder "<HOST_MACHINE_PATH>", "/home/vagrant/jmeter", type:"virtualbox", :mount_options => ['dmode=774','fmode=775'] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
20201126
Update with latest JMeter version and also added plugin to handle http2 request