Tuesday, December 15, 2015

MySQL store global persistent user variables

9:45 PM Posted by Dilli Raj Maharjan No comments
Install MySQL Global User Variables UDF. Global User Variables UDF is a MySQL extension which helps storing global user defined variables persistently.


Go to URL: https://www.pureftpd.org/project/mysql-udf-global-user-variables/download
























Click on appropriate method of download either HTTP or FTP.

wget https://download.pureftpd.org/mysql-udf-global-user-variables/global-user-variables-1.2.tar.gz















Extract downloaded tar file.

tar xzvf global-user-variables-1.2.tar.gz











Change directory to extracted directory and install it.

cd global-user-variables
make install











Now we can find udf_global_user_variables.so. We need to copy it to mysql plugin directory.

ll udf_global_user_variables.so
cp udf_global_user_variables.so /usr/lib64/mysql/plugin/


Now login to mysql and execute following command to create function.

mysql -u root -p

DROP FUNCTION IF EXISTS global_set;
CREATE FUNCTION global_set RETURNS INTEGER
  SONAME 'udf_global_user_variables.so';

DROP FUNCTION IF EXISTS global_get;
CREATE FUNCTION global_get RETURNS STRING
  SONAME 'udf_global_user_variables.so';

DROP FUNCTION IF EXISTS global_add;
CREATE FUNCTION global_add RETURNS INTEGER
  SONAME 'udf_global_user_variables.so';










































Now we can set variables with following command. In case below VAR_GOLD_PRICE is a variable and 48000 is the value.

do global_set("VAR_GOLD_PRICE",48000);

To read the variable value we can use following command.

select global_get("VAR_GOLD_PRICE");




































The value is readable globally and persistent till mysql server reboots.

We can set the string variables as below.

do global_set("VAR_MEMBER_NAME","Dilli Raj Maharjan");
select global_get("VAR_MEMBER_NAME");






Wednesday, December 9, 2015

Install Zabbix on Linux

7:43 PM Posted by Dilli Raj Maharjan , 1 comment

Zabbix is a software for monitoring availability and performance of IT infrastructure components. It is opensource and helps gathering statistical data of system health. 


Following are its core features:
  1. A web-based interface
  2. Secure user authentication
  3. A flexible user permission schema
  4. Agents based data gathering and agent-less monitoring
  5. Polling and trapping support.
  6. Zabbix-proxy to centrally collect information and upload to zabbix server.
  7. Remote commands support
  8. True open-source software 
  9. Notification by SMS, Jabber, email, skype, IM, Voice
  10. Visualisation 

Requirement

Memory size: 128 MB 
Disk size: 256 MB 

Backend database: 

  1. MySQL 5.0.3 or later
  2. PostgreSQL 8.1 or later
  3. Oracle 10g or later
  4. SQLite 3.3.5 or later
  5. IBM DB2 9.7 or later

Zabbix frontend requires:

  1. Apache 1.3.12 or later
  2. PHP 5.3.0 or later
  3. PHP extensions: gd, bcmath, ctype , libXML, xmlreader, xmlwriter, session, sockets, mbstring, gettext, ibm_db2, mysqli, oci8, pgsql, sqlite3
  4. OS Packages: net-snmp.x86_64, snmp.x86_64, OpenIPMI-libs.x86_64, mysql-server

Install required package with yum command below.

yum -y install httpd.x86_64 php.x86_64 php-bcmath.x86_64 php-common.x86_64 php-gd.x86_64 php-mysql.x86_64 php-odbc.x86_64 php-xml.x86_64 php-mbstring

Download fping from URL below:

wget  http://pkgs.repoforge.org/fping/fping-3.1-1.el6.rf.x86_64.rpm
rpm ivh fping-3.1-1.el6.rf.x86_64.rpm







Download iksemel package

http://repo.zabbix.com/non-supported/rhel/6/x86_64/iksemel-1.4-2.el6.x86_64.rpm


Download Zabbix rpm.

  1. Go to URL http://www.zabbix.com/download.php
  2. Under Zabbix Packages heading select the version of OS and architecture.
  3. Choose desired version and download 











Package description:

