Tuesday, April 28, 2009

linux startx failure resolved

X11 was failing to start after moving the hard drive to AMD X2 motherboard with ATI RADEON on board graphic adaptor.

Resolution:
In system setup, increased the AGP buffer from 32MB to 64MB

Monday, April 27, 2009

Fedora 10 update GDM config to allow root login

Type your root password. Next, make a backup of /etc/pam.d/gdm, enter:
cp /etc/pam.d/gdm /root
Now open /etc/pam.d/gdm using gedit or vi text editor, enter:
gedit /etc/pam.d/gdm
OR
vi /etc/pam.d/gdm
Alternatively, you can do everything in a one command:
su -c 'gedit /etc/pam.d/gdm'
Find line that read as follows:

auth required pam_succeed_if.so user != root quiet

Remove or comment out line by prefixing #.

# auth required pam_succeed_if.so user != root quiet

Save and close the file. Logout from terminal and from GUI itself. Now you should be able login as root user using GDM GUI login manager.

linux graphical display configuration (X or Xorg)

To probe for current hardware and create xorg.conf.new file run:
X -configure

you can use the created file by copying it to /etc/X11/xorg.conf
or set it via:
X -config xorg.conf.new

to get all availbale commands:
X -help

To view the log information:
tail /var/log/xorg.0.log

Another linux text editor

nano

Fix linux booting when moving hard drive to another motherboard

Linux uses initrd image ( initial ram drive ) to startup the system.
The image file is located under (/boot/initrd-(kernel version).img)
if this image is not compatible with the current hardware, then we need to create a new one under the same hardware devices.
All we need is Fedora installation disk 1 to boot up in a "rescue mode" and do the follow:
- chroot /mnt/sysimage
- mkinitrd initrd_new-(kernel version, use the latest number, it can also be found under /lib/module/) (kernel version)
i.e. : mkinitrd /boot/initrd_new-2.4.18-0.12.img 2.4.18-0.12
- vi /boot/grub/menu.ls
- replace the current initrd file name with the newly created one
- exit then exit to reboot the system

Issues with kobool server migration

httpd.conf:
- Comment: AddDefaultCharset UTF-8
- Adding NameVirtualHost *:80
- Adding AllowOverride all to root folders ( it was all by default in Apache 2.0, but none in 2.2 )
- Adding Option +Include to default folder
- Adding AddOutpuFilter INCLUDES .htm
- Adding AddOutpuFilter INCLUDES .html
- Changing Timeout from 120 to 30
- Adding ExpiresActive On
- Adding ExtendedStatus On
- Setting ServerName www.kobool.com:80
- Setting SSL server root folder and server name to kobool.com
ssl.conf> ServerName kobool.com:443
ssl.conf>DocumentRoot /var/www/html/kobool.com
Skipped httpd.conf:
- commenting AddDefaultCharset UTF-8
- commenting ErrorLog logs/error_log
- commenting CustomLog logs/access_log combined
- removing index.php from DirectoryIndex
- KeepAlive On
- MaxKeepAliveRequrest 0
instead of 100
- KeepAliveTimeout 20
Perl script:
- Replacing encode() with Encode::from_to($text,"utf8", "MIME-Q",1) in window1256.pm
- paid2cashu.pl: remove "dbcards" from db_connect()



Email header encoding problem fixed

Using Encode::encode($text, "MIME-Q"); is not giving the same results with 32 bit and 64 bit linux.

But, using Encode::from_to($text, "utf8", "MIMI-Q", 1) gave the right encoding for email header.

Probably because of the last parameter (1)

Sunday, April 26, 2009

remove kobool mailer ip address from exclude black list (xbl)

Kobool was added to xbl at: http://www.spamhaus.org/
as it was listed in CBL at: http://cbl.abuseat.org/lookup.cgi?ip=154.6.115.157

The reason was the hostname was not set to xxx.kobool.com
Fix:
edit /etc/sysconfig/network
and set hostname to: main.kobool.com

restart the machine.

mail loops back to me mx problem

I fixed this problem by removing extra sub-domains from "Local Domains" list in SendMail configuration.


localhost
localhost.localdomain
kobool.com
muslim-web.com
mail.kobool.com
main.kobool.com

Saturday, April 25, 2009

