Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Feb 25, 2015

Centos7 Upgrading Kernel to 3.19

Centos 7 is the latest release from the community.  Centos7 is shipped with 3.10 Kernel. Many times people may need the latest Kernel. This article telling about how to upgrade from 3.10 to latest upstream kernel.

# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
# yum --enablerepo=elrepo-kernel install kernel-ml

Once the installation is finished, make sure you have got new kernel.

# awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg

CentOS Linux, with Linux 3.19.0-1.el7.elrepo.x86_64
CentOS Linux, with Linux 3.10.0-123.el7.x86_64
CentOS Linux, with Linux 3.10.0-123.20.1.el7.x86_64

CentOS Linux, with Linux 0-rescue-b6ea1092b61e4ac7a546ba4454bd63d0

If the CentOS kernel version 3.19.x is listed first, then set grub to use 0 which will set the system to boot off the newer kernel. You might want to leave some of the older 3.10.x kernels on the system in case you decide to revert to the stock CentOS 7 kernel, but you can always modify the default kernel to use later on.

# grub2-set-default 0

Update the grub2 config so it's aware of the changes we just made.

# grub2-mkconfig -o /boot/grub2/grub.cfg

# reboot

Check the new kernal.

# uname -a

Linux compute1 3.19.0-1.el7.elrepo.x86_64 #1 SMP Mon Feb 9 09:57:29 EST 2015 x86_64 x86_64 x86_64 GNU/Linux



Feb 2, 2015

3 Node MySQL Cluster using Percona

Percona XtraDB Cluster is an active/active high availability and high scalability open source solution for MySQL clustering. It integrates Percona Server and Percona XtraBackup with the Galera library of MySQL high availability solutions in a single package which enables you to create a cost-effective MySQL high availability cluster. 

Here following a 3 node mysql cluster using Percona. The infrastructure is as follows.

All the Nodes are running on Centos 6.6. The IPAddress / Hostnames  of the Nodes are as follows. Turn off IPTABLES in all these nodes, OR allow traffic between these nodes.

192.168.1.1      cluster-node1
192.168.1.2      cluster-node2
192.168.1.3      cluster-node3

Add these entries in each and every nodes /etc/hosts files.

#vim /etc/hosts
192.168.1.1      cluster-node1
192.168.1.2      cluster-node2
192.168.1.3      cluster-node3

Disable SELINUX

Set Up SSH Keys and place into authorized_keys so all the id_rsa.pub values are in authorized_keys on all servers.

# ssh-keygen -t rsa
# cd /root/.ssh/
# cp id_rsa.pub authorized_keys 
# chmod 600  /root/.ssh/authorized_keys
# chmod 700  /root/.ssh/

Install the Needed Repositories for Percona & Socat.

# yum -y install http://www.percona.com/downloads/percona-release/percona-release-0.0-1.x86_64.rpm
# yum -y install http://mirror.pnl.gov/epel/6/x86_64/epel-release-6-8.noarch.rpm
# wget http://www.percona.com/downloads/RPM-GPG-KEY-percona /etc/pki/rpm-gpg/RPM-GPG-KEY-percona 
# wget http://www.percona.com/downloads/RPM-GPG-KEY-percona /etc/pki/rpm-gpg/RPM-GPG-KEY-percona 
# yum -y install socat

Remove the following applications to avoid the dependencies, Later we can bring them back.

# rpm -e mysql-libs postfix cronie redhat-lsb-core redhat-lsb-printing redhat-lsb-graphics libcgroup numad redhat-lsb sysstat crontabs cronie-anacron redhat-lsb-compat

Install the Percona Cluster Packages (Repeat the following Commands in all the Nodes)

#yum -y install Percona-XtraDB-Cluster-full-56

Start the Server.

[root@cluster-node1 ~]#  /etc/init.d/mysql start
Starting MySQL (Percona XtraDB Cluster)......... SUCCESS! 
[root@cluster-node2 ~]# /etc/init.d/mysql start
Starting MySQL (Percona XtraDB Cluster)......... SUCCESS!
[root@cluster-node3 ~]# /etc/init.d/mysql start
Starting MySQL (Percona XtraDB Cluster)......... SUCCESS! 

