==== client side ====
we will make a script in each server to pump date into a file. so when we check at backup server, we will check if this file was backup to backup server since it will update the date everyday.\\
below is the script contain (/root/record)
----------------- Start ---------------------------
#! /bin/sh
echo `date` > /root/assessment
then use crontab -e to run this script everyday
0 12 * * * /root/record > /dev/null 2>&1
----------------- End ---------------------------
==== backup server side ====
at the server side, i had make a folder name assessment and put the script inside.\\
below is the script contain (check_assessment)
------------------- Start -------------------------------
#! /bin/sh
echo "assessment done on `date`" > /mnt/backup/assessment/assessment_result.txt -> this is to pump the date it run the script
echo " " >> /mnt/backup/assessment/assessment_result.txt -> give an empty space
for host in `cat /mnt/backup/assessment/list` # -> this is to loop the server list
do
echo $host >> /mnt/backup/assessment/assessment_result.txt -> this is to pump the server name before it start check so we know the result is belong to which server
for n in {1..9} -> loop to check folder 01-09
do
FILE="/mnt/backup/$host/0$n/root/assessment"
if [ -f $FILE ];
then
cat $FILE >> /mnt/backup/assessment/assessment_result.txt -> if the file exist, copy the date to assessment_result.txt
else
echo "day $n didnt backup" >> /mnt/backup/assessment/assessment_result.txt -> if the file not exist, echo what day it didnt backup
fi
done
for n in {10..31} -> loop day 10-31
do
FILE="/mnt/backup/$HOST/$n/root/assessment"
if [ -f $FILE ];
then
cat $FILE >> /mnt/backup/assessment/assessment_result.txt
else
echo "day $n didnt backup" >> /mnt/backup/assessment/assessment_result.txt
fi
done
echo " " >> /mnt/backup/assessment/assessment_result.txt
done
uuencode /mnt/backup/assessment/assessment_result.txt /mnt/backup/assessment/assessment_result.txt | mail -s "[My-Backup] monthly check result" sat.support@my.offgamers.com -> this is to email the result to us as attachment
--------------------------- End -----------------------------------------
then put the server name you want this script to check into a file name list
example:-
my-domain
my-proxy
my-dns1
my-dns2
then use crontab -e to run this script every first day of the month
this blog was created for my own personal notes. If any of the post is useful for you, i happy to hear that but if there is any mistake make on my notes, please correct me
Wednesday, October 12, 2011
Wednesday, August 24, 2011
Nagios Alert using Gammu
Nagios Alert Notification Using Gammu
Install Epel repo
- Download the latest EPEL repository
- Run the rpm install command
Install Gammu
There are 3 package need to be install
#vi /etc/gammurc
[gammu]
port = /dev/ttyS0
connection = at19200
for the connection type, please refer to the mobile model at http://wammu.eu/phones/
plug the mobile to the server and test if it can detect the mobile by using this command
#gammu –identify
#gammu –monitor 1
# ls -l /dev/ttyS0 crw-rw—- 1 root dialout 4, 64 jan 5 16:14 /dev/ttyS0
Nagios is usually running as user “nagios”, so any notification command would be executed as “nagios”. We can see user nagios wouldn’t have permissions to access devices connected to /dev/ttyS0.
We’ll apply the SUID bit (set-UID) on the command in charge of sending SMS notifications, this will execute gammu on behalf of user root.
# chmod 4755 /usr/bin/gammu
Now we test to send out a sms testing by
# echo “test” | gammu –sendsms TEXT 0128157399
If you want break, press Ctrl+C…
Sending SMS 1/1….waiting for network answer..OK, message reference=181
This proof it is success
- gammu
- gammu-devel
- gammu-libs
#vi /etc/gammurc
[gammu]
port = /dev/ttyS0
connection = at19200
for the connection type, please refer to the mobile model at http://wammu.eu/phones/
plug the mobile to the server and test if it can detect the mobile by using this command
#gammu –identify
#gammu –monitor 1
# ls -l /dev/ttyS0 crw-rw—- 1 root dialout 4, 64 jan 5 16:14 /dev/ttyS0
Nagios is usually running as user “nagios”, so any notification command would be executed as “nagios”. We can see user nagios wouldn’t have permissions to access devices connected to /dev/ttyS0.
We’ll apply the SUID bit (set-UID) on the command in charge of sending SMS notifications, this will execute gammu on behalf of user root.
# chmod 4755 /usr/bin/gammu
Now we test to send out a sms testing by
# echo “test” | gammu –sendsms TEXT 0128157399
If you want break, press Ctrl+C…
Sending SMS 1/1….waiting for network answer..OK, message reference=181
This proof it is success
Edit Nagios
We will start to edit nagios to allow send out command to trigger sms notification.
#vi /etc/nagios/objects/commands.cfg
then add this part into it
this will ask nagios to execute a script and pass the parameter to script
#vi /etc/nagios/objects/contacts.cfg
then add this part into it
#vi /etc/nagios/objects/commands.cfg
then add this part into it
this will ask nagios to execute a script and pass the parameter to script
define command{
command_name host-notify-by-sms
command_line /bin/bash /etc/nagios/nagios-test "$HOSTNAME$" "$HOSTSTATES$" "$HOSTOUTPUT$" "$SHORTDATETIME$"
}
define command{
command_name notify-by-sms
command_line /bin/bash /etc/nagios/nagios-test "$HOSTALIAS$" "$SERVICESTATE$" "$SERVICEOUTPUT$" "$SHORTDATETIME$"
}
then we edit the contact part#vi /etc/nagios/objects/contacts.cfg
then add this part into it
define contact{
contact_name sms
alias sms
service_notification_period 24x7
host_notification_period 24x7
service_notification_options c,r
host_notification_options d,r
service_notification_commands notify-by-sms
host_notification_commands host-notify-by-sms
}
define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members nagiosadmin, sms
}
Script
hostname=$1 hoststates=$2 hostoutput=$3 shortdatetime=$4 echo "Host: $hostname / state: $hoststates / Info: $hostoutput / Date: $shortdatetime" | ssh root@172.30.10.98 'gammu --sendsms TEXT 012345678' echo "Host: $hostname / state: $hoststates / Info: $hostoutput / Date: $shortdatetime" | ssh root@172.30.10.98 'gammu --sendsms TEXT 0123338888'
The script will accept the parameter and form a message using echo and pass it to another server which was install with Gammu to send out the sms
So in order to allow Nagios to use ssh, below section need to be perform
Nagios SSH
We will using Nagios to setup ssh keygen so that it can no need input password when ssh to gammu server
Done, now nagios allow to use SSH and able to enter the gammu server
- login to Nagios server as root
- change to nagios user using
- then we create the keygen for nagios
- then scp the id_rsa.pub to the gammu server and add into authorized keys
Done, now nagios allow to use SSH and able to enter the gammu server
Nagios timeout
Nagios default timeout for notification was 30 second and was not enough if we need to send out sms alert more than 3 number.
Therefor we will need to increase the timeout #vi /etc/nagios/nagios.cfg
Original was
Therefor we will need to increase the timeout #vi /etc/nagios/nagios.cfg
Original was
notification_timeout=30then edit
notification_timeout=60
Tuesday, August 9, 2011
Linux smallest partition
VM partition for non-heavy usage Standard 4GB storage
| partition | mount point | filesystem | size (MB) | type |
|---|---|---|---|---|
| /dev/sda1 | /boot | ext3 | 100 | primary |
| /dev/sda2 | / | ext3 | 2,000 | primary |
| /dev/sda3 | swap | swap | 300 | primary |
| /dev/sda4 | - | - | - | extended |
| /dev/sda5 | /home | ext3 | 200 | logical |
| /dev/hda6 | /tmp | ext3 | 500 | logical |
| /dev/hda7 | /var | ext3 | remaining | logical |
When doing yum update, the package was download to /var partition before proceed to installation part.
So make sure /var partition is enough for the yum update
Wednesday, July 27, 2011
log rotate
this is to add function to rotate specific log
create a new file at /etc/logroate.d/
and write this into it for rotate log function
/var/log/SAT-backup/*.log {
monthly
rotate 4
missingok
compress
}
create a new file at /etc/logroate.d/
and write this into it for rotate log function
/var/log/SAT-backup/*.log {
monthly
rotate 4
missingok
compress
}
Wednesday, July 20, 2011
Centos change resolution
you can change the console resolution at
/boot/grub/grub.conf
add vga=775 at the end of kernal line
/boot/grub/grub.conf
add vga=775 at the end of kernal line
Thursday, June 30, 2011
Centos - basic knowledge
change DNS setting
/etc/resolve.conf
change host IP
/etc/sysconfig/network-script/ifcfg-eth0
change hostname
/etc/sysconfig/network
The easiest way to do it is
# system-config-network
/etc/resolve.conf
change host IP
/etc/sysconfig/network-script/ifcfg-eth0
change hostname
/etc/sysconfig/network
The easiest way to do it is
# system-config-network
Monday, June 6, 2011
Adding Swap Space
To add a swap file:
- Determine the size of the new swap file in megabytes and multiply by 1024 to determine the number of blocks. For example, the block size of a 64 MB swap file is 65536.
- At a shell prompt as root, type the following command with count being equal to the desired block size:
dd if=/dev/zero of=/swapfile bs=1024 count=65536 - Setup the swap file with the command:
mkswap /swapfile - To enable the swap file immediately but not automatically at boot time:
swapon /swapfile - To enable it at boot time, edit /etc/fstab to include the following entry:
/swapfile swap swap defaults 0 0The next time the system boots, it enables the new swap file.
- After adding the new swap file and enabling it, verify it is enabled by viewing the output of the command cat /proc/swaps or free.
- First must stop the swap file created by:
swapoff /swapfile - Then delete the:
rm -rf /swapfile
Subscribe to:
Posts (Atom)