Thursday, April 16, 2015

Install Ansible :
Great tool for cluster mgmt
http://docs.ansible.com/intro_installation.html
note:make sure that all of your hosts are ssh via key



Install on Centos:


#sudo yum install ansible

go to the  /etc/ansible/hosts and edit it like the following example:


# This is the default ansible 'hosts' file.
# # It should live in /etc/ansible/hosts 
# # - Comments begin with the '#' character 
# - Blank lines are ignored 
# - Groups of hosts are delimited by [header] elements 
# - You can enter hostnames or ip addresses 
# - A hostname/ip can be a member of multiple groups 
# Ex 1: Ungrouped hosts, specify before any group headers. 
#green.example.com 
10.20.0.2 

[servers]  
10.20.0.3 
10.20.0.4 
10.20.0.5 
10.20.0.6 
10.20.0.7 
10.20.0.8 

 
[computes] 
10.20.0.4 
10.20.0.5 
10.20.0.6 
10.20.0.7 
10.20.0.8 

[mesos] 
111.111.111.15 
111.111.111.16 
 

Now to run a command:

example #1 run cmd on all servers

#ansible all -a "date"
10.20.0.4 | success | rc=0 >> 
Thu Apr 16 10:18:27 UTC 2015 
10.20.0.6 | success | rc=0 >> 
Thu Apr 16 10:18:27 UTC 2015 
10.20.0.7 | success | rc=0 >> 
Thu Apr 16 10:18:27 UTC 2015 
10.20.0.5 | success | rc=0 >> 
Thu Apr 16 10:18:27 UTC 2015 
10.20.0.8 | success | rc=0 >> 
Thu Apr 16 10:18:28 UTC 2015
10.20.0.2 | success | rc=0 >> 
Thu Apr 16 10:18:28 UTC 2015 
111.111.111.16 | success | rc=0 >>
Thu Apr 16 10:18:28 UTC 2015
111.111.111.15 | success | rc=0 >>
Thu Apr 16 10:18:28 UTC 2015
10.20.0.3 | success | rc=0 >> 
Thu Apr 16 10:18:28 UTC 2015




example #2 run hostname cmd on all servers


# ansible computes -a "hostname" 
10.20.0.8 | success | rc=0 >> 
node-6.domain.tld 
10.20.0.4 | success | rc=0 >> 
node-2.domain.tld 
10.20.0.6 | success | rc=0 >> 
node-4.domain.tld 
10.20.0.7 | success | rc=0 >> 
node-5.domain.tld 
10.20.0.5 | success | rc=0 >> 
node-3.domain.tld

Sunday, March 15, 2015


example for iptables on centos:


# configuration written by system-config-securitylevel
# Manual customization of this file is not recommended.

#################################################################################
# Filtering table:
#################################################################################
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [0:0]

######################################################
# INPUT - beginning
# -----------------
# allow packets of already established connections:
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

# INPUT to firewall from loopback - all allowed (lo)
# --------------------------------------------------
-A INPUT -i lo -j ACCEPT

# INPUT to firewall - from NTTNode (eth2)
# --------------------------------------
# allow any traffic from inside:
-A INPUT -i eth2 -j ACCEPT

# INPUT to firewall - from OpenVPN connections (tun0)
# ---------------------------------------------------
# allow any traffic for OpenVPN clients:
-A INPUT -i tun0 -s 192.168.100.0/24 -j ACCEPT

# INPUT to firewall - from KVM VMs connections (virbr0)
# ---------------------------------------------------
# allow any traffic for KVM VMs:
-A INPUT -i virbr0 -s 10.80.90.0/24 -j ACCEPT

# INPUT to firewall - from Internet (eth3)
# ----------------------------------------
# allow pings for connection testing:
-A INPUT -i eth0 -p icmp --icmp-type echo-request -j ACCEPT

#
# allow incoming OpenVPN connections:
-A INPUT -i eth0 -p tcp -m state --state NEW -m tcp --dport 1194 -j ACCEPT
-A INPUT -i eth0 -p udp -m state --state NEW -m udp --dport 1194 -j ACCEPT
#
# allow SSH on port 22000
-A INPUT -i eth0 -p tcp -m tcp --dport 22000 -m state --state NEW -j ACCEPT

######################################################

# FORWARDING - beginning
# ----------------------
# allow packets of already established connections:
-A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT

