Thursday, February 26, 2015

Replace failed RAID controller

OK, here is some experience on building a RAID server and fixing hardware failure. This is quite interesting as software engineers do not often have the chance to work on hardware.

The server uses PERC 6/E card to connect to a disk array. The disks in the disk array have the same physical capacity, say 1TB, but configured as logical drives with large capacity each (which effectively means you combine several physical drives into one logical drive).  PERC stands for PowerEdge RAID Controller. "E" in 6/E stands for External, which means HDDs are in a expansion box separate from the server box, attached to server using a SCSI interface such as MD1000 or MD3000. Correspondingly "I" in 6/I means "Internal", where HDDs are in the same server box. PowerEdge is a server brand of Dell. Relevant servers are listed on this wiki page: List of Dell PowerEdge Servers.

[1] is a very good step by step guide on how to do the configuration on a PERC 6/I card. It is the same for configuring a PERC 6/E card. [2] is a more general and complete guide.

There are several things one can do.

At boot time, press CTRL-R to enter PERC configuration utility. Once in the configuration utility, you can see a list of PERC cards, click "enter" on one to enter its configuration. In the next page "VD Mgmt", press "F2" for actions to choose from, including: Create New VD, Clear Config, Foreign Config (Import/Clear).

In the case the PERC card failed, the speed to access PERC configurations can be painfully slow each operation. Once the new good card is replaced on board, all steps are very much faster. The difference is like 10-30 minutes versus a few seconds.

PERC configuration is written to each RAID disk. In case of a PERC failure, just replace the PERC card and "import" foreign configuration. A configuration is "foreign" means the PERC configuration does not match configuration information on the RAID disks. When a PERC card fails its configuration may become inconsistent with information on the disks, and you may see warning lights on the disks blinking and the status of the lights is inconsistent upon each reboot.

If 1 or 2 disks in array failed, you just pull it out and insert a new disk. RAID should rebuild automatically.

If a large number of disks are in foreign state, you may want to clear foreign configuration and recreate from scratch. Note that for new setup you can "Initialize" the disks to clean them, but for disks with existing data (in the case of recovering from a failed PERC card, where disks with data should keep intact) you should not initialize the disks since you want to preserve the data.

If you need to create new VD (Virtual Disks), you need to choose RAID level, then assign disks to use, and set some options.

It's actually quite a lot of fun.

[1] DELL Tutorial: Create RAID Using PERC 6/i Integrated BIOS Configuration Utility
[2] Dell™ PERC 6/i, PERC 6/E and CERC 6/i User's Guide


Saturday, February 21, 2015

Redis better than memcache?

Why Redis beats Memcached for caching

Memcached: good when 1) static/small data, 2) better horizontal scaling

Redis: good when:
1) more data structure support
2) faster for more clients
3) larger object size limit (512MB v.s. 1MB of memcached)
4) stored data can be manipulated, not opaque
5) more control over LRU policies (6)
6) tunable persistence
7) offers replication

On Redis, Memcached, Speed, Benchmarks and The Toilet
  Redis: ~ 80-100k GET/SET per sec, better for more clients.
  Memcached: ~ 60-80k GET/SET per sec

An update on the Memcached/Redis benchmark
  Memcached: 1 instance running multiple threads, overhead causes less speed per thread.
  Redis: single thread. Can run multiple instances together.

Friday, January 16, 2015

Detach a series of databases in MSSQL

declare CUR cursor for
    SELECT name
    FROM master..sysdatabases
    where name like 'ABC_%'

declare @db varchar(50)
declare @msg varchar(200)

open CUR

fetch next from CUR into @db
while @@FETCH_STATUS = 0
begin
    set @msg = 'detach ' + @db
    raiserror (@msg, 0, 1) with nowait
   
    exec sp_detach_db @db, 'true'
   
    fetch next from CUR into @db
end

close CUR
deallocate CUR


---- Below is batch script to quickly remove disk files. Note you can use multiple wild card match. ----

ECHO OFF

FOR /f "tokens=*" %%i in ('DIR /a:d /b D:\mssql_db\*abc* D:\mssql_db\*xyz*') DO (
    ECHO %%i
    rmdir /s /q "D:\mssql_db\%%i"
)

Wednesday, November 19, 2014

Hadoop - The Definitive Guide

Hadoop - The Definitive Guide, 3rd edition.

Just got this book over the weekend. Now reading.

The 2nd edition of this book is available here.

Reference:
[1] 15+ Great Books for Hadoop

Wednesday, November 5, 2014

How jQuery is written from scratch?