zabbix-agent-*.rpm Client agent that will be installed on the Zabbix client. Need to be installed on every machine that is intended to monitor.
zabbix-web-*.rpm Web interface to configure Zabbix server. It comes with two backend database flavor.
  • zabbix-web-mysql-*.rpm
  • zabbix-web-pgsql-*.rpm
Zabbix-proxy-*.rpm Optional package component that will centrally collect data and upload to zabbix server. It comes with three backend database.
  • zabbix-proxy-mysql-*.rpm
  • zabbix-proxy-pgsql-*.rpm
  • zabbix-proxy-sqlite3-*.rpm
Zabbix-server-*.rpm Core package the installed the zabbix server. It comes with two backend database 
  • zabbix-server-mysql-*.rpm
  • zabbix-server-pgsql-*.rpm
At least zabbix-web-*.rpm and Zabbix-server-*.rpm package is required to install on monitoring server.

Install zabbix-server package.

rpm -ivh zabbix-2.4.7-1.el6.x86_64.rpm zabbix-server-2.4.7-1.el6.x86_64.rpm zabbix-server-mysql-2.4.7-1.el6.x86_64.rpm



Install  zabbix-web packages

rpm -ivh zabbix-web-2.4.7-1.el6.noarch.rpm zabbix-web-mysql-2.4.7-1.el6.noarch.rpm





Configure backend database to store zabbix data. In my case I am using mysql as backend database.Install mysql initial database(Fresh Database)

mysql_install_db 
































Start mysql database

/etc/init.d/mysqld start


















Login as user root and change mysql root password

mysql -u root 
update mysql.user
set password=PASSWORD('*******')

where user='root';

Create mysql database zabbix with character set utf8

Create database zabbix character set utf8;

Create user zabbix

grant all on zabbix.* to zabbix@'localhost' identified by '********';
flush privileges;
















Now create required schema objects.

cd /usr/share/doc/zabbix-server-mysql-2.4.7/create/
mysql -uzabbix -p zabbix < schema.sql
mysql -uzabbix -p zabbix < images.sql
mysql -uzabbix -p zabbix < data.sql














Edit zabbix_server.conf file to set database IP, User and client. Add following lines on the file.

vi /etc/zabbix/zabbix_server.conf 
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=(your zabbix password)

Modify php.ini configuration file
Change following parameter values

max_execution_time 300
memory_limit 128M
post_max_size 16M
upload_max_filesize 2M
max_input_time 300
date.timezone Asia/Kathmandu

Start httpd and zabbix-server

/etc/init.d/httpd start
/etc/init.d/zabbix-server start








Make sure these services are startup at boot.

chkconfig httpd on
chkconfig zabbix-server on
chkconfig mysqld on








Monitor logfile with command below


tail -f /var/log/zabbix/zabbix_server.log 




































Verify all services are started properly.

Web configuration

Open following URL on browser.

http://192.168.1.250/Zabbix












Click on Next

Verify all pre-requisites are installed and click on next.


Configure database connections parameters and click on Test connection.

Click on next if Test connection returns OK

Enter hostname, name and port and click on next


Verify the Pre-Installation Summary and Click on Next to continue.


Click on Finish to complete Installation.

Login with Admin/zabbix


Friday, December 4, 2015

Shrink Oracle Virtualbox virtual machines to claim unused space

6:53 AM Posted by Dilli Raj Maharjan , No comments
Over the time, we can notice that the size of the dynamically growing virtual disks vdi file keep growing on Oracle Virtual box. Deleting the files inside the Guest Machine does not free up any space in the Host Machine's hard drive. We need to shrink vdi file to claim unused space.
Please follow the steps below to claim unused space.

We can notice that the size of the DGMaster.vdi is 20GB











Delete unnecessary files from the Guest machine.

Power off the guest machine.

Convert vdi file to compact.

VBoxManage modifyvdi DGMaster.vdi --compact








Power On the Guest Machine and install zero free package inside it.


We can get package from URL below. Package for EL5 works perfect for EL6 too.

http://rpm.pbone.net/index.php3/stat/4/idpl/15277264/dir/redhat_el_5/com/zerofree-1.0.1-5.el5.x86_64.rpm.html
rpm -ivh zerofree-1.0.1-5.el5.x86_64.rpm 




