Run the following Commands

#mysql -e "CREATE FUNCTION fnv1a_64 RETURNS INTEGER SONAME 'libfnv1a_udf.so'" 
#mysql -e "CREATE FUNCTION fnv_64 RETURNS INTEGER SONAME 'libfnv_udf.so'"
#mysql -e "CREATE FUNCTION murmur_hash RETURNS INTEGER SONAME 'libmurmur_udf.so'"

Bring in Back the removed packages

#yum -y install postfix cronie redhat-lsb-core redhat-lsb-printing redhat-lsb-graphics libcgroup numad redhat-lsb sysstat crontabs cronie-anacron redhat-lsb-compat

Create the my.cnf file in first node and insert the following contents

#vim /etc/my.cnf
[mysqld]

datadir=/var/lib/mysql
user=mysql

# Path to Galera library
wsrep_provider=/usr/lib64/libgalera_smm.so

# Cluster connection URL contains the IPs of node#1, node#2 and node#3
# cluster-node 1 192.168.1.1
# cluster-nod3 2 192.168.1.2
# cluster-nod3 3 192.168.1.3
wsrep_cluster_address=gcomm://192.168.1.1,192.168.1.2,192.168.1.3

# In order for Galera to work correctly binlog format should be ROW
binlog_format=ROW

# MyISAM storage engine has only experimental support
default_storage_engine=InnoDB

# This changes how InnoDB auto increment locks are managed and is a requirement for Galera
innodb_autoinc_lock_mode=2

# Node #1 address
wsrep_node_address=192.168.1.1

# SST method
#wsrep_sst_method=xtrabackup
 wsrep_sst_method=rsync      #
# wsrep_sst_method=rsync_wan  #
# wsrep_sst_method=mysqldump  # SLOW

# Cluster name
wsrep_cluster_name=percona_cluster

# Authentication for SST method
wsrep_sst_auth="root:password" 

# server_id
server_id=3232235553  #SELECT INET_ATON('192.168.1.1')

#[client]
socket=/var/lib/mysql/mysql.sock

Start the First Clustering Node.

#/etc/init.d/mysql start --wsrep-cluster-address="gcomm://"
Starting MySQL (Percona XtraDB Cluster)...................................... SUCCESS!

Read the grastate.dat file . (It will be in /var/lib/mysql)

[root@cluster-node1 mysql]# cat grastate.dat
# GALERA saved state
version: 2.1
uuid:    68aa64c3-a966-11e4-96dd-b6bab6cb5af6
seqno:   -1

cert_index:

Check the Cluster Status.

mysql>select @@hostname\G show global status like 'wsrep_cluster_size' \G

*************************** 1. row ***************************

@@hostname: controller-node1
1 row in set (0.00 sec)

*************************** 1. row ***************************

Variable_name: wsrep_cluster_size
        Value: 3
1 row in set (0.00 sec)

#Now copy the following Contents in /etc/my.cnf file of Second Node

#vim /etc/my.cnf
[mysqld]

datadir=/var/lib/mysql

user=mysql

# Path to Galera library

wsrep_provider=/usr/lib64/libgalera_smm.so

# Cluster connection URL contains the IPs of node#1, node#2 and node#3

# cluster-node 1 192.168.1.1
# cluster-nod3 2 192.168.1.2
# cluster-nod3 3 192.168.1.3
wsrep_cluster_address=gcomm://192.168.1.1,192.168.1.2,192.168.1.3

# In order for Galera to work correctly binlog format should be ROW

binlog_format=ROW

# MyISAM storage engine has only experimental support

default_storage_engine=InnoDB

# This changes how InnoDB auto increment locks are managed and is a requirement for Galera

innodb_autoinc_lock_mode=2

# Node #1 address

wsrep_node_address=192.168.1.2