This probably helps: http://www.mikedoesweb.com/2012/creating-your-own-javascript-library/

This is a minimum javascript library whose grammar is very similar to jQuery: _('id').function(). It helps to understand how jQuery is written from scratch.

I think I can start writing a javascript library similar to jQuery now :).

Tuesday, November 4, 2014

Wikipedia management

Wikipedia is a nice open source project. However it may incur a lot of hackers' interests if it is open for edit. Hackers may register large number of spam accounts, create new pages and modify existing pages. This is what's happening to a wikipedia I'm managing right now.

Although quite straightforward, I keep log of these management tips of wikipedia.

The default settings are in wiki/includes/DefaultSettings.php. But changes to settings can be made in wiki/LocalSettings.php, the changes here will override default settings.

1) To change logo, change this line:

$wgLogo = "$wgStylePath/common/images/wiki.png";


2) To disable anonymous user (not logged in) creating new page and editing, add this to the end of LocalSettings:

#
# See: http://www.mediawiki.org/wiki/Manual:User_rights
#

#
# not-logged-in user
#
$wgGroupPermissions['*']['createaccount'] = false; # no new user registration.
//$wgGroupPermissions['*']['read']          = true;      # default is true, so no need to add this statement.
$wgGroupPermissions['*']['edit'] = false;
$wgGroupPermissions['*']['createpage'] = false;

#
# logged-in user. 
# Add this if you want to disable logged-in users from createpage/edit actions.
#
#$wgGroupPermissions['user']['edit'] = false;
#$wgGroupPermissions['user']['createpage'] = false; // true;

#
# sysop
# If you disabled logged-in users actions, you may want to enable sysop's permission here.
#
#$wgGroupPermissions['sysop']['edit'] = true;
#$wgGroupPermissions['sysop']['createpage'] = true;

After you disabled new user's createaccount ability, you will want to manually create new accounts. You can do this by logging in as sysop, and going to "Special pages -> Login / create account".

3) Email setting. Use $wgSMTP to change email setting: either use Pear Mail or PHP Mail.

Refer to the last post "Fix Bluehost wikipedia email problem".


Fix Bluehost wikipedia email problem

I'm managing a website hosted by Bluehost.com.

From CPanel I installed wikipedia. However the email function does not work. It says: "bluehost Mailer returned: Failed to add recipient: [email] … Mailer returned: Unknown error in PHP's mail() function."

I followed instruction at http://www.mediawiki.org/wiki/Manual:$wgSMTP to add email SMTP setting to wiki/LocalSettings.php:

$wgSMTP = array(
 'host'     => "mail.example.com", 
 'IDHost'   => "example.com",      
 'port'     => 26,                 
 'auth'     => true,               
 'username' => "my_user_name",     
 'password' => "my_password"       
);

Still it does not work. I followed Bluehost's email setting page, use either SSL/TLS setting or non-SSL setting. Still it fails.

Finally I tried to find out where $wgSMTP is used: grep -i wgSMTH */*, and found it being used in /wiki/includes/UserMailer.php. It comes down to the function send().  When $wgSMTP is used, it uses Pear Mail; otherwise, it uses PHP Mail. Since I'm using PHP Mail in a personal project on the same server, I tried to check what's different it uses PHP Mail from my use. On line 359 of UserMailer.php, it has this code:

foreach ( $to as $recip ) {
      if ( $safeMode ) {
          $sent = mail( $recip, self::quotedPrintable( $subject ), $body, $headers );
      } else {
          $sent = mail( $recip, self::quotedPrintable( $subject ), $body, $headers, $wgAdditionalMailParams );
      }
}

I print out $headers, it is:

From: CareerAssist Wiki Return-Path: apache@www.careerassist.org Date: Tue, 04 Nov 2014 04:41:29 -0700 Message-ID: X-Mailer: MediaWiki mailer MIME-Version: 1.0 Content-type: text/plain; charset=UTF-8 Content-transfer-encoding: 8bit

Since I'm using the PHP's mail() function in a personal project on the same server and it works well, where I simply use: $headers = "From: [email]";

So I replace the $headers here with this simpler rendition:

foreach ( $to as $recip ) {
      if ( $safeMode ) {
          $sent = mail( $recip, self::quotedPrintable( $subject ), $body, $headers );
      } else {
          $headers = "From: [email]";
          $sent = mail( $recip, self::quotedPrintable( $subject ), $body, $headers, $wgAdditionalMailParams );
      }
}

Then it works! This also shows it takes the 2nd path here ($safeMode is false).

Thus I got wikipedia email working on Bluehost, with this hack into wikipedia's source code.


Blog Archive

Followers