# FORWARDING - from NTTNode to Internet (eth2 --> eth0)
# ----------------------------------------------------
# allow any outgoing traffic:
-A FORWARD -i eth2 -o eth0 -j ACCEPT

# FORWARDING - from NTTNode to OpenVPN clients (eth0 --> tun0)
# -----------------------------------------------------------

# FORWARDING - from Internet to CI VM (eth0 --> virbr0)
# ---------------------------------------------------
-A FORWARD -i eth0 -o virbr0 -j ACCEPT

# FORWARDING - from NTTNode to CI VM (eth2 --> virbr0)
# ---------------------------------------------------
-A FORWARD -i eth2 -o virbr0 -j ACCEPT

# FORWARDING - from OpenVPN to Node12 (tun0 --> eth2)
# ---------------------------------------------------
# allow any traffic for OpenVPN users:
-A FORWARD -i tun0 -o eth2 -s 192.168.100.0/24 -j ACCEPT

# FORWARDING - from CI VM to NTTNode (virbr0 --> eth2)
# ----------------------------------------------------
# allow any traffic for OpenVPN users:
-A FORWARD -i virbr0 -o eth2 -j ACCEPT

# FORWARDING - from CI VM to Internet (virbr0 --> eth0)
# ----------------------------------------------------
# allow any traffic for OpenVPN users:
-A FORWARD -i virbr0 -o eth0 -j ACCEPT

# FORWARDING - from CI VM to OpenVPN client (virbr0 --> tun0)
# ---------------------------------------------------
# allow any traffic for OpenVPN users:
-A FORWARD -i virbr0 -o tun0 -j ACCEPT

# FORWARDING - from OpenVPN client to CI VM (tun0 --> virbr0)
# ---------------------------------------------------
# allow any traffic for OpenVPN users
-A FORWARD -i tun0 -o virbr0 -j ACCEPT

# FORWARDING - from OpenVPN to Internet (tun0 --> eth0)
# -----------------------------------------------------
-A FORWARD -i tun0 -o eth0 -j ACCEPT

# FORWARDING - from kvm to kvm (virbr0 --> virbr0)
# ----------------------------------------------------
-A FORWARD -i virbr0 -o virbr0 -j ACCEPT

# FORWARDING - from Internet to OpenVPN clients (eth0 --> tun0)
# -------------------------------------------------------------

# FORWARDING - from Internet to CI VM (eth0 --> virbr0)
# ----------------------------------------------------

# FORWARDING - from CI VM to Internet (virbr0 --> eth0)
# ----------------------------------------------------
-A FORWARD -i virbr0 -o eth0 -j ACCEPT

# FORWARDING - from NTTNode to OpenVPN clients (eth2 --> tun0)
# ----------------------------------------------------
-A FORWARD -i eth2 -o tun0 -j ACCEPT

# COMMIT filtering rules
COMMIT

#################################################################################
# NAT table:
#################################################################################
*nat
:PREROUTING ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]

# enable NAT for any outgoing traffic (eth2-->eth0 or tun0-->eth0)
-A POSTROUTING -o eth0 -j MASQUERADE

# COMMIT NAT rules
COMMIT

Monday, November 3, 2014

How to troubleshoot openstack neutron?

neutron net-list
neutron router-list
neutron subnet-list
neutron port-list
ovs-vsctl show ip netns list
How to disable server on OpenStack-nova

[root@os-controller ~(keystone_admin)]# nova service-disable compute-0-3.local nova-compute
+-------------------+--------------+----------+
| Host              | Binary       | Status   |
+-------------------+--------------+----------+
| compute-0-3.local | nova-compute | disabled |
+-------------------+--------------+----------+
[root@os-controller ~(keystone_admin)]# nova-manage service list
Binary           Host                                 Zone             Status     State Updated_At
nova-consoleauth os-controller.local                  internal         enabled    :-)   2014-07-21 09:45:47
nova-scheduler   os-controller.local                  internal         enabled    :-)   2014-07-21 09:45:48
nova-conductor   os-controller.local                  internal         enabled    :-)   2014-07-21 09:45:48
nova-cert        os-controller.local                  internal         enabled    :-)   2014-07-21 09:45:51
nova-compute     compute-0-3.local                    nova             disabled   XXX   2014-07-21 09:42:36
nova-compute     compute-0-2.local                    nova             enabled    :-)   2014-07-21 09:45:47
nova-compute     compute-0-1.local                    nova             enabled    :-)   2014-07-21 09:45:48
nova-compute     compute-0-0.local                    nova             enabled    :-)   2014-07-21 09:45:47
nova-console     os-controller.local                  internal         enabled    :-)   2014-07-21 09:45:55
[root@os-controller ~(keystone_admin)]#