linux networking change computer name in the local network

In redhat/Fedora:
edit /etc/sysconfig/network
NETWORKING=yes
HOSTNAME="main.kobool.com"

Note: changing HOSTNAME requires rebooting the computer to take effect

Friday, April 24, 2009

Apache: applying configuration chages without restarting

/etc/init.d/httpd reload

or

apachectl -k graceful

references:
http://www.cyberciti.biz/faq/apache-making-changes-config-file-without-restarting/

Edit network configuration for a network adapter controlled by Network Manager

edit the following file
/etc/sysconfig/network-scripts/ifcfg-eth0


for example: add
DNS1=xxx.xxx.xxx.xxx

static ip address could be set for this interface as well

After finishing editing:
service network restart

Thursday, April 23, 2009

Wednesday, April 22, 2009

Assign static IP addresses for libvirt hosts

Steps:
virsh net-edit default
Add host tag inside dhcp with the following attributes:
mac='xx:xx:xx:xx:xx:xx'
name='slaveX'
ip='192.168.122.nn'

linux dhcp server configuration

Run the following command to control dhcp behavior:

dnsmasq [options]

Or edit /etc/dnsmasq.conf to change the settings

virsh-clone error "list index out of range" resolution

This error happens when there is multiple disks defined in the virtual machine and the command is specifying only one target image file
This usually happen if CD rom drive is defined.
Resolution:
Remove the CD from device list of the source machine.

Virsh console

Exit console via Ctrl + ]

Read more here:
http://magazine.redhat.com/2008/06/18/virsh/

Tuesday, April 21, 2009

linux Screen utility

Keyboard shortcuts

KeyActionNotes
Ctrl+a cnew window
Ctrl+a nnext windowI bind F12 to this
Ctrl+a pprevious windowI bind F11 to this
Ctrl+a "select window from listI have window list in the status line
Ctrl+a Ctrl+aprevious window viewed



Ctrl+a Ssplit terminal horizontally into regionsCtrl+a c to create new window there
Ctrl+a :resizeresize region
Ctrl+a :fitfit screen size to new terminal sizeCtrl+a F is the same. Do after resizing xterm
Ctrl+a :removeremove regionCtrl+a X is the same
Ctrl+a tabMove to next region



Ctrl+a ddetach screen from terminalStart screen with -r option to reattach
Ctrl+a Aset window title
Ctrl+a xlock sessionEnter user password to unlock
Ctrl+a [enter scrollback/copy modeEnter to start and end copy region. Ctrl+a ] to leave this mode
Ctrl+a ]paste bufferSupports pasting between windows
Ctrl+a >write paste buffer to fileuseful for copying between screens
Ctrl+a <read paste buffer from fileuseful for pasting between screens



Ctrl+a ?show key bindings/command namesNote unbound commands only in man page
Ctrl+a :goto screen command promptup shows last command entered

Linux Virtualization documentation ( libvirt )

http://www.libvirt.org/docs.html

Run a command on virtual terminal

To run /bin/bash on a virtual terminal
openvt -vl /bin/bash

To specify terminal #9:
openvt -c 9 -vl /bin/bash

Adding replication slave user

grant replication slave on *.* to 'slave_user'@'%' identified by 'password';

Monday, April 20, 2009

changing mysql root password

SET PASSWORD FOR 'bob'@'%.loc.gov' = PASSWORD('newpass');

That is equivalent to the following statements:

UPDATE mysql.user SET Password=PASSWORD('newpass')
WHERE User='bob' AND Host='%.loc.gov';
FLUSH PRIVILEGES;

configuring service autostart option

This could be done using chkconfig program

To check the service startup option in different runlevels (i.e. mysqld):
chkconfig | grep mysqld

to enable a service in all runlevels
chkconfig mysql on

to enable a service in specific runlevel
chkconfig --level 3 mysqld on
To add a new service:
chkconfig --add mysqld

Linux RunLevels:

0 - System halt; no activity, the system can be safely powered down. 
1 - Single user; rarely used. 
2 - Multiple users, no NFS (network filesystem); also used rarely. 
3 - Multiple users, command line (i.e., all-text mode) interface; the standard runlevel for most Linux-based server hardware. 
4 - User-definable 
5 - Multiple users, GUI (graphical user interface); the standard runlevel for most Linux-based desktop systems. 
6 - Reboot; used when restarting the system.

