Friday, September 15, 2023

Kernel maps

.

What is the difference between exec and fork?



    1. fork starts a new process which is a copy of the one that calls it,  while exec replaces the current process image with another (different)  one.
    2. Both parent and child processes are executed simultaneously in case  of fork() while Control never returns to the original program unless  there is an exec() error.

Thursday, August 24, 2023

Linux Performance trouble shooting

Linux Performance trouble shooting

Load Avg 1 min 5 min 15 min

CPU Script to hog the CPU

cpuhog.sh

while true
do yes > /dev/null
done

Disk hog io hog
 
dd if = /dev/sda of=dev/zero

%us : user space utilization started by user/application
%sy : system space Kernel side utilization
%ni : nice -20 highest 90 is lower
%id : idle amount of time CPU is not doing anything
%si : time waiting for the CPU for the IO
%hi : Hardware inturupt
%si : Software inturrupt
%st : Referect stleth used for Virtual System
Cat /proc/interrupt

Load avg ( we will get the info from the following location)

cat /proc/lodavg

cat /proc/slabinfo | grep -i den

cat /proc/meminfo | grep -i slab (Kernel Memory usge )

Buffer consist of metatdata

cat /proc/slabinfo | grep -i den

How to check the dentry size

slabtop | grep -i den

Command to find the kernel Memory

cat /proc/meminfo | grep -i slab (Kernel Memory usge )
Cache app =====> ram (cache) ====> disk
CPU L1/L2/L3 cache =====> Cache====> disk

Command to check the L1 and L2 cache


Shared memory shared by different process

pmap -i

command to free the cache memory (never run the same in the prod box)

sync && echo 3 > /proc/sys/vm/drop_caches (never run the same in the prod box)

to Free page cache dentries and inodes
echo 3

to free dentires and inodes

echo 2
to free page cache
ehco 1
lscpu | grep L1.l2 cache

command to find the which CPU is using for which processor
ps -eo pid,arfs,psr

Command to find the how many CPU are present

cat /proc/cpuinfo | grep -i processor

Saturday, July 1, 2023

How to upgrade the Firmware in Fortigate firewall

Upgrade path is 6.4.3-b1778 => 6.4.5-b5651 => 6.4.7-b1911 => 6.4.8-b1914
 
Fortigate Model: FG_100E / FG_100F
 
Ensure you have downloaded the required incremental firmware for the fortigate model FG_100F as per the below upgrade path:
6.4.3-b1778 => 6.4.5-b5651 => 6.4.7-b1911 => 6.4.8-b1914
 
1. Login to VPN if available.
 
2. Login to the FortiGate Firewall: https://<IP-ADDR>
 
3. Take configuration backup
Login to FortiGate >> Dashboard >> System Information widget >> Backup >> Local PC >> OK >> fg100f-<hostname>_xxxx.conf
 
4. Navigate to System >> Firmware >> Check Current version say for instance: FortiOS v6.4.2 build1723 (GA) >> Upload Firmware >> Select File: Browse >> 6.4.5-b5651 >> Enable the HA sync option if available (But currently its standalone) >> Click upload the firmware >> Ok
 
5. After the new firmware has been installed, the system reboots.
 
6. Repeat the above steps for Ver: 6.4.7-b1911 => 6.4.8-b1914
 
7. Upon completion check the Fortigate Firmware version on both Primary and Standby nodes.

Sunday, June 18, 2023

Tuesday, April 11, 2023

How to create a VPC in AWS with two instances of CentOS 9 using Terraform:

  1. Install Terraform on your local machine.
  2. Create a new directory for your Terraform project.
  3. Create a new file in the directory named "main.tf".
  4. Add the following code to "main.tf":

main.tf

 provider "aws" {
  region = "us-east-1"
}

resource "aws_vpc" "example_vpc" {
  cidr_block = "10.0.0.0/16"
}

resource "aws_subnet" "example_subnet_1" {
  vpc_id     = aws_vpc.example_vpc.id
  cidr_block = "10.0.1.0/24"
}

resource "aws_subnet" "example_subnet_2" {
  vpc_id     = aws_vpc.example_vpc.id
  cidr_block = "10.0.2.0/24"
}

