How To Know If You Have a 64-bit Processor

August 5th, 2009 Masao No comments

If you have asked yourself, “Do I have a 64-bit processor?”, then here are several ways to find out:
uname

# uname -p
x86_64

cpuinfo

# cat /proc/cpuinfo
flags		: fpu vme de pse tsc msr pae mce cx8 apic mtrr
pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm
pbe syscall lm constant_tsc arch_perfmon pebs bts rep_good pni
dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm lahf_lm tpr_shadow
bogomips	: 4255.87
clflush size	: 64
cache_alignment	: 64
address sizes	: 36 bits physical, 48 bits virtual

The “lm” flag stands for Long Mode.

You can read more in this file:
/usr/src/kernels/#.#.#-#.#.fc11.x86_64/arch/x86/include/asm/cpufeature.h

#define X86_FEATURE_LM (1*32+29) /* Long Mode (x86-64) */

lshw

# lshw
     *-cpu
          description: CPU
          product: Intel(R) Core(TM)2 CPU          6420  @ 2.13GHz
          width: 64 bits

From the lshw manpage:

lshw is a small tool to extract detailed information on the hardware configuration of the machine. It can report exact memory configuration, firmware version, mainboard configuration, CPU version and speed, cache configuration, bus speed, etc. on DMI-capable x86 or IA-64 systems and on some PowerPC machines (PowerMac G4 is known to work).

Categories: Hardware, Linux Tags:

How to Fix Ugly Sidebar in Wordpress iNove Theme

August 5th, 2009 Masao No comments

The iNove theme gives your wordpress blog a Mac-ish look and feel. However, the sidebar has some ugly built-in widgets. Here’s how to remove them.

In themes/inove/sidebar.php, remove everything between these lines:

<!-- sidebar north END -->
...
delete everything here
...
<!-- sidebar south END -->

Done!

Categories: Wordpress Tags:

MySQL Slow Query Optimization Tips

July 26th, 2009 Masao No comments

Slow Query Example

SELECT
    widget_id
  , widget_name
  , COUNT(DISTINCT type) AS num_types
FROM widget
GROUP BY type
ORDER BY num_types DESC

With lots (>100K) of rows, this query will get slow because it orders on an aggregate COUNT DISTINCT function. Remove the ORDER BY to make this fast again.

Categories: MySQL Tags:

How to Convert Seconds to Minutes in BASH

July 22nd, 2009 Masao No comments

This is how to convert seconds into HH:MM:SS in bash:
$ date -d '1970-01-01 100 sec' +'%H:%M:%S'
00:01:40

Categories: Bash Tags:

How to fix: error while loading shared libraries: liblwres.so.50

July 16th, 2009 Masao No comments

To fix this error:
# nslookup mydomain.com
nslookup: error while loading shared libraries: liblwres.so.50: cannot open shared object file: No such file or directory

Do this:
# ldconfig
# dig mydomain.com
; <<>> DiG 9.6.1-RedHat-9.6.1-2.fc11 <<>> mydomain.com
...

From the ldconfig manpage:

ldconfig creates the necessary links and cache to the most recent shared libraries found in the directories specified on the command line, in the file /etc/ld.so.conf, and in the trusted directories (/lib and /usr/lib). The cache is used by the run-time linker, ld.so or ld-linux.so. ldconfig checks the header and filenames of the libraries it encounters when determining which versions should have their links updated.

Categories: Linux, Troubleshooting Tags:

How to Optimize MySQL Queries Using Indexes

July 15th, 2009 Masao No comments

When optimizing a query, the order of fields matter in a multi-field index.

In general, you should use the most selective fields first.

For example, in a hypothetical location index, use zip, city, state, rather than the reverse.

Source: MySQL Forums, Jay Pipes, Performance Tuning Best Practices Presentation

Categories: MySQL Tags:

How to Check Disk Speed on Linux

June 26th, 2009 Masao No comments

/sbin/hdparm -tT /dev/sda

Categories: Linux Tags:

How to Fix “SSH Public Key Authentication Failed”

June 3rd, 2009 Masao 1 comment

If your SSH public key authentication is failing with errors like this:

$ ssh -vvv myhost.com
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /home/kitamura/.ssh/id_dsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply

…try these permissions on the server:

server$ chmod go-w ~/    (same as 755)
server$ chmod 700 ~/.ssh
server$ chmod 600 ~/.ssh/authorized_keys

more troubleshooting tips

Categories: Linux, SSH, Troubleshooting Tags:

MySQL Schema Best Practices

May 14th, 2009 Masao 1 comment
  1. Use UNSIGNED INT (or BIGINT if needed) for primary key, since you don’t need negative primary keys.
  2. Don’t use ON DELETE CASCADE, since you might delete rows you wanted to keep.  Explicitly delete rows in your code.
  3. Don’t use ON UPDATE CASCADE, since you might want to change the ID in the parent table of the row being referenced, without changing the ID of the child row.
  4. Always use foreign keys to constrain your data and require that foreign keys reference rows that actually exist.
  5. Use UNIQUE KEYS where necessary and where they conceptually make sense.  All fields in the UNIQUE KEY must be NOT NULL for the key to be effective.
  6. Use singular table names, unless a row represents a plural object.  (A table of chairs would be called “chair”, unless a row represented a set of “chairs”).  This makes code generation easier (esp. for tables named “category”, “specialty”, “country”, etc)

Update:

Keep data types as small as possible for what you need
• Don’t use BIGINT unless you have to! Waste of space.
• Especially true on indexed columns
• Fundamental principle: The smaller your data types, the more records will fit into the index blocks. The more records fit in each block, the fewer reads are needed to find your records.

