Skip to main content

Posts

Showing posts from 2014

NGINX - Load Balancing Web Servers.

Setting up NGINX for HTTP load balancing. Nginx server is running as below. nginx-server : nginx.server.com  //nginx Below are the 3 server which run a web application which needs to be load balanced. Server1 : node1.application.com  //web_server Server2 : node2.application.com  //web_server Server3 : node3.application.com  //web_server Install NGINX on RHEL/Centos6 Step 1 : Create a Repo. in [ vim /etc/yum.repos.d/nginx.repo ] CENTOS6 [nginx] name=nginx repo baseurl= http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=0 enabled=1 RHEL: [nginx] name=nginx repo baseurl= http://nginx.org/packages/rhel/$releasever/$basearch/ gpgcheck=0 enabled=1 Step 2 : Installation  [ahmed@ngnix ~]$ sudo yum install nginx Step 3 : Configuration:  sudo vim /etc/nginx/nginx.conf #------BEGIN CONFIG------------ user  nginx; worker_processes  1; error_log  /var/log/nginx/error.log warn; pid        /var/run/nginx.pid;

Enabling HBase Authorization - HBase 0.96

Add this below tag to hbase-site.xml in all the Master and Region Server. <!-- Addding Authorization -->   <property>     <name>hbase.security.authorization</name>     <value>true</value>   </property>   <property>     <name>hbase.coprocessor.master.classes</name>     <value>org.apache.hadoop.hbase.security.access.AccessController</value>   </property>   <property>     <name>hbase.coprocessor.region.classes</name>     <value>org.apache.hadoop.hbase.security.token.TokenProvider,org.apache.hadoop.hbase.security.access.AccessController</value>   </property>   <property>     <name>hbase.rpc.engine</name>     <value>org.apache.hadoop.hbase.ipc.SecureRpcEngine</value>   </property> <!--End Authorization --> [ahmed@master home]# sudo -u hbase hbase shell hbase(main):002:0> grant ERROR: wrong number of arguments (0 for 2) Here is some h

Mounting DVD/CD on Linux (Centos 6.5)

Check where we have DVD/CD mount points. [ahmed@zabbixmin ~]$ ll /dev | grep sr0 lrwxrwxrwx 1 root  root           3 Dec 26 16:46 cdrom -> sr0 lrwxrwxrwx 1 root  root           3 Dec 26 16:46 cdrw -> sr0 lrwxrwxrwx 1 root  root           3 Dec 26 16:46 dvd -> sr0 lrwxrwxrwx 1 root  root           3 Dec 26 16:46 dvdrw -> sr0 lrwxrwxrwx 1 root  root           3 Dec 26 16:46 scd0 -> sr0 brw-rw---- 1 root  cdrom    11,   0 Dec 26 16:46 sr0 Mount using auto select mode, from /dev/sr0 to /media/ -r : Mount the file system read-only. A synonym is -o ro. -t : Type [ahmed@zabbixmin ~]$ sudo mount -r -t auto /dev/sr0 /media/ [ahmed@zabbixmin ~]$ cd /media/ [ahmed@zabbixmin media]$ ls manifest.txt     VMwareTools-9.6.1-1378637.tar.gz  vmware-tools-upgrader-64 run_upgrader.sh  vmware-tools-upgrader-32 [ahmed@zabbixmin media]$ More Details : http://linux.about.com/od/commands/l/blcmdl8_mount.htm

'yum' Download 'rpms' without Installing to Specific

Install the package including " downloadonly " plugin: (RHEL5/CentOS5) # yum install yum-downloadonly (RHEL6/CentOS6) # yum install yum-plugin-downloadonly Run yum command with " --downloadonly " option as follows: # yum install --downloadonly --downloaddir=<directory> <package> Confirm the RPM files are available in the specified download directory. Before using the plugin, check /etc/yum/pluginconf.d/downloadonly.conf to confirm that this plugin is " enabled=1 "

