Saturday, September 29, 2012

SMTP Relay in Exchange 2007 OR Exchange 2010 (for testing )& Restricting Outbound Email



You may want to do some email testing in the staging environment for real customers minus sending them actually.
By Default exchange is not open realy.
If you already have exchange in your environment and it is  used in the production. then you need to create another dummy domain for the testing. e.g stage.local.
You can use a VM for installing both AD & Exchange on a single machine.
Open up the
exchange MMC
                Server Configuration
                                Hub Transport
 create a "new Receive connector"

 

  

 
 


Now Open the powershell
Get-ReceiveConnector "StageTest" | Add-ADPermission -User "NT AUTHORITY\ANONYMOUS LOGON" -ExtendedRights "ms-Exch-SMTP-Accept-Any-Recipient"

The above will allow the relay to the Anonymous group for that connector.

Now as we may not want that email will go outside the machine (to real customers). We need to create a "transport rule".
Create a user mailbox  e.g  "catchall" .  This will be catch all the emails that you will be sending to the real customer.

open exchange MMC
Organization Configuration==>Hub Transport ==> Transport Rules


Click on the new transport rule on the right side>
Give it a name e.g Mail Redirect


 
 

This should do the trick. To be extra sure you can remove the DNS and Gateway entry of the machine. (in that way this machine will  work inside the LAN only)


A Receive connector that is configured to accept messages from all remote IP addresses through SMTP port 25   This connector typically accepts connections from all IP address ranges. The usage type for this connector is Internal. This connector is created automatically during setup. This connector only accepts mail from other Exchange servers that are part of the same Exchange organization. By default, this connector does not accept anonymous submissions.


Monday, September 24, 2012

Message Tracking in Exchange 2007 & Exchange 2010 + powershell script

#add the below line for exchange 2007  & if you want to schedule the job with windows task scheduler. otherwise you can ignore it
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin
# Control variables
$daystoparse=1
$smtpServer="192.168.x.x"
$from="user-send@myDomain.com"
$to="user-receive@myDomain.com"
$subject=" Failed mails report - " + (Get-Date -format F) + " PST"
$body=""

#Prepare target file name based on current date pattern, to second granularity
$date=Get-Date -format yyyy-MMM-dd-HH-mm-ss
$targetfile = "D:\Mailfail\MessageTrack" + $date + ".csv"

# Create start and end date for parsing the mail-log files
# Startdate is always relative to current date, 1 day back
# Enddate is now()
$today = get-date
$rundate = $($today.adddays(-$daystoparse)).toshortdatestring()
$startdate = $rundate + " " + $today.Hour + ":" + $today.Minute + ":" + $today.Second + " AM"
$enddate = Get-Date -format G

get-messagetrackinglog -ResultSize Unlimited -Sender:abc@myDomain.com -EventID "FAIL" -Start $startdate -End $enddate | select timestamp, eventid, source,messagesubject, sender, {$_.recipients},clientip, clienthostname, serverip, serverhostname, connectorid, {$_.recipientstatus}, totalbytes, recipientcount, relatedrecipientaddress, returnpath | export-csv $targetfile

$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = $from
$msg.To.Add($to)
$msg.Subject = $subject
$msg.Body = $body
$att = New-Object Net.Mail.Attachment($targetfile)
$msg.Attachments.Add($att)
$smtp.Send($msg)
$att.Dispose()
====================================

save the above script as by any name e.g messageTrack.ps1 and schedule it via windows job scheduler.

for that create a bat file e.g schedule.bat and put the below line.

Powershell.exe -command "& {d:\scripts\messageTrack.ps1}"





It is important to note that if you are running Exchange based scripts from the Windows Command prompt by passing them as a parameter to Powershell.exe you should add the following line at the top of each script:

For Exchange 2007

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin

For Exchange 2010
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010



It will send one day report (mail fail) (or any other based on the argument you set) to the email id you choose.

If you want to send the email to multiple users then  add the users one by one and separate them by comma

$msg.to.add("user1@mydomain.com,user2@mydomain.com")

