Labels

hpunix (63) marathi kavita (52) linux (21) solaris11 (10) AWS (5) numerology (5)

Wednesday, December 12, 2018

ec2-user is not able to do sudo - Linux + AWS


ec2-user is not able to do become root user:

ec2-user is not able to do sudo or ec2-user is not able become root user.

I was getting below error when I logged in as ec2-user with the .ppk file and then I was trying to become root user by using #sudo –i


[ec2-user@cloud_home]# sudo : effective uid is not 0, is sudo installed setuid root ?

While doing initial troubleshooting, we got to know that someone has changed the /usr/bin/sudo file permission accidentally. [But even he was unaware about that]

Answer :


1.      Login to AWS console and stop the instance
2.      Detach the root disk (/dev/sda1)
3.      Attach it to any running server [who are in same availability zone] as data disk [/dev/xvdg – device name of the disk given by AWS at the time of attaching it]
4.      Start the Instance from AWS console

5.      mount the disk on OS
[root@cloud_home2]# mount /dev/xvdg2 -o no-uuid /mnt ; cd  /mnt ; ls -l usr/bin/sudo

6.      Change permission of /usr/bin/sudo
[root@cloud_home2]# chmod u+s /mnt/usr/bin/sudo ; ls -l usr/bin/sudo

7.      Un-mount temporary mount point
[root@cloud_home2]# umount /mnt

8.      Detach the disk from this server
9.      And re-attach to original server as root disk where we are getting problem.
10. Start instance
11. Login with ec2-user

12. Now try to do sudo and this time you will be able to it.

[ec2-user@cloud_home]# sudo –i
[root@cloud_home]#

Regards,
Kirraan Jadhav


Saturday, December 8, 2018

How to uninstall package/rpm in Linux


How to uninstall package/rpm in Linux:


rpm (redhat package manager) is a powerful tool which can be used to build, install, query, verify, update, and remove/erase individual software packages. 

Below commands can be used to remove packages or rpm:


[root@cloud_home]# rpm –ev [Package Name]

-e = to erase specified package name or rpm

If we want to remove package without removing that package dependency then 

[root@cloud_home]# rpm –ev –-nodeps [Package Name]

Or we can remove package by using yum command as well.
[root@cloud_home]# yum remove [Package Name]

Above commands has given by assuming that we already know the exact package name.

If you don’t know the exact package name then to find out it use below command To get the package name. In below example we are finding package name for httpd:


[root@cloud_home]# rpm –q httpd


Regards,
Kirraan Jadhav

Wednesday, November 21, 2018

ssh login issue - linux


The user is getting below error when he is trying to login to server via putty:

Error: disconnected no supported authentication methods available (server sent publickey)

The user is getting login prompt and so after entering username he is trying to hit enter so he can use his password, but the screen shows the error as mentioned above.

Ans: There are two methods for authentication
1.     Password authentication
2.     ssh key authentication

After entering username the server will authenticate the user first via password and if it not successful then it will ask for key. The authentication is getting done by checking /etc/ssh/sshd_config file

The possibilities could be that in sshd_config file we might have disabled the password authentication and so server is trying to check public key as authentication from password is failed. But the user has not provided the key so user got above error.

To resolve this, edit the file /etc/ssh/sshd_config and change line

root@cloud home]# vi /etc/ssh/sshd_config
PasswordAuthentication no


to

root@cloud home]# PasswordAuthentication yes


and restart the ssh daemon to re-read sshd_config file

root@cloud home]# service sshd restart




Regards,
Kiiran B Jadhav

Thursday, May 10, 2018

How to start ncpa (Nagios) service - Linux


How to start ncpa (Nagios) service:

The Nagios server will communicate with the host when the Nagios agent/service running on the client server.

If the service is not running then the Nagios server will not be able to communicate with the host, in that case we may need to restart the Nagios service. How to do that?

Here are the steps:

