Wednesday, January 18, 2023

Learning Linux - Operate Running Systems(Part-3)

In part 2 of this learning Linux basics, we tried constructing basic shell scripts using the condition, Loops, etc.

In the part 3 series of Learning Linux, We will try to perform the below Linux operations,

    1. boot, reboot, shutdown

    2. Change Linux OS operating modes

    3. Gain root access after interrupting the boot process

    4. troubleshoot bootloaders


- Boot, reboot, and shutdown a system safely:

    Reboot & shutdown: systemctl restart / systemctl poweroff

    schedule shutdown/reboot: shutdown 2:00 'shutting down for maintenance at 2 AM morning'

    shutdown -r 2:00 'rebooting  for maintenance at 2 AM morning'

- Boot or change the system into different operating modes

    Operating Modes(Targets)

- Graphical.target

- Multi-user.target

- Emergency.target

- Rescue.target

     Change Mode: systemctl set-default multi-user.target, 

     Switch Mode: systemctl isolate graphical. target

- Interrupt the boot process in order to gain access to a system

    Red Hat 8: 

    - Open GRUB Edit mode while booting

       


    - In the edit mode, Insert text rd.break at the end of the Linux GRUB syntax. CTL + X to proceed with the boot

   

    - You will be in Emergency target mode with swich_root login. The root file system will be default mounted as ro(read only). To check type: mount | grep /sysroot

    - You must remount the root file system with rw(read write) mode to change the root password. Run the below command to remount in rw mode: mount -o remount rw /sysroot.

    - Type cd /sysroot to change directory to root from Swich_root. 

    - Now you should be able to change root password. Type passwrd root 

    -  then at the end we must create a special file touch /.autorelabel . reboot


    Red Hat 9:

    - Start GRUB loader in edit mode and change crash kernel mode from ro to rw. At the end of Kernel syntax, we will add string: init=/bin/bash


    - Now, press CTRL + X to continue with boot process

    - In the next couple of seconds, you should be already in with root access. Type passwrd root to change the root password and type: touch /.autorelabel and exec /sbin/init to continue the boot process to load the OS.

- Install, configure and troubleshoot bootloaders
           When you in a situation where GRUB is unable to load the OS or getting errors. You might have to rebuild the GRUB config to fix the boot issue. Please follow the below steps

  1. Boot from bootable USB drive and start into 'Troubleshooting' mode
  2. you're in rescue mode and you should be prompted to try couple of options like 1. Continue: This will try to search for root filesystem and mount it for you, 2. Read-Only mode: Mount root fs in ro, 3. Skip to shell, 4. Quit(reboot).
  3. Select 1, Press 'Enter' and type: chroot /mnt/sysroot to get into root access mode
  4. Now, To Generate new GRUB config type: grub2-mkconfig -o /boot/grub2/grub.cfg (BIOS), grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg(EFI)
  5. Now, GRUB should be install on the first sector of OS disk. you need to find the physical disk holding the /boot and install the grub conf there.

lsblk (to find the block devices)

                grub2-install /dev/sda ( This will place the GRUB in first sector of disk /dev/sda) OR 

dnf reinstall grub2-efi grub2-efi-modules shim(EFI) 

  


    6. exit from troubleshoot mode to reboot the system

- Modify the GRUB configuration file 

    Open /etc/default/grub file in vim with sudo access. Modify the required parameters and save the file 

  •     grub2-mkconfig -o /boot/grub2/grub.cfg (BIOS), grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg(EFI)
  • reboot

- Diagnose and manage processes