Sunday, April 19, 2009

Shredding data using linux

shred -vfz -n 100 /dev/(h|s)d(a|b|c)

sample
shred -vfz -n 100 /dev/sdb

Here /dev/sdb is my whole hard disk. And I am asking shred to make (-n) 100 passes by overwriting the entire hard disk with (-z) zeros. And shred program (-f) forces the write by changing the permissions wherever necessary.

Saturday, April 18, 2009

delete hard drive content using dd command

Use the following command:

dd if=/dev/zero of=/dev/sd(a|b|c) bs=1024

To earse from specific offeset in the output device add seek=(blocks count)

for example to start erasing at 10 KB:
dd if=/dev/zero of=/dev/sdb bs=1024 seek=10

Friday, April 17, 2009

linux vituralization commands

References:
http://virt-manager.et.redhat.com/index.html
https://help.ubuntu.com/8.10/serverguide/C/libvirt.html

management shell:
virsh

Install virtrual machine
virt-install

Clone virtual machine
virt-clone

Search for text in a folder using grep

command syntax:
grep text_to_find wildcard

Sample
grep XEN /boot/*

Clonning VirtualBox hard disk on the same machine

"C:\Program Files\Sun\xVM VirtualBox\VBoxManage.exe" clonevdi "mydisk.vdi"
"mydisk2.vdi"

If there are snapshots, the new disk will contain the root disk version before taking any snapshots.
In order to get the latest disk, all snapshots have to be discarded ( or merged )


Thursday, April 16, 2009

Change hostname on Fedora Core

Change hostname on Fedora Core

To change the hostname on a Fedora Core system, firstly edit these lines in the "/etc/hosts" file:

127.0.0.1 localhost.localdomain localhost
::1 localhost.localdomain localhost

Then, in the "/etc/sysconfig/network" file, write new hostname in that line: "HOSTNAME=localhost.localdomain"

To make the changes permanent, the network service must be restarted via this command:

# service network restart

Showing linux active processes

Use the command:
ps


common options are: aux

Sample:
ps aux

To find a specific process pipe the output to grep
Sample:
ps aux | grep Network

Wednesday, April 15, 2009

Installing flash-plugin on Fedora 10 64 bit

Follow instructions on:
http://fedoraproject.org/wiki/Flash

1. Install flash yum version from adobe site
2. run:
yum install flash-plugin nspluginwrapper.x86_64 nspluginwrapper.i386 alsa-plugins-pulseaudio.i386 libcurl.i386

Tuesday, April 14, 2009

Saving disk image with linux dd command

to save
dd if=/dev/sda bs=1024 | gzip > /path/to/image.gz

to restore:
gunzip < /path/to/image.gz | dd of=/dev/sda bs=1024

Note:
Add "count=1 bs=446" to exclude the partition table from being written to disk. You can manually restore the table.

Firewall commonly required open ports

The following ports are commonly open in server boxes
  • 21: ftp
  • 22: ssh
  • 23: telnet
  • 25: smtp
  • 80: http
  • 110: pop3
  • 137upp, 138udp, 139tcp, 445tcp: Samba
  • 443: https
  • 873: rsync
  • 995: pop3 over ssl
  • 2049: NFS
  • 3306: mysql
  • 5900: vnc
  • 5901: xvnc
  • 10000: webmin

How to setup a mysql slave server to works as a master for other servers

We can setup mysql server to be a slave and master at the same time.
However, slave updates will not be logged in master logs unless "log-slave-update" variable is set in my.cnf or via CHANGE MASTER TO statement

my.cnf:
[mysqld]
log-slave-update

or:
CHANGE MASTER TO --log-slave-update

Monday, April 13, 2009

MySQL Bulk update instructions and sample

Instead of updating multiple records via perl or php loop, it can be done totally using mysql scripts.
- create temporary table and fill it in with the data that would be used to update your target table
- update target table joined with the temporary table and set the records fields values to the values of the temp table records.

this technique was used in 4h_cron.pl and a huge gain of performance was achieved.

#Update ask_count
$dbh->do(
qq{
create temporary table tmp_questions_text(
id integer auto_increment,
question integer,
ask_count integer,
primary key (id)
)
}
);

$dbh->do(
qq{
insert into tmp_questions_text (question, ask_count)
select question, count(question) as ask_count
from questions
group by question
}
);

$ret_info->{updated_questions} = int(
$dbh->do(
qq{
update questions_text
join tmp_questions_text
on questions_text.id = tmp_questions_text.question
and questions_text.ask_count <> tmp_questions_text.ask_count
set questions_text.ask_count = tmp_questions_text.ask_count
}
)
);

Creating linux user for email account only

Create regular user with shell option set to /sbin/nologin
Mailbox will not be created until first email is received.
dovecot will give +w permission not found when mailbox is not found, as dovecot does not have permission to create files in /var/mail/ folder.

Reference:
http://www.tecmint.com/add-users-in-linux/

Thursday, April 9, 2009

MySQL debuggin via EXPLAIN or DESCRIBE

I started exploring the usage of EXPLAIN and DESCRIBE commands to debug slow queries.
No conclusion yet

http://dev.mysql.com/doc/refman/5.0/en/using-explain.html

Wednesday, April 8, 2009

mysql 5.x hangs in copy to tmp table

This happens with nested queries.

It is a known bug in version 5. It looks like it is going to be fixed with 6.0 release.

However, here are some reasons:
-Tables are over indexed: reduce the number of indexes solved the problem with some cases

Monday, April 6, 2009

mytop tool

A good tool that keeps polling mysql "show full processlist" and display it in a linux "top" like report

There is one error in first time run which could be fixed by following the instructions in this post:
http://forums.cpanel.net/showthread.php?p=497485

Friday, April 3, 2009

kobool setup issues

  • use sftp or rsync to get files from remove servers
  • use nfs to get files from local network servers
  • install CPAN ( yum install perl-CPAN.x86_64 )
  • Apache: make sure startup.pl is located in one of the @INC folders ( i.e. : /etc/httpd )
  • Apache: verify the used lib folders in use() statement in startup.pl
  • Apache: enable index.shtml as folder index document
  • Apache: enable shtml processing with htm extensions ( AddOutputFilter INCLUDES .htm )
  • Apache: check error log at /var/log/httpd/error_log
  • httpd.conf > uncomment NameVirtualHost
  • start dovecot
  • grant all on *.* to 'root'@'123.233.423.34' identified by 'passw'

Apache Virtual Hosts overlap problem

NameVitrualHost *:80
http://www.heavymind.net/2007/07/25/virtualhosts-nightmare-on-suse/

Installing perl CPAN

in order to install CPAN modules we need CPAN first
yum install perl-CPAN.x86_64

then to install CPAN module (i.e. IP::Country):
perl -MCPAN -e shell

then
install IP::Country

to search for a package
i /package name/

Wednesday, April 1, 2009

Show line numbers in vi and vim

execute :set number in editor command line ( :set nonumber to cancel )

To set it permanently:
edit or creat .exrc in your linux home folder
add "set number" in a separate line

linux: listing active listening services

netstat -ltp
chkconfig --list | grep 3:on

Sample (netstat -ltp )

Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 *:nfs *:* LISTEN -
tcp 0 0 *:mysql *:* LISTEN 2309/mysqld
tcp 0 0 *:40971 *:* LISTEN -
tcp 0 0 *:rquotad *:* LISTEN 2191/rpc.rquotad
tcp 0 0 *:vnc-server *:* LISTEN 3036/vino-server
tcp 0 0 *:sunrpc *:* LISTEN 1798/rpcbind
tcp 0 0 *:ndmp *:* LISTEN 2521/perl
tcp 0 0 *:http *:* LISTEN 2383/httpd
tcp 0 0 *:55632 *:* LISTEN 2206/rpc.mountd
tcp 0 0 *:ftp *:* LISTEN 2227/vsftpd
tcp 0 0 *:ssh *:* LISTEN 2103/sshd
tcp 0 0 *:36374 *:* LISTEN 1813/rpc.statd
tcp 0 0 localhost.localdomain:ipp *:* LISTEN 2447/cupsd
tcp 0 0 localhost.localdomain:smtp *:* LISTEN 4982/sendmail: acce
tcp 0 0 *:https *:* LISTEN 2383/httpd