Tuesday, February 9, 2010

SUDO on FreeBSD

as root install

sudo located at /usr/ports/security/sudo
make configure
make && make install

edit conf at

ee /usr/local/etc/sudoers

example and edit :

# Runas alias specification

# User privilege specification
root ALL=(ALL) ALL
kenan ALL=(www) ALL

note :

This Sudo command limits the user's power on the basis of the configuration made on the file "/etc/sudoers".
Generally in default case you might see something like this:

root ALL=(ALL) ALL
Above, you can see ALL 3 times. But what does it mean?
The first ALL: Run from any(all) host
The Second ALL: From any Terminal
The third ALL: Can Run any command

example :
usename ALL=(group) ALL


** note : !/usr/bin/su (this will prevent user to sudo su)

General sudoers File Record Format
usernames/group servername = (usernames command can be run as) command

Lock / Unlock user on FreeBSD

Lock user :

pw lock nameuser

unlock user :

pw unlock nameuser

Tuesday, January 19, 2010

Rollback with MySQL Transaction Log

Yesterday was a Grey Monday (almost turning into Black Monday)..

It happened that one of the MySQL DB was not backed-up and to make things more thrilling, one the table on the db was compromised.
Alhamdulillah, again, Zaman came to save the day.

Here what we did to rollback the transaction using the transaction log :

  1. Read the transaction log in /var/db/myql/hostname-bin.xxxxxx
    This is binary format. In order to read the file, you have to use mysqlbinlog command :

    mysqlbinlog mysql-bin.000001

    This will show every single transaction happened on that particular server.

  2. Then setup new MySQL server (I strongly advise you to setup a new database since we do not want to mess the existing one.)

  3. Dump the compromised db structure only (without data) then restore it in the new server.

  4. Then simply run the mysqlbinlog command and extend it to restore back to the server :

    mysqlbinlog mysql-bin.xxxxxx --database=yourdbname | mysql -uroot -p yourdbname

    If you want to exclude the last transaction which normally will be the culprit, you can use --stop-datetime option. You should know when is the last point/time (before the culprit transaction) of the transaction.



    By reading the transaction log, you will find the timestamp provided by MySQL. For example : 1263759884

    Since mysqlbinlog format needs human readable format, you have to convert the timestamp to human readable format. Here is one of the online date converter :

    http://www.epochconverter.com/

    Once converted, append it into the command :



    mysqlbinlog mysql-bin.000024 --database=yourdbname --stop-datetime="2010-01-17 22:11:16" | mysql -uroot -p yourdbname

    That's it.

Thursday, January 14, 2010

Add HDD on VMWARE (linux)

- choose vm that you wish to add the HDD
- edit setting
- add and choose HDD
- follow the instruction
- fdisk -l to see all hdd status
- you will noticed /dev/sdb (not partitoned)
- format new partition : [root@localhost ~]# mkfs -t ext3 /dev/sdb1
-
Create mount point and set up automatic mount when system start up [root@localhost ~]# mkdir /newdisk
-
Add the following line into fstab
/dev/sdb1 /newdisk ext3 defaults 1 1

reboot machine


Wednesday, January 13, 2010

Add HDD on VMWARE (FreeBSD)

I just finish adding HDD onto my Vmware server.

the step :

- choose vm that you wish to add the HDD
- edit setting
- add and choose HDD
- follow the instruction
- after adding go to server (freebsd)
- type sysinstall
- choose fdisk
- BEWARE! please make sure your HDD before you format it!
- after you choose your HDD, choose A and W (write the HDD)
- after finish,exit and choose label
- choose C (create) , edit the label and W (write) the HDD.
- edit the fstab (ee /etc/fstab)

example :
but beware too remember the path your HDD before edit the fstab.

/dev/da1s1d /data ufs rw 2 2

- save and reboot.