Process Management: 

  • Examples: ps, ps aux (ax=all processes, u=user oriented format), 
  • ps u -U rahul ( All processes running by user rahul), 
  • ps lax (show nice values for processes), 
  • ps faux (show the parent of process), 
  • top,  pgrep -a syslog (process grep),  
  • nice -n <value -20/19> process id/name
  • renice <value> process id(sudo renice 7 8290), 
  • lsof -p 1(show the open files used by process id), Example: sudo lsof | grep sshd |  grep -i reg | sed 's/.* //g'(reg files used by ssd),
  • sudo lsof /var/log/messages(what process using the file)

        Process Signals: 

  • kill -l (list the valid signals) , 
  • pkill -KILL bash ( Kill the matching processes), 
  • ctrl + z (Pause the open program/process) and fg will bring it back(fg - foreground), 
  • sleep 180 & (Make the program run in background) and fg <id> will bring it back., 
  • bg 1 (make the first background program to run), 

- Locate and analyze system log files

        rsyslog = rocket-fast system for log processing(Default daemon for linux OS)

           Following log file: example tail -f /var/log/messages

        Journalctl

  • Example: journalctl /bin/sudo(Logs for a program), 
  • journalctl -u sshd.service(Log reported by a unit - service), 
  • journalctl -f(follow mode), 
  • journal -p err ( filter the logs by priorities like info, warning, err, crit), 
  • sudo journalctl -p info -g '^c' (g = grep, search for logs starting letter c),
  • last (who logged in), lastlog  

-> echo "Thank you :)"





Saturday, December 24, 2022

RDPClient_SSL(TsSslEventHandshakeContinueFailed): 2022-12 Cumulative Update for Windows Server 2016 for x64-based Systems (KB5021235)

 Hi there, 

Post installation of this update - "2022-12 Cumulative Update for Windows Server 2016 for x64-based Systems (KB5021235)" on one of the domain controllers in Azure VM.  We started facing a weird RDP Authentication issue where users with even the correct credential failed to take an RDP session of remote systems in another network(site).

After investigating further, We noticed the below warning message in the event log for RDP Service-

RDPClient_SSL: An error was encountered when transitioning from TsSslStateHandshakeInProgress to TsSslStateDisconnecting in response to TsSslEventHandshakeContinueFailed (error code 0x80004005).

In the end, we had to uninstall this CU Update - KB5021235 from the domain controller which has fixed the issue.

So if you're having a similar issue, I request you to please try uninstalling this update or hold for installation. 

Hopefully, the Microsoft update team will fix this issue very soon.

Thank you,

 

Wednesday, December 14, 2022

Learning Linux - Create a simple shell script(Part-2)

 In part 1 of this blog series, We have seen how to work on essential Linux commands. In part 2, We will assist you to understand the basic logic and loop format while creating your first bash script. 

Prerequisites: I am hoping you have basic knowledge and experience with Linux. 

- Use scripting to automate system maintenance tasks

Scripting: #! Shebang - #!/bin/bash , # comment a line or text

- Conditional Logic(if)

IF Example: 

if [condition block] 

then

Command section

elif [condition block] 

then 

Command section

else 

Command section

fi 

    Conditional Operators

              
                

        






   

    -Processing shell command exit codes

        Exit Code: run 'echo $?' post running any command to know the exit code


    - Use Looping constructs (for, etc.) to process file, command line input

For Loop: Perform repetitive tasks 

Example: 

for mission in $(cat mission-names.txt)

do 

create-and-launch-rocket $mission

done

    while Loop usage: wait in the loop until specific condition matches/create infinite loops/Menu driven programs

Example:

while [$rocket_status = "launching"]

do

sleep 2

rocket_status = rocket-status $mission_Name

done

-> echo "Thank You :) "

Tuesday, November 29, 2022

Learning Linux - Essential Commands(Part-1)

As part of this blog series, I am trying to consolidate the most common Linux commands and their usage in a very simplified manner so that you may recall them while you're performing any related tasks.


- Log into the local/remote system
SSH, Telnet, VNC Server/client

- Read, and use System Documentation
command --Help, Manual Pages with man command, 
Searching for commands - apropos, Tab/auto-completion

- Create, Delete, Copy, and Move Files and Directories
Listing files & Directories - ls, absolute path/relative path,
Current/Working Directory - cd, Creating file - touch,
copying file - cp [source] [destination], Move Files - mv [source] [destination]
Deleting files & Directory - rm,