# SST method

#wsrep_sst_method=xtrabackup
 wsrep_sst_method=rsync      #
# wsrep_sst_method=rsync_wan  #
# wsrep_sst_method=mysqldump  # SLOW

# Cluster name

wsrep_cluster_name=percona_cluster

# Authentication for SST method

wsrep_sst_auth="root:password" 

# server_id

server_id=3232235553  #SELECT INET_ATON('192.168.1.2')

#[client]

socket=/var/lib/mysql/mysql.sock

Start the Cluster in Second Node.


[root@cluster-node2]#/etc/init.d/mysql start

Starting MySQL (Percona XtraDB Cluster)........................... SUCCESS!



Now check the Status in Both Nodes.

First Node
mysql> select @@hostname\G show global status like 'wsrep_cluster_size' \G
*************************** 1. row ***************************
@@hostname: controller-node1
1 row in set (0.00 sec)

*************************** 1. row ***************************
Variable_name: wsrep_cluster_size
        Value: 2
1 row in set (0.00 sec)


Second Node
mysql> select @@hostname\G show global status like 'wsrep_cluster_size' \G
*************************** 1. row ***************************
@@hostname: controller-node2
1 row in set (0.00 sec)

*************************** 1. row ***************************
Variable_name: wsrep_cluster_size
        Value: 2
1 row in set (0.00 sec)

Now, We are adding 3 Node to the Cluster. 

#Now copy the following Contents in /etc/my.cnf file of Third  Node

#vim /etc/my.cnf


[mysqld]

datadir=/var/lib/mysql

user=mysql

# Path to Galera library

wsrep_provider=/usr/lib64/libgalera_smm.so

# Cluster connection URL contains the IPs of node#1, node#2 and node#3

# cluster-node 1 192.168.1.1
# cluster-nod3 2 192.168.1.2
# cluster-nod3 3 192.168.1.3
wsrep_cluster_address=gcomm://192.168.1.1,192.168.1.2,192.168.1.3

# In order for Galera to work correctly binlog format should be ROW

binlog_format=ROW

# MyISAM storage engine has only experimental support

default_storage_engine=InnoDB

# This changes how InnoDB auto increment locks are managed and is a requirement for Galera

innodb_autoinc_lock_mode=2

# Node #1 address

wsrep_node_address=192.168.1.3

# SST method

#wsrep_sst_method=xtrabackup
 wsrep_sst_method=rsync      #
# wsrep_sst_method=rsync_wan  #
# wsrep_sst_method=mysqldump  # SLOW

# Cluster name

wsrep_cluster_name=percona_cluster

# Authentication for SST method

wsrep_sst_auth="root:password" 

# server_id

server_id=3232235553  #SELECT INET_ATON('192.168.1.3')

#[client]

socket=/var/lib/mysql/mysql.sock

[root@cluster-node3]#/etc/init.d/mysql start

Starting MySQL (Percona XtraDB Cluster)........................... SUCCESS!

Now Check the Cluster status in Each nodes. 



First Node
mysql> select @@hostname\G show global status like 'wsrep_cluster_size' \G
*************************** 1. row ***************************
@@hostname: controller-node1
1 row in set (0.00 sec)

*************************** 1. row ***************************

Variable_name: wsrep_cluster_size
        Value: 3
1 row in set (0.00 sec)


Second Node

mysql> select @@hostname\G show global status like 'wsrep_cluster_size' \G
*************************** 1. row ***************************
@@hostname: controller-node2
1 row in set (0.00 sec)

*************************** 1. row ***************************

Variable_name: wsrep_cluster_size
        Value: 3
1 row in set (0.00 sec)

Third Node

mysql> select @@hostname\G show global status like 'wsrep_cluster_size' \G
*************************** 1. row ***************************
@@hostname: controller-node2
1 row in set (0.00 sec)

*************************** 1. row ***************************

Variable_name: wsrep_cluster_size
        Value: 3
1 row in set (0.00 sec)