Zabbix Installation 2.4 - CentOS 6.5

Adding Repos and Install Server Configuration . [ahmed@server ~]# rpm -ivh http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm [ahmed@server ~]# yum install mysql-server mysql [ahmed@server ~]# yum install zabbix-server-mysql zabbix-web-mysql [ahmed@server ~]# yum install zabbix-agent Create Database. [ahmed@server ~]# mysql -uroot mysql> create database zabbix character set utf8 collate utf8_bin; mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix'; mysql> exit Creating Schema. [ahmed@server ~]# cd /usr/share/doc/zabbix-server-mysql-2.4.0/create [ahmed@server ~]# mysql -uroot zabbix < schema.sql [ahmed@server ~]# mysql -uroot zabbix < images.sql [ahmed@server ~]# mysql -uroot zabbix < data.sql Setting Configuration. [ahmed@server ~]# vi /etc/zabbix/zabbix_server.conf DBHost=localhost DBName=zabbix DBUser=zabbix DBPassword=zabbix Start Server. [ahmed@server ~]# service zabbix-server start Apache Con

Adding services to auto start after reboot.

1. List All Services, Using ' –list ' parameter will displayed all services and their current status in each run-level configuration. [ahmed@server ~]# chkconfig --list myservermgesrv  0:off   1:off   2:on    3:on    4:on    5:on    6:off abc-servc       0:off   1:off   2:off   3:on    4:off   5:on    6:off xyz:ahmed       0:off   1:off   2:off   3:on    4:off   5:on    6:off ... 2. Adding mysqld, zabbix-server, zabbix-agent, httpd to chkconfig [ahmed@server ~]# chkconfig --level 235 mysqld on [ahmed@server ~]# chkconfig --level 235 zabbix-server on [ahmed@server ~]# chkconfig --level 235 zabbix-agent on [ahmed@server ~]# chkconfig --level 235 httpd on 3. To Disable any run-level use the off parameter. [ahmed@server ~]# chkconfig --level 2 mysqld off

Disable SELinux

SELinux is a security extension of CentOS that should provide extended security.  Edit /etc/selinux/config and set SELINUX=disabled vim /etc/selinux/config # This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: #     enforcing - SELinux security policy is enforced. #     permissive - SELinux prints warnings instead of enforcing. #     disabled - No SELinux policy is loaded. SELINUX= disabled # SELINUXTYPE= can take one of these two values: #     targeted - Targeted processes are protected, #     mls - Multi Level Security protection. SELINUXTYPE=targeted Afterwards we must reboot the system: [ahmed@server ~]# reboot

Creating Local Repos in Server

Creating Local Repository on server. mkdir -p /server/rpms Copy 'rpms' which are downloaded and move to /server/rpms  cp -rf from_rpms /server/rpms createrepo /server/rpms This will create all the necessary xml files in the directory. Next create a file called ' local_repos.repo '  sudo vim /etc/yum/yum.repos.d/local_repos.repo Add the below lines. [LOCAL_REPO] name=LOCAL_REPO baseurl=file:///server/rpms gpgcheck=0  enabled=1  Save the file in /etc/yum/yum.repos.d/ 

error was 14: PYCURL ERROR 6 - "" Error: Cannot find a valid baseurl for repo: base

I finished installing CentOS 6.5, but when I tried running yum update I got: [zabbixmin@zabbix ~]# yum update Loaded plugins: fastestmirror, refresh-packagekit Determining fastest mirrors Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=6&arch=i386&repo=os error was 14: PYCURL ERROR 6 - "" Error: Cannot find a valid baseurl for repo: base How can I fix it? Solution : Just execute  dhclient  in the terminal, this will initialize your network interface and you should be up and running. ​

Saving 'yum install' Packages

