Tuesday, January 3, 2017

Setup ansible environment with specific version on Ubuntu


sudo apt-get update
sudo apt-get install python-dev python-pip libssl-dev libffi-dev -y
sudo pip install --upgrade pip

sudo pip install six==1.10.0
sudo pip install shade==1.16.0
sudo pip install ansible==2.2.1.0

The versions above shows the versions which were used by OpenStack Interop Challenge workload needed versions.

Tuesday, December 13, 2016

cron automation

Use cron to setup automated log file removal or other periodic tasks in linux environment is very useful. Here are the steps to automate that.

1. Run the following command to export the current crontab:
 
crontab -u john -l > john-cron-backup.txt

2. Edit the exported john-cron-backup.txt file to your need.

3. Run the following command to restore from the edited file to make it taking effects:
    
crontab -u john john-cron-backup.txt
 
Here is an example backup file: 

MAILTO=""
SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin

# m h  dom mon dow   command
0 1 * * 1 rm -r -f /var/log/**/*.gz
0 1 * * 1 rm -r -f /var/log/**/*.log.1
0 1 * * 1 rm -r -f /var/log/*.gz
 
    
 

Tuesday, December 6, 2016

How to backup and restore alive Ubuntu server

Backup and restore alive Ubuntu system is useful for developers who maintain and install systems all the time, the follow procedure should help when your system is using lvm file system.

Backup the live Ubuntu system by following the below steps:

Use df -h command to figure out what is the logical volume where the root file system is on. Also look into /dev directory for the logical volumes. In the example below, the logical volume that holds the entire system is /dev/vg00/vg00-lv01

Only do this once when the system is clean:
1. Create a logical volume from a volume group (vg01) which will store the backup:
           lvcreate -L 40G -n space vg01
2. Create the file system on the new logical volume:
           mkfs -t ext4 /dev/vg01/space
3. Create snapshot of the root logical volume:
           lvcreate --size 6G -s -n cleansystem /dev/vg00/vg00-lv01
4. Create a directory to mount the logical volume:
           mkdir /space
           mount /dev/vg01/space /space           mkdir -p /space/snap /space/backup
5. Mount snapshot and save everything
          mount /dev/vg00/cleansystem /space/snap
          cd /space/snap
          tar -pczvf /space/backup/cleansystem.tar.gz *
          umount /space/snap
          lvremove /dev/vg00/cleansystem

After these steps, a tar.gz file named cleansystem.tar.gz should be produced in /space/backup directory. This is the file should be kept for restore later.

Restore the Ubuntu sytem by following the below steps:

The follow steps are to recover the system from the saved tar.gz in /space/backup directory, assume that the logical volume which contains the backup tar.gz file has been mounted on /space.

lvcreate —size 20G -s -n resetpoint /dev/vg00/vg00-lv01

mount /dev/vg00/resetpoint /space/snap

cd /space/snap

rm -r -f *

tar -xvf /space/backup/cleansystem.tar.gz

umount /space/snap

lvconvert —merge /dev/vg00/resetpoint

Monday, November 28, 2016

crontab gotches

when you use crontab -e to add new tasks, the chances are that you found that for some reason that your scripts or command did not seem to run, the reason most likely is because that path was not set up right. Since cron job does not actually have any environment variables setup, so these command which normally resides in /bin, /sbin probably can not be found, the easy solution is to add that at the top of the crontab file when you start the following command:

    crontab -e

MAILTO=""
SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin

The MAILTO will make sure that the script won't try to send out an email on the command output.

Wednesday, November 16, 2016

Useful networking commands

  
1. Add a default gateway:
 
route add default gw {IP-ADDRESS} {INTERFACE-NAME}
 
for example:
  route add default gw 9.30.217.1 br-ex
 
 
2. Find the default gateway:
 
route -n
 
The destination with 0.0.0.0 should indicate the default gateway and its interface
 
3. How to assign ip, broadcast and netmask to an interface:
 
ifconfig eth0 172.16.25.125 netmask 255.255.255.224 broadcast 172.16.25.63
 
4. Assign ip, broadcast and netmask using ip command:
 
ip address add {IP_CIDR} brd + dev {INTERFACE-NAME} 
 
for example: 
 
    ip addr add 192.168.1.50/24 brd + dev eth0 
 
5. Add a default gateway using IP command:
 
ip route add default via {GATEWAY_IP_ADDRESS} dev {INTERFACE-NAME

for example:

   ip route add default via 9.30.217.1 dev br-ex
 

Thursday, November 10, 2016

Excellent OVN related information

Dustin Spinhirne has these excellent OVN blogs, having the link below to be referenced often.

http://blog.spinhirne.com/p/blog-series.html#introToOVN

Few network related commands

To see how many bridges exist in your system:

      ovs-vsctl list-br

To verify the connectivities amongs hosts:

     netstat -antp | grep destination-IP
   
     For example, to see a host and the connectivity at ip 10.0.2.25, use this command:
  
  netstat -antp | grep 10.0.2.25
 
  Here is the results:
 
tcp        0      0 10.0.2.26:60536         10.0.2.25:5672          ESTABLISHED 6977/python
tcp        0      0 10.0.2.26:60526         10.0.2.25:5672          ESTABLISHED 31103/python
tcp        0      0 10.0.2.26:34444         10.0.2.25:6642          ESTABLISHED 6717/ovn-controller
tcp        0      0 10.0.2.26:60542         10.0.2.25:5672          ESTABLISHED 6977/python
tcp        0      0 10.0.2.26:60538         10.0.2.25:5672          ESTABLISHED 6977/python
tcp        0      0 10.0.2.26:39282         10.0.2.25:3306          ESTABLISHED 31103/python
tcp        0      0 10.0.2.26:60528         10.0.2.25:5672          ESTABLISHED 31103/python
 
5672 is the default port for rabbitmq
6642 is the port for ovn south bound db
3306 is the default port for mysql