You can see that, the Value has changed to 3. All are Good Now.


Testing.

Create a Test Database in First Node, You can see that it will be replicated in Another nodes.









Jan 14, 2015

Over-Committing And Ballooning in KVM

Over-Committing the resource is a vital part in Virtualization. Idea of over-committment is to allocate more memory to guest machines than the host really has. Suppose a 2GB host is running two guest operating system who is having 2GB memory, in this case we can say its over committed.

In Ballooning process, Host have a right to take the free memory from Guest machines if its there. Consider the above said example, where suppose one virtual machine is using 1GB and other 1GB is free, host can ask the guest to return the free memory. Guest will give it back and host can allocate somewhere else. And if the reduced guest wants to run an application that consumes more than the 1G it currently has, it has to grow again. 

virtio_balloon - This is the driver who open a communication pathway between Host and the Guest virtual machines. Hypervisor (Host) uses this communication pathway to over-committ the resource from Guest machines. If you are not loaded the virtio_balloon driver, you are not able to do the following.

1. The guest operating system ignores memory requests from the hypervisor.
2. The hypervisor cannot over-commit the memory.

The main problem is, this ballooning process is not automatic. it's entirely manual. Someone (or some tool) is supposed to be watching the pressure in the host and guest and then operate the balloon accordingly. In 2013 October KVM forum, Redhat introduced Automatic Ballooning. You can find the presented slides here, and its available with from Kernel 3.10 onwards. I would say, its still experimental and need more feedback.

Jan 7, 2015

How to Know Interface is Connected to network - Linux

If you are managing the Linux server remotely, and your Data Center technician informed you that he already connected the Cable to an interface, but in case of Blade servers he cannot identify he connected to which interface (Not only him, nobody). Most of the cases there will be more than 3 interfaces, in this case identify which interface is connected you can use the following command.

[root@compute ~]# ethtool em1
Settings for em1:
    Supported ports: [ TP FIBRE ]
    Supported link modes:   10baseT/Half 10baseT/Full
                            100baseT/Half 100baseT/Full
                            1000baseT/Full
    Supported pause frame use: No
    Supports auto-negotiation: Yes
    Advertised link modes:  10baseT/Half 10baseT/Full
                            100baseT/Half 100baseT/Full
                            1000baseT/Full
    Advertised pause frame use: No
    Advertised auto-negotiation: Yes
    Speed: Unknown!
    Duplex: Unknown! (255)
    Port: Twisted Pair
    PHYAD: 2
    Transceiver: internal
    Auto-negotiation: on
    MDI-X: Unknown
    Supports Wake-on: g
    Wake-on: d
    Link detected: no

[root@compute ~]#

Here is the output, and you can see the parameter Link detected: no. Which mean its not connected.

[root@compute ~]# ethtool p3p1
Settings for p3p1:
    Supported ports: [ FIBRE ]
    Supported link modes:   10baseT/Half 10baseT/Full
                            100baseT/Half 100baseT/Full
                            1000baseT/Full
                            2500baseX/Full
                            10000baseT/Full
    Supported pause frame use: Symmetric Receive-only
    Supports auto-negotiation: Yes
    Advertised link modes:  10baseT/Half 10baseT/Full
                            100baseT/Half 100baseT/Full
                            1000baseT/Full
                            2500baseX/Full
                            10000baseT/Full
    Advertised pause frame use: Symmetric Receive-only
    Advertised auto-negotiation: Yes
    Link partner advertised link modes:  1000baseT/Full
                                         10000baseT/Full
    Link partner advertised pause frame use: No
    Link partner advertised auto-negotiation: Yes
    Speed: 10000Mb/s
    Duplex: Full
    Port: FIBRE
    PHYAD: 1
    Transceiver: internal
    Auto-negotiation: on
    Supports Wake-on: d
    Wake-on: d
    Current message level: 0x00000000 (0)
                  
    Link detected: yes
[root@compute ~]# 