1. nagios_listener service will be responsible for communication.

   Check whether that service is running or not by using systemctl or ps -ef command.





or 

[root@cloud home]# ps -ef |grep -i ncpa



2. If the service is not running then restart it.
[root@cloud home]# systemctl restart ncpa_listener


3. Verify the status of the service by below commands:








or





4. To make this service to be started automatically after server reboot:

4.1 check the chkconfig output:










the ncpa_listener is showing "off" for all run levels.

4.2 Make status of ncpa_listener as "on" so it can start after run level 3
[root@cloud home]# chkconfig ncpa_listener on

4.3 Verify the status:








The ncpa_listener is having "on" value for run level 3, 4 and 5.

Note : Please read more about run levels.

So by following above steps we can restart the ncpa_listener service and make it start automatically after server reboot.


Regards,
Kiran Babu Jadhav


Tuesday, March 6, 2018

How to run cronjob at 5 hours interval + Linux


How to run cronjob at 5 hours interval + Linux

In our day to day task, we get request of cron job scheduling so the script/service will run after certain time interval.

If we want our cronjob (eg. restarting rsyslog service) to run after every 5 hours, then we can edit crontab with below entries:

1. Edit crontab file, it will edit the crontab file of root user.

[root@cloud home]# crontab -e

2Make below entry:

0 */5 * * *

[root@cloud home]# 0 */5 * * * systemctl restart rsyslog

Or

0 5,10,15,20 * * *

[root@cloud home]# 0 5,10,15,20 * * * systemctl restart rsyslog

3 List crontab file:

[root@cloud home]# crontab -l

Crontab fields:
= * - first * shows minutes [0-59]
= * - second * shows hour [0-23]
= * - third * shows Day of month [1-31]
= * - Fourth * shows month [0-12]
= * - Fifth * shows day of week [0-7]


Regards,
Kiiran B Jadhav

Friday, February 16, 2018

Yum repo through NFS method

Yum repo through NFS method :

