Tikejhya: Ashish Nepal

Knowledgebase

Month: December 2012 (Page 1 of 2)

How to repair/restore lost permision, file ownership

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

How to repair/restore lost permision, file ownership

Its always possible to run into trouble by chown(ing) or chmod(ing) / or /usr /home
or simillar crucial files and binary, Where below given tips can help you out.

# Restore chowned files/binary to default

rpm --setugids  

(e.g. rpm –setugids mysql, This will help you recover)

#Restore chmod’ed files/binary to defaults

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

rpm --setugids 

#To reset permision of all package

rpm --setperms -a
rpm --setugids -a

# Clone / Restore Permission from Different Server
# Retrive permision from server1

find / /usr /home -xdev | xargs getfacl -P > /tmp/permissions

#repair in server2
# Copy file across and restore permision

setfacl --restore=/tmp/permissions

MailBox

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

Mailbox utility

How to test if mail server is open relay

    http://www.mailradar.com/openrelay/

Testing spf (There is nice tool provided by kitterman.com)

    http://www.kitterman.com/spf/validate.html

There are various ways of check SPF records from linux command:

dig TXT ashishnepal.com
host -t txt ashishnepal.com

 

Testing mx boxes white and blacklist.

http://whatismyipaddress.com/blacklist-check
http://mxtoolbox.com/SuperTool.aspx#

Linux utility command host

Using host command to detect dns propagation, TTL, or records.

Host usages various different options.
-a is equivalent to -v -t *
-c specifies query class for non-IN data
-C compares SOA records on authoritative nameservers
-d is equivalent to -v
-l lists all hosts in a domain, using AXFR
-i IP6.INT reverse lookups
-N changes the number of dots allowed before root lookup is done
-r disables recursive processing
-R specifies number of retries for UDP packets
-t specifies the query type
-T enables TCP/IP mode
-v enables verbose output
-w specifies to wait forever for a reply
-W specifies how long to wait for a reply
-4 use IPv4 query transport only
-6 use IPv6 query transport only
-s a SERVFAIL response should stop query

However i assume general purpose would be something like this:

# Check A record of domain

 host -t A ashishnepal.com

# Check MX record of domain

 host -t mx ashishnepal.com

# Check txt records

 host -t txt ashishnepal.com

Identically you could test SPF, and other _domainkey and so on.
e.g.

host -t txt _domainkey.ashishnepal.com

Zabbix Installation in CENTOS

While installating zabbix in centos there could be below given problems (May occur.)

Zabbix installation in CENTOS

checking for IKSEMEL... no
configure: error: Jabber library not found

solution : yum install iksemel-devel

Missing XMLWriter

yum install php-xml

checking for net-snmp-config... no
configure: error: Invalid NET-SNMP directory - unable to find net-snmp-config

yum install net-snmp-devel

yum install php-bcmath

PHP MB string	yes	 	 	Ok
if fail : isntall php-mbstring
could you face problem from php.ini

need to fix, date.timezone = "Europe/London"

default zabbix username and password for login is
Admin and password blank.

however if that creates problem.
update password,

USE zabbix;
UPDATE users SET passwd=md5(‘newpassword’) WHERE alias=’Admin’;

How to setup zabbix_proxy

Name: ashish.nepal.com
Groups : (Any wished)
DNS name : this should be same as Name, hostname in /zabbix_agentd.conf (in agent)
IP address : local ip (which is corresponding by proxy server)
monitored by proxy : proxy server name (should be in drop down).

/etc/zabbix/zabbix_agentd.conf

Hostname=same name as DNS name and name of server in GUI (Front end)
Server=internalip,zabbix_serverip

How to create trigger for Mysql Replication status in Zabbix

Show how many minutes slave is lagging behind Master

UserParameter=give.some.name,mysql -uzabbix -ppassword -e "SHOW SLAVE STATUSG" | grep Behind | cut -d ":" -f 2

Show if Slave sql is running Or Not

UserParameter=mysql.slave.lag,mysql -uzabbix -ppassword -e 'show slave statusG' | grep Slave_SQL_Running | awk '{print $2}' | sed 's/No/0/;s/Yes/1/'

How to Allow zabbix User to monitor rabbitmqctl

Userparameter to be added in rabbitmq server which is zabbix_agentd

vi /etc/zabbix/zabbix_agentd.conf

UserParameter should look like this if not exact.