Source: Jay Pipes, MySQL Presentation, Index Coding Optimization

  • Smaller is better – use the smallest data type necessary.  When in doubt, use the smallest one you don’t think you’ll exceed.
  • Avoid NULL if possible – Nullable columns make indexes, stats, and value comparisons more complicated.
  • Use simpler data types when possible – use integers for IP addresses
  • For storage and computation, INT(1) and INT(20) are equivalent.  The numeric is for display purposes only for applications such as the command line client.
  • Use FLOAT over DECIMAL for speed – the CPU performs the computations natively, as opposed to the server making the DECIMAL calculation

Source: O’Reilly High Performance MySQL

Categories: MySQL Tags:

How To Install CPAN Dependencies Without Interaction

May 13th, 2009 Masao No comments

How to Automatically Install CPAN Dependencies without having to answer “yes” to each question:

export PERL_MM_USE_DEFAULT=1
Categories: Linux Tags:

How to List Files of a Package Installed by YUM/RPM

May 7th, 2009 Masao No comments
# rpm -ql mysql-devel
/usr/include/mysql
/usr/include/mysql/chardefs.h
/usr/include/mysql/decimal.h
/usr/include/mysql/errmsg.h
...
Categories: Fedora, Linux, RPM, YUM Tags:

How to Monitor Multi-Core CPU Usage on Linux

April 9th, 2009 Masao No comments

Here’s how to monitor multiple cores on Linux:

# mpstat -P ALL

Example:

Monitor all CPU’s in 1 second intervals forever

# mpstat -P ALL 1

Categories: Bash, Linux, Monitoring Tags:

How to Renew Your DHCP IP Address on Linux

April 7th, 2009 Masao No comments

If Synergy fails for you with this error: “Server refused client with name XXX”, then your IP might conflict with another machine on the same network.

Here’s how to renew your IP on Linux:

### Release your current IP
$ sudo dhclient -r

### Request a new IP
$ sudo dhclient
Categories: Linux, Synergy Tags:

How to Connect Vista and Samba on Fedora 10

April 6th, 2009 Masao No comments
  1. Go through the usual setup at Samba.org or use YUM (yum install -y samba)
  2. By default, the smb.conf allows sharing of home directories.
  3. Add a Samba user (smbpasswd -a myusername)
  4. On Fedora, run SELinux Administration
  5. On the left menu, click “Boolean”.
  6. Scroll down to “samba”, and check the box next to “Allow samba to share users home directories”.
  7. Also on Fedora, make sure your Firewall allows the Samba ports 139 and 445.
  8. On Windows Vista, now map the network drive.

Sample smb.conf:

[homes]
        comment = Home Directories
        browseable = no
        writable = yes
;       valid users = %S
;       valid users = MYDOMAIN\%S
Categories: Linux, Samba, Troubleshooting, Windows Tags:

How to Disable Media Manager Services

March 31st, 2009 Masao 2 comments

UPDATE: Roxio has made it harder to disable “Media Manager Services” now.

In Windows Vista:

  1. Click the Start button, type “msconfig” and hit enter.
  2. When the small “User Account Control” window pops up, click continue.
  3. Click the Startup tab
  4. Look for “CommonSDK” in the Startup items in the left column.
  5. Check the Command column, which should say “RoxWatchTray9.exe”
  6. Uncheck the box for that row.
  7. Restart your machine.

ALTERNATE OLDER VERSION:

After installing Roxio Creator, you might have a system tray icon that you can’t seem to get rid of.

Here’s how to turn off the Media Manager Services icon:

  1. Start Roxio Creator
  2. On the left side, click Audio.
  3. Then click Audio CD
  4. On the left bottom, click Settings
  5. Uncheck Watch Folders at Startup
  6. Then click OK
Categories: Everything Else Tags:

How to Require Login to Edit Mediawiki

March 22nd, 2009 Masao No comments

Add this to LocalSettings.php:

$wgGroupPermissions['*']['edit'] = false;
Categories: Mediawiki Tags:

How To Get Yesterday’s Date using BASH Shell Scripting

February 17th, 2009 Masao 2 comments

The new short way:
$ date -d '1 day ago' +'%Y/%m/%d'
2009/07/21

Or the longer way:
Yesterday in epoch seconds
$ yesterday=$((`date +'%s'` - 86400))

Get default formatted yesterday's date
$ date -d "1970-01-01 $yesterday sec"
Tue Feb 17 01:27:32 PST 2009

Same thing in YY-MM-DD
$ date -d "1970-01-01 $yesterday sec" +"%Y-%m-%d"
2009-02-17

Categories: Bash, Linux Tags:

How To Centralize Bookmarks using Firefox and Google Bookmarks

February 12th, 2009 Masao No comments
  1. Create a label in Google Bookmarks with all the bookmarks you want to centralize.
  2. Then, create a live bookmark in Firefox with the following URL, replacing the label name with the one you created:

http://www.google.com/bookmarks/lookup?hl=en&sort=title&output=rss&q=label:live

Categories: Firefox Tags:

How to Quickly Add Multiple Indexes to a MySQL Table

February 10th, 2009 Masao No comments

Instead of:


ALTER TABLE my_table ADD KEY `key1` (`apple`);
ALTER TABLE my_table ADD KEY `key2` (`banana`);

do this:


ALTER TABLE my_table
ADD KEY `key1` (`apple`),
ADD KEY `key2` (`banana`);

Categories: MySQL Tags:

ssh_exchange_identification: Connection closed by remote host

February 5th, 2009 Masao No comments

On the destination server, remove the known_hosts file:

rm ~/.ssh/known_hosts

Also, try this in your /etc/hosts.allow file

/etc/hosts.allow:
SSHD: ALL

Categories: Linux, SSH, Troubleshooting Tags: