Posts

Showing posts with the label Linux

Sysstat - collect system stats

The sysstat service is responsible for the regular collection of system performance information. Through the use of cron and sadc (System Activity data collector), sysstat gathers SAR data at n minute intervals daily. The service has little impact on overall server performance. The default sysstat configuration overwrites collected performance information every 7 days. Sysstat is provided as part of the sysstat package – it also provides useful system performance gathering utilities including; mpstat, iostat and sar. Service: /etc/init.d/sysstat start|stop Configuration File:  /etc/sysconfig/sysstat Log location: /var/log/sa/ server1# cat /etc/default/sysstat # # Default settings for /etc/init.d/sysstat, /etc/cron.d/sysstat # and /etc/cron.daily/sysstat files # # Should sadc collect system activity information Valid values # are "true" and "false". Please do not put other values, they # will be overwritten by debconf! ENABLED="true" Change History Size: ...

LINUX - RAM Usage

The RAM (Random Access Memory) is an essential component of a Linux system that has to be monitored closely. In some conditions, we may run out of memory with very slow response times to our server or be completely unresponsive. Linux machine has swap file which acts as an Extra RAM for the machine Check RAM available on Machine: # free -g               total        used        free      shared  buff/cache   available Mem:             31           1          25           0           4          29 Swap:            31           1          29 Commands to check RAM usage on Linux Machines: 1) TOP command to get the  high Memory...

LINUX - CPU Usage

Checking CPU and RAM is one of the important Task. Though we have monitoring enable to check CPU and RAM stats we ran into a situation where we need to check the CPU and RAM utilization live during debugging session. CPU: To list No of  CPU run  lscpu same can be checked using cat /proc/cpuinfo $ lscpu Architecture:          x86_64 CPU op-mode(s):        32-bit, 64-bit Byte Order:            Little Endian CPU(s):                12 On-line CPU(s) list:   0-11 Thread(s) per core:    2 Core(s) per socket:    6 Socket(s):             1 NUMA node(s):          1 Vendor ID:             GenuineIntel CPU family:            6 Model:                 158 Model name:   ...

Ansible Playbook

Ansible Playbook Playbooks are created in YAML format using modules available in ansible To list the available modules $ansible-doc -l  To know more about a specific module used ansible-doc modulename $ansible-doc <modulename> Below playbook use apt module to install Nginx and TFTP packages on ubuntu machines  $ cat  install.yml ---  - name: Install Packages    gather_facts: false    become: yes    hosts: NODE    tasks:      - name: Install packages         apt: pkg={{ item }} state=present update_cache=true        with_items:             - nginx             - tftp $ cat list.ini [NODE] localhost server1 server2 $ansible-playbook -i list.ini install.yml --syntax-check (Verify syntax ) playbook: install.yml Ansible playbook created runs on all the host under NODE group in list.ini file $ansible-playbook -i...

Ansible

Ansible and Basic Commands Ansible is an open-source and  Infrastructure Management Tool. The Ansible file is in YAML format. Ansible is Agentless works with SSH Protocol. Ansible is written and uses Python Ansible has many modules to perform various operations without any programming knowledge.   Ansible Configuration file: PATH: /etc/ansible/ansible.cfg remote_tmp  = /commlocation (change to common location to avoid permissions issue) forks          = 50 (Adjust to number of instances to connect parallelly )  Default hosts file Path: /etc/ansible/hosts [TEST1] server1 server2 [TEST2] server3 server4 Command Usage: Ansible to use default host file  $ansible all -m ping -o (run on all the hosts in the hosts file) $ansible TEST1 -m ping -o (run on nodes under TEST1 group) to use a custom host file create a file and pass an argument with -i as below 4cat hostfile.ini [NODE1] testserver1 testserver2 [NODE2] testserver3 testserver4...

SSL cert check

Below are the different ways to check the SSL cert and its validity remotely NMAP is used to check the port and services running on the remote machine $nmap --script ssl-cert -p PORT   URL The OpenSSL program is a command-line tool for using the various cryptography functions of OpenSSL's crypto library from the shell.  It can be used for Creation and management of private keys, public keys and parameters Public key cryptographic operations Creation of X.509 certificates, CSRs and CRLs Calculation of Message Digests Encryption and Decryption with Ciphers SSL/TLS Client and Server Tests Handling of S/MIME signed or encrypted mail Time Stamp requests, generation and verification openssl s_client -showcerts -connect URL:PORT

kernel fallback to older version - Ubuntu

Kernel upgrade is a simple and smooth process. However, there are a few cases for which all ways need a fallback kernel available. NOTE:  Test changes first in using #1 before making the permanent changes to the system.  Temporary:  Boot into the previous version of Kernel: Interrupting the boot process using ESC key keep will splash the available kernel version on the system. Select the kernel.  2) Permanent  Method 1: sudo view /boot/grub/grub.cfg and copy the full name of your old kernel. sudo vi /etc/default/grub and, at the top, change GRUB_DEFAULT=0 to instead read GRUB_DEFAULT=your_kernel_name_from_grub.cfg , and save the change (you may like to keep a copy of the original file for safety). sudo update-grub Method 2:        1. grep -A100 submenu  /boot/grub/grub.cfg |grep menuentry       2. update  GRUB_DEFAULT=gnulinux-advanced-version>gnukernl-kernel-version in /etc/default/grub     ...

Ubuntu Kernel and Upgrade

