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 ~]#

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

**** Do update  /etc/my.cnf

[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


in vim /etc/php.init

# line 440: change to Zabbix recomended

max_execution_time =
# line 449: change to Zabbix recomended

max_input_time =
# line 457: change to Zabbix recomended

memory_limit =
# line 729: change to Zabbix recomended

post_max_size =
# line 878: change to Zabbix recomended

upload_max_filesize =
# 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
  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/”

- 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

#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.


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


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

/etc/my.cnf file  sample

# 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]

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 -k vfs.fs.size[c:,free]

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

Saturday, April 14, 2012

Apache Logs

Find unique IP addresses that hit your webserver

cat /var/log/httpd/access_log |awk '{print $1}' | sort | uniq | wc -l
  1. first we use the cat command to list all the entries in the apache log file.
  2. we send that to awk which extracts the first item on each line which should be the IP
  3. then we sort all the IPs, this is needed for the uniq command
  4. we apply the uniq filtering command to remove duplicate IPs
  5. then we count the number of lines left using word count command wc
# filter out unique requests for a given day, in this case Jan 1st 2012
cat /var/log/httpd/access_log |  grep "\[01/Jan/2012" |awk '{print $1}' | sort | uniq | wc -l

# getting a list of unique referrers
cat /var/log/httpd/access_log | awk '{print $11};' | awk -F / '{print $3}' | sort | uniq

Install VMware tools by command line + CentOS 6.2

  1. In Sphere Client: Right click on the VM > Guest > Install/update VMware Tools
  2. On the VM console in command line, (without GUI installed):
  3. mkdir /cdrom, or anyother mount point you like
  4. mount the vitural cdrom from step 1; mount /dev/cdrom /cdrom
  5. cd /tmp
  6. tar -xvf /cdrom/VMwareTools (tab to auto-complete)
  7. cd vmware (tab to auto-complete)
  8. ./vmware-install.pl; accept defaults, you might have to install peral as well
  9. umount /cdrom
  10. In Vsphere Client: Guest > Install/upVMware Tools > OK
  11. To confirm the install; in the client > VM Summary tab and look for OK next to VMWare Tools
  12. Restart VM

Monday, April 9, 2012

Linux- copy methods

Linux- copy methods

Download a file

Download a file whose URL contains a “&” (note quotes)
wget http://www.example.com/min.php?page=home&user=ma
Draw an entire site (recursive download)
wget-r http://www.example.com/
Resume a download
wget-c http://www.example.com/xyz.html
Download files only an extension (here,. Jpg)
wget-A.jpg http://www.example.com/
Limit download speed
wget – limit-rate = 30k http://www.example.com/
Download via ftp (With authentication)
wget-r l4 ftp://username:password @ example.com /

If there are a list of pages, files, and so on that I want to grab for the script, I can list one URL-formatted item per line within a file. For example, if the file was ~/bin/getme, I would use:

wget -i ~/bin/data/getme

To download a copy of a complete web site, up to five levels deep, you use the -r option (for recursive):

wget -r site.com -o logfile

Instead of having the progress messages displayed on the standard output, you can save it to a log file with the -o option:


Copy the file "foobar.txt" from a remote host to the local host
$ scp your_username@remotehost.edu:foobar.txt /some/local/directory

Copy the file "foobar.txt" from the local host to a remote host

Copy the directory "foo" from the local host to a remote host's directory "bar"

Copy the file "foobar.txt" from remote host "rh1.edu" to remote host "rh2.edu"

$ scp your_username@rh1.edu:/some/remote/directory/foobar.txt \

Copying the files "foo.txt" and "bar.txt" from the local host to your home directory on the remote host

$ scp foo.txt bar.txt your_username@remotehost.edu:~

Copy multiple files from the remote host to your current directory on the local host

$ scp your_username@remotehost.edu:~/\{foo.txt,bar.txt\}  .


$ rsync options source destination

Source and destination could be either local or remote. In case of remote, specify the login name, remote server name and location.

Synchronize Two Directories in a Local Server

$ rsync -zvr /var/dir1/ /root/dir2
-z  :enable compression
-v :verbose
-r    : recursive
-a : preserve time stamp
-d : sync the directory tree structure

Preserve timestamps during Sync using rsync -a

rsync -azv /var/dir1/ /root/dir2

rsync -arzv /var/dir1/ /root/dir2       (this will do recursively)
a = archive - means it preserves permissions (owners, groups), times, symbolic links, and devices.
r = recursive - means it copies directories and sub directories
v = verbose - means that it prints on the screen what is being copied 

Synchronize Only One File

To copy only one file, specify the file name to rsync command
rsync -v /var/singlefile /root/myfile/

Synchronize only the Directory Tree Structure (not the files)

rsync -v -d abc@ .

Use of "/" at the end of path:
When using "/" at the end of source, rsync will copy the content of the last folder.
When not using "/" at the end of source, rsync will copy the last folder and the content of the folder.

When using "/" at the end of destination, rsync will paste the data inside the last folder.
When not using "/" at the end of destination, rsync will create a folder with the last destination folder name and paste the data inside that folder.

Synchronize with the Directory Name
What if you wanted to not just copy all of the files under /myDir/, but also the /myDir/ directory name. Just leave off the last "/" after the "/myDir" directory name. This will tell rsync to copy the directory name and all files under that directory. On the remote server you will then see the directory structure /backups/myDir/.
rsync -avz /myDir user@remotemachine:/backups/

Incremental Backups using rsync

The following example will make an incremental backup of the directory /data/working/ and put a copy of any file that changes into a dated directory in /BACKUP/ . This can be used to keep a daily backup tree of any changed files and not have to overwrite the previous days files. Note that this method does need to copy the entire file if it changes as the new files are made in the directory named under current day.
rsync --backup --backup-dir=`date +%Y.%m.%d` -a /data/working/ /BACKUP/

lftp -c "set ftp:list-options -a;
open ftp://$USER:$PASS@$HOST;
lcd $LCD;
cd $RCD; 
mirror --reverse \
        --delete \
        --verbose \
        --exclude-glob a-dir-to-exclude/ \
        --exclude-glob a-file-to-exclude \
        --exclude-glob a-file-group-to-exclude* \
        --exclude-glob other-files-to-exclude"

Upload a file

lftp -e 'put /local/path/yourfile.txt; bye' -u user,password ftp.remote.com 

Download a file

lftp -e 'set net:timeout 10; get yourfile.txt; bye' -u user,password ftp.remote.com 

Mirroring / Recursive upload

When using the mirror command, LFTP is recursive by default.
Mirror everything from the /local/path to the root of the remote FTP site, including all subdirectories and their files. The -R switch means “reverse mirror” which means “put” [upload]. Remote path is simply /, the root.

lftp -e 'mirror -R /local/path/ /' -u user,password ftp.remote.com

Recursive Download

To mirror remote to local, just omit the -R param and swap remote path with local. Be careful with this. Don’t overwrite your local changes.

lftp -e 'mirror / /local/path/' -u user,password ftp.remote.com  

Special Characters in Username or Password

Special characters in your username or password must be escaped with backslashes:

lftp -e 'put /pathToyourfile.txt; bye' -u user,password\!\! ftp.remote.com