Wednesday, 25 October 2017

Alert: *** System restart required *** [ubuntu]


We must reboot our server when we install a new kernel or libraries, Ubuntu Linux can tell you if the system needs a reboot when you login as root user.

*** System restart required ***

The above warning will appear on the login screen, we may miss this warning. So here is the simple script for administrators to find exactly when the system requires reboot.

You can manually find the file: /var/run/reboot-required, which indicates System restart required.

Instead of a manual search, you can use below script to identify the ubuntu notification of 'system restart required’ at every login and never miss the warning.

Add the below lines in the file: /root/status.sh

#!/bin/bash
if [ -f /var/run/reboot-required ]
then
   echo -e "\033[33;31m[*** Hello $USER, you must reboot your machine ***]\033[0m"
else
   echo -e "\033[33;32m\n*** System reboot is NOT required now ***\n`cat /var/lib/update-notifier/updates-available`\n\033[0m"
fi

Now we can add the file path: /root/status.sh in /root/.bashrc file to check 'whether the reboot required' task at every login made by root user.

# echo "/root/status.sh" >> /root/.bashrc && tail -n3 /root/.bash

Thanks !!

Monday, 10 July 2017

Glimpse on Systemd: A Modern Service Manager for Linux


  • Systemd is a system and service manager for Linux operating systems. It is designed to be backwards compatible with SysV init scripts, and provides a number of features such as parallel startup of system services at boot time, on-demand activation of daemons, support for system state snapshots, or dependency-based service control logic. It may refer to all the packages, utilities and libraries around daemon.
  • Systemd was designed to overcome the shortcomings of init and itself is a background processes which is designed to start processes in parallel, thus reducing the boot time and computational overhead. It has a lot other features as compared to init.
Why there was a need to replace init?
  • A init process starts serially i.e., one task starts only after the last task startup was successful and it was loaded in the memory. This often resulted into delayed and long booting time. However, systemd was not designed for speed but for getting the things done neatly which in turns avoid all the UN-necessary delay.

Systemd_cheatsheet:




Thanks to tecmint for made such a clarity post on init and systemd concepts.

Tuesday, 4 July 2017

Steps to install pssh on CentOS7:

Here are the simple steps for the installation of pssh on CentOS7:

pssh is a program for executing ssh in parallel on a number of hosts. It provides features such as sending input to all of the processes, passing a password to ssh, saving output to files, and timing out.

Install epel:

# yum install epel-release

Install pssh:

# yum install pssh

create pssh_hosts.txt file and enter the hosts need to target:

# cat pssh_hosts.txt
# write hosts per line like follows
#user@target_ip
root@192.168.100.100

we should do key-pair between the master host and targets, this is the only way to get things done.(simply login the target from master node for Host key verification)

# ssh root@192.168.100.100

Test with single commands

# pssh -h /path/to/pssh_hosts.txt -A -O PreferredAuthentications=password -i "hostname"
# pssh -h /path/to/pssh_hosts.txt -A -O PreferredAuthentications=password -i "uptime"

Output:

[root@master pssh]# pssh -h ./pssh_hosts.txt -A -O PreferredAuthentications=password -i "uptime"
Warning: do not enter your password if anyone else has superuser
privileges or access to your account.
Password:
[1] 16:27:59 [SUCCESS] root@192.168.100.100
21:27:57 up 1 day,  1:30,  1 user,  load average: 0.00, 0.01, 0.05

To executes scripts on the target machines:


# cat pssh/tst.sh
#!/bin/bash
touch /root/CX && echo "File created"

# pssh -h ./pssh_hosts.txt -A -O PreferredAuthentications=password -I<./tst.sh

make it simple:

# pssh -H '192.168.100.101' -l 'root' -A -O PreferredAuthentications=password -I< ./tst.sh

Output:

[root@master pssh]# pssh -H '192.168.100.101' -l 'root' -A -O PreferredAuthentications=password -I< ./tst.sh
Warning: do not enter your password if anyone else has superuser
privileges or access to your account.
Password:
[1] 16:24:30 [SUCCESS] 192.168.100.101

To execute commands without password prompting, we need to create key-pair between the servers.


Creating key pair:

We are trying to attempt login serverB from serverA

Create SSH-Kegen Keys on serverA:

# ssh-keygen -t rsa

Copy the 'id_rsa.pub' file from serverA to master serverB:

# ssh-copy-id root@<serverB-ip>

Now try logging into the machine, with:   "ssh 'root@serverB-IP'"
and check to make sure that only the key(s) you wanted were added.

(or)

# cat .ssh/id_rsa.pub | ssh root@<serverB-ip> 'cat >> .ssh/authorized_keys'

Now try to login the serverB from serverA:

# ssh root@serverB-IP

Output:

Last login: d.a.t.e a.n.d t.i.m.e from serverA-ip

Okay, Lets try the commands without password:


Through pssh_hosts.txt file:

# pssh -h '/path/to/pssh_hosts.txt' -i 'hostname'
[1] 13:27:56 [SUCCESS] root@192.168.100.100
Master

For single host:

# pssh -H '192.168.100.101' -i 'hostname'
[1] 13:31:16 [SUCCESS] 192.168.100.101
master

Well, executing script this time,

Through pssh_hosts.txt file:

# pssh -h '/root/pssh/pssh_hosts.txt' -I<./tst.sh
[1] 13:32:23 [SUCCESS] root@192.168.100.100

For single host:

# pssh -H '192.168.100.101' -I<./tst.sh
[1] 13:33:42 [SUCCESS] 192.168.100.101

Thanks.