UserParameter=mess.message.ready,sudo /usr/sbin/rabbitmqctl -n rabbit@servername list_queues name messages_ready | grep 'which-queue' | awk '{ print $2 }'
UserParameter=mess.queues.messages,sudo /usr/sbin/rabbitmqctl -n rabbit@servername list_queues name messages | grep 'which-queue' | awk '{ print $2 }'
UserParameter=mess.queues.memory,sudo /usr/sbin/rabbitmqctl -n rabbit@servername list_queues name messages | grep 'which-queue' | awk '{ print $2 }'

You would probably recieve error , as sudo is only allowed in TTY, if not using sudo, it would yeild Permission denied.

how to add user in sudo
visudo

%zabbix ALL=(ALL) NOPASSWD: /usr/sbin/rabbitmqctl
Defaults:%zabbix !requiretty
Defaults:zabbix !requiretty

(This is allow Default requiretty to exclude in for given senario)

cannot recreate Zabbix semaphores for IPC key

zabbix_agentd [8394]: Can’t recreate Zabbix semaphores for IPC key 0x7a028449 Semaphore ID 196608. Operation not permitted.

You should check ipcs and kill those with below given command, where it may vary, as awk $3 is username in the given senario

ipcs -s | awk ' $3 == "507" {print $2, $3}' | awk '{ print $1}' | while read i; do ipcrm sem $i; done

And you should restart rabbitmq-server and ctl, which might prompt you to node rabbit@….

Other useful parameter would be [RABBITMQ]

rabbitmqctl -n rabbit@server list_queues | grep -cv '...'
rabbitmqctl -n rabbit@server list_exchanges | grep -cv '...'
rabbitmqctl -n rabbit@server list_queues name durable | awk '{ print $2 }'
rabbitmqctl -n rabbit@server list_queues name messages_ready | awk '{ print $2 }'
rabbitmqctl -n rabbit@server list_queues name messages_unacknowledged | awk '{ print $2 }'
rabbitmqctl -n rabbit@server list_queues name messages | awk '{ print $2 }'
rabbitmqctl -n rabbit@server list_queues name consumers | awk '{ print $2 }'
rabbitmqctl -n rabbit@server list_queues name memory | awk '{ print $2 }'
rabbitmqctl -n rabbit@server list_exchanges name durable | awk '{ print $2 }'
rabbitmqctl -n rabbit@server list_exchanges name type | awk '{ print $2 }'

Memcached Monitoring using zabbix

UserParameter=memcached.stat.,echo -e "statsnquit" | nc 127.0.0.1 11211 | grep "STAT $2 " | awk '{print $$3}'
memcache.curr.connection,echo -e "statsnquit" | nc 127.0.0.1 11211 | grep "STAT $2" | grep "curr_connections" | awk '{print $3}'

Zabbix Real Time Data Log Count

Zabbix Log count Does not provide the real time output by simply doing tail with pipe command, however counting log file and simply gathering the change of number would provide accurate data.

wc -l logfile

And in zabbix UI, count as delta (simple change).

###########################################################

Script to write Userparameter In zabbix (Automated Script)

###########################################################

#!/bin/bash
rm -f /etc/zabbix/backup/zabbix_agentd.conf.*
cp /etc/zabbix/zabbix_agentd.conf /etc/zabbix/backup/zabbix_agentd.conf.`date +%s`
VAR=`grep -w "# Include=/etc/zabbix/zabbix_agentd.userparams.conf" /etc/zabbix/zabbix_agentd.conf`
RETVAL=$?
[ $RETVAL -eq 0 ] && sed -i 's/# Include=/etc/zabbix/zabbix_agentd.userparams.conf/ Include=/etc/zabbix/zabbix_agentd.userparams.conf/g' /etc/zabbix/zabbix_agentd.conf

RETVAL=$?
echo "$RETVAL"

echo "now"

if [ -f "/etc/zabbix/zabbix_agentd.userparams.conf" ]; then
    echo "User parameter File exists"


rm -f /etc/zabbix/backup/zabbix_agentd.userparams.conf.*
cp /etc/zabbix/zabbix_agentd.userparams.conf /etc/zabbix/backup/zabbix_agentd.userparams.conf.`date +%s`
echo "Userparameter=$1,$2" >> /etc/zabbix/zabbix_agentd.userparams.conf