- Create and manage hard links
Introduction to iNode - stat [file], hard link - ln [path_to_target_file] [Path_to_link_file],
Limitations - Only Hard links to files, not folder, Only Hard links to files on same filesystem,

- Create and manage soft links
soft links - ln -s [path_to_target_file] [Path_to_link_file], readlinks [soft link file]

- List, set, and change standard file permissions
Owner & Groups - chown [user] [file], chgrp [group] [file], Files & Directory Permission - 
chmod [permissions] [file/directory], 

- SUID, SGID, and Sticky Bit
SUID - chmod 4664 file, SGID - chmod 2664 file, Stickybit - chmod 1777 file

- Search for files
find [path/to/direcotory] [search parameters], 
                Search Parameters - Name - find -name felix, 
                Search Parameters - Modified time - find -mmin [minute],  
                Search Parameters - file size - find -size [size], 
                Search expressions - find -name "f*" -mmin [minute] # AND Operator, 
                find -name "f*" -o -mmin [minute] # OR Operator,   
                find -not -name "f*" ,  find /! -name "f*" # NOT Operator, 
                # Find files with permissions- find -perm 664 // find -perm u=rw,g=rw,o=r, 
                # Find files with at least permission- find -perm -664 // find -perm -u=rw,g=rw,o=r, 
                # Find files with any of these permissions- find -perm /664 // find -perm /u=rw,g=rw,o=r

- Compare and manipulate file content
cat, tac, tail, head, Transforming text: sed 's/canda/canada/g' file.txt(lookupmode), 
                Sed -i 's/canda/canada/g' file.txt(inplacemode)
cut -d '' -f 1 file.txt(delmitedmode), Uniq & Sort: uniq file.txt, sort file,
Comparing files: diff diff file1 file2, diff -c diff file1 file2 , diff -y diff file1 file2

- Search files using Grep
Searching with grep: grep [option] 'search pattern' file, 
                grep 'centos' /etc/os-release, 
                grep -i 'centos' /etc/os-release(Non-case-insensetive),
grep -r 'centos' /etc/os-release(recursive), 
                grep -ir 'centos' /etc/os-release(Case-Ins.+recursive),                 
                grep -vi 'centos' /etc/os-release(invert-match), 
                grep -wi 'centos' /etc/os-release(words), 
                grep -oi 'centos' /etc/os-release(only-matching), 

- Analyze text using basic regular expressions
Regex Operators: ^, $, ., *, +, {}, ?, |, [], (), [^], 
                The Line Begin with: ^, 
                The line End with: $, 
                Match AnyONE Characters: . Example: grep -r 'c.t' /etc/,
Escape for special characters: \: Example: grep '\.' \etc\login.defs, 
                Match the previous element o or more matches: *, 

- Extended Regular Expressions
Previous elements can exist "this many" times: {}, Example: egrep -r '10{,3}' /etc/, 
                Make the previous element optional: ?, Example: egrep -r 'disabled?' /etc/, 
                Match one thing or the other: |, Example: egrep -ir 'enabled?|disabled?' /etc/, 
                Range or Sets: [], Example: egrep -r 'c[au]t' /etc/, 

-  Use input-output redirection (>, >>, |, 2>, etc.)
Stdin(<), stdout(1>, >), and stderr(2>), Redirection: >, >> , 
                Example: over right, date > output.txt, 
                append, date >> output.txt 
                heredoc(<<EOF) and here string(<<<) 
                Example: sort <<EOF .Input value. > EOF (Here Document or heredoc), 
                bc <<< 1+3+6 == 10(here string)

- Archive, backup, compress, unpack, and uncompress files
1. Archiving, 2. Compression, 3. Backup
tar = tape archive, 
                Listing: tar --list --file archive.tar, 
                Creating tar file: tar --create --file archive.tar file1, 
                Add to exising archive: tar --append --file archive.tar file1,
Extracting: tar --extract --file archive.tar --directory /tmp/

- Compress and Uncompress files
Common archiving tools: tar, zip 
Common Compress and Uncompress tools: gzip, bzip2, xz
Compress: gzip file1, bzip2 file2 xz file3, 
                Decompression: 
                 gunzip file.gz or gzip --Decompress file.gz, 
                 bunzip file.bz2 or bzip2 --Decompress file.bz2,
unxz file.xz or xz --Decompress file.xz

Common Compress and Uncompress with tar: 
                 tar --create --file archive.tar file1, 
                 tar --create --gzip --file archive.tar.gz file1(with combining gzip),
tar --create --bzip2 --file archive.tar.bz2 file1(with combining bzip2), 
                tar --create --xz --file archive.tar.xz file1(with combining xz)
Autocompress: 
                 tar --create --autocompress --file archive.tar.gz file1(Select compression utility automatically), 
                 tar --extract --file    archive.tar.gz 

- Backup files to a Remote System
Syncing two Directories: 
                rsync, Example: rsync -a pictures/ aroon@9.9.83.2:/home/aroon/pictures/
Disk Imaging: dd, 
                 Example: sudo dd if=/dev/vda of=diskimage.raw bs=1M status=progress

- Securely transfer files between systems
Securely transfer files: 
                 scp, Example: scp aaron@192.168.1.27:/home/aaron/myfule.tgz /home/aaron/myfiles.tgz (Copy from remote to local), 
                 scp /home/aaron/my_archive.tar aaron@192.168.1.27:/home/aaron/my_archive.tar (local to remote), 
                 scp aaron@192.168.2.37:/home/aaron/my_archive.tar aaron@192.168.1.27:/home/aaron/my_archive.tar ( remote to remote)

Securely transfer files: sftp, Example: sftp aaron@192.168.1.27(connecting sftp server), 
                 get family.jpg (interactive command(get) to download to local), 
                 get -r /picture (interactive command(get) to download recursive to local), 
                 put family.jpg (interactive command to upload to local),  
                 put -r /my_pictures (interactive command to upload recursive  to local)




-> echo "Thank You :) "


Monday, April 19, 2021

Exchange Server - Creating addition Global Address List(GAL)

Hi There, 

I hope you are doing well!

I would like to guide you through the process of creating an additional Global address list in the Exchange-Onprem environment. This solution has been tested on Ex2019.

Requirement: Create an additional address book for users who belongs to a different business unit with a different domain name/ different SMTP domain name (Example - mydomain.com). 


Step1:  Create New GAL using the recipient filter to a windows email address like *@mydomain.com

New-GlobalAddressList -Name "AAA Global Address List" -RecipientFilter {((Alias -ne $null) -and (((ObjectClass -eq 'user') -or (ObjectClass -eq 'contact') -or (ObjectClass -eq 'msExchSystemMailbox') -or (ObjectClass -eq 'msExchDynamicDistributionList') -or (ObjectClass -eq 'group') -or (ObjectClass -eq 'publicFolder'))) -and (WindowsEmailAddress -like "*@mydomain.com") )}

Update-GlobalAddressList "AAA Global Address List"


Step2: Create the following Address list like All Users, All Room, All DLs, etc.

- All Distribution Lists

New-AddressList -Name "AAA All Distribution Lists" -RecipientFilter {((Alias -ne $null) -and (ObjectCategory -like 'group') -and (WindowsEmailAddress -like "*@mydomain.com"))}

- All Rooms

New-AddressList -Name "AAA All Rooms" -RecipientFilter {((Alias -ne $null) -and (((RecipientDisplayType -eq 'ConferenceRoomMailbox') -or (RecipientDisplayType -eq 'SyncedConferenceRoomMailbox'))) -and (WindowsEmailAddress -like "*@mydomain.com"))}

- All Users

New-AddressList -Name "AAA All Users" -RecipientFilter {((Alias -ne $null) -and (((((((ObjectCategory -like 'person') -and (ObjectClass -eq 'user') -and (-not(Database -ne $null)) -and (-not(ServerLegacyDN -ne $null)))) -or (((ObjectCategory -like 'person') -and (ObjectClass -eq 'user') -and (((Database -ne $null) -or (ServerLegacyDN -ne $null))))))) -and (-not(RecipientTypeDetailsValue -eq 'GroupMailbox')))) -and (WindowsEmailAddress -like "*@mydomain.com"))}


Step3: Create an Offline Address Book 

New-OfflineAddressBook -Name "AAA Offline Address Book" -AddressLists "AAA Global Address List"
Update-OfflineAddressBook "AAA Offline Address Book" 


Step4: Create an Address Book Policy which we will later apply to the respective business users.

New-AddressBookPolicy -Name "AAA ABP" -AddressLists "AAA All Distribution Lists", "AAA All Users" -RoomList "AAA All Rooms" -OfflineAddressBook "AAA Offline Address Book" -GlobalAddressList "AAA Global Address List"


Step5:  Finally, Apply this policy to a few test accounts to confirm if it's working as expected using the below command. Later, you can apply to all users.

Set-Mailbox -identity Username -AddressBookPolicy "AAA ABP"

Note: After creating this new GAL, If the Email Address Policy is set to default to all users, everyone within the organization will be able to see this new GAL in ADDRESS BOOK. To prevent it, you must apply the new 'Email Address Policy' individually to all users in the different business units (As per the above requirement).

*You may replace the domain - mydomain.com and name format "AAA ---" according to your company naming format.

Feel free to comment if you have any questions or concerns.

Best Regards,
Rahul 






Monday, February 24, 2020

Backup an Oracle DB using Veeam Plugin for Oracle RMAN

In this short article, I will try to cover the basic steps about how to take a backup of Physical windows based Oracle Server using the 'Veeam plugin for Oracle RMAN'.
In my scenario, normal backup through an agent was getting failed with the error message: 'Unable to perform a backup: Oracle Automatic Storage Management (ASM) disk configuration is not supported'.

After further discussion with Veeam's support and my oracle DBA team, we decided to proceed with Veeam Plugin for Oracle RMAN. So, Let's begin,

Prerequisites:
 1. Veeam Backup server 
     Version   - Minimum Veeam 9.5 u4
     License  - Veeam Enterprise Plus or Veeam Universal License(VUL)
      
2. Oracle Server
     Version - Minimum 11gR2
     Port - From Oracle Server to Veeam Bkp(10006, 2500 to 3300)
     RMAN Script - Attached the sample script in the bottom. for more info, Click Here> 
     Permission - Backup service account should have access to the Oracle Server to perform the backup operation using the RMAN script.


Procedural:

Step1- Deployment of Veeam plugin for RMAN on Oracle Server
             The setup file(MSI) can be found in the Veeam Backup and replication setup ISO image under the plugin folder. Once installed, Next, you need to configure the plugin as follow-.

Double Click on 'Veeam Plugin for Oracle RMAN configuration wizard' from the Desktop icon.














Type the FQDN/IP address of the Backup server with Veeam admin credential
















Add Repository
















Now you should be able to see that Veeam Plug has created the required device and channel configuration. Save the configuration by using the export option and click Finish.
















Step2: Initiate the backup using RMAN Script.
         In my case, I wanted to take the full backup of the Oracle DB with an option of arching the logs as well. Below is the sample script file for the same. For more info, Click Here>  
After the successful execution of the below script,  Veeam Plugin for Oracle RMAN will create the required backup job in the Veeam backup server side automatically.

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
rman target Credential here(exmple- sys/Password@DBName)
crosscheck archivelog all;
Delete noprompt expired archivelog all;
crosscheck archivelog all;
run
{
backup as compressed backupset database;
backup as compressed backupset archivelog all;
backup current controlfile;
delete force noprompt archivelog until time 'SYSDATE-2';
}
+++++++++++++++++++++++++++++++++++++++++++++++++++++++

Backup Job Creation at Veeam Backup server-side after successful execution of RMAN commands:



Thank you,