Thursday, November 4, 2010

How To Monitor Mysql using Zenoss

On the Zenoss server ensure your device has the Mysql zenpack

On the mysql server you plan to monitor do the following;

Add a user to Mysql so that zenoss can connect.

mysql -u root -p

grant ALL PRIVILEGES ON *.* TO ‘zenoss’@'yourzenossdomain’ IDENTIFIED BY ‘yourpassword’;

FLUSH PRIVILEGES;

Don’t forget to open port 3306 on the firewall of the Mysql server if necessary.

On the Zenoss server add the mysql user and password to zproperties of the device.

If Mysql version <5> 5

You can test that your monitored server can authenticate from your Zenoss server by

mysql -u zenoss -p -h yourmonitoredserverip


credit to http://www.how-to-linux.com

Friday, October 29, 2010

Downgrade PHP on ubuntu Server

go to /usr/local/sbin

create this script

nano downgrade.sh

enter

#!/bin/bash
# by Ruben Barkow (rubo77) http://www.entikey.z11.de/

# Originally Posted by Bachstelze http://ubuntuforums.org/showthread.php?p=9080474#post9080474
# OK, here's how to do the Apt magic to get PHP packages from the karmic repositories:

echo "Am I root? "
if [ "$(whoami &2>/dev/null)" != "root" ] && [ "$(id -un &2>/dev/null)" != "root" ] ; then
echo " NO!

Error: You must be root to run this script.
Enter
sudo su
"
exit 1
fi
echo " OK";


# finish all apt-problems:
apt-get -f install

# remove all your existing PHP packages. You can list them with dpkg -l| grep php
PHPLIST=$(for i in $(dpkg -l | grep php|awk '{ print $2 }' ); do echo $i; done)
echo these pachets will be removed: $PHPLIST
# you need not to purge, if you have upgraded from karmic:
aptitude remove $PHPLIST
# on a fresh install, you need purge:
# aptitude remove --purge $PHPLIST


#Create a file each in /etc/apt/preferences.d like this (call it for example /etc/apt/preferences.d/php5_2);
#
#Package: php5
#Pin: release a=karmic
#Pin-Priority: 991
#
#The big problem is that wildcards don't work, so you will need one such stanza for each PHP package you want to pull from karmic:

echo ''>/etc/apt/preferences.d/php5_2
for i in $PHPLIST ; do echo "Package: $i
Pin: release a=karmic
Pin-Priority: 991
">>/etc/apt/preferences.d/php5_2; done

# duplicate your existing sources.list replacing lucid with karmic and save it in sources.list.d:
#sed s/lucid/karmic/g /etc/apt/sources.list | sudo tee /etc/apt/sources.list.d/karmic.list

# better exactly only the needed sources, cause otherwise you can get a cachsize problem:
echo "# needed sources vor php5.2:
deb http://de.archive.ubuntu.com/ubuntu/ karmic main restricted
deb-src http://de.archive.ubuntu.com/ubuntu/ karmic main restricted

deb http://de.archive.ubuntu.com/ubuntu/ karmic-updates main restricted
deb-src http://de.archive.ubuntu.com/ubuntu/ karmic-updates main restricted

deb http://de.archive.ubuntu.com/ubuntu/ karmic universe
deb-src http://de.archive.ubuntu.com/ubuntu/ karmic universe
deb http://de.archive.ubuntu.com/ubuntu/ karmic-updates universe
deb-src http://de.archive.ubuntu.com/ubuntu/ karmic-updates universe

deb http://de.archive.ubuntu.com/ubuntu/ karmic multiverse
deb-src http://de.archive.ubuntu.com/ubuntu/ karmic multiverse
deb http://de.archive.ubuntu.com/ubuntu/ karmic-updates multiverse
deb-src http://de.archive.ubuntu.com/ubuntu/ karmic-updates multiverse

deb http://security.ubuntu.com/ubuntu karmic-security main restricted
deb-src http://security.ubuntu.com/ubuntu karmic-security main restricted
deb http://security.ubuntu.com/ubuntu karmic-security universe
deb-src http://security.ubuntu.com/ubuntu karmic-security universe
deb http://security.ubuntu.com/ubuntu karmic-security multiverse
deb-src http://security.ubuntu.com/ubuntu karmic-security multiverse
" >> /etc/apt/sources.list.d/karmic.list