The kernel is the heart of the system which converts the human-readable language to machine-understandable language  Steps: 1) Identify the current version of kernel 2) Update the repository 3) Install kernel   Identify the current version of kernel: uname is used to check the kernel of a machine #uname -a Linux hostname 4.4.0-186-generic #216-Ubuntu SMP Wed Jul 1 05:34:05 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux # uname -sr Linux 4.4.0-186-generic Update the repository:  apt-get update apt-get remove Install Kernel: apt-get install --install-recommends linux-generic-{version} linux-headers-{version} linux-modules-{version} reboot the server #reboot -f  verify the current kernel using # uname -sr   Once verified we can remove the old kernel version to list all the old kernels use  dpkg -l|grep linux-image* apt-get remove --purge linux-image-{older-kernel-version} Note: It is always recommended to have at least one alternate kernel to fall back...

Reduce LVM

Reduce an LVM: consider the lvm size is 15G and want it to reduce to 10G unmount the filesystem #umount /mnt/pathtreduce #e2fsck -ff /dev/vgname/lvname #resize2fs  /dev/vgname/lvname 10G (10G is the final size to which you want to reduce) #lvreduce -l -5G /dev/vgname/lvname # mount  /dev/vgname/lvname  /mnt/pathtreduce

LVM

Logical Volume Management: Dynamic Partitions (create/resize/delete) partitions.  In simple if you have multiple disks we can group all the disks into a single partition or multiple partitions  volumes using LVM .   Steps: 1) Identify the correct partition attached to the Node and format 2) Create a Physical Volume on the disk 3) Create a Volume Group 4) Create Logical Volume 5) Create Filesystem of the logical Volume Identify the correct partition attached to the Node: Identify the Correct Partition attached to the Node using fdisk or lsblk or any other disk management tools /dev/sdb or /dev/sdc and convert the disk to an LVM disk  #fdisk /dev/sdb create a partition with the key "n" assigning +size of capacity change the type partition with key "t" assigning "8e" (lvm partition)  Enter key "w" to save changes,  Press key "p". #partprobe /dev/sdb (To update the kernel) Identify the correct partition attached to the Node: #   pvcreate /d...

SSH and its configuration files permissions

Every user has .ssh   folder under the user home directory to manage the ssh connections and store keys that are used to connect.   .SSH folder permission plays an important role in setting up connections so please make sure the permissions and intact. chmod 700 ~/.ssh (Folder to store ssh config and ssh keys) chmod 644 ~/.ssh/authorized_keys (store public keys to establish passwordless ssh connection) chmod 644 ~/.ssh/known_hosts (stores key information which connected to the node) chmod 644 ~/.ssh/config (customize and manage ssh connections) chmod 600 ~/.ssh/id_rsa (RSA private key) chmod 644 ~/.ssh/id_rsa.pub (RSA public key) For more information use the below command $man ssh_config

Install SSH and enable ssh for root login

 SSH is SECURE SHELL which is used to connect remote Linux Servers. It uses port 22 for connection. Application name: openssh-server and openssh-client  Install ssh on the server: apt-get install openssh-server -y  Start and Stop Service: $service sshd (status|start|stop) ● ssh.service - OpenBSD Secure Shell server    Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)    Active: active (running) since Mon 2021-11-15 22:27:10 PST; 2 months 28 days ago  Main PID: 1195 (sshd)    CGroup: /system.slice/ssh.service            └─1195 /usr/sbin/sshd -D   NOTE: By default ssh login for root is disabled to enable ssh for use change PermitRootLogin no to PermitRootLogin yes in   /etc/ssh/sshd_config file. root@server:~# grep PermitRootLogin  /etc/ssh/sshd_config # Ubuntu16 requires PermitRootLogin set to 'yes'. PermitRootLogin yes

SSH-PASSWORDESS

SSH: SSH (SECURE SHELL ) is an Open Source and most trusted protocol that is used to remote login to other Linux Machines. Scenario: If you would like to connect to another remote host via command line we can use ssh <hostname> to connect to the host by entering username and password . Command: server1 $ ssh server2 password: one you have entered the password you will be login to the server2 via command line. In IT Industry we may need to work with multiple hosts. Entering a password every time connecting to other hosts is a very time-consuming and repetitive task. to overcome this we have a password-less authentication method using ssh keys. Generating ssh keys: $ssh-keygen -t rsa (Press Enter for every question asked after executing the command) This generates the RSA keys id_rsa and id_rsa.pub keys now you can manually append the authorized_keys on the remote host(server2) with the .pub key on the node(server1) on which you have created the keys. or run the below...

Tools for working Linux professional

There are many tools and packages that help to make the IT-Admin life easier. Below are a few that I have used. ssh nslookup Ping fping echo   strace ps vmstat top netstat ss awk sed dmesg jq xmlstarlet Basic Tools:  They are many tools or packages available that help IT-Admin.  Below are a few which I use frequently. Installation OS: One should know the OS Installation and Boot process to better understand how the OS or application works. SSH: If you are a working Linux professional. Learning ssh and configuring passwordless ssh is the first thing to start.  Clusters-ssh:  Cluster ssh is a simple tool to manage multiple hosts I used way back before started working with Ansible  Cron Job:  Cron Job is used to run the scripts or tasks that needed to run on a Linux machine on a schedule Ansible: This makes our job easy. if you haven't started  Ansibling you better start today. Easy to learn and simple to use. you can start automating your day-t...