In the second attempt but with another interface you can see the Link detected: yes. Change the interfaces names accordingly. In my case those are em1 and p3p1

May 28, 2012

Make Skype Icon Visible in Gnome Desktop Ubuntu 12.04

If you are using Ubuntu 12.04 with Gnome - Classic Desktop , you may experience a problem with not displaying SKYPE icon in the system tray. This can be solved in an easy method. You need to install Status NotifierItem plugin. If you are using 64Bit install of Ubuntu , you need to install i386 version of sni-qt.

sudo apt-get install sni-qt:i386

Thats it !!! login to skype and skype icon will be displayed in your system tray.


May 2, 2012

Reverse SSH Tunneling OR "Poor mans VPN"

In corporate networks , the servers will be placed behind a NAT for security reasons. Its not possible to access the server behind the NAT from outside network. And here comes a way to access servers behind NAT through SSH , its called Reverse SSH Tunneling OR Poor Mans VPN.

Scenario.

IP Address of the Server you need to access 192.168.20.55
IP Address of the Client from which you are trying 150.57.9.9


1. SSH from the destination to the source (with public ip) using command below:


ssh -R 2080:localhost:22 sourceuser@150.57.9.9

2. Now you can SSH from source to destination through SSH tuneling:

ssh localhost -p 19999


May 1, 2012

KVM (Virtualization) Tips



KVM Tips.


Assumptions

1.You should have a working KVM Environment
2.You should have knowledge in Linux and little Networking.
3.You should have basic level knowledge in Virtualisation

1.To Check whether KVM has been installed

virsh -c qemu:///system list

You will see the following...

[root@server1 ~]# virsh -c qemu:///system list
 Id Name                 State
----------------------------------

[root@server1 ~]#

Which means your KVM server is up and running.

2.To View all the running Guests

virsh --connect qemu:///system

virsh# list -all

Id Name                 State
----------------------------------
  3 vm11                 running
  - vm10                 shut off

virsh #

3.Start a Virtual Machine
virsh# start vm10

4.Stop a Virtual Machine
virsh# shutdown vm10

5.Suspend a Virtual Machine

virsh# suspend vm10

6.Forcefully Shutdown a virtual Machine (ie remove power plug)

virsh# destroy vm10

7.Exit the Virtual shell
virsh# Exit

Static Route in Linux

Static Route is using for improving the overall performance of your network. Also you can use static route for implementing Sub Networks. Suppose you are having different branch office to be connected with a Head office who is linked with a T1 line , Static route will be use full.

1.To View the routes in your system

ip route show

route -n

2.Adding a route in the Linux Machine.

route add default gw 10.10.100.1 eth0

This will create a ROUTE in the interface eth0 for a gateway to 10.10.100.1

This will be lose once you restart the network. For Adding a static route , you should follow the below steps.

vi /etc/sysconfig/network-scripts/route-eth0

Append the following

10.10.1.0/8 via 10.120.194.5

This will byepass all the traffic to 10.120.194.5 router through eth0

Apr 22, 2012

VLAN With Hypervisor - KVM

IDEA.


Some times we need a VLAN inside the Linux machine to communicate with outside network. Specifically when we are dealing with Blade Servers. KVM Hypervisor only allows outside traffic through this VLAN only OR Management IP. We are not considering management NIC here.

The traffic from BladeS erver is allowed to main switch only through this VLAN. When a packet come from the Blade , the particular port of the switch will ask challenge to the packet for VLAN information. So we need to create a separate VLAN inside the Linux machine.

HowTO

cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0.300

vi /etc/sysconfig/network-scripts/ifcfg-eth0.300

Find the Word DEVICE and change its name to eth0.300 (Normally that should be eth0)

Add the Line       VLAN=yes

Restart the Network    /etc/init.d/network restart.

Adding a new VLAN

vconfig add eth0 5

Assigning an IPAddress to the VLAN

ifconfig eth0.5 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255 up

For Shutting down a VLAN

ifdown eth0.300

For Remove a VLAN

vconfig rem eth0.300