aptitude update

apache2ctl restart

echo install new from karmic:
aptitude -t karmic install $PHPLIST

# at the end retry the modul libapache2-mod-php5 in case it didn't work the first time:
aptitude -t karmic install libapache2-mod-php5

apache2ctl restart

chmod +x /usr/local/sbin/downgrade.sh
run the script
sh downgrade/sh

wait until it finish
now you done

Tuesday, August 31, 2010

APR-1 Apache upgrade problem

I face a problem when i want to upgrade apache form 2.2.14 to 2.2.16.
When the upgrade is running the running stop at apr-1
than this step save my life.

It wasn't clear to me, but, in the end I uninstalled apr1, and then let the 'apache install' reinstall it. Here's the sequence that worked for me

pkgdb -F;portsclean -CDD;portsnap fetch update
cd /usr/ports/www/apache22
make deinstall clean
portupgrade -f -o devel/apr1 devel/apr
cd /usr/ports/devel/apr1
make deinstall clean
cd /usr/ports/www/apache22
make install clean

Taken from http://forums.freebsd.org/archive/index.php/t-14338.html

Thursday, August 19, 2010

Portupgrade

I learn something new from my sifoo

try to run portupgrade :

portupgrade /var/db/pkg/namepackage

make fetch-recursive-list

Thursday, July 22, 2010

Mysql Replication

Follow this step to create / install a replication DB for mysql

http://www.howtoforge.com/mysql_database_replication

if uo have an error after / fini9sh installation using thie replication try this :

error 1 =

>LOAD DATA FROM MASTER;
Query OK, 0 rows affected, 1 warning (0.12 sec)
>

try to run this :

mysql> GRANT RELOAD on *.* to repl@'%' identified by 'your_password';
OR
mysql> GRANT SUPER on *.* to repl@'%' identified by 'your_password';



Reference : http://www.linuxismybff.com/howto/mysql/mysql-basic-replication-setup/

if you still have this warning error try to run this :

mysql -u root -p
Enter password:
SLAVE STOP;

CHANGE MASTER TO MASTER_HOST='192.168.0.100', MASTER_USER='slave_user', MASTER_PASSWORD='
', MASTER_LOG_FILE='mysql-bin.006', MASTER_LOG_POS=183;

START SLAVE;
quit;

Monday, June 28, 2010

Install SNMPD on Ubuntu

1.Installation

root@ibsen:~# sudo apt-get install snmpd
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libmpich1.0gf libdc1394-22 genisoimage linux-headers-2.6.27-7 libgfortran2 dvd+rw-tools linux-headers-2.6.27-7-generic libcarp-clan-perl libxml-xql-perl libparse-yapp-perl
rdate python-xml localechooser-data gcc-4.2-base libimage-size-perl libdebconfclient0 libvisual-0.4-0 libmyth-python perlmagick libvisual-0.4-plugins libavdevice52
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
libperl5.10 libsensors3 libsnmp-base libsnmp15
Suggested packages:
lm-sensors
The following NEW packages will be installed:
libperl5.10 libsensors3 libsnmp-base libsnmp15 snmpd
0 upgraded, 5 newly installed, 0 to remove and 3 not upgraded.
Need to get 2463kB of archives.
After this operation, 7987kB of additional disk space will be used.
Do you want to continue [Y/n]?

answer y

2. Configuration

Move existing /etc/snmp/snmpd.conf configuration file to /etc/snmp/snmpd.conf.org

mv /etc/snmp/snmpd.conf  /etc/snmp/snmpd.conf.org

Create a new /etc/snmp/snmpd.conf file:

rocommunity  public
syslocation "PDC, Peters DataCenter"
syscontact peter@it-slav.net

Make snmpd use the newly created file and make it listen to all interfaces:

Edit /etc/default/snmpd

Change from:

# snmpd options (use syslog, close stdin/out/err).
SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -I -smux -p /var/run/snmpd.pid 127.0.0.1'

To:

# snmpd options (use syslog, close stdin/out/err).
#SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -I -smux -p /var/run/snmpd.pid 127.0.0.1'
SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -I -smux -p /var/run/snmpd.pid -c /etc/snmp/snmpd.conf'