Saving Packages when doing a yum installation. These packages can be used again on a different server without having to download them again. sudo vim /etc/yum.conf  [main] cachedir=/var/cache/yum/$basearch/$releasever  keepcache=0  debuglevel=2  logfile=/var/log/yum.log  … #some more details here …  # PUT YOUR REPOS HERE OR IN separate files named file.repo  # in /etc/yum.repos.d  Change the line ` keepcache=0 ` to ` keepcache=1 ` This cache all the data in ' cachedir ' location. Some test here. [zabbix@localhost yum]$ sudo yum install yum-plugin-downloadonly ... [zabbix@localhost yum]$ pwd /var/cache/yum [zabbix@localhost yum]$ find . -name '*.rpm' -print | grep yum ./x86_64/6/base/packages/yum-utils-1.1.30-30.el6.noarch.rpm ./x86_64/6/base/packages/yum-plugin-downloadonly-1.1.30-30.el6.noarch.rpm ./x86_64/6/base/packages/yum-3.2.29-60.el6.centos.noarch.rpm [zabbix@localhost yum]$

Replace string in Multiple Files using 'grep' in Linux

Below is the command to find and replace a string in current directory. grep -rl '<string_to_find>' ./ | xargs sed -i 's/<string_to_find>/<new_string>/g' Here is a command which will replace all occurance of 'ahmed' with 'aariz' grep -rl 'ahmed' ./ | xargs sed -i 's/ahmed/aariz/g' More Information here : http://vasir.net/blog/ubuntu/replace_string_in_multiple_files ​

Import Large Dump into MySQL.

Had to import a Large File into Mysql today. Here is how you do it. :) Step 1 : Login mysql -u root -p database_name Step 2 : Set network buffer length to a large byte number set global net_buffer_length=1000000; Step 3 : Set maximum allowed packet size to a large byte number set global max_allowed_packet=1000000000; Step 4: Disable foreign key checking to avoid delays,errors and unwanted behaviour set foreign_key_checks = 0; Step 5 : Import Dump source My_Large_Dump_File.sql Step 6: Remember to enable foreign key checks when procedure is complete SET foreign_key_checks = 1; More Details on Importing Large Dump is here. https://cmanios.wordpress.com/2013/03/19/import-a-large-sql-dump-file-to-a-mysql-database-from-command-line/ ​

Fetch Monitoring Data from Item to CSV file.

NOTE : Initial script was taken from http://doc.bonfire-project.eu/R2/monitoring/bonfire_monitoring_data_to_csv.html Location for the Original File : http://doc.bonfire-project.eu/R2/_static/scripts/fetch_items_to_csv.py Have done some minor changes as per my need. This script gets monitoring data from Items from Zabbix server and creates a CSV file. For a range of time given. Time range is given in ‘yyyy-mm-dd hh:mm:ss’ format. For the range we give start datetime and end datetime, if only start datetime is specified then time period will be start datetime to now() Script can do 2 things: Single key data into csv Multiple keys read from a file and creates a single csv, with all the keys (creates a .csv file). Single key data into csv This option will connect to Zabbix and collection a single key monitoring data. CSV file is created with the key_name.csv format. python -s 127.0.0.1 -h host-in-zabbix -u admin -p zabbix -k key-in-zabbix -t1 '2014-10-16 12:00:00

Zabbix Item Creation using OID and Name CSV files.

This script is to create a xml import file from a csv file. We use 2 csv file for this. First is the OID csv file . This OID file will contain all the range of OIDs which can be configured on the device. OID CSV will be similar to the CSV sample given below. Information (Name) configured in those OIDs above, with index . This file contains all the configuration information done on the device. Will give the index of the configured variable. CSV format as below Below is the OID csv file. (We will called it OID CSV File) module_name oid_name oid datatype start end description voip_destination status 1.3.6.1.2.1.2.2.18.0 string 0 1000 some description voip_destination flags 1.3.6.1.2.1.2.2.18.1 string 0 1000 some description voip_destination type 1.3.6.1.2.1.2.2.18.2 string 0 1000 some description Here is the sample csv output for the above file. module_name,oid_name,oid,datatype,start,end,description voip_destination,status,1.3.6.