DEV Community

piyushsachdeva for AWS Community Builders

Posted on

How To Install Multiple Gitlab Runners On a Single AWS EC2 machine

In this quick tutorial, I am going to show you how you can install multiple Gitlab Runners on a single AWS EC2 machine.

Step 1

Provision a EC2 server

Login to you AWS console--> EC2 --> Hit launch instances

Launch Instance
Give it a name such as Gitlab-Runner and select a suitable Linux Image. In this demo, I have selected an Ubuntu image

Create the EC2 instance

Then scroll down and select the key-pair that you would want to use for this instance or you can create a new key-pair. Once the key-pair is selected, you can create a new security group with the wizard and open access to port 22(SSH) from your local machine or a CIDR range and for your application server so that gitlab runner can ssh into your application server for code deployment. You can optionally use an existing security group as well.

Create a security group

Scroll down to the advance details section and keep everything as default except the user data section. Add the below user data script and hit Launch instance.



#!/bin/bash
sudo apt-get update -y
curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh" | sudo bash

sudo apt-get install gitlab-runner -y

#install docker 
curl -fsSL https://get.docker.com -o get-docker.sh 
sudo bash get-docker.sh

cd /var/run/ 
sudo chmod 777 docker.pid docker.sock



Enter fullscreen mode Exit fullscreen mode

User data script

Step 2

Register the Runner

Once server is running, login to the server using EC2 instance connect or ssh client such as Putty and enter the command

gitlab-runner register

then enter your gitlab running when prompted

Gitlab Runner Register

Go to your Gitlab UI --> Settings --> CICD and Expand the section in front of Runners

Gitlab Runner

Copy the registration token from here and paste the same in the terminal prompt

Copy the token

Enter the details as below to register the runner

Register Runner

Step 3

Start the Runner

  • Start the runner using the below command: sudo gitlab-runner start

once it is started, hit refresh on the Gitlab page and you would see the runner as active

Runner as active

Give yourself a pat on the back! you were able to perform the task successfully!

Step4

Register second runner(Optional)
Now , if you would like to register multiple runners on the same ec2 server, using can do so by following the same method. Give a different name and tag to the runner as follows

Second runner

Now, refresh the page to see the new runner as well

Runner final

You can use the runners based on the tags or the names.

That's all folks. If you have enjoyed the blog and learned something new today. Feel free to hit the like button and follow me for more such content.

I have also published a full end to end tutorial for Gitlab CI CD Pipeline, feel free to check that out using the below link

Top comments (0)