else
        echo "There isnt any Userparameter.conf : Creating File"
                touch /etc/zabbix/zabbix_agentd.userparams.conf
                chown zabbix:zabbix /etc/zabbix/zabbix_agentd.userparams.conf

fi

Linux Command at

# at

At allows fairly complex time specifications, extending the POSIX.2 standard. It accepts times of the form HH:MM to run a job at a specific time of day.

[root@tikejhya]

at 01:05
at> cd /data/scripts/; ./run-something.sh
at> 

# control d to end of command

How to track at jobs?

at -l
atq

see job ids track at /var/spool/at

you will be seeing to-be run command around end of the file.

iRedMail

iRedMail

SMTP Error: SMTP error(451): Failed to add recipient

Solution
/etc/init.d/iredapd restart

Problem
Dec 4 17:16:44 YOUR_PC amavis[16875]: (16875-01) (!)ClamAV-clamd: Can’t connect to UNIX socket /tmp/clamd.socket: No such file or directory, retrying (2)

Solution: service clamd start

Dec 4 17:06:23 postfix/smtp[16669]: 77E29439272: to=, relay=none, delay=1.1, delays=1.1/0.05/0/0, dsn=4.4.1, status=deferred (connect to 127.0.0.1[127.0.0.1]:10024: Connection refused)

Please restart both amavisd and Postfix and then check with

Alert (General Script)

This script checks recent upload from one of my server which naming convention is pretty much standard ending with today’s date.

This script can be used as tip to use loop read (content inside some directory), Email notification.

#!/bin/bash
#### Directory variable####
LOG_DIR='/data/1/ /data/2/ /data/3/


##### Email notification if failure##########
RCPT="tikejhya@ashishnepal.com"


##### Loop starts here############

for i in $LOG_DIR;do
        file=`ls -lrt $i | grep -i `date +%Y-%m-%d --date='1 day ago'`_23 | tail -5 | wc -l`

        if [ $file -ne 0 ];then

        echo "File Were uploaded $i" >> /data/logs/upload_success



                else

                                echo "Alert: Files are Not uploaded for $i" >> /data/logs/uploads_error
                                echo "Files not uploaded to $i for `date +%Y-%m-%d --date='1 day ago'`" | mail -s "ATTENTION" $RCPT

fi
done
exit 0

Split content of file using blank line as seperator

# split content of file using blank line as seperator

perl -ne 'if (($s .= $_) =~ s/(.*)n{2}//s) {open F, sprintf(">request_%04d", $n++); print F $1; close F}' test_goto

MySQL Replication missing random data

MySQL Replication issues

Recently I had problem mysql replication, i.e. replication seems to be missing in some random occasion. It was clueless and if i test manually all use to work, but some field in some coloum donot get updated.

And i had my.cnf with ignore DB

Ignored DB:

replicate-ignore-db = mysql
replicate-ignore-db = test

While testing manually, all queries seemed to work and i was unable to troubleshoot or narrow down problem area.

I was directed to mysqlperformanceblog which pointed me to right track which mentions senario of ignore db and how binlogs are not created and accordingly replication will not take place as slave has got no idea since no binlog is available.

If you wouldl like to read further (http://www.mysqlperformanceblog.com/2009/05/14/why-mysqls-binlog-do-db-option-is-dangerous/)

And it was right feedback from a user in stackoverflow (dba branch).

“It is less error-prone if you use the replicate-wild-* options”

replicate-wild-ignore-table = mysql.*
replicate-wild-ignore-table = test.*

Wanted to share if some of other are getting same problem.

using kill command under Linux/UNIX

First find out what is the process running, or which process you want to kill if its causing any issue.

# ps aux | grep php

There should be output like

php 3486 0.0 0.1 4248 1432 ? S Nov1 0:00 /usr/bin/php -xxxxxxxxx
php 3492 0.0 0.5 13752 3936 ? Ss Nov1 0:00 /usr/bin/php

Now kill using pid
# kill 3486

You could also use command pidof
# pidof httpd

If you wish to kill all process running as php
# kill $(ps aux | grep 'php' | awk '{print $2}')

Killing zombie

#kill $(ps aux | awk '{ print $8 " " $2 }' | grep -w Z | awk '{ print $2 }')

Dig

Dig Command line utility

#Unix command dig

dig ashishnepal.com +trace

Page 1 of 2

Powered by WordPress & Theme by Anders Norén