Now umount the partition or make it read only. In my case I am freeing space from root partition so I need to reboot my Guest Machine to single user mode and make it read only.


Boot the system to single user mode
mount -o remount,ro /dev/mapper/vg_oel1-lv_root


















Now find and fill unused, unallocated blocks with zero. 

zerofree -v /dev/mapper/vg_oel1-lv_root







Output can be interpreted as: Total number of modified blocks/Total number of free blocks/Total number of blocks


Mount back the root partition to rw mode and poweroff the guest machine.

mount -o remount,rw /dev/mapper/vg_oel1-lv_root
poweroff


Now execute VBoxManage compact command from Host Machine to reclaim unused space. After modifyvdi completes you may notice the file size change.

VBoxManage modifyvdi DGMaster.vdi --compact






















We can notice that Size of DGMaster.vdi has been decreased from 20GB to 14GB.

Tuesday, December 1, 2015

Linux Network Interface Card Bonding

7:24 PM Posted by Dilli Raj Maharjan , No comments

Channel Bonding helps two or more NIC card act as single. It increase the bandwidth and provides redundancy. In case on one physical NIC is down network traffic moves to another NIC card providing High Availability. We use bond driver to achieve it.

The following instructions are tested on:
OS: CentOS 6.7 installed on Virtual box Version 5.0.10 r104061
VM adapter settings: Bridged Adapter, Paravirtualized Network (virtio-net)
2 Ethernet Adapters eth0, eth1

Create bonding.conf file inside directory /etc/modprobe.d and add following linesalias bond0 bonding








Add following lines on the file bond0 interface configuration file /etc/sysconfig/network-scripts/ifcfg-bond0

DEVICE=bond0
IPADDR=192.168.1.254
NETWORK=192.168.1.0
NETMASK=255.255.255.0
USERCTL=no
BOOTPROTO=none
BONDING_OPTS="miimon=100 mode=1 fail_over_mac=1"
ONBOOT=yes
NM_CONTROLLED=no













Add following lines on file eth0 and eth1 configuration files
/etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0
USERCTL=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
BOOTPROTO=none
NM_CONTROLLED=no











/etc/sysconfig/network-scripts/ifcfg-eth1

DEVICE=eth1
USERCTL=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
BOOTPROTO=none
NM_CONTROLLED=no











Now restart network service

/etc/init.d/network restart









Verify failover

Ping IP 192.168.1.254 from another host.

ping 192.168.1.254


Keep watching the /var/log/message log file for interface down.


tail -f /var/log/message

Plug OFF cable from eth0. Message on the log file will be displayed as below
Dec  1 07:53:45 svn NetworkManager[1581]: <info> (eth0): carrier now OFF (device state 1)
Dec  1 07:53:45 svn kernel: bonding: bond0: link status definitely down for interface eth0, disabling it
Dec  1 07:53:45 svn kernel: bonding: bond0: making interface eth1 the new active one.

Plug ON cable on eth0
Dec  1 07:53:55 svn NetworkManager[1581]: <info> (eth0): carrier now ON (device state 1)
Dec  1 07:53:56 svn kernel: bonding: bond0: link status definitely up for interface eth0, 4294967295 Mbps full duplex.

Plug OFF cable on eth1
Dec  1 07:54:00 svn NetworkManager[1581]: <info> (eth1): carrier now OFF (device state 1)
Dec  1 07:54:00 svn kernel: bonding: bond0: link status definitely down for interface eth1, disabling it
Dec  1 07:54:00 svn kernel: bonding: bond0: making interface eth0 the new active one.

Plug ON cable on eth1
Dec  1 07:54:04 svn NetworkManager[1581]: <info> (eth1): carrier now ON (device state 1)
Dec  1 07:54:04 svn kernel: bonding: bond0: link status definitely up for interface eth1, 4294967295 Mbps full duplex.
[root@svn ~]# 


During cable Plug on and OFF, We can notice there is 0% Packet loss output from Ping result

--- 192.168.1.254 ping statistics ---
26 packets transmitted, 26 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 0.377/0.496/1.085/0.188 ms