resource "aws_security_group" "example_sg_1" {
  name_prefix = "example_sg_1"
  vpc_id      = aws_vpc.example_vpc.id

  ingress {
    from_port = 22
    to_port   = 22
    protocol  = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }
}

resource "aws_security_group" "example_sg_2" {
  name_prefix = "example_sg_2"
  vpc_id      = aws_vpc.example_vpc.id

  ingress {
    from_port = 22
    to_port   = 22
    protocol  = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }
}

resource "aws_instance" "example_instance_1" {
  ami           = "ami-0a5ae2501482eae54"
  instance_type = "t2.micro"
  subnet_id     = aws_subnet.example_subnet_1.id
  vpc_security_group_ids = [aws_security_group.example_sg_1.id]
}

resource "aws_instance" "example_instance_2" {
  ami           = "ami-0a5ae2501482eae54"
  instance_type = "t2.micro"
  subnet_id     = aws_subnet.example_subnet_2.id
  vpc_security_group_ids = [aws_security_group.example_sg_2.id]
}

Note: In this example, we are using the US East 1 region, so please change it to the region of your choice.

  1. Save the file.
  2. Initialize your Terraform project by running terraform init in your project directory.
  3. Create a plan for your infrastructure by running terraform plan.
  4. Apply the changes to create your VPC and instances by running terraform apply.
  5. Once the instances have been created, you can access them via SSH using their public IP addresses.

And that's it! You should now have a VPC with two instances of CentOS 9 running in AWS, created using Terraform.

 

From chat GPT. 



Create a VPC in AWS with two instances of Centos 9

  1. Log in to your AWS Console.
  2. Navigate to the VPC Dashboard by clicking on the "Services" menu at the top of the page and selecting "VPC."
  3. Click on the "Create VPC" button.
  4. Enter a name for your VPC and specify the CIDR block that you want to use. For example, you can use "10.0.0.0/16".
  5. Click on "Create".
  6. Now, navigate to the "Subnets" section of the VPC dashboard.
  7. Click on the "Create subnet" button.
  8. Enter a name for your subnet, select the VPC you just created, and choose a CIDR block for your subnet. For example, you can use "10.0.1.0/24".
  9. Repeat steps 7 and 8 to create a second subnet with a different CIDR block. For example, you can use "10.0.2.0/24".
  10. Now, navigate to the "Security Groups" section of the VPC dashboard.
  11. Click on the "Create Security Group" button.
  12. Enter a name for your security group, select your VPC, and configure the inbound rules to allow SSH traffic.
  13. Repeat step 11 and 12 to create a second security group for the second instance.
  14. Now, navigate to the "EC2" section of the AWS console.
  15. Click on the "Launch Instance" button.
  16. Select "CentOS 9" as your operating system and choose an instance type.
  17. Choose the first subnet you created in step 8.
  18. Select the first security group you created in step 12.
  19. Click on "Launch Instance".
  20. Repeat steps 15-19 to launch a second instance in the second subnet with the second security group.

Created from Chat GPT. 

.

Monday, April 10, 2023

How to get the information on unreadable blocks on the disk

badblocks -s /dev/sda # Test for unreadable blocks on disk sda
.

How to check TCP UDP and Unix sockets open ports .

netstat -ntlp # open TCP sockets 

netstat -nulp # open UDP sockets  

netstat -nxlp # open Unix sockets

Thursday, March 16, 2023

How to perform the rsync .

vi sync-sh
#!/bin/bash
/usr/bin/rsync -avzc /var/www/html username@ipaddress:/var/www/

Saturday, March 4, 2023

Reboot the node using ipmi if non of the option is working.

Login to ILOM shell run the following command 

i2ctool -n CPLD -w 0x1a a5 in ILOM shell

Saturday, February 25, 2023

Disk usage script.

#!/bin/bash
# Threshold (in percentage) threshold=80
# disk usage
disk_usage=$(df -h | awk '{ print $5 }' | grep -v Use | sort -n | tail -1 | cut -d'%' - f1)
# Send an email notification if the disk usage exceeds the threshold if [ $disk_usage -ge $threshold ]; then
echo "Disk usage is critical ($disk_usage%)." | mail -s "Disk Usage Alert" gurudatta.nadig@gmail.com
fi

Note: Taken from net