Ref:
     http://technet.microsoft.com/en-us/library/ee692801.aspx
     http://technet.microsoft.com/en-us/library/bb124926.aspx

- Exchange 2007 message tracking
- Message Tracking in exchange 2007
- How to track messages in exchange 2007
- Exchange 2007 message tracking attachment
-create message tracking in exchange 2007 and send them as attachment
-Exchange 2007 Script: how to run as a scheduled task


Saturday, September 15, 2012

Memory Leak

#ps -aux                         ==> check for the change in value of VSZ for zabbix agent


USER    PID %CPU %MEM    VSZ       RSS   TTY   STAT START   TIME COMMAND
root         1      0.0        0.0          24892  1576   ?        Ss        Jul01     0:06     /sbin/init
root         2      0.0         0.0         0              0     ?        S          Jul01     0:00    [kthreadd]
root         3      0.0         0.0         0              0     ?        S          Jul01     0:00    [migration/0]
root         4      0.0        0.0         0              0     ?        S          Jul01     0:29    [ksoftirqd/0]
root         5      0.0        0.0         0              0     ?        S          Jul01     0:00    [migration/0]
root         6      0.0        0.0        0               0    ?        S          Jul01     0:00    [watchdog/0]
zabbix   25064  0.0      0.0   50420    2272     ?        S      Aug27    25:03       /usr/sbin/zabbix_agentd
zabbix   25065  0.0      0.0   50436    1120   ?        S      Aug27     16:37         /usr/sbin/zabbix_agentd
zabbix   25066  0.0      0.0   50436    1120   ?        S     Aug27     16:42          /usr/sbin/zabbix_agentd
zabbix   25067  0.0     0.0   80436    1120   ?        S      Aug27     16:30          /usr/sbin/zabbix_agentd
zabbix   25068  0.0    0.0    70428     908   ?        S     Aug27       0:32             /usr/sbin/zabbix_agentd


Or you can also run the top command and press M.

Wednesday, September 12, 2012

How to disable wireless when connected to LAN + Dell Latitude E6430

Settings wireless to turn off on physical LAN connection

 
Go to BIOS by press F12 during reboot.


Power Mgt ==> wireless radio control == > check the "Control WLAN RADIO & Control WWAN RADIO".

Reboot the laptop.

 Now it will


automatically disable wireless card/adapter  when connected to LAN
auto-switch wireless and lan on windows 7

 

 

 

ssh-keygen - Password-Less SSH Login

Step 1
[root@host1 ]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
dd:1c:62:5c:d0:87:39:f0:29:18:a0:f0:15:d2:a4:32 root@host1
The key's randomart image is:
+--[ RSA 2048]----+
|  . .o=o. o+.o   |
|   o =.  + o=..  |
|  E +   . = +o   |
|   o     o = .   |
|        S . o    |
|                 |
|                 |
|                 |
|                 |
+-----------------+

Step 2
[root@host1]# ssh-copy-id -i ~/.ssh/id_rsa.pub host2

Step3.
[root@host1 ]# ssh host2

Monday, September 10, 2012

Zabbix_get to know the items value + how to get the percente disk space usage by zabbix on windows OR “Not supported” by Zabbix.

for windows percentage disk space free

Template_Windows:vfs.fs.size[c:,free].last(0)}<1g br="br">(in item value use the "numeric unassigned")


Template_Windows:vfs.fs.size[c:,pfree].last(0)}<10 br="br">(in item value use the "numeric flot")
 OR
you can add:

HTML Code:
PerfCounter = LogicalDisk:PercentFreeSpaceOnC,"\LogicalDisk(C:)\% Free Space",900
PerfCounter = LogicalDisk:PercentFreeSpaceOnD,"\LogicalDisk(D:)\% Free Space",900

on you zabbix_agentd.conf. And create trigger to alert you when machine has lower then 10% or 5%


OR

Run zabbix_get on the Zabbix server machine.

for example

