nrpe dead but subsys locked

nrpe dead but subsys locked  error
service dead but subsys locked

check if the port used by nrpe is  already used by other processess like xinetd
netstat -tulnp | grep 5666
or
lsof -ni udp:5666
lsof -ni tcp:5666


This means the service was running at one time, but has crashed.
When you start a service, it creates a "lock" file to indicate that the service is running. This helps avoid multiple instances of the service. When you stop a service, this lock file is removed.
When a running service crashes, the lock file exists but the process no longer exists. Thus, the message.
Look at the two areas /var/run/*.pid and /var/lock/subsys/*. These are expected to agree with each other. That is, if the (emtpy file) lockfile /var/lock/subsys/crond exists, then the first line of the file /var/run/crond.pid is expected to contain the PID of the process running for this service. If no such process is running, then something is wrong. If a process is indeed running (as you see) but it is not that PID, then something is probably confused.



http://serverfault.com/questions/26276/what-does-service-name-dead-but-subsys-locked-mean

http://www.linuxquestions.org/questions/linux-networking-3/service-dead-but-subsys-locked-376488/

Create a New User and Grant Permissions in MySQL

create/delete users 
-------------------- 

CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';

DROP USER ‘demo’@‘localhost’;

Change passwords
-------------------
mysqladmin -u USER -p password NEWPASSWORD

mysqladmin -u marcelo -p oLdpa$$word 'NEwP@$$'
mysql> use mysql;

SET PASSWORD FOR 'user-name-here'@'hostname-name-here' = PASSWORD('new-password-here');
flush privileges;

GRANTING/REVOKE PRIVILEGES
--------------------------

GRANT ALL PRIVILEGES ON *.* TO 'newuser'@'localhost';

OR

GRANT ALL PRIVILEGES ON demoDB.* TO 'newuser'@'localhost';

GRANT SELECT,UPDATE,DELETE ON testDB.* TO 'demo-user'@'localhost';

REVOKE UPDATE ON testDB.* FROM 'demo-user'@'localhost';

GRANT ALL ON testDB.* TO 'demo-user'@'localhost';

FLUSH PRIVILEGES;
show grants for 'demo-user'@'localhost';


Privileges:-
= = = = = = 
ALL PRIVILEGES,CREATE,DROP,DELETE,INSERT,SELECT,UPDATE,GRANT OPTION

  • ALL PRIVILEGES- as we saw previously, this would allow a MySQL user all access to a designated database (or if no database is selected, across the system)
  • CREATE- allows them to create new tables or databases
  • DROP- allows them to them to delete tables or databases
  • DELETE- allows them to delete rows from tables
  • INSERT- allows them to insert rows into tables
  • SELECT- allows them to use the Select command to read through databases
  • UPDATE- allow them to update table rows
  • GRANT OPTION- allows them to grant or remove other users' privileges
To provide a specific user with a permission, you can use this framework:
 GRANT [type of permission] ON [database name].[table name] TO ‘[username]’@'localhost’;


The root login can be changed with the following command:
---------------------------------------------------------- 
rename user 'root'@'localhost' to 'newAdminUser'@'localhost';




setup and use GIT

signup / singn in  to github.com


yum install git

git config --global user.name "urgensherpa"
git config --global user.email  "urgen.sherpa@outlook.com"


create new repository in github <using webbrowser>
eg.  repo name is   test


#mkdir  /home/nepal/test
#cd /home/nepal/test
git init
git remote add origin https://github.com/urgensherpa/test.git
                                                                        ^               ^
            <username>/<reponame>

make some files in /home/nepal/test

git add  dbconnect.php     <update only 1 file>
git add .                   <update all/multiple current dir>
git commit  -m 'first commit'
git  push origin master
<enter your user name and password for github>

check in your github.com account to see changes

when you change your files

git add  .
git commit -m 'second commit'
git push origin master
<enter your user/password for github.com>

edit some file  eg.  function.php
git  add  .
git commit -m 'third commit'
git reset --soft HEAD^    #this will reset the commit but the change made in file function.php is as is


git reset --hard HEAD^  #it will reset + changes made is reverted back to last commit that is second commit

==============cloning=================
git clone https://github.com/urgensherpa/test.git

ls -l     #see the cloned repo in your local current dir
make changes in files
echo  "test abcd" >>  dbconnect.php
git add .
git commit -m "added new file"
git push origin master
<user/pass for github.com>

===================================
http://stackoverflow.com/questions/7106012/download-a-single-folder-or-directory-from-a-github-repo


Create a new repository on GitHub. To avoid errors, do not initialize the new repository with README, license, or gitignore files. You can add these files after your project has been pushed to GitHub.

  1. Open Terminal (for Mac users) or the command prompt (for Windows and Linux users).
  2. Change the current working directory to your local project.
  3. Initialize the local directory as a Git repository.
    git init
    
  4. Add the files in your new local repository. This stages them for the first commit.
    git add .
    # Adds the files in the local repository and stages them for commit. To unstage a file, use 'git reset HEAD YOUR-FILE'.
  1. Commit the files that you've staged in your local repository.
    git commit -m 'First commit'
    # Commits the tracked changes and prepares them to be pushed to a remote repository. To remove this commit and modify the file, use 'git reset --soft HEAD~1' and commit and add the file again.
  1. Copy remote repository URL fieldAt the top of your GitHub repository's Quick Setup page, click
  1. to copy the remote repository URL.
  2. In the Command prompt, add the URL for the remote repository where your local repository will be pushed.
    git remote add origin remote repository URL
    # Sets the new remote
    git remote -v
    # Verifies the new remote URL
    
  3. Push the changes in your local repository to GitHub.
    git push origin master
    # Pushes the changes in your local repository up to the remote repository you specified as the origin 
     
     
     
    git init
    git add .
    git commit -m "Initial commit"
    git remote add origin <project url>
    git push -f origin master 

cpulimit linux

apt-get install cpulimit
yum install cpulimit    <enable epel>

#Eg. . on centos 6.5   with cpulimit-0.1-1.20140722gitcabeb99.el6.x86_64.rpm

cpulimit -p 8645 -l 10    
#limits this process to 10 % of cpu

cpulimit -e /usr/local/bin/myprog -l 20
#limits the CPU usage of /usr/local/bin/myprog to 20%

X% of one CPU. So for example, if you set "-l 100" on a dual-core machine, you are limiting the usage to 50% of available CPU resource.

To find out PID of the process use any of the following:
# ps aux | less
# ps aux | grep firefox
# pgrep -u vivek php-cgi
# pgrep lighttpd



LVM PART 1 data restore after accidental removal of logical volume

 Data Restore after  accidental  remove/delete of logical volume                     
Preparing  testing enviroment :

After creating partition use below command

partx        /dev/sda
pvcreate     /dev/sda4   /dev/sda5
vgcreate  VG1    /dev/sda4 /dev/sda5
vgs                                                              #display vg's
lvcreate  -L  4G -n  lv001   VG1
lvscan         or           lvdisplay


mke2fs -t  ext4  -j  
/dev/volgroup001/lv001
Add more space to logical volume (here lv001 is increased from 4gb to 6gb)
lvresize -L 6GB /dev/volgroup001/lv001                     
After resizing
 resize2fs   /dev/volgroup001/lv001

Accidental removal of logical volume

#lvremove    /dev/volgroup001/lv001     
#ll /etc/lvm/archive   ##contains the arhive of lvm data
[root@demo1 ~]# ll /etc/lvm/archive/
total 44
-rw-------. 1 root root 1761 Oct  8 15:46 vg_demo1_00000-1563239603.vg
-rw-------. 1 root root 1135 Oct 20 18:34 volgroup001_00000-1225438891.vg
-rw-------. 1 root root 1135 Oct 20 18:36 volgroup001_00001-1361506140.vg
-rw-------. 1 root root 1731 Oct 21 19:56 volgroup001_00002-1489665094.vg
-rw-------. 1 root root 1731 Oct 22 18:46 volgroup001_00003-1149849750.vg
-rw-------. 1 root root 1733 Oct 23 10:46 volgroup001_00004-1224808495.vg
-rw-------. 1 root root 1741 Oct 23 10:46 volgroup001_00005-843600971.vg
-rw-------. 1 root root 1733 Oct 23 10:56 volgroup001_00006-965431690.vg
-rw-------. 1 root root 1734 Oct 23 13:24 volgroup001_00007-1544816747.vg
-rw-------. 1 root root 1130 Oct 23 13:29 volgroup001_00008-1538079247.vg
-rw-------. 1 root root 1552 Oct 23 18:02 volgroup001_00009-1668760531.vg

#vgcfgrestore --list  volgroup001                              

  File:        /etc/lvm/archive/volgroup001_00008-1538079247.vg
  VG name:        volgroup001
  Description:    Created *before* executing 'lvcreate -L 4G -n lv001 volgroup001'
  Backup Time:    Thu Oct 23 13:29:51 2014

  
  File:        /etc/lvm/archive/volgroup001_00009-1668760531.vg
  VG name:        volgroup001
  Description:    Created *before* executing 'lvresize -L 6GB /dev/volgroup001/lv001'
  Backup Time:    Thu Oct 23 18:02:56 2014

  
  File:        /etc/lvm/backup/volgroup001
  VG name:        volgroup001
  Description:    Created *after* executing 'lvresize -L 6GB /dev/volgroup001/lv001'
  Backup Time:    Thu Oct 23 18:02:56 2014

#######
read the description and backuptime and select the file eg. /etc/lvm/archive/volgroup001_00009-
1668760531.vg    
#######

######   NOW RESTORRING   ######

#vgcfgrestore   -f    /etc/lvm/archive/volgroup001_00009-1668760531.vg     volgroup001
#lvscan
#lvchange -ay /dev/volgroup001/lv001         ##lvchange= change attribute ,  -ay = activateall -yes
#lvscan




vgcfgrestore -f   /etc/lvm/backup/volgroup001


now mount the lvm again

=================================================================

parted
select /dev/sdb

or   parted /dev/sdb
mklabel msdos
mkpart primary 1  10GB                                #1MB to 10GB = approx. 10 GB partition is created

print  or p ##view partition table

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  525MB   524MB   primary  ext4         boot
 2      525MB   21.5GB  20.9GB  primary               lvm



set   <partition-number>  lvm on
quit

partx /dev/sdb

pvcreate  /dev/sdb5 /dev/sdb6 /dev/sdb7

or

pvcreate /dev/sdb[567]

##extend volume group with name volgroup 001

vgextend  volgroup001 /dev/sdb5 /dev/sdb6 /dev/sdb7  

To expand rest of space in VG enter similar command like below:-

lvextend -l +100%FREE /dev/myvg/testlvm

icinga monitor mysql slave replication

icinga monitor msyql slave replication status

At SLAVE mysql server create a user with replication privileges
mysql> GRANT REPLICATION CLIENT on *.* TO 'nagios'@'%' IDENTIFIED BY '1LumbIni2$';
mysql> flush privileges;

 service mysql restart

At  ICINGA server
download nagios mysql slave monitoring script

wget  http://www.claudiokuenzler.com/nagios-plugins/check_mysql_slavestatus.sh
chown icinga.icinga check_mysql_slavestatus.sh; chmod +x check_mysql_slavestatus.sh;

  #./check_mysql_slavestatus.sh -H 198.50.176.187 -u nagios -p 1LumbIni2$ -P 3306
OK: Slave SQL running: Yes Slave IO running: Yes / master: 5.9.240.235 / slave is 0 seconds behind master | delay=0s

Define commands in commands.cfg
# 'check_mysql_slavestatus' command definition
define command{
command_name check_mysql_slavestatus
command_line $USER1$/check_mysql_slavestatus.sh -H $HOSTADDRESS$ -P $ARG1$ -u $ARG2$ -p $ARG3$
}

# 'check_mysql_slavestatus' command definition with delay check
define command{
command_name check_mysql_slavestatus
command_line $USER1$/check_mysql_slavestatus.sh -H $HOSTADDRESS$ -P $ARG1$ -u $ARG2$ -p $ARG3$ -w $ARG4$ -c $ARG5$
}

Now create service for checking

define service{
use generic-service ; Name of service template to use
host_name gskhanalslave
service_description MySQL Replication Status
check_command check_mysql_slavestatus!3306!nagios!1LumbIni2$
}


inotify inodes

What are inodes?

In a nutshell, inodes are the data structure Linux servers use to store information about a file. inodes are set to a specific number on your server. When you write files to the server, you are using an inode for each file. When your inodes reach their limit, you will get Disk Space errors and other strange behaviors with your site.

How do I view my servers inodes?

Below is the Linux command for finding the inodes for your server. This command is ran through shell.
df -i
Get to know inotify
Inotify is a Linux kernel feature that monitors file systems and immediately alerts an attentive application to relevant events, such as a delete, read, write, and even an unmount operation. 
http://www.infoq.com/articles/inotify-linux-file-system-event-monitoring
Inotify is a file change notification system in the Linux kernel, available since version 2.6.13. 
grep INOTIFY_USER /boot/config-$(uname -r)
CONFIG_INOTIFY_USER=y
# pwd
/proc/sys/fs/inotify
root@web01 [/proc/sys/fs/inotify]# ls
./  ../  max_queued_events  max_user_instances  max_user_watches 
#bydefault value in max_user_watches is = 8192 
#echo 65535 > /proc/sys/fs/inotify/max_user_watches
# cat /proc/sys/fs/inotify/max_user_watches          
65536 
To make the change permanent, edit the file /etc/sysctl.conf and add this line to the end of the file:
fs.inotify.max_user_watches=65535
If this server is a VPS and it is running in a OpenVZ container then you are NOT allowed to modify any kernel parameter of that container. and you will get below error
root@vps01 [/proc/sys/fs/inotify]# sysctl -w fs.inotify.max_user_watches=65535 error: permission denied on key 'fs.inotify.max_user_watches'
change it from host

user and group quota SWAP fstab file and parted command part 2

parted
select /dev/sdb
mklabel msdos
mkpart primary 1  10GB       # here partition starts from 1  that's  1 MB
quit

mkfs.ext4 -j  /dev/sdb1
OR
mke2fs -t ext4 -j /dev/sdb1

-j = journaling is an option as provided for transaction oriented processing of writes to disk in event of posssible corruption introduced by abrupt power outages

usermod -a -G admins  urgen
mount -o remount,rw /

use blkid to ascertain UUID of recently created partion for /etc/fstab
#blkid
UUID="9b317d2e-f873-4f1e-a12c-0a57e54c5657" /projectx ext4 defaults 0  0


when mounted roughly about 2% is used to manage journaling the file system

= = = = = = = = = =USER QUOTA = = = = = = =
yum install quota*
vim  fstab

uuid="sdklfjdskljf"  /home ext4 defaults,usrquota,grpquota 0  0

mount  -o  remount,rw   /drive
  quotacheck -cug   /drive/
  quotacheck -mcug  /home  ##this will create q.check db and generate disk usage table
                                            ##use -m option to overwrite the need of single user mode
  quotaon /drive
edquota urgen
Disk quotas for user urgen (uid 501):
  Filesystem                blocks       soft        hard             inodes     soft     hard
  /dev/sdb1                 90        2000000    2097000          4        0        0
                          [used block] <-- [around 2GB]-->
  repquota -a

Note:quotacheck should be run in SINGLE user mode when system reboots
quotacheck should be run in SINGLE user mode when system reboots
use:
m = dont remount filesystem read-only
a = (all)check all filesystems
g = check group files
u = check user files
c = create new quota files
quotacheck -mcug  /home  ##this will create quota check db and generate disk usage table

quotacheck -avug   #checks quotas
quotacheck -mavug   #force check quota or update quota data

edquota username

quota username
repquota  /drive  #report quota for all user

 = = = =  = = = =  = = = = = GROUP QUOTA = = = = = = = = = = = = = =
#quotaon /drive
[root@demo1 drive]# edquota -g urgen

Disk quotas for group urgen (gid 501):
  Filesystem                   blocks       soft       hard     inodes     soft     hard
  /dev/sdb1                     11000      10000      11000          6        5        0

Make sure of the group owner ship of filecreated
-------------------------------------------------

# quota -g urgen     ##check quota usage for group urgen



Do not attempt to resize a partition on a device that is in use.
Before resizing a partition, boot into rescue mode (or unmount any partitions on the device and turn off any swap space on the device).
Start parted, where /dev/sda is the device on which to resize the partition:
parted /dev/sda       
View the current partition table to determine the minor number of the partition to resize as well as the start and end points for the partition:
print
To resize the partition, use the resize command followed by the minor number for the partition, the starting place in megabytes, and the end place in megabytes. For example:
resize 3 1024 2048

= = = = = = = = =SWAP Space = = = = = = = = =
TRY TO MAKE SWAP PARTITIN ON A DEDICATED PARTITION OR DRIVE
check Swap with  top | free -m | swapon -s
 [root@monitor1 ~]# parted /dev/sdb
GNU Parted 2.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p                                                              
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  10.2GB  10.2GB  primary  ext4
(parted) help mkpart                                                                                    #displays help for mkpart
(parted) mkpart  primary   linux-swap  10.2GB   11.2GB                          ##add 1 GB swap
(parted)print
Number  Start   End     Size    Type     File system  Flags
 1      1049kB  10.2GB  10.2GB  primary  ext4
 2      10.2GB  11.2GB  959MB   primary
# we might not see filesystem type here in parted ,we check with fdisk -l /dev/sdb command

# mkswap /dev/sdb2
vim /etc/fstab
UUID=05bb80f0-2c4e-46d8-98bf-2f7d8cbf8a8f none swap defaults 0 0
swapon -s   ##check your current unchanged swap
swapon -a   ## reload fstab with changed swap

swapoff -a  ##disables swap

++++++++++SWAP File+++++++++++++++++
dd  if=/dev/zero  of=/swapdir/swapfile3GB   bs=1024   count=3145728
mkswap   /swapdir/swapfile3GB
vim /etc/fstab
/swapdir /swapfile3GB  none swap defaults 0 0
OR
/swapdir /swapfile3GB  none swap sw 0 0

swapon -a



user and group quota fstab file part 1

UUID="2c6180d9-8ecd-41bb-a3b7-7be2c9e29395"  /drive  ext4 defaults,usrquota,grpquota 0 0

first  column=device
2nd column= mount point
3rd = type of FS
4th = mount options,

auto and noauto  =  With the auto option,"auto is default"[auto cause FS to mount at boot noauto the opposite]
user and nouser = user means allow norrmaluser to mount FS ,"no user is default"nouser disable normal user to mount.
exec and noexec= exec is default, exec allow execute binaries on that partition and noexec dont allow,
ro and rw = rw is default

sync and async=async is default,    in "sync"when you, for example, copy a file to the floppy, the changes are physically

written to the floppy at the same time you issue the copy command.
in "async" the changes may be physically written to it long time after issuing the command.

defaults Uses the default options that are rw, suid, dev, exec, auto, nouser, and async.

5th and 6th columns: Dump and fsck options

5th is dump option. Dump checks it and uses the number to decide if a file system should be backed up. If it's zero,
dump will ignore that file system. If you take a look at the example fstab, you'll notice that the 5th column is zero in

most cases.

The 6th column is a fsck option. fsck looks at the number in the 6th column to determine in which order the file systems

should be checked. If it's zero, fsck won't check the file system. 

change screen resolution ubuntu vmware

Run: xrandr
this will display available resolutions. Then you can perform the following:

xrandr -s 1024x768