and restart snmpd

/etc/init.d/snmpd restart


Credit to http://www.it-slav.net/blogs/2009/02/05/install-and-configure-snmp-on-ubuntu/

Wednesday, June 23, 2010

Change usr directory to other HDD / Partition

to change the usr directory in freebsd (i already make it)
add new hdd to your server, format it. let say i give the new patition is /usr2
after finish format

cd /usr2
dump 0af - /usr | restore rf -

After the dump completed, edited /etc/fstab.
Delete the line with /usr in /etc/fstab.
Updated the line with /usr2, changed /usr2 for /usr. (inside fstab)
Then rebooted. Finally the system started with a new /usr filesystem.

Done!

Credit to BSD Forum!

reset your mysql root password

Stop mysql dulu

#/usl/local/etc/rc.d/mysql-server stop.

#mysqld_safe --skip-grant-tables

than open new shell and go to the mysql-server

#mysql --user=root mysql

now you enter the mysql server and run this command

update user set Password=PASSWORD('new-password') where user='root';
flush privileges;
exit;

start the server

done

Tuesday, June 15, 2010

make symbolic link on Unix

# ln -s /usr/home /home or ln -s /data/moodle2/ moodle2

Sunday, June 13, 2010

How to Lock / Unlock User in ubuntu

For Locking User from command Line

$ sudo usermod -L waxs This will Lock user account named waxs

For Locking User from command Line

$ sudo usermod -U waxs This will UnLock user account named waxs

Thursday, June 3, 2010

list all installed application on ubuntu

list all installed application on ubuntu

dpkg --get-selections

Tuesday, June 1, 2010

Centos - Adduser

You can also do this from the command line, below are the equivalent commands. You need to have root level access to use the commands below.
  • usr/sbin/useradd [options] login_name
    creates a new user
  • usr/sbin/usermod [options] login_name
    modifies a user’s attributes
  • usr/sbin/userdel [options] login_name
    deletes the specified user. Use the -r option to automatically remove the user’s home directory and mail spool.
  • usr/bin/passwd login_name
    sets the password for the specified user
  • usr/sbin/groupadd [options] group_name
    creates a new group
  • usr/sbin/groupmod [options] group_name
    modifies a group’s attributes
  • usr/sbin/groupdel group_name
    deletes the specified group

Sunday, May 23, 2010

Restore compressed backup files (MYSQL)

the commandline is :

gunzip < [backupfile.sql.gz] | mysql -u [uname] -p[pass] [dbname]

** if you dump file bz2 you can use bunzip2

Thursday, May 20, 2010

Script to rename multiple table in MySQL

Baru-baru ni aku faced problem untuk rename table prefix secara pukal...kat database tu ada 186 tables...
kalau nak tukar satu-satu...pergghh...memang lebam...setelah google punya google...aku jumpa solution ni...tapi kena pakai ruby script dan tukar ke sql statement..tapi kalau korang nak pakai convert ke php pun x de hal...guna concept yg sama jek...

