JMeter Setup | AWS Linux AMI (AWS EC2)

  • SSH into the Amazon EC2 machine

ssh -i yourkey.pem ec2-user@11.111.11.11

  • Download Apache JMeter

wget https://downloads.apache.org/jmeter/binaries/apache-jmeter-5.6.3.tgz

  • Extract the downloaded compressed file

tar -xzf apache-jmeter-5.6.3.tgz

  • Move folder into the /opt/ folder

sudo mv apache-jmeter-5.6.3 /opt/

  • Set JMeter environment variable and path

export JMETER_HOME=/opt/apache-jmeter-5.6.3
export PATH=$PATH:$JMETER_HOME/bin
source ~/.bashrc

  • Download and install custom JDK

yum search java | grep "17"
sudo yum install java-17-amazon-corretto.x86_64

  • Copy certificate and test plan into the AWS EC2 machine

sudo scp -i yourkey.pem certificate.pfx ec2-user@11.111.11.11:/home/ec2-user
sudo scp -i yourkey.pem yourtestplan.jmx ec2-user@11.111.11.11:/home/ec2-user

  • Download JMeter plugins manager directly into the /ext folder; else, download and copy into the EC2 machine from your local machine

cd /opt/apache-jmeter-5.6.3/lib/ext
curl -O https://repo1.maven.org/maven2/kg/apc/jmeter-plugins-manager/1.9/jmeter-plugins-manager-1.9.jar

or

sudo scp -i yourkey.pem jmeter-plugins-manager-1.9.jar ec2-user@11.111.11.11:/opt/apache-jmeter-5.6.3/lib/ext

  • Download Throughput Shaping Timer plugin from the link and copy the below mentioned jar files into the respective folders

sudo scp -i yourkey.pem jmeter-plugins-tst-2.6.jar ec2-user@11.111.11.11:/opt/apache-jmeter-5.6.3/lib/ext
sudo scp -i yourkey.pem jmeter-plugins-cmn-jmeter-0.7.jar ec2-user@11.111.11.11:/opt/apache-jmeter-5.6.3/lib/

  • JMeter Test runner with certificate and it’s password exporting results into the .jtl file

jmeter -Djavax.net.ssl.keyStore=/home/ec2-user/certificate.pfx -Djavax.net.ssl.keyStorePassword=111111 -n -t /home/ec2-user/yourtestplan.jmx -l /home/ec2-user/results.jtl

  • Copy results.jtl from AWS EC2 machine into the local machine

sudo scp -i yourkey.pem ec2-user@11.111.11.11:/home/ec2-user/results.jtl /local-machine-path/

  • Generate HTML report from the generated results.jtl file

jmeter -g /local-machine-path/results.jtl -o ./destination-folder/

Create an EC2 instance | Terraform

This post helps you to create a basic EC2 instance (free tier) through Terraform AWS provisioning DSL scripting language
  • Download Terraform CLI
https://www.terraform.io/downloads.html
  • Extract and move terraform inside bin folder
mv ~/Downloads/terraform /usr/local/bin/

terraform version
  • Create a new project and a file with extension .tf
  • Copy and paste the below script
provider "aws" {
version = "~> 2.0"
region = "us-west-2"
shared_credentials_file = "~/.aws/credentials"
profile = "prashanth"
}
data "aws_ami" "amazon-linux-2" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = ["amzn2-ami-hvm*"]
}
filter {
name = "architecture"
values = ["x86_64"]
}
}
resource "aws_instance" "test" {
ami = "${data.aws_ami.amazon-linux-2.id}"
associate_public_ip_address = true
instance_type = "t2.micro"
}
  • Now, initialize terraform
terraform init
  • Compile the terraform file for any issues
terraform plan
  • Finally apply terraform
terraform apply -auto-approve

Configure Selenium Jenkins job with Ruby Env setup from Jenkins User

