Wednesday, May 23, 2012

SSD & CentOS 6+


SSD  & CentOS 6+

SSDs can be divided into three classes, based on throughput:
  • The first class of SSDs use a PCI-Express connection, which offers the fastest I/O throughput compared to other classes. This class also has a very low latency for random access.
  • The second class uses the traditional SATA connection, and features fast random access for read and write operations (though not as fast as SSDs that use PCI-Express connection).
  • The third class also uses SATA, but the performance of SSDs in this class do not differ substantially from devices that use 7200rpm rotational disks.
For all three classes, performance degrades as the number of used blocks approaches the disk capacity. The degree of performance impact varies greatly by vendor. However, all devices experience some degradation.
Enabling discard support is most useful when there is available free space on the file system, but the file system has already written to most logical blocks on the underlying storage device.
At present, ext4 is the only fully-supported file system that supports discard. 

To enable discard commands on a device, use the mount option discard. For example, to mount /dev/sda2 to /data with discard enabled, run:
mount -t ext4 -o discard /dev/sdb1 /data

By default, ext4 does not issue the discard command.
This is mostly to avoid problems on devices which may not properly implement the discard command. The Linux swap code will issue discard commands to discard-enabled devices, and there is no option to control this behavior.

There are basically two big things to do
-        enable discard/trim support in the file system
-       Limit write operations to the SSD. You want to enable discard to deal with underlying drive specific performance degradation that will happen over time

Move /tmp to ram.  This depends on how much ram you have and how much /tmp space you use, but it really helps to limit writes to the SSD

Change the mount options for your ext4 filesystem
-       change data from the default of ordered to writeback. This reduces the journal data to meta-data only, thus limiting writes.
-       change the commit value from the default of 5 seconds to 10, or 15. This gets you a 2 to 3x write savings, though you risk losing a bit more data if you lose power.
-       If you don't need access time records (mtime and ctime should be enough for most folks) disabling atime will also limit write operations. 
Ex:   /dev/sdb1        /      ext4     defaults,discard,data=writeback,noatime,commit=15     1 1
A/ mount file systems with the "noatime" option.
"noatime" prevents the file system from updating file access times.
"noatime" includes "nodiratime" (prevents directory access time updates).

Consider whether you need journals
            File system journals make file system reconstruction (fsck for
example) possible, and running without any journal makes catastrophic
file system failure far more likely. On the other hand, journals
require extra write operations, Sometimes it's easy enough to
reconstruct a file system that it's not worth the cost in terms of SSD
write operations.
echo "noop" > /sys/block/sda/queue/scheduler
in /etc/rc.d/rc.local.
OR
one can eliminate journaling altogether by doing this to a unmounted or read-only ext4
tune2fs -O ^has_journal /dev/sda1
 Then there will be no journal. While you are at it the command:
tune2fs -r 1024 /dev/sda1
will reduce the root-reserved blocks to 1k (4MB) 
Get rid of /tmp
Put it on ramdisk. The X11 server makes a huge number of tiny
writes to /tmp and if these flush to disk at a high rate it creates a
load of writes. Adding this line to /etc/fstab does the trick.
none /tmp tmpfs defaults 0 0

To enable trim, use the "discard' mount option in fstab for all mounted partitions from the SSD. The "swap" partition automatically uses TRIM. For example from /etc/fstab ....

Code:
UUID=ffc6a6fc-1bf3-4f25-ab17-067b0515e85a /   ext4    noatime,discard,data=writeback 1 1
UUID=24941fe7-6d23-4969-951e-0872d4b81b0e /home      ext4    noatime,discard,data=writeback 1 2
UUID=2bbebe51-c0f8-4296-ba0a-e715bf84dc67 swap       swap    defaults                       0 0


Few useful Commands

fdisk -u -l /dev/sdX
cat /sys/block/sda/queue/scheduler
Use iotop -oPa and sort by disk writes to see how much programs are writing to disk
Using “tune2fs –l /dev/sdb”, we can see the file system block size is 4KB with journal turned on.
Using “more /sys/fs/ext4/sdc/lifetime_write_kbytes” to see how much has been written to the disk so far