Ikut ni :


  1. masuk mysql...pastu show tables;
  2. copy semua tables yg korang nak rename tu...
  3. paste kat dlm script ni (dlm cth ni aku bagi nama file ni batch_rename.sh ) :

    OLD_PREFIX = "mdl"
    NEW_PREFIX = "mdlsirap"
    data=<<-EOD | mdl_assignment | | mdl_assignment_submissions | | mdl_backup_config | | mdl_backup_courses | | mdl_backup_files | | mdl_backup_ids | | mdl_backup_log | | mdl_block | | mdl_block_instance |

    | mdl_block_pinned |

    EOD
    tables = []
    data.each_line do |line|
    if line=~/(#{OLD_PREFIX}\w+)/
    puts "RENAME TABLE #{$1} TO #{NEW_PREFIX}#{$1};"
    end
    end


  4. Pastu runkan script ni pakai ruby punya command-line (aku assume korang dah install ruby) :
    #ruby batch_rename.sh
  5. Dia akan kluar output :
    RENAME TABLE mdl_assignment TO mdlsirap_assignment;
    RENAME TABLE mdl_assignment_submissions TO mdlsirap_assignment_submissions;
    RENAME TABLE mdl_backup_config TO mdlsirap_backup_config;
    RENAME TABLE mdl_backup_courses TO mdlsirap_backup_courses;
    RENAME TABLE mdl_backup_files TO mdlsirap_backup_files;
    RENAME TABLE mdl_backup_ids TO mdlsirap_backup_ids;
    RENAME TABLE mdl_backup_log TO mdlsirap_backup_log;
    RENAME TABLE mdl_block TO mdlsirap_block;
    RENAME TABLE mdl_block_instance TO mdlsirap_block_instance;
    RENAME TABLE mdl_block_pinned TO mdlsirap_block_pinned;
  6. just masukan sql statement ni dlm satu file lain...tapi kalau nak senang...buat step no. 4 tu camni :
    #ruby batch_rename.sh > a.sql
  7. Runkan sql file tu guna mysql...:
    #mysql namadatabase <>
  8. Selesai....
reference :
http://zerokspot.com/weblog/e/676/

Wednesday, May 19, 2010

Repair table MYSQL

Today i face 1 problem when i want mysqldump my D. my error is

Incorrect key file for table 'mdl_block_instance'; try to repair it

This command to help you to auto-repair your table on mysql

mysqlcheck -uusername -p --auto-repair namedatabase

Tuesday, May 11, 2010

Netcat Tar

This is suitable if you don't have enough space on the source machine.

On sender :

tar -czf - directory-name | nc -l 3333

on receiver :

nc sender-ip-address 3333 > mybackup.tar.gz


Courtesy : Sifoo Zaman.

Change Login Directory (FreeBSD)

today i learn something.

How to change directory when login.

Login as root
setenv EDITOR ee (i need this because i don't know how to use VI in BSD)
type vipw
edit the directory at user you want to edit
save & exit

DONE

Thursday, May 6, 2010

Hidden Apache directory listing

If you are on an RPM installation of Apache (which i dont really recommend) you will find the apache configuration file probably here:

/etc/httpd/conf/httpd.conf

If you are using apache from the source tar balls ( like real men ) probably you will find the configuration file here:

/usr/local/apache/conf/httpd.conf

Using an editor like vi , edit the httpd.conf file and scroll until you find a line like this:

Options All Indexes FollowSymLinks MultiViews

To disable directory browsing carefully remove the line that says: Indexes and leave the line like this:

Options All FollowSymLinks MultiViews

Restart your apache webserver and thats it

reference http://www.felipecruz.com/blog_disable-directory-listing-browsing-apache.php

Tuesday, May 4, 2010

Setting Clock on Centos

what im doing to configure clock on centos

install ntp

yum install ntp

after finish run

ntpdate ntp.asia.pool.org

done!

Search using mysqlbinlog (troubleshoot)

simply go to or where your mysqlbinlog located :

after you find it run this command
mysqlbinlog mysql-bin.0000xx | grep nametosearch > namefile.txt

Dump using sed & mysqldump

Dump table mysql using sed

sed -n '/^-- Table structure for table \`nametable\`/,/^-- Table structure for table/p" namedb > namatable.sql

using mysqldump

mysqldump -c -u username -ppassword databasename tablename > /tmp/databasename.tablename.sql

restore DB / table

mysql -u username -ppassword databasename < /tmp/databasename.sql Dump table mysql using sed

sed -n '/^-- Table structure for table \`nametable\`/,/^-- Table structure for table/p" namedb > namatable.sql

using mysqldump

mysqldump -c -u username -ppassword databasename tablename > /tmp/databasename.tablename.sql

restore DB / table

mysql -u username -ppassword databasename < /tmp/databasename.sql

Mysqldump only the structure

run this command for mysql backup only the data structure

mysqldump -d -h localhost -u root -pmypassword databasename > dumpfile.sql

Wednesday, April 21, 2010

How To Rsync at Freebsd Using ssh.

Before rsync,your have to make sure your BSD box already insttaled rsync. If you don't have it please to do so and please to install both of your server.

You can install rsync using ports (Please to csup your ports 1st to get the new packages)

#cd /usr/ports/net/rsync/
#make config
#make && make install
#rehash.

Start to rsync.

i am only rsync forder usr/src.
#rsync -av -e "ssh -l admin" root@servername:/usr/src/ /usr/src/

After finish do not reboot, please re-compile.
** I recommended to csup the stable_supfile 1st before your compile your kernel.

#cd /usr/src
#make cleanworld && make cleandir
#make buildworld
#make buildkernel KERNCONF=YOUR_KERNEL_HERE' (default is GENERIC).
#make installworld
#make installkernel KERNCONF=YOUR_KERNEL_HERE' (default is GENERIC).
#reboot

Then start to rsync other folder.
Your can exclude any folder that you think not necessary.
I am rsync some folder such as boot or usr/src.

#rsync -av --exclude=/boot --exclude=/usr/src -e "ssh -l admin" root@servername:/ /

password will be prompted. Then enter password. wait until finish the rsync.

After finish

change ip address,hostname and vhost.

To change hostname.
#ee /etc/hosts

To change ip address
#ee /etc/rc.conf

to change vhost ** If you use it.
# ee /usr/local/etc/apache22/extra/httpd-vhosts.conf

then reboot your server

Rsync on linux box

Consider you already have 2 Linux server then open terminal or ssh at the new Linux server.

type command below

#rsync -av --exclude=/boot-e ssh username@oldserverhost:/(source) /(destination)

or standard rsync

#rsync -av -e ssh username@oldserverhost:/home/old_home/ /home/new_home/


password will be prom then enter password.
i exclude boot file because it need difficult configuration. You also can exclude the folder you want to rsync too such as /root /home /lib or anything else.

After finish the transferring data, your have to reconfigure, the Ip address,hostname or any necessary file need such as apache, mysql or others that you use.

*Ip tables or firewall at linux sometime need to stop to running the application.

Monday, March 22, 2010

Mysqldump

this how the usual CLI for mysqldump
mysqldump -u username -p dbname > backupname.sql

restore back from mysql

mysql -u username -p dbname '<' yousqldumpfile.sql

Recently, I was facing problem to restore a UTF8-Enabled database which stores a lot of Arabic text in the db itself.

I have to re-dump back the db by appending the --default-character-set=charset_name option in the dump command :

mysqldump -uroot -p --default-character-set=utf8 --databases yourdbname > yourdumpfile.sql

To restore, again you have to append the same option :

mysql -uroot -p --default-character-set=utf8 '<' youdumpsql.sql ** i need to add '<' because i will become hidden in this blog,if you want tu use the sqldump please to remove ' at '<' on restore CLI.

Thanks

Tuesday, March 16, 2010

Backup filesystem using dumpfs (FreeBSD)

finally i got to backup filesystem using dumpfs

- i got script from this web http://my.galagzee.com/2009/07/17/freebsd-dump-filesystem-shell-script/
- touch a new file name "dumpfs.sh" and put at /usr/local/sbin/
- paste the script inside dumpfs.sh
- set at /etc/crontab

to restore from backup dumps
- restore rf 20100305_0


reference :
- http://my.galagzee.com/2009/07/17/freebsd-dump-filesystem-shell-script/

Tuesday, March 9, 2010

Vmware format ubuntu add hdd

Let's get going!
Removing and creating a partition
Having decided your drive's name (let's call it sda) we must now remove the default partition that the manafacturer put there:
sudo fdisk /dev/sda
This will start fdisk. We want to remove the partion(s), there should only be one.
Press d (for delete).
It might ask you for the partition number, press 1 and enter. If there are more then delete them too.

Now to make a new partition.
Press n (for new), then p (for primary), then 1 and then simply press enter for the next two questions.
This will make a new partition that uses the entire disk. If you want more complex partitioning then read the fdisk manual (man fdisk) or use parted or some other app.
Here's what we did with n, the values will differ from yours:

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (197-621, default 197):
Using default value 197
Last cylinder or +size or +sizeM or +sizeK (197-621, default 621): +128M


Now to write the new partion and exit, press w and enter.
You should be ready to make a filesystem now.

Making a filesystem : "Formatting"
You need to put a system in-place, on the disk, such that it can handle files. This is called (unsurprisingly) a filesystem.
The one we are going to use is called "ext3". On Gnu/Linux we are spoiled for choice and there are loads of filesystems you can use, go do some research if you want to.
So, let's make the filesystem:sudo mkfs.ext3 /dev/sda1
* Note the 1 at the end, because we are making the filesystem in that partition (thanks Mike)

Now it will go off and do strange stuff, simply wait for it to finish.

Using the new file system
Well, at this point you should be able to right-click on the icon (on your Desktop) and choose "mount" (I assume that's the verb it will present to you). After that you should be able to open a window and use the drive*
* all this assumes it's an external USB drive.
If you cannot then you will need to mount it yourself, try:
sudo mkdir /media/sda1
sudo mount /dev/sda1 /media/sda1
Note: We are actually mounting the first partition on the drive, hence the 1 at the end: sda1
And the mounted directory can be anywhere you like, but its common location is /media.

Monday, March 8, 2010

Change location HDD from original VM to another VM

If you have 1 server seperate 2 HDD example 1 for OS & another for data. Let talk about when the OS have a problem than how gonna you take out the HDD data to another VM machine. So this tutorial i made for me and for you as a knowledge tp know.

server A - original server have 2 HDD
server B - server

scenario

- when OS in server A crash or corrupted, don't panic! here the step. your data is save because you have a separated HDD on your VM.
- firstly create your new VM, install OS (for me i using Freebsd) after finish please add another HDD when the installation is completed. so now you have 2 HDD (the size on additional HDD depend on your server & need (in my case i create same capacity with the original server capacity for data))
- log in into server B and format the HDD using sysinstall (fdisk & label) the HDD. (remember to add at /etc/fstab for your new HDD)
- after finish format, open VM client browse the datastore your server A located.
- copy the second HDD.vmdk ( by default your HDD will namely nameserver_1.vmdk) copy this file and browse the folder server B & paste inside the folder server B.
- after finish copy you need to rename your the vmdk file that you copy from server B. To this try to ssh inside the vmware machine, by default your vm not allow the ssh protocol you need to open it.
- ssh your VM, go to /vmfs/volumes/datastore1 , go to path your server directory
- backup the nameserverB_1.vmdk to nameserverB_1ORI.vmdk
- rename the vmdk that you copy before nameserverA_1.vmdk to nameserverB_1.vmdk
- turn on your VM.

DONE

Tuesday, March 2, 2010

htpasswd tips

to add another user on htpasswd file

htpasswd -s alimdevpass username

Monday, March 1, 2010

FreeBSD (add extra HDD on VMWare Environment)

FreeBSD add another HDD on VMWARE and format it

- shutdown your server.
- open your vmware & choose the server you want to add
- edit & add HDD
- Turn on your server.
- become as root type sysinstall
- choose configure & FDISK
- choose a additional HDD that you add before. (BEWARE!!! Do not edit the existing HDD on your server,this may cause your server corrupted!)
- choose entire disk if you want to use all disk & W button (write)
- please choose NONE "do not tpuch master boot record"
- after finish push q button
- go back to main menu & choose Label (this is use to label your HDD)
- select C to create the FS (depend on your need) exp : /test01
- and select W to write the changes
- Select Q and edit at FSTAB (ee /etc/fstab)
- add this line to you fstab line
exp : /dev/da1s1 /test01 ufs rw 2 2
- save and reboot your server.

Sunday, February 21, 2010

Update / Upgrade Ubuntu Server

sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade


If the kernel or kernel modules have been updated, you should reboot your computer/server.

Thursday, February 11, 2010

No netwrok after clone/copy using VMWare ESX

After making a copy/clone of an ubuntu server 8.10, i face a network problem.

1. "ifconfig" shows no eth0 device, just the 127.0.0.1 loopback
2. "/etc/init.d/networking restart" reports:

SIOCSIFADDR: No such device
eth0: ERROR while getting interface flags: No such device
SIOCSIFNETMASK: No such device
SIOCSIFBRDADDR: No such device
eth0: ERROR while getting interface flags: No such device
Failed to bring up eth0.

Solution
When you create a complete clone/copy of your vmware machine, a new ethernet MAC address is assigned.

follow this step :
as a root
run this CLI
# rm -fr /etc/udev/rules.d/70-*
# reboot

after wakeup, try ifconfig.
now you get your network back.

Salud!

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.

Setting in FSTAB add HDD in FreeBSD or Unix

ee /etc/fstab

/dev/da2s1 /studentdata ufs rw 2 2

Monday, January 11, 2010

Script to rename multiple table in MySQL

Baru-baru ni aku faced problem untuk rename table prefix secara pukal...kat database tu ada 186 tables...
kalau nak tukar satu-satu...pergghh...memang lebam...setelah google punya google...aku jumpa solution ni...tapi kena pakai ruby script dan tukar ke sql statement..tapi kalau korang nak pakai convert ke php pun x de hal...guna concept yg sama jek...

Ikut ni :


  1. masuk mysql...pastu show tables;
  2. copy semua tables yg korang nak rename tu...
  3. paste kat dlm script ni (dlm cth ni aku bagi nama file ni batch_rename.sh ) :

    OLD_PREFIX = "mdl"
    NEW_PREFIX = "mdlsirap"
    data=<<-EOD | mdl_assignment | | mdl_assignment_submissions | | mdl_backup_config | | mdl_backup_courses | | mdl_backup_files | | mdl_backup_ids | | mdl_backup_log | | mdl_block | | mdl_block_instance |

    | mdl_block_pinned |

    EOD
    tables = []
    data.each_line do |line|
    if line=~/(#{OLD_PREFIX}\w+)/
    puts "RENAME TABLE #{$1} TO #{NEW_PREFIX}#{$1};"
    end
    end


  4. Pastu runkan script ni pakai ruby punya command-line (aku assume korang dah install ruby) :
    #ruby batch_rename.sh
  5. Dia akan kluar output :
    RENAME TABLE mdl_assignment TO mdlsirap_assignment;
    RENAME TABLE mdl_assignment_submissions TO mdlsirap_assignment_submissions;
    RENAME TABLE mdl_backup_config TO mdlsirap_backup_config;
    RENAME TABLE mdl_backup_courses TO mdlsirap_backup_courses;
    RENAME TABLE mdl_backup_files TO mdlsirap_backup_files;
    RENAME TABLE mdl_backup_ids TO mdlsirap_backup_ids;
    RENAME TABLE mdl_backup_log TO mdlsirap_backup_log;
    RENAME TABLE mdl_block TO mdlsirap_block;
    RENAME TABLE mdl_block_instance TO mdlsirap_block_instance;
    RENAME TABLE mdl_block_pinned TO mdlsirap_block_pinned;
  6. just masukan sql statement ni dlm satu file lain...tapi kalau nak senang...buat step no. 4 tu camni :
    #ruby batch_rename.sh > a.sql
  7. Runkan sql file tu guna mysql...:
    #mysql namadatabase <>
  8. Selesai....
Credit to Sirap.Dol.

Enable the query cache in MySQL to improve performance

from mysql server

$ mysql -u root –p

set cache inside mysql shell

mysql> SET GLOBAL query_cache_size = 16777216;

mysql> SHOW VARIABLES LIKE 'query_cache_size';

exit and edit my.cnf

(on ubuntu)
cd /etc/mysql/my.cnf

# nano /etc/my.cnf

add

query_cache_size = 268435456
query_cache_type=1
query_cache_limit=1048576

Sunday, January 10, 2010

SUDO in FreeBSD / Unix

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

example :
usename ALL=(group) ALL


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

Set environment : setenv EDITOR ee


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

Friday, January 8, 2010

Can't create table (errno: 708) (Mysql BUGS)

I recently face my mysql problem like this.

mysql> alter table 19m4t_enrol_authorize engine=ndbcluster;
ERROR 1005 (HY000): Can't create table './lmsdb/#sql-2ece_a.frm' (errno: 708)

when i want to cluster my tables on my other nodes this error appear.

The Solution is go to my mysql management node and i increase
increase "MaxNoOfAttributes"
into my ndb_mgm.conf

example :

DataMemory = 24G
IndexMemory = 4G
MaxNoOfOrderedIndexes = 1024
MaxNoOfAttributes = 10000
MaxNoOfTables = 2500
MaxNoOfConcurrentOperations = 250000
MaxNoOfConcurrentIndexOperations = 250000

reboot all machine.

DONE!

Wednesday, January 6, 2010

Check RAM on FreeBSD

Install :

# cd /usr/ports/sysutils/freecolor
# make install clean

$ freecolor -m -o