Note: (Follow this post before proceeding)

  • Start with creating a new Jenkins job by clicking Jenkins > New Item
  • Enter the job name, select Freestyle project, and click ok

  • Choose Source Code Management > Git and enter the prompt GitHub repo. Enter the branch name if different.

  • Now, select Build > Add build step > Execute shell

  • And follow these steps in shell to run selenium cucumber tests
  1. Set temporary RVM environment setup
  2. source /var/lib/jenkins/.rvm/bin/rvm

    or

    source ~/.rvm/bin/rvm
  3. Create rvm gemset and switch to it
  4. rvm gemset create test
    rvm gemset use test
  5. Install the ruby libraries
  6. gem install bundler
    bundle install
  7. Run Selenium cucumber tests
  8. cucumber features/scenarios/**/*.feature
  9. Finally, apply changes

Skip the manual temporary RVM environment setup [Optional]

  • Go to Manage Jenkins > Manage Plugins, click on the Available tab
  • Enter rvm in the filter

  • Select checkbox, download & restart Jenkins to take effect
  • Now, open the job created earlier and click Configure

  • you’ll see an extra newly added option, Run the build in a RVM-managed environment under Build Environment section

  • Add the installed ruby version in it (say, ruby-2.4.1) and remove source ~/.rvm/bin/rvm from the Execute shell

 

Install RVM and Ruby on Amazon Linux as Jenkins/Root User

Install RVM and Ruby as a Jenkins User

  • Install Jenkins (Follow this link)
  • Become a root user
sudo su
  • Install prerequisites for RVM and Ruby
yum install -y gcc openssl-devel libyaml-devel libffi-devel readline-devel zlib-devel gdbm-devel ncurses-devel ruby-devel gcc-c++ jq git patch autoconf automake bison libtool patch sqlite-devel
  • Set password for Jenkins as a root user (if needed)
sudo passwd jenkins

  • Switch as Jenkins User

  • Import GPG key before RVM install
curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -

[run the cmd if the above didn't work]
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
  • Install RVM
curl -sSL https://get.rvm.io | bash -s stable --ruby
  • Export temporary setup
source /var/lib/jenkins/.rvm/scripts/rvm
  • Verify RVM and Ruby installations
rvm -v && which rvm
ruby -v && which ruby

Install RVM and Ruby as a Root User [optional]

  • Install Jenkins (Follow this link)
  • Become a root user
sudo su
  • Install prerequisites for RVM and Ruby
yum install -y gcc openssl-devel libyaml-devel libffi-devel readline-devel zlib-devel gdbm-devel ncurses-devel ruby-devel gcc-c++ jq git
  • Import GPG key before RVM install
curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
  • Install RVM
curl -sSL https://get.rvm.io | bash -s stable --ruby
  • Now, run the temporary RVM environment for effect
source /usr/local/rvm/scripts/rvm
  • Verify RVM and Ruby installations
rvm -v && which rvm
ruby -v && which ruby

Jenkins installation on Amazon Linux AMI (AWS EC2)

Prerequisites

  • Become a root user
sudo su
  • Update yum (since Amazon Linux is based on RedHat Linux)
yum update -y
  • Install Java 8 and purge Java 7
yum install java-1.8.0
  • Remove Java 7
yum remove java-1.7.0-openjdk

Install Jenkins

  • Download Jenkins from the RedHat repo
wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
  • Import the verification key using the package manager RPM
rpm --import https://pkg.jenkins.io/redhat/jenkins.io.key
  • Install Jenkins
yum install jenkins --nogpgcheck -y
  • Start Jenkins
service jenkins start
  • Open the Jenkins URL with server IP and Jenkins default port
http://xx.xxx.xxx.xxx:8080/
  • The default Jenkins password can be copied from the below-mentioned file
cat /var/lib/jenkins/secrets/initialAdminPassword

Edit Jenkins default port (optional)

  • Edit Jenkins config file (vi commands: “i” for insert mode, “ESC” key to escape the inserting mode, “:wq” for write an quit)
vi /etc/sysconfig/jenkins
  • Update port
JENKINS_PORT="8081"
  • Check Jenkins installation
fuser -v -n tcp 8080
netstat -na | grep 8080
  • Auto start Jenkins service
sudo chkconfig --list jenkins
sudo chkconfig jenkins on