Activate Logging agent on Multiple Compute Engine VM Instances effortlessly in GCP

Ashish kanojia
3 min readJun 6, 2021

Logging is the record of events or the software run in a system, It is indispensable to enable logging whenever possible since it eases out the event audit process and also gives a better picture to the cybersecurity team working on the system, tagging any suspicious event tagged on the log.

In the era of cloud computing, the importance of security is inevitable although most of it is taken care of by Google cloud infrastructure. However, some additional things we can implement to enhance the transparency of the process running in our compute engine (IaaS) service, i.e. VM Instances, by enabling the logging agent. To Enable the logging agent On a single VM is straightforward describe in GCP documentation. But what if the number of VM running in a project are multiple in numbers? What if the VM running in a different zone and there is a need for an automation script? I articulate the answer to all the above questions below.

Step 1: Consider 6 VM instance running in different regions

[ Path ]: Navigation menu > Compute Engine > VM instances

Step 2: Check It’s logging status (you can skip this step)

[ Path ]: Navigation menu > Monitoring.

[ Relative Path ]: Resource Dashboard tiles > Click on VM instance

The below snapshot clearly picture the instance without install Agent

Step 3: Go to google cloud shell

[ Path ]: Top right Toolbar> Activate Cloud Shell button.

Step 4: Create a new file for Running the script with name log_agent.sh using below command:

vi log_agent.sh

Step 5: Copy the below code and paste in it and save it by pressing :wq and enter.

Step 6: Give executable permission by using below command

chmod +x log_agent.sh

Step 7: Execute the file by using below command

sh log_agent.sh

[Note]: the execution time of the script is solely depend on the number of VM Instances deployed.

Successfully deployment message

Step 8: Check the logging status once again after execution. follow same path as mention in step 2.

For any query or valuable feedback please contact- Ashish Kanojia

--

--