Tuesday, July 28, 2015

Migrating Cacti from One Server to another (Ubuntu 12.04 to Ubuntu 14.04)

You may need to migrate cacti from one server to another due to one reason or another, i did this lab migration from ubuntu server 12.04 to 14.04, i use this HOW TO (http://lifein0and1.com/2008/05/15/migrating-cacti-from-one-server-to-another/), doing some few modification according to need. Below are steps

1. Install Cacti on the New Server
2. Turn Off Cacti at the Old Server
3. Migrate the Database
4. Copy the RRD Files as XML
5.Reconvert the XML back to RRD File
6. Activate the New Cacti


1.  Install Cacti on the New Server
a. Use the following link (http://www.unixmen.com/install-cacti-ubuntu-14-04/), after finishing installation on command line, don't go to browser until step 6 when activating the new cacti.

b. Turn-off the poller
Run the command

$ sudo vim /etc/cron.d/cacti

Disable the poller by putting the character ‘#’ in front of the crontab entry then save & quit


2. Turn Off Cacti at the Old Server
Run the command

$ sudo vim /etc/cron.d/cacti

Disable the poller by putting the character ‘#’ in front of the crontab entry then save & quit.


3. Migrate the Database
a. At the old server run the command

$ sudo mysqldump -u root  -p  cacti > ~/cacti.sql

When it asks for the password, enter the password for mysql database

b. SCP on the old data and grap the data and move it to new server.

c. On the server run the following
$ sudo mysql -u root -p cacti < ~/cacti.sql


4. Copy the RRD Files as XML
Do the following on the old server

a. Go to the directory
$ cd /var/lib/cacti/rra/

c. Run the script
$ sudo ls -1 *.rrd | awk '{print "rrdtool dump "$1" > "$1".xml"}' | sh -x

d. Tar and Gzip the XML files using the command
$ sudo tar -czvf ~/rrd.tgz *.rrd.xml


5.Reconvert the XML back to RRD File

a. SFTP into the old server and download the ‘rrd.tgz’ created in the step before

b. Move the file to the new directory
/var/lib/cacti/rra/

c. Untar the file
tar -xzvf rrd.tgz

d. Run the command
$ sudo ls -1 *.rrd.xml | sed 's/\.xml//' | awk '{print "rrdtool restore "$1".xml "$1}' | sh -x

e. Change ownership of all RRD files to www-data by running the command:
$ sudo chown www-data:www-data *.rrd


6. Activate the New Cacti

a. Visit the new site and set the mode to ‘Upgrade’
b. Reactivate the Poller

Run the command
$ sudo vi /etc/cron.d/cacti

Enable the poller by removing the character ‘#’ in front of the crontab entry then save & quit


Enjoy!

Monday, July 27, 2015

How to mount/connect usb drive in Linux server

If you want to copy something from/to the server from usb drive, your required to connect it or simply mounting the usb, below are steps

a. Connect the usb drive to the server

b. Check if it is connected by running the following command

  #fdisk -l

eg.

root@myserver:/home/admin# fdisk -l

Disk /dev/sda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders, total 312581808 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000cff3c

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      499711      248832   83  Linux
/dev/sda2          501758   312580095   156039169    5  Extended
/dev/sda5          501760   312580095   156039168   8e  Linux LVM

Disk /dev/mapper/cpvirt--vg-root: 155.6 GB, 155604484096 bytes
255 heads, 63 sectors/track, 18917 cylinders, total 303915008 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/cpvirt--vg-root doesn't contain a valid partition table

Disk /dev/mapper/cpvirt--vg-swap_1: 4177 MB, 4177526784 bytes
255 heads, 63 sectors/track, 507 cylinders, total 8159232 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/cpvirt--vg-swap_1 doesn't contain a valid partition table
Note: sector size is 4096 (not 512)

Disk /dev/sdb: 3000.6 GB, 3000592982016 bytes
255 heads, 63 sectors/track, 45600 cylinders, total 732566646 sectors
Units = sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x000b061a

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *         256   732566591  2930265344   83  Linux



c. Create a new mount point/directory where the usb disk will be mounted

# mkdir /mnt/sdb1


d.  Mount /dev/sdb1 which is the location of our usb disk to the new created mount point

#mount -t ext4 /dev/sdb1 /mnt/sdb1

e. To make the change permanent edit /etc/ftab with the new mount point

# echo ''/dev/sdb1 /mnt/sdb1 ext4 defaults 0 0'' >> /etc/fstab


f. Mount all entries in /etc/fstab in not already mounted

# mount -a

g. Check if the usb drive is mounted

#mount | grep sdb1

h. The mounting is done, to access usb drive content, you may run the following command

# cd /mnt/sdb1



Enjoy!



Friday, July 17, 2015

How to repair filesystem in Linux after power failure

For some of the countries, its normal to have power fluctuations and you find your linux server goes down due to power failure, when it comes up, it good linux administration practice to repair incase there is any corrupted file system due to power failure, below is the command


$ sudo Shutdown -Fr now

Only that command will make your life good after power failure. Enjoy!

Sunday, July 12, 2015

Controlling user bandwidth by Firewall and Queues in Mikrotik Router

Heavy downloads and uploads has become problems in most of networks now days, as users are running different bandwidth hungry applications such as peer-to-peer, video downloads etc which lead to slow down of whole network because of only one single user or some few users who are doing heavy downloads/uploads.
This lab is going to show you how to limit all users to specific speed in three simple steps using firewall mangle rules and queues in mikrotik router, in this lab am going to limit all users at 1Mbps bandwidth speed, which means that will be maximum speed reached by each particular user in the network despite available bandwidth.

Below are steps

a.  Create a customized queue types with preferred speed for each individual user,

Command:

/queue types

add name="PCQ_Download" kind=pcq pcq-rate=1M pcq-limit=50 
     pcq-classifier=dst-address pcq-total-limit=2000 pcq-burst-rate=0 
     pcq-burst-threshold=0 pcq-burst-time=10s pcq-src-address-mask=32 
     pcq-dst-address-mask=32 pcq-src-address6-mask=64 pcq-dst-address6-mask=64 

add name="PCQ_Upload" kind=pcq pcq-rate=1M pcq-limit=50 
     pcq-classifier=dst-address pcq-total-limit=2000 pcq-burst-rate=0 
     pcq-burst-threshold=0 pcq-burst-time=10s pcq-src-address-mask=32 
     pcq-dst-address-mask=32 pcq-src-address6-mask=64 pcq-dst-address6-mask=6


By winbox or web config:

Go to Queues-Queue Types, and add , example below is for PCQ_Download


b. Mark all the packet, which is to be queued for specific speed

Command:

/ip firewall mangle
 add chain=prerouting action=mark-packet new-packet-mark=user_download 
     passthrough=yes in-interface=wlan1-gateway 

 add chain=prerouting action=mark-packet new-packet-mark=user_upload 
     passthrough=yes in-interface=ether1-local

Note am marking download packets from wan interface in which for my case is wireless interface because am using wireless radio as a router, also am marking upload from LAN interfaces in which from this lab is ether1-local

By winbox or web config:
Go to ip firewall mangle , and add, example below is for user dowload




c. Finally create a tree queue for limiting every individual user speed

Command:

/queue tree
  add name="UserDownload" parent=global packet-mark=user_download 
     limit-at=0 queue=PCQ_Download priority=8 max-limit=0 burst-limit=0 
     burst-threshold=0 burst-time=0s 

  add name="UserUpload" parent=global packet-mark=user_upload limit-at=0 
     queue=PCQ_Upload priority=8 max-limit=0 burst-limit=0 
     burst-threshold=0 burst-time=0

By winbox or web config:
Go to queue tree , and add, example below is for user dowload

You're done, below is the torch output before and after settings

Before:

Single user was able to reach 2.2Mbps


After:
All users are limited at 1Mbps as per our setting


Hope it help someone, drop me a comment, if you face difficulties implementing any of the step.

Cheers!

Saturday, July 11, 2015

Ubuntu 14.04 Lost Password recovery

There are cases when you forget the login password of your Linux machine, as this case which happens to my friend who is new to Linux, after installing the Linux server he didn't remember the password of the user he created during installation, so he was planning to re-install the server, there is no need for doing re-installation, just follow the following procedure to recover your password.


  1. Boot your system and choose Advanced Options for Ubuntu,


    2.   Then, choose Recovery mode,


   3. It will take you to different recovery mode options,

  4. From Recovery Menu Options, choose to Drop to root shell prompt


  5. It is going to drop you on shell prompt, you need to run the following         
      commands to change you password.

       i. First is to mount root file system
           # mount -rw -o remount /
  
       ii. In case you don't remember the user you created during installation, 
           check the created users in the system by running the following
            # ls  /home/

          Output may differ, according to the user created, for this case of mine,   there was only one user called silas

       iii. Change the password of the existed user
             # passwd silas

        iv. After changing the password your done, now reboot your system
              # reboot


Hope is going to help someone, Enjoy!