[root@abc ~]# zabbix_get -s 10.10.10.33 -k system.swap.size[,free]
5379874816
[root@abc ~]# zabbix_get -s 10.10.10.33 -k vfs.fs.size[c:,free]
56677302784
[root@abc ~]# zabbix_get -s 10.10.10.33 -k vfs.fs.size[c:,pfree]
77.957042
[root@abc ~]# zabbix_get -s 10.10.10.33 -k vfs.fs.size[c:,free]
56677367296


Troubleshooting:
If your item isn’t receiving any data even though there are error entries in the log then enable detailed logging in Zabbix to verify that the agent and server haven’t a problem. (If they do then the status of the item will be changed to “Not supported” by Zabbix.)

To enable logging, make sure there is DebugLevel=5 and LogFile=/var/log/zabbix-agent/zabbix_agentd.log (without a leading #)  in /etc/zabbix/zabbix_agentd.conf.

One possible cause of problem is if Hostname in /etc/zabbix/zabbix_agentd.conf and in the Zabbix UI differ, f.ex. if one of them is fully qualified and the other isn’t.

Saturday, September 8, 2012

cvs lock delete


Find /cvs | grep ‘/#cvs.’ > /tmp/cvs_lock
cat /tmp/cvs_lock | while read line; do  if [ -d $line ]; then echo "deleteing $line DIR"; rm -rf $line; fi; if [ -f $line ]; then echo "deleting $line FILE"; rm -f $line; fi; done | tee -a /tmp/del_log_cvs_lock

Wednesday, September 5, 2012

Dstat Logging


To log the data in a csv format so that it can be used later for processing & generate graphs

dstat -ts --top-io --top-bio --noheaders --nocolor --output /tmp/dstat.csv 5 > /dev/null &

The main output is redirected to /dev/null, which means it won't get 
written anywhere.  Instead you'll get a CSV file at /tmp/dstat.csv.


Schedule it via cron every minute


#  Run dstat and log the reports

* * * * * root dstat -ts --top-io --top-bio --noheaders --nocolor 5 3 >> /var/log/dstat.txt


If you prefer a log of the data in CSV format, put this into the file instead:


#  Run dstat and log the reports

* * * * * root dstat -ts --top-io --top-bio --noheaders --nocolor --output /var/log/dstat.csv 5 3 > /dev/null


Rotate the created log

If you plan to leave the dstat logger running (and aren't just going to run it for a day or so to check on a burst of disk activity) you'll want to rotate its log occasionally to keep it from getting too big.
To that end, create a file for editing at "/etc/logrotate.d/dstat" and put the below entry to this.
/var/log/dstat.csv {
  rotate 5
  weekly
  compress
  missingok
  notifempty
}

Also
use "iotop" & "vmstat 1"
run vmstat 1 and watch the bo (buffer out) column.
If it's a userspace process you may see it with "iotop".

Monday, August 27, 2012

Mount a linux server dir to another linux server directory


Say we have 2 servers named as
server1                 (192.168.1.45)
server2                 (192.168.1170)

we want to mount a directory of 192.168.1.45 on the .170 server

Step1.
install nfs server on server1 (.45)
#yum install nfs-utils nfs4-acl-tools portmap
#chkconfig nfs on

Step2.
Share the directory on server1(.45)
#vim /etc/exports
/image1 192.168.1.170(rw)
save the file {it will give server2 (.170) read write access}
# exportfs -avr

Step3.
Mounting the /image1 directory on the server2
you need to create a directory on server2 where you want to mount the directory from server1
#mkdir /image1

#vim /etc/fstab
192.168.1.45:/image1     /image1 nfs hard,intr 0 0
save and close the  file

#mount -t nfs -a

the above command will mount the server1 shared directory to the server2 directory(/image1).

Saturday, August 4, 2012

How to Disable ndr's in sendmail


 vi /etc/mail/sendmail.mc

Change the below line
dnl # define(`confPRIVACY_FLAGS', `authwarnings,novrfy,noexpn,restrictqrun')dnl
  TO
define(`confPRIVACY_FLAGS', `authwarnings,nobodyreturn')dnl

save and exit

Restart the Sendmail


Remove directory from CVS



CVS doesn't really keep directories under version control. If you want to remove a directory from a project, you first remove all the files in it, then use update -P to remove the directory from the working directory.

CVS checkout and update will always check out empty directories; that's just the way CVS is built. Do an update with "-P" -- "prune" -- to remove empty directories:

cvs update -dP

(Adding "-d" will update new directories that have appeared since your last update; otherwise, CVS will ignore them.)

Cvs tends to work on a two phase approach regarding directories that's why there is a -P option for many cvs commands to "Prune empty directories".

When this has happened, e.g. want to rename a directory I've just added, I delete the directory, delete the entry for the directory in the CVS/Entries file, it'll be a line perpended with a "D".

If I've committed, I make sure my current working area that contains the empty directory/ies is all checked in. Then I blow away the part of the work area that I have added the directories to.
Ex.

/mySandbox/Project_to_remove/etc_etc
/mySandbox/Project_to_remove/emptyDir


I make sure everything is up to date in both directories containing the stuff I want to keep. I then blow away Project_to_remove from within mySandbox.
Going back and checking out the same work area, e.g. Project_to_remove will give me the work area without the empty dirs.
Or just leave everything as is and use the -P option to get CVS check everything out (or update everything) then prune out the empty dirs.

Renaming Directories

checkout the project, make the changes on the local working copy, delete the CVS project in the repository and import the changed project again.



Redirect HTTPS TO HTTP

URL Rewriting


open your httpd.conf file and put the lines below.
-----------------------------------------------------------------
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R,L]
-----------------------------------------------------------------

Apache have a good document for this.

http://httpd.apache.org/docs/2.2/misc/rewriteguide.html
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html


How to Mount Windows Share with CentOS

1. Install below package
#yum install samba-client
#yum install cifs-utils
2. create a file to keep/save you windows password in that. (you can also pass them directly on shell)
cd /home/nk
vim secret.txt
username=Domain\windowsUsername
password=YourPassowrForWindowsDomain

save and exit by :wq

4. make a directory where you want to mount the windows share folder
mkdir /mnt/nk

5.pass the below command to mount the windows shared folder to Centos folder
mount -t cifs //192.168.1.14/share /mnt/nk/ -o credentials=/home/nk/secret.txt

here : 192.168.1.14 is the windows machine IP
           "share" is the name of the folder you want to share(make sure you have access to this)

6. check that folder is mounted by "mount" command

Or
 mount -t cifs //192.168.1.14/share /mnt/nk/ -o -o username=#####,password=######
 
If the machine is in domain
mount -t cifs //192.168.1.14/share /mnt/nk/ -o -o username=DomainName/xxxx,password=xxxx



Tuesday, July 31, 2012

GUI for CentOS 6.2 minimal install Edition

yum groupinstall "Desktop" "Desktop Platform" "X Window System" "Fonts"
yum groupinstall basic-desktop desktop-platform x11 fonts 

Once the minimal installation is done & then you are installing the 
Deskstop Packages changing Default runlevel from 3 to 5 does not start 
Xorg for GUI hence we need to add “exec /etc/X11/prefdm -nodaemon” in 
/etc/inittab file.
 

Thursday, July 12, 2012

base.bind.h ealing Lost connection to xxxt(GC). Running in disconnec ted mode: unlatch

Jul 12 19:14:52 pimage1-rl adclient[1986]: INFO  base.bind.h
ealing Lost connection to xxxt(GC). Running in disconnec
ted mode: unlatch
Jul 12 19:14:52 pimage1-rl adclient[1986]: INFO  base.bind.h
ealing Reconnected to xxxxxxxxxxt(GC).  Running in connected
mode.
Jul 12 19:45:22 pimage1-rl adclient[1986]: INFO  base.bind.h
ealing Lost connection to xxxxxxxxxx(GC). Running in disconn
ected mode: unlatch
Jul 12 19:45:22 pimage1-rl adclient[1986]: INFO  base.bind.h
ealing Reconnected to xxxxxxxxxx(GC).  Running in connected mo
de.





"adreload" and even "centrifydc restart"

In ADUC, right click on the Computer object, select "Reset Account"

On client side:

Run the command "adkeytab -C" or "adkeytab -r" as root


restart adclient one more time. If it still continues to be in disconnected mode,  "adinfo -g " check the output for examination. 

Friday, July 6, 2012

mysql question


>how much the expected data base size would be
>what/what kind of application is going to deploy
> connection type b/n application & data base (is application using connection pool etc etc)
>Security of data base (users in database eg. root pwd secure in database & connect only thru localhost)
>What mysql table engine preferred (myISAM or Innodb ) ==> how is our applicaiton (e.g if more insert and select then go with myISAM
and if more update and select then go with innodb
and if more insert + delete + select then go with innodb
and if one time bulk insert + one time delete + select then myisam
>reason               myisam -- lock table level
innodb -- locks table in row level
If databases have majority of innodb table then
setup server with following parameter
innodb_buffer_size s/b 65-75 % of available RAM and so on
>Before that I need to know the config of the system

                - RAM
                - What processor
                - What media (SATA or SAS or SSD)

Wednesday, July 4, 2012

How to delete all the root mail in linux by mutt + root mailbox full or 5.2.2: Permanent Failure: Mailbox Status: Mailbox full

How to delete all the root mail in linux by mutt

#mutt
/root/Mail does not exist. Create it? ([yes]/no):
yes

Then press "D"
At the bottom it asks "Delete messages matching:"
 ~s .*

-*-Mutt: /var/spool/mail/root [Msgs:46339 New:46339 Del:46339 48M]---(date/date)-

press "q" to quit and "y" to confirm

Monday, July 2, 2012

Too many files open

No. of Open Files
# lsof | wc -l

[root@aqua ~]# sysctl fs.file-max
fs.file-max = 10000
[root@aqua ~]# sysctl fs.file-max
fs.file-max = 10000

File Descriptor in Kernal memory
[root@aqua ~]# sysctl fs.file-nr
fs.file-nr = 2928       0       10000

a. 2828 is no. of allocated file handles
b. 0 no. of unused but alloted handles
c. 10000 system wide maximum number of file handles

No. of file handles used by a process xxx
#lsof -p xxx|wc -l
 
=================
Too Many files open

use lsof command
ps aux
ps aux | grep jetty
lsof -p 1105
lsof -p 1105 | wc -l
ll /proc/11105/fd
ll /proc/1105/fd | sort -g +10 -10

To sort by the Name column
lsof -p 1105 | sort +10 -10 >/tmp/openFiles.txt

The FD column is the File Descriptor column. It is either the number of the file or one of the following:

    cwd current working directory
    Lnn library references (AIX)
    err FD information error (see NAME column)
    jld jail directory (FreeBSD)
    ltx shared library text (code and data)
    Mxx hex memory-mapped type number xx
    m86 DOS Merge mapped file
    mem memory-mapped file
    mmap memory-mapped device
    pd parent directory
    rtd root directory
    tr kernel trace file (OpenBSD)
    txt program text (code and data)
    v86 VP/ix mapped file

Determine the limit

Each user has a limit for the number of open files. This limit applies to each process run by the user. For example say the limit is 1024 and the user has three processes running, each process can open 1024 files for a total of 3072.

To determine the soft limit:
ulimit -Sn
1024

To determine the hard limit:
ulimit -Hn
2048

ulimit -n shows you the soft limit. The soft limit is the limit applied for opening files. The hard limit is the limit you can increase the soft limit to.

Increase the Limit

To increase the limit to 10000 use the following command:

ulimit -Sn 10000

You can change the hard limit too, ulimit -Hn 10000. ulimit -n 10000 changes both the soft and hard limits to the same value.

Note: Once you reboot the limit is reset.
You cannot determine the limit of the root user using ulimit. For example:

sudo ulimit -n
sudo: ulimit: command not found
To make the limits bigger and to make the change permanent, edit your configuration file and reboot.

You can use * in the limit.conf file instead of a user name to specify all users, however this does not apply to the root!

    soft nofile 10000
    hard nofile 10000
    
    The limit.conf file is applied during the boot process. 
    
    
    You cannot start a process late enough in the boot process! For example: “sudo update-rc.d tomcat defaults 99 01″ is at the end and it is still too late.

The work around is to force the limit to be set before starting the process. Put “ulimit -n 4000″ before starting your process, then the limit.conf file is processed here.

There is another file limit in the system, the total number of files that can be opened by all processes.

To see the file max value:
sysctl -a | grep fs.file-max
fs.file-max = 170469 
  
 
File descriptor can be limited in both system level and shell level.
 
To check maximum number of fd in system type 'cat /proc/sys/fs/file-max'.
730437
 
If u want to set it add 'fs.file-max = 200000' to /etc/sysctl.conf
 
 
To check shell level limit
 
Shell level 'ulimit -n' 

1024

In /etc/security/limits.conf
* soft nofile 2048
* hard nofile 2048
 
 
To get total number of handle that a process use
 
lsof -p PID |wc -l
 
 
For File Descriptors == >  Easy way to edit the file
 
echo "#### Custom Addedlines ####">> /etc/security/limits.conf 
echo "* soft nofile 32768" | sudo tee -a /etc/security/limits.conf
echo "* hard nofile 32768" | sudo tee -a /etc/security/limits.conf
echo "root soft nofile 32768" | sudo tee -a /etc/security/limits.conf
echo "root hard nofile 32768" | sudo tee -a /etc/security/limits.conf
 
 
For User limits  == > 

* soft nofile 32768
* hard nofile 32768
root soft nofile 32768
root hard nofile 32768
* soft memlock unlimited
* hard memlock unlimited
root soft memlock unlimited
root hard memlock unlimited
* soft as unlimited
* hard as unlimited
root soft as unlimited
root hard as unlimited
 
 
In addition, you may need to be run the following command:
sysctl -w vm.max_map_count=131072
The command enables more mapping. It is not in the limits.conf file.



Disable Swap

Disable swap entirely. This prevents the Java Virtual Machine (JVM) from responding poorly because it is buried in swap and ensures that the OS OutOfMemory (OOM) killer does not kill


sudo swapoff --all

 
 
OR
 
echo "*   soft    nofile  131070" >> /etc/security/limits.conf
echo "*   hard    nofile  131070" >> /etc/security/limits.conf

echo 0 > /proc/sys/vm/swappiness
echo "vm.swappiness=0" >> /etc/sysctl.conf


Note
Both the “hard” and the “soft” ulimit affect MongoDB’s performance. The “hard” ulimit refers to the maximum number of processes that a user can have active at any time. This is the ceiling: no non-root process can increase the “hard” ulimit. In contrast, the “soft” ulimit is the limit that is actually enforced for a session or process, but any process can increase it up to “hard” ulimit maximum.
A low “soft” ulimit can cause can't create new thread, closing connection errors if the number of connections grows too high. For this reason, it is extremely important to set both ulimit values to the recommended values
 
 OR
sudo vim /etc/security/limits.conf

*           soft    nofile         10000
*           hard    nofile         20000
Modify the common-session file with the following: sudo vim /etc/pam.d/common-session
session required pam_limits.so
==
you can set system wide limits by editing /etc/security/limits.conf and /etc/pam.d/common-session, however, this only applies interactive and non-interactive shells (and processes started by them).
If you want to try system wide limits, then add a line like the following to /etc/security/limits.conf:
*  -  nofile 65000

In /etc/pam.d/common-session, enable the limits module by adding:
session required pam_limits.so

Keep in mind that all this really does is have PAM set the limit for 
interactive and non-interactive shells when loaded. Processes then 
pickup these limits when started from shells/scripts. You should 
probably do a restart to fully enact these settings. 


and reboot the system.

The option with wildcard *didn’t work for me , because I used root accout to run my programms and wildcard option doesn’t affect the superuser.