How to list ports on Openstack neutron?

from os neutron run:
#neutron port-list | awk '{print $2}' | xargs --verbose -i neutron port-show {} | grep -i device
How to re-size qcow2 image using guest-fish?


#######################################################################################################################################################################################################################
resize Image using virt-resize i.e. guestfish
#######################################################################################################################################################################################################################
1.copy the original image twice not to harm the original
# cp tinyCentos.qcow2 tinyCentosTmp.qcow2
# cp tinyCentos.qcow2 tinyCentos30.qcow2

2.view all file systems:
[root@s4-5 templates]# virt-filesystems --long -h --all -a tinyCentos30.qcow2
Name                  Type       VFS  Label MBR Size Parent
/dev/sda1             filesystem ext4 -     -   500M -
/dev/VolGroup/lv_root filesystem ext4 -     -   3.5G -
/dev/VolGroup/lv_swap filesystem swap -     -   1.0G -
/dev/VolGroup/lv_root lv         -    -     -   3.5G /dev/VolGroup
/dev/VolGroup/lv_swap lv         -    -     -   1.0G /dev/VolGroup
/dev/VolGroup         vg         -    -     -   4.5G /dev/sda2
/dev/sda2             pv         -    -     -   4.5G -
/dev/sda1             partition  -    -     83  500M /dev/sda
/dev/sda2             partition  -    -     8e  4.5G /dev/sda
/dev/sda              device     -    -     -   5.0G -


3.enlarge the image by 30Gb:
[root@s4-5 templates]# qemu-img resize tinyCentos30.qcow2 +30G
Image resized.


4.View the filesystems after enlargement:
[root@s4-5 templates]# virt-filesystems --long -h --all -a tinyCentos30.qcow2
Name                  Type       VFS  Label MBR Size Parent
/dev/sda1             filesystem ext4 -     -   500M -
/dev/VolGroup/lv_root filesystem ext4 -     -   3.5G -
/dev/VolGroup/lv_swap filesystem swap -     -   1.0G -
/dev/VolGroup/lv_root lv         -    -     -   3.5G /dev/VolGroup
/dev/VolGroup/lv_swap lv         -    -     -   1.0G /dev/VolGroup
/dev/VolGroup         vg         -    -     -   4.5G /dev/sda2
/dev/sda2             pv         -    -     -   4.5G -
/dev/sda1             partition  -    -     83  500M /dev/sda
/dev/sda2             partition  -    -     8e  4.5G /dev/sda
/dev/sda              device     -    -     -   35G  -


5.resize the lvm partitions:
[root@s4-5 templates]# virt-resize --expand /dev/sda2 --LV-expand /dev/VolGroup/lv_root  tinyCentosTmp.qcow2 tinyCentos30.qcow2
Examining tinyCentosTmp.qcow2 ...
**********

Summary of changes:

/dev/sda1: This partition will be left alone.

/dev/sda2: This partition will be resized from 4.5G to 34.5G.  The LVM
    PV on /dev/sda2 will be expanded using the 'pvresize' method.

/dev/VolGroup/lv_root: This logical volume will be expanded to maximum
    size.  The filesystem ext4 on /dev/VolGroup/lv_root will be
    expanded using the 'resize2fs' method.

**********
Setting up initial partition table on tinyCentos30.qcow2 ...
Copying /dev/sda1 ...
 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
Copying /dev/sda2 ...
 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
Expanding /dev/sda2 using the 'pvresize' method ...
Expanding /dev/VolGroup/lv_root using the 'resize2fs' method ...

Resize operation completed with no errors.  Before deleting the old
disk, carefully check that the resized disk boots and works correctly.
[root@s4-5 templates]#