stop all application/System  services on the box,
unmount sdbX and sdcX
run tune2fs to set stride, stripe-width options
change mounting option on sdb, sdc to use noatime
mount again
start application/System services 



mkfs.ext4 -b 1024 -E stride=128,stripe-width=128 -O ^has_journal /dev/sda1
mkfs.ext4 -b 4096 -E stride=32,stripe-width=32 /dev/sda3 

Ref

Monday, May 21, 2012

Exchange 2007 DG & List of all forwarding address list

Fetch the DG members from Exchange 2007

Get-DistributionGroupMember –identity “group name” | ft name, primarysmtpaddress | Export-CSV c:members.csv



Find all users with Forwarding Address is set

Get-Mailbox | Where {$_.ForwardingAddress -ne $null} | Select Name, ForwardingAddress, DeliverToMailboxAndForward c:/myfile.txt 









Tuesday, May 15, 2012

Mail Server - TODO

- Check for the open relay  , it should not configured for that :)
- Restrict the application servers by IP to relay email. you can use to test (http://www.abuse.net/relay.html )
- Check for the DNS and Reverse DNS
- Use SPF
- Use AntiSpam & Antivirus tools
- Monitor incoming and outgoing tools.
- Check RBL for the mail server blacklisting
-

Partition Alignment

#sudo fdisk -luc

turn off MSDOS mode

#sudo fdisk -H 32 -S 32 -cu /dev/yourdisk

1 Gigabyte = 2,097,152 sectors
1 Megabyte = 2,048 sectors


total_sectors / 2,097,152 (sectors in 1GB) = Total Gigabytes
remaining_sectors / 2,048 (sectors in 1MB) = Total Megabytes

Example
2,097,152 X 25 = 52,428,800 (25GB)
2,048 X 750 = 1,536,000 (750MB)
(2,097,152 X 12) + (2,048 X 500) = 26,189,824 (12GB+500MB)


Remember: If you're aligning partitions make sure to start at a sector evenly divisable by 512.
When asked for the size of your partition you'll need to prefix a + to your sectors.
Your last partition may consume the rest of the disk without a worry.


Alignment.

thumb rule is all about your partition starting at a sector evenly divisable by 512. The size of your partition and/or where it ends does not matter. As long as your partition starts at a sector divisable by 512 you're good.

If you had the following partitions sizes ready to go and you could sacrifice 512 bytes per partition without a worry, you subtract 1 sector from each partition. Doing it this way insures no gaps between partitions.


52,428,800 (25GB) - 1 sector = 52,428,799
1,536,000 (750MB) - 1 sector = 1,535,999
26,189,824 (12GB+500MB) - 1 sector = 26,189,823


start at 2,048 because this is the most common start sector in almost all guides. The following example assumes you don't mind shaving 512 bytes per partition by subtracting 1 sector each. In other words you don't need the absolute size and in that process create no gaps between partitions.


Start       End
2,048       +52,428,799  # This partition ends at 52,430,847, the next partition starts at 52,430,848 (evenly divisable by 512)
52,430,848  +1,535,999   # This partition ends at 53,966,847, the next partition starts at 53,966,848 (evenly divisable by 512)


The following example assumes you do mind shaving 512 bytes and want absolute sizes. If you need an absolute size per partition and cannot subtract 1 sector per partition you simply start your next partition at a sector evenly divisable by 512.


Start       End
2,048       +52,428,800  # This partition ends at 52,430,848, our next partition cannot start there. It will start at 52,430,848 + 512 = 52,431,360 (evenly divisable by 512)
52,431,360  +1,536,000   # This partition ends at 53,967,360, our next partition cannot start there. It will start at 53,967,360 + 512 = 53,967,872 (evenly divisable by 512)
53,967,872  +26,189,824  # This partition ends at 80,157,696, our next partition cannot start there. It will start at 80,157,696 + 512 = 80,158,208 (evenly divisable by 512)


Reinstalling the agents on ESX

Reinstalling the agents on ESX

  1. Disconnect the ESX host in vCenter Server. Right-click the host and click Disconnect.
  2. Log in as root to the ESX host using an SSH client.
  3. Run this string of commands in the SSH session:

    service mgmt-vmware stop && service vmware-vpxa stop && service vmware-vmkauthd stop && service xinetd restart && rpm -qa | grep -i vpxa | awk '{print $1}' | xargs rpm -ef $1 && userdel vpxuser && rpm -qa | grep -i aam | awk '{print $1}' | xargs rpm -ef $1 && service mgmt-vmware start && service vmware-vmkauthd start

    Note: This is a concatenated list of commands strung together with the "&&" operator. This is useful in stringing together multiple commands as the next command does not start until the previous one has completed successfully.

    These are the commands you are running:
    • service mgmt-vmware stop && service vmware-vpxa stop && service vmware-vmkauthd stop && service xinetd restart stops the management services for the service console.
    • rpm -qa | grep -i vpxa | awk '{print $1}' | xargs rpm -ef $1 removes the vpxa agent.
    • userdel vpxuser removes the vpxa user that is installed once you connect the host to vCenter Server.
    • rpm -qa | grep -i aam | awk '{print $1}' | xargs rpm -ef $1 removes the AAM RPM (HA) which is reinstalled when you configure HA.
    • service mgmt-vmware start && service vmware-vmkauthd start restarts the services.
    • vmware-cmd -l lets you know when hostd is up and running so that you can reattach it to vCenter Server.
    Note: When you see a list of virtual machines output, the command sequence is complete.
  4. Log in to the vCenter Server using VMware Infrastructure/vSphere Client.
  5. Choose the ESX host from the Inventory.
  6. Right-click on the ESX host and click Connect. This step initiates a re-install of the agent.

Friday, May 4, 2012

Create ext4 partition


  1. Upgrade your system: yum update 
  2. Format the partition: mkfs.ext4 /dev/sdxY (replace sdxY with the device to format (e.g. sda1))
  3. Mount the partition
  4. Add an entry to /etc/fstab, using the filesystem 'type' ext4 
 df -T | awk '{print $1,$2,$NF}' | grep "^/dev"

Format an external/Second HDD with ext4

First,  delete any existing partition and create a new Linux partition using fdisk:

1
# fdisk /dev/sdb
Assuming /dev/sdb is the external or second hard disk. Use d to delete the partition and use n to create a new partition. 83 is the ID of the native Linux partition.
Them,  use mkfs.ext4 to format the partition with ext4:

1
# mkfs.ext4 /dev/sdb1
Note that mkfs.ext4 expects a partition as its argument.
use tune2fs to adjust some parameters:

1
2
# tune2fs -m 0 /dev/sdb1
# tune2fs -L secondDisk01 /dev/sdb1
The -m option is for adjusting the percentage of reserved blocks. The reserved blocks are used by privileged processes which is by default 5% of the hard disk size. Since I’m using the external/second hard disk solely as a storage, I set this to 0 so I can also use those 5% for storage. The -L option is for labeling the filesystem.

Wednesday, May 2, 2012

Free NX [Error: Call to bind failed for font TCP port 11000]





Info: Proxy running in client mode with pid '98196'.
Session: Starting session at 'Mon Apr 30 18:22:52 2012'.
Warning: Connected to remote version 3.4.0 with local version 3.5.0.
Info: Connection with remote proxy completed.
Error: Call to bind failed for font TCP port 11000. Error is 112 'Address already in use'.
Session: Session terminated at 'Mon Apr 30 18:22:52 2012'.

 
This can happen if you have multiple NX connection to multiple machine.
sometime it can be due to the base display number. you can change that with
some other port. but make sure that port is not used by some other application.
 Or
Just start one connection at a time with nx client instead of multiple 
 
 
 

The setting is in the file # cat  /etc/nxserver/node.conf

 

# The base display number from which sessions are started.
#DISPLAY_BASE=1000

 
 
 
tar zcvf ~/ssh_freenx_config.tgz $(rpm -ql openssh-server freenx | grep etc)

How to Setup NTP server and Client (CentOS/RHEL)

NTP (Network time protocol) is used to  synchronize a computer's time in a local network (usually behind firewall )with another reference time source.

Steps:
1. Install NTP package
2. configure ntp.conf
3. start ntpd daemon
4.check   with ntpq -n

check the correct

cat /etc/sysconfig/clock

rpm -qa ntp

one US and one Canada NTP Server

http://www.pool.ntp.org/zone/north-america

http://www.pool.ntp.org/zone/ca

http://support.ntp.org/bin/view/Servers/StratumOneTimeServers


vim /etc/ntp.conf
# permit the source to query or modify the service on this system.
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery

# Permit all access over the loopback interface.  This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict -6 ::1

# Hosts on local network are less restricted.
restrict 10.1.1.0 mask 255.255.255.0 nomodify notrap
restrict 10.10.10.0 mask 255.255.255.0 nomodify notrap

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server time-a.nist.gov

server time-nw.nist.gov
server 0.ca.pool.ntp.org
server 1.ca.pool.ntp.org
# Undisciplined Local Clock. This is a fake driver intended for backup
# and when no outside source of synchronized time is available.
#server 127.127.1.0     # local clock
fudge   127.127.1.0 stratum 10



#service ntpd restart



 ntpdate -u  0.ca.pool.ntp.org

 ntpq -p

Tuesday, April 24, 2012

ZABBIX installation on Linux (CentOS 6.2 or RedHat 6.2)

Install Zabbix Server + CentOS 6.2 (64 bit)



[root@imonitor-lr ~]# rpm -Uvh http://ftp.jaist.ac.jp/pub/Linux/Fedora/epel/6/x86_64/epel-release-6-7.noarch.rpm
Retrieving http://ftp.jaist.ac.jp/pub/Linux/Fedora/epel/6/x86_64/epel-release-6-7.noarch.rpm
warning: /var/tmp/rpm-tmp.tFsRI4: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Preparing...                ########################################### [100%]
   1:epel-release           ########################################### [100%]
[root@imonitor-lr ~]#



- FROM EPEL Repos
# yum --enablerepo=epel -y install zabbix-server-mysql zabbix-agent zabbix-web-mysql

**** Do update  /etc/my.cnf
innodb_file_per_table=1

Reason
[InnoDB tables currently store data and indexes into a shared tablespace (/var/lib/mysql/ibdata1). Due to the shared tablespace, data corruption for one InnoDB table can result in MySQL failing to start up on the entire machine. Repairing InnoDB corruption can be extremely difficult to perform and can result in data loss for tables that were not corrupted originally during that repair process. 

Since MySQL 5.5 will be using InnoDB as the default storage engine, it is important to consider the consequences of continuing to utilize the shared tablespace in /var/lib/mysql/ibdata1 

Changing to per-table tablespace with innodb_file_per_table

As an option to resolve the issue, MySQL has a configuration variable called innodb_file per_table. To use this variable, the following could be placed into /etc/my.cnf to convert InnoDB to a per table file for each InnoDB engine table:innodb_file_per_table=1 ]

#cd /usr/share/doc/zabbix-server-mysql-*/create/schema
shell> mysql -u'username' -p'password'
mysql> create database zabbix character set utf8;
mysql> quit;
shell> cd create/schema
shell> cat mysql.sql | mysql -u'username' -p'password' zabbix
shell> cd ../data
shell> cat data.sql | mysql -u'username' -p'password' zabbix
shell> cat images_mysql.sql | mysql -u'username' -p'password' zabbix


FLUSH PRIVILEGES;  


in vim /etc/php.init

# line 440: change to Zabbix recomended

max_execution_time =
600
# line 449: change to Zabbix recomended

max_input_time =
600
# line 457: change to Zabbix recomended

memory_limit =
256M
# line 729: change to Zabbix recomended

post_max_size =
32M
# line 878: change to Zabbix recomended

upload_max_filesize =
16M
# line 946: uncomment and add your timezone

date.timezone =
Asia/Calcutta # whatever your timezone is


[root@imonitor ~]#
/etc/rc.d/init.d/zabbix-server start

Starting ZABBIX server:
[ OK ]

[root@imonitor ~]#
/etc/rc.d/init.d/zabbix-agent start

Starting ZABBIX agent:
[ OK ]

[root@imonitor ~]#
/etc/rc.d/init.d/httpd restart

Stopping httpd:
[ OK ]

Starting httpd:
[ OK ]

[root@imonitor ~]#
chkconfig zabbix-server on

[root@imonitor ~]#
chkconfig zabbix-agent on





Install the Zabbix Agent only on CentOS 6.2  by YUM (On other Linux Hosts)

For 64 bit
rpm -Uvh http://mirror.cse.iitk.ac.in/fedora//epel/6/x86_64/epel-release-6-7.noarch.rpm

** if this does not work then browse/check the appropriate revision of  epel-release-6-7.noarch.rpm on the site.

yum install zabbix-agent

After Installing the zabbix agent it is a good idea for disable the EPEL repository
#perl -npi -e 's/enabled=1/enabled=0/' /etc/yum.repos.d/epel.repo


For 32 Bit
rpm -Uvh http://mirror.cse.iitk.ac.in/fedora//epel/6/i386/epel-release-6-5.noarch.rpm

Install the Zabbix Agent only on CentOS 6.2  from Source

Download the Zabbix from the zabbix.com/download


# mkdir /etc/zabbix

 wget http://prdownloads.sourceforge.net/zabbix/zabbix-1.8.11.tar.gz
 tar -xzvf zabbix-1.8.11.tar.gz

 cd zabbix-1.8.11
./configure --enable-agent
 -------------------------------------------
Configuration:
  Detected OS:           linux-gnu
  Install path:          /usr/local
  Compilation arch:      linux
  Compiler:              gcc
  Compiler flags:        -g -O2
  Enable server:         no
  Enable proxy:          no
  Enable agent:          yes
  Agent details:
    Linker flags:          -rdynamic
    Libraries:             -lm  -lresolv
  LDAP support:          no
  IPv6 support:          no
***********************************************************
*            Now run 'make install'                       *
*                                                         *
*            Thank you for using Zabbix!                  *
*                                  *
***********************************************************

-----------------------------------------------------

make install
make clean
#useradd -m -s /bin/bash zabbix
mkdir /etc/zabbix







cp misc/conf/zabbix_agentd.conf /etc/zabbix

vim /etc/zabbix/zabbix_agentd.conf
change the below two files as
     Server=[IP address or Name of your zabbix Server]
     Hostname=[Host Name of your agent machine]


cp misc/init.d/redhat/8.0/zabbix_agentd /etc/init.d/

vim /etc/init.d/zabbix_agentd
change the progdir to progdir=”/usr/local/sbin/”
 
#progdir="/usr/local/zabbix/bin/"
progdir="/usr/local/sbin/"

- Add the following lines in /etc/services:zabbix-agent 10050/tcp # Zabbix Agent
zabbix-agent 10050/udp # Zabbix Agent
zabbix-trapper 10051/tcp # Zabbix Trapper
zabbix-trapper 10051/udp # Zabbix Trapper


e.g
#echo "zabbix_agent 10050/tcp" >> /etc/services
#echo "zabbix_server 10051/tcp" >> /etc/services

#chkconfig --add zabbix_agentd
#chkconfig --level 35 zabbix_agentd on
#chmod 755 /etc/init.d/zabbix_agentd
[root@ZagentMachine init.d]# service zabbix_agentd start
Starting zabbix_agentd:                                    [  OK  ]

Confirm if this is running

[root@ZagentMachine init.d]# ps -C zabbix_agentd
  PID TTY          TIME CMD
  528 ?        00:00:00 zabbix_agentd
  530 ?        00:00:00 zabbix_agentd
  531 ?        00:00:00 zabbix_agentd
  532 ?        00:00:00 zabbix_agentd
  533 ?        00:00:00 zabbix_agentd
  534 ?        00:00:00 zabbix_agentd

Now configure the Zabbix Server from the web for this agent...

Configuration>host>create host>
Name [name of the host you want to monitor]
Choose the group you want to put it in
Link it to the template Linux as this is agent installed on the linux box.
check the profile box and put some information about the machine , after this the machine will also be visible in the inventory tab.


Install a windows agent for zabbix
visit the below site and download the agent.

http://www.suiviperf.com/zabbix/index.php

Install them as per the architecture of your machine. [32 Bit or 64 Bit]


http://

Administration -> Media Types -> Email
  • Setup server, helo, email from address
Administration -> Users
  • Setup each user who'll get notified, make sure they have media type "Email" added with their address
Configuration -> Hosts -> Create host
  • In Linux Servers hostgroup
  • Define dns name, ip, connect by IP
  • If the machine is a simple networking device that will only be monitored using SNMP, add it to Template_SNMPv2_Device, and you're done. 
Configuration -> Templates -> Create template

    Give it a name (Template_CentOS_HTTP)
    In Templates group

Configuration -> Templates -> Template_CentOS_HTTP -> Items

    Create Item
    Host: Template_CentOS_HTTP
    Description: HTTP Basic Check
    Type: Simple_check
    Key: http,80

Configuration -> Templates -> Template_CentOS_HTTP -> Triggers

    Create Trigger
    Name: "HTTP Trigger"
    Expression: {Template_CentOS_HTTP:http,80.last(0)}#1
    Severity: High

Configuration -> Actions ->

    Create Action
    name: Email notifications
    Event source: triggers
    Default Subject: add "{HOST.DNS}:" to the beginning
    Default message: add "{HOST.DNS}:" to the beginning
    Conditions: make host have to be from "Linux Servers" hostgroup, and Template_CentOS_HTTP:HTTP trigger" is not 1
    Email affected users




Note:
/etc/my.cnf file  sample


[mysqld]
# paths
datadir                         = /var/lib/mysql/data
tmpdir                          = /tmp/mysqltmp
# network
connect_timeout                 = 60
wait_timeout                    = 28800
max_connections                 = 2048
max_allowed_packet              = 64M
max_connect_errors              = 1000
# limits
tmp_table_size                  = 512M
max_heap_table_size             = 256M
table_cache                     = 512
# logs
log_error                       = /var/log/mysql/mysql-error.log
slow_query_log_file             = /var/log/mysql/mysql-slow.log
slow_query_log                  = 1
long_query_time                 = 20
# innodb
innodb_data_home_dir            = /var/lib/mysql/data
innodb_data_file_path           = ibdata1:128M;ibdata2:128M:autoextend:max:4096M
innodb_file_per_table           = 1
innodb_status_file              = 1
innodb_additional_mem_pool_size = 128M
innodb_buffer_pool_size         = 14G
innodb_flush_method             = O_DIRECT
innodb_io_capacity              = 2000
innodb_flush_log_at_trx_commit  = 2
innodb_support_xa               = 0
innodb_log_file_size            = 512M
innodb_log_buffer_size          = 128M
# experimental
innodb_stats_update_need_lock   = 0
# other stuff
event_scheduler                 = 1
query_cache_type                = 0






** Use tmpfs filesystem for Temporary Files
Using memory instead of local disks will allow a much faster creation of temporary tables on MySQL.
First, create the mountpoint:
mkdir /tmp/mysqltmp

Add this line in your /etc/fstab:
tmpfs /tmp/mysqltmp tmpfs rw,uid=mysql,gid=mysql,size=1G,nr_inodes=10k,mode=0700 0 0
Finally, you need to define this path in /etc/my.cnf and restart MySQL:
tmpdir = /tmp/mysqltmp



===========================
To find out if any item is supported by the zabbix or not use the zabbix_get command from the server
For example to calculate the percent disk space used by the c drive in windows , run the below command.
[aqua~]# zabbix_get -s -k vfs.fs.size[c:,pfree]
77.957042

note: while creating an item here choose "numeric float" instead of "numeric unassigned"
Or to know the free disk space in c drive

[root@aqua ~]# zabbix_get -s 10.10.10.33 -k vfs.fs.size[c:,free]
56677367296

[root@aqua ~]# zabbix_get -s 10.10.10.33 -k system.cpu.load[,avg15]
0.172222