If we have Repository server (Where all the patches or RPMs (redhat package manager) are stored under some directories(filesystem) then we can  mount them from repo server to destination server through NFS.

In this example:
repohost = servername where all repositories are stored
/repo/rhel6/rhel7-base = RHEL base packages stored here
/repo/rhel6/latest-update = RHEL latest update packages stored here

Note : We can mount entire mount point as well, instead of mounting only above two directories of the mountpoint

/repo/yum & /repo/yum-update = repo mountpoint on client server

On repository server:

On client server:

1. Create mountpoint /repo/yum where we will store base packages

[root@cloud home]# mkdir -p /repo/yum

2. mount exported NFS remote filesystem /repo/rhel6/rhel7-base
[root@cloud home]# mount repohost:/repo/rhel6/rhel7-base /repo/yum

3. Create mount point /repo/yum-update
[root@cloud home]# mkdir -p /repo/yum-update

4. mount exported NFS remote filesystem /repo/rhel7/latest-update
[root@cloud home]# mount repohost:/repo/rhel7/latest-update /repo/yum-update


5. Edit /etc/auto.master file:
[root@cloud home]# vi /etc/auto.master
 /repo   /etc/auto.yum
 
6. Edit /etc/auto.yum file:

[root@cloud home]# vi /etc/auto.yum
yum   -fstype=nfs   repohost:/repo/rhel6/rhel7-base
yum-update   -fstype=nfs   repohost:/repo/rhel7/latest-update

 7. Edit /etc/yum.conf file:

[root@cloud home]# vi /etc/yum.conf
[yum]
name=yum
baseurl=file:///repo/yum
enabled=1
gpgcheck=0

[yum-update]
name=yum-update
baseurl=file:///repo/yum-update
enabled=1
gpgcheck=0

Tuesday, February 13, 2018

How to increase FS which is in LVM in AWS

How to extend EBS volume which is part of LVM:
And
How to increase FS which is in LVM in AWS :

As our day to day task, we may get request to increase filesystem size by some GB value. Suppose that filesystem is part of LVM and the instance is hosted on AWS then below steps you can follow.

1. Fist you have to identify the volume for server
2. Identify the volume from AWS and increase size
3. Make new size visible on server/instance.
4. Extend the mountpoint and hence filesystem to desired value.

Note: Here we are not adding new volume we are using existing volume only. The steps for new volume are different and quite simple too.

In this example, we are going to extend the existing volume /dev/xvdm (current size: 700GB) by 300GB which is part of LVM or belongs to volume group “VolGroup02”. Mount point name is /application.

From AWS End:
  1. Login to AWS console and search our instance with instance ID or instance name.
  2. Check devices attached to respective instance. Check for /dev/sdm (On server, we will see it as /dev/xvdm) volume which we are going to increase by 300GB
  3. Click on volume /dev/sdm and choose modify volume option and increase it by 300GB. New size will be 1000GB.
After modifying the volume from AWS end we have to check on server whether it is modified or not.

From Server End:

1. Check size of our volume on server.
    #pvs |grep -i xvdm


It will not show the new size.


2. Resize the PV so the total size of the volume will be visible
#pvresize /dev/xvdm


 3. Recheck the size of volume; it will show new value now. 




Now we want to extend the mountpoint /application

4. Extend the logical volume by lvextend
    
+100%FREE - It will use 100%  of the free space to extend the volume.



5. Resize the filesystem.

6. Check new size of filesystem.

[root@mycloud ~]# df -h /applicaiton


Regards,
Kiran Jadhaw

Thursday, February 1, 2018

How to increase EBS volume size + AWS

How to increase EBS volume size + AWS


There are two ways we can extend the EBS (Elastic Block Store) volume size:

1st method:

1.1 Identify the volume (Volume ID) (eg. /dev/sdm) of an Instance which you want to                  extend.                  
        Note down the size of the volume (eg.200GB)

1.2 Take snapshot of that volume (It may take 1-2 hrs depending on the size of the                       volume).

        Note down the snapshot ID and monitor the snapshot status. It should show 100%

1.3 Detach the volume from the instance (/dev/sdm)

1.4 Extend the snapshot to the new size (eg. extend it by 300GB) New Size will be 500GB.

1.5 Attach this volume as new volume to the instance (/dev/sdn) 

        New device name will be assigned to this volume. It will get assigned in alphabetical              order.


Volume is extended from AWS end.


Note : reboot may require if the extended volume size is not visible from OS end.


2nd Method : 


2.1 Identify the volume (Volume ID) (eg. /dev/xvdm) of an Instance which you want to                  extend. 
        Note down the size of the volume (eg.200GB)

2.2 use “modify volume” option from action menu and extend the volume size to 500GB. 

        Here volume optimization will happen, it may take 2-3 hours depending on the size of the volume. Once the optimization is 100% then we can be sure that the volume/disk is extended from AWS end.


Note: On the fly we are extending the volume size here.


Login to the instance and depending on the OS (Windows + Linux) make the extended disk size visible from OS end (I'll write a post on this soon).



Regards,
Kirann Jadhav

Tuesday, January 23, 2018

How to start service automatically after reboot + Linux

How to start service automatically after reboot + Linux

Many time we have to restart few services after reboot. So we manually login to the server and then start the service manually every time the server reboot.

To avoid this manual intervention, we can run below commands to run any service (eg. Httpd) automatically after reboot.

This we can called as simple kind of automation :)

Commands:

  1. #systemctl status httpd à to checke status of httpd service. The status disabled shows that the service is not configured to start on boot.
  1. #systemctl enable httpd  - to enable httpd service to start after boot


  1. #systemctl status httpd -  Recheck the httpd service, The status enabled will start service after boot.









Note: Above commands are applicable in RHEL 7 & higher version.

Regards,

Kirann Jadhav