6.Optional if you want to compress it run:
[root@s4-5 ready_for]# qemu-img convert -c -f qcow2 -O qcow2 tinyCentos30.qcow2 tinyCentos30diet.qcow2
[root@s4-5 ready_for]# ll
-rw-r--r-- 1 root root  307429376 Sep  3 02:08 tinyCentos30diet.qcow2
-rw-r--r-- 1 root root 5854593024 Sep  3 01:15 tinyCentos30.qcow2
-rw-r--r-- 1 root root  943587328 Jun 22 06:02 tinyCentos.qcow2
-rw-r--r-- 1 root root  943587328 Sep  3 01:08 tinyCentosTmp.qcow2
[root@s4-5 ready_for]#
How to re-size a qcow2 image?

#stop VM and from the hypervisor resize its disk
[root@compute-0-0 ~]# qemu-img resize /zone01/image.qcow2 +35G
Image resized.
-----------------------------------------------------------------------------------------------
#start the VM and login to it
#run fdisk -l
[root@dev ~]# fdisk -l

Disk /dev/vda: 69.8 GB, 69793218560 bytes
16 heads, 63 sectors/track, 135233 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00043b46

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *           3        1018      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2            1018       62416    30944256   8e  Linux LVM
Partition 2 does not end on cylinder boundary.

Disk /dev/mapper/vg_dev-lv_root: 25.4 GB, 25375539200 bytes
255 heads, 63 sectors/track, 3085 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/vg_dev-lv_root doesn't contain a valid partition table

Disk /dev/mapper/vg_dev-lv_swap: 6308 MB, 6308233216 bytes
255 heads, 63 sectors/track, 766 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/vg_dev-lv_swap doesn't contain a valid partition table
[root@dev ~]#
-----------------------------------------------------------------------------------------------
#run fdisk on the extended dev
[root@dev ~]# fdisk /dev/vda

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (1-135233, default 1): 62417
Last cylinder, +cylinders or +size{K,M,G} (62417-135233, default 135233):
Using default value 135233
Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/vda: 69.8 GB, 69793218560 bytes
16 heads, 63 sectors/track, 135233 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00043b46

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *           3        1018      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2            1018       62416    30944256   8e  Linux LVM
Partition 2 does not end on cylinder boundary.
/dev/vda3           62417      135233    36699768   8e  Linux LVM

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
-----------------------------------------------------------------------------------------------
#reboot the vm
#when the VM goes up:
[root@dev ~]# pvscan
  PV /dev/vda2   VG vg_dev   lvm2 [29.51 GiB / 0    free]
  Total: 1 [29.51 GiB] / in use: 1 [29.51 GiB] / in no VG: 0 [0   ]
[root@dev ~]#
-----------------------------------------------------------------------------------------------
#create Physical volume
[root@dev ~]# pvcreate /dev/vda3
  Writing physical volume data to disk "/dev/vda3"
  Physical volume "/dev/vda3" successfully created
[root@dev ~]#
-----------------------------------------------------------------------------------------------
#extend Volume group
[root@dev ~]# vgextend vg_dev /dev/vda3
  Volume group "vg_dev" successfully extended
[root@dev ~]# pvscan
  PV /dev/vda2   VG vg_dev   lvm2 [29.51 GiB / 0    free]
  PV /dev/vda3   VG vg_dev   lvm2 [35.00 GiB / 35.00 GiB free]
  Total: 2 [64.50 GiB] / in use: 2 [64.50 GiB] / in no VG: 0 [0   ]
[root@dev ~]#
-----------------------------------------------------------------------------------------------
#Extending logical volume
[root@dev ~]# lvextend -L+34G /dev/vg_dev/lv_root
  Extending logical volume lv_root to 57.63 GiB
  Logical volume lv_root successfully resized
[root@dev ~]#
-----------------------------------------------------------------------------------------------
#resizing the file system
[root@dev ~]# resize2fs /dev/vg_dev/lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_dev/lv_root is mounted on /; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 4
Performing an on-line resize of /dev/vg_dev/lv_root to 15108096 (4k) blocks.
The filesystem on /dev/vg_dev/lv_root is now 15108096 blocks long.
[root@dev ~]#
[root@dev ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_dev-lv_root
                       57G  3.5G   51G   7% /
tmpfs                 1.9G   88K  1.9G   1% /dev/shm
/dev/vda1             485M   36M  424M   8% /boot
[root@dev ~]#


more commands:
#Extend to all free size
lvextend -l+100%FREE /dev/VolGroup/lv_home

#show vol groups
vgdisplay