Wednesday, August 26, 2009

FreeBSD iSCSI Initiator Installation and Configuration

SkyHi @ Wednesday, August 26, 2009
Q. How do I install and configure iSCSI initiator service under FreeBSD server?

A. FreeBSD 7.x has full support for iSCSI. Older version such as FreeBSD 6.3 requires backport for iSCSI. Following instruction are known to work under FreeBSD 7.0 only.
FreeBSD iscsi_initiator driver

The iscsi_initiator implements the kernel side of the Internet SCSI (iSCSI) network protocol standard, the user land companion is iscontrol and permits access to remote virtual SCSI devices via cam.
Compile driver

Please note that FreeBSD 7.x has this driver compiled by default. You can skip this step if driver exists at /boot/kernel/iscsi_initiator.ko. To compile this driver into the kernel,
# cd /usr/src/sys/i386/conf
# cp GENERIC ISCSIKERNEL
# vi ISCSIKERNEL
Place the following lines in your kernel configuration file:
device iscsi_initiator
Save and close the file. Building a Kernel, type the following commands:
# cd /usr/src
# make buildkernel KERNCONF=ISCSIKERNEL
Install the new kernel:
# make installkernel KERNCONF=ISCSIKERNEL
Now reboot the system:
# reboot
Install iSCSI Initiator driver under FreeBSD

You need FreeBSD kernel driver for the iSCSI protocol. You need to use driver called /boot/kernel/iscsi_initiator.ko. You can load this driver by typing following command as root user:
# kldload -v iscsi_initiator.ko
Output:

Loaded iscsi_initiator.ko, id=6

Alternatively, to load the driver as a module at boot time, place the following line in /boot/loader.conf:
# vi /boot/loader.conf
# Beginning of the iSCSI block added by Vivek
iscsi_initiator_load="YES"
# End of the block added by Vivek
Save and close the file.
FreeBSD iscontrol command to login / negotiator / control for an iSCSI initiator session

Now, you need to use iscontrol command. First, do a discovery session and exit:
# iscontrol -d targetaddress=iSCSI-SERVER-IP-ADDRESS initiatorname=nxl
# iscontrol -v -d targetaddress=192.168.1.100 initiatorname=nxl
Please note down the list of available targetnames/targetadresses. Once you know the target name, edit /etc/iscsi.conf file:
# vi /etc/iscsi.conf
Append config directives as follows:

officeiscsi {
authmethod = CHAP
chapIName = YOUR-ISCSI-USERNAME
chapSecret = YOUR-ISCSI-PASSWORD
initiatorname = nxl
TargetName = iqn.XYZZZZZZZZZZZZZ # whatever "iscontrol -v -d " gives you
TargetAddress = 192.168.1.100:3260,1 # your iscsi server IP
}

Save and close the file.
Where,

* officeiscsi { : Start config for iSCSI.
* authmethod : Set authentication method to chap
* chapIName : Your username
* chapSecret : Your password
* initiatorname : if not specified, defaults to iqn.2005-01.il.ac.huji.cs:
* TargetName : is the name by which the target is known, not to be confused with target address, either obtained via the target administrator, or from a discovery session.
* TargetAddress : is of the form domainname[:port][,portal-group-tag] to quote the RFC: The domainname can be specified as either a DNS host name, a dotted-decimal IPv4 address, or a bracketed IPv6 address as specified in [RFC2732].
* } : End of config

Start an iSCSI session

The following command will read options from /etc/iscsi.conf, use the targetaddress found in the block nicknamed myiscsi, login and negotiate whatever options are specified, and start an iscsi-session.
# iscontrol -c /etc/iscsi.conf -n officeiscsi
Once you run the iscontrol command it should create a new device in /dev directory. To see the device name run dmesg command:
# dmesg
Format iSCSI volume

Now run sysinstall command to format just discovered iSCSI device name at /dev location:
# sysinstall
Select Custom > 3 Partition > Select iSCSI device name such as da1. Once formatted just mount device, enter:
# mkdir /iscsi
# mount /dev/da1s1 /iscsi
You may also need to update /etc/fstab file:
/dev/ad1s1 /iscsi ufs rw 3 3

Reference: http://www.cyberciti.biz/faq/freebsd-iscsi-initiator-howto/

Setting Up a CentOS / Red Hat Linux DHCP Client

SkyHi @ Wednesday, August 26, 2009
Q. How do I setup my Red Hat / CentOS / Fedora Linux system to get IP address and other information via a DHCP server for eth0 interface?

A. You can edit eth0 configuration file to switch between static and dhcp networking configuration under RHEL / Fedora or CentOS Linux. Simply edit /etc/sysconfig/network-scripts/ifcfg-eth0 file.
Backup existing static configuration

First backup existing network configuration file using cp command:
# cp /etc/sysconfig/network-scripts/ifcfg-eth0 /root/ifcfg-eth0.bak
Configuring a DHCP Client

Setting up a Linux for dhcp can be done by editing file using a text editor such as vi:
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
Following is sample static configuration:
DEVICE=eth0
BOOTPROTO=static
HWADDR=00:19:D1:2A:BA:A8
IPADDR=10.10.29.66
NETMASK=255.255.255.192
ONBOOT=yes
Replace static configuration with DHCP:
DEVICE=eth0
BOOTPROTO=dhcp
HWADDR=00:19:D1:2A:BA:A8
ONBOOT=yes
Save and close the file. Just restart network service:
# /etc/init.d/network restart
Please note that you need a configuration file for each device that you want to configure to use DHCP.

Reference: http://www.cyberciti.biz/faq/setting-up-a-linux-for-dhcp/

FreeBSD Install Applications

SkyHi @ Wednesday, August 26, 2009
Q. How do I install applications under FreeBSD operating systems?

A. Just like any other open source operating system, FreeBSD comes with a rich set of applications. You need to install all 3rd party apps using:

[]a] Ports collection - For installing packages from source code

[b] Binary packages - For installing pre-built binary packages
FreeBSD Install Application using pkg_add command (binary method)

You need to use pkg_add command for installing software package distributions. If your package file name is foo-1.2.tgz, enter:
# pkg_add foo-1.2.tgz
You can install package using internet i.e. use the remote fetching feature. This will determine the appropriate objformat and release and then fetch and install the package.
# pkg_add -r -v {package-name}
# pkg_add -r -v bash
# pkg_add -r -v mysql-server
Task: View installed packages

Use pkg_info command:
# pkg_info
Sample output:

bash-3.2.25 The GNU Project's Bourne Again SHell
cvsup-without-gui-16.1h_3 General network file distribution system optimized for CVS
db41-4.1.25_4 The Berkeley DB package, revision 4.1
gettext-0.16.1_3 GNU gettext package
libiconv-1.11_1 A character set conversion library
mysql-client-5.1.22 Multithreaded SQL database (client)
nagios-statd-3.12 Daemon/client to check remote host information for Nagios
net-snmp-5.3.1_7 An extendable SNMP implementation
perl-5.8.8_1 Practical Extraction and Report Language
portupgrade-2.4.3_2,2 FreeBSD ports/packages administration and management tool s
python25-2.5.1_1 An interpreted object-oriented programming language
rsnapshot-1.3.0 Filesystem snapshot utility based on rsync(1)
rsync-2.6.9_2 A network file distribution/synchronization utility
ruby-1.8.6.111_1,1 An object-oriented interpreted scripting language
ruby18-bdb-0.6.2 Ruby interface to Sleepycat's Berkeley DB revision 2 or lat

You can get detailed package information by entering following command:
$ pkg_info {package-name}
# pkg_info rsync-2.6.9_2
Output:

Information for rsync-2.6.9_2:

Comment:
A network file distribution/synchronization utility

Required by:
rsnapshot-1.3.0

Description:
rsync is a replacement for rcp that has many more features.

rsync uses the "rsync algorithm" which provides a very fast method for
bringing remote files into sync. It does this by sending just the
differences in the files across the link, without requiring that both
sets of files are present at one of the ends of the link beforehand.
This makes rsync a good remote file distribution/synchronization utility
in a dialup PPP/SLIP environment.

Note, requires rsync on the destination machine.

There is a Computer Science Technical Report on the rsync algorithm is
included in the distribution, and is available as
ftp://samba.anu.edu.au/pub/rsync/tech_report.ps

WWW: http://rsync.samba.org/

FreeBSD Install Application using ports (source method)

/usr/ports directory has FreBSD ports collection installed. Always update FreeBSD ports collection before installing a new software:
# portsnap fetch
# portsnap update
Before you can install any applications you need to know what you want, and what the application is called. Use wheris command to find out exact location under /usr/ports directory. For example find out bash package location enter:
# whereis bash
Output:

/usr/ports/shells/bash

To install bash, enter:
# cd /usr/ports/shells/bash
# make install clean
The FreeBSD web site maintains an up-to-date searchable list of all the available applications, at http://www.FreeBSD.org/ports/

Reference: http://www.cyberciti.biz/faq/howto-freebsd-install-application/

Apache Web Server .htaccess File , AllowOverride All, Order deny allow

SkyHi @ Wednesday, August 26, 2009
Q. I'm using CentOS Linux server with Apache 2 and PHP. I've created .htaccess file for URL rewrting and other configuration options. However, my Apache version 2 .htaccess configuration is not working at all. How do I fix this problem?

Q. .htaccess is Apache's directory-level configuration file. It allows end user to congigure authentication and other options without editing main httpd.conf file.
Make sure AccessFileName set to .htaccess

Search httpd.conf for AccessFileName directive. It defines name of the distributed configuration file:
# grep -i AccessFileName httpd.conf
Make sure users are allowed to use .htaccess file

What you can put in these files is determined by the AllowOverride directive. This directive specifies, in categories, what directives will be honored if they are found in a .htaccess file. If this directive is set to None, then .htaccess files are completely ignored. In this case, the server will not even attempt to read .htaccess files in the filesystem.
# grep -i AllowOverride httpd.conf
When this directive is set to All, then any directive which has the .htaccess Context is allowed in .htaccess files:
AllowOverride ALL
Save and close the file. Restart httpd:
# service httpd restart


<directory "/var/www/html/home.example.com/html">
Order deny, allow
Deny from all
Allow from 192.168.100
</directory>




<directory "/var/www/html/home.example.com/html">
AllowOverride All
</directory>




##Virtualhost Location
Include /etc/httpd/conf/sites



Reference: http://www.cyberciti.biz/faq/apache-htaccess/

What Would Cause a Lot of ARP Broadcasts From One System / Machine

SkyHi @ Wednesday, August 26, 2009
Q. I'm experiencing decreased network performance due to ARP broadcasts coming from one system. What would cause a lot of ARP broadcasts from one server / computer?

A. ARP convers a 32 bit IP address into a 48-bit Ethernet address. The Address Resolution Protocol (ARP), is used to do this under FDDI or Ethernet. ARP works by broadcasting a packet to all hosts attached to an Ethernet. The packet contains the IP address the sender is interested in communicating with. Most hosts ignore the packet. The target machine, recognizing that the IP address in the packet matches its own, returns an answer.
Reasons For Excessive ARP Broadcasts Requests

[a] Duplicate IP addresses - Make sure IPs are correctly assigned. Use arpping command to detect all duplicate IP address.

[b] Make sure subnet masks are valid for entire network.

[c] Disable IPMI-LAN connection if not used via BIOS or motherboard / server setup utility

[d] Replace NIC as it may be soon going out of service (failing NIC)

I recommend running Ethereal software - a network protocol analyzer for Unix and Windows to troubleshoot problem further.

Search Multiple Words / String Pattern Using grep Command

SkyHi @ Wednesday, August 26, 2009
Q. How do I search multiple string using grep command? For example I'd like to search word1, word2, word3 and so on within /path/to/file. How do I force grep to search multiple words?

A. grep command supports regular expression pattern.
Grep command example

To search multiple words, use following syntax:
grep 'word1|word2|word3' /path/to/file

For example, search warning, error, and critical words in a text log file called /var/log/messages, enter:
$ grep 'warning|error|critical' /var/log/messages
To just match words, add -w swith:
$ grep -w 'warning|error|critical' /var/log/messages

FreeBSD Configure Apache 2.2 PHP with FastCGI mod_fcgi Module

SkyHi @ Wednesday, August 26, 2009
I'd like to switch from mod_php5 to mod_fastcgi. I'm using FreeBSD 7 release along with following software:

+ Apache 2.2
+ PHP as mod_php5
+ MySQL DB 5.1.23 server
How do I configure php as FastCGI server?

mod_fcgid has a new process management strategy, which concentrates on reducing the number of fastcgi server, and kick out the corrupt fastcgi server as soon as possible. It is a binary compatibility alternative to Apache module mod_fastcgi; so your existing fastcgi programs do not need to be recompiled. mod_fcgid supports suEXEC.
Why run PHP5 as mod_fcgi / mod_fastcgi?

FastCGI as has some serious advantages over mod_php5:

* You can do user level separations. You can enable quotas per user. Limit users by processes and CPU consumption.
* chroot security call per user possible
* According to several reports fastcgi works much faster than mod_php and cgi mode.

Step # 1: Install mod_fcgid

Make sure your ports are upto date:
# portsnap fetch update
Install mod_fcgid:
# cd /usr/ports/www/mod_fcgid
# make install clean
Make sure php supports FastCGI

Make sure php-cgi binary exists and it is compiled with fastcgi support:
# cd /usr/ports/lang/php5
# make showconfig | grep -i FASTCGI

Output:

FASTCGI=on "Enable fastcgi support (CGI only)"

Another way to test fastcgi support, enter:
# /usr/local/bin/php-cgi -v
Output:

PHP 5.2.5 with Suhosin-Patch 0.9.6.2 (cgi-fcgi) (built: Mar 6 2008 09:15:41)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies

If you don't see word cgi-fcgi, recompile php with fastcgi support by visiting /usr/ports/lang/php5
# cd /usr/ports/lang/php5
# make config
# make install clean
Step # 3: Load mod_fcgi module

Open your httpd.conf file located at /usr/local/etc/apache22/ directory:
# vi /usr/local/etc/apache22/httpd.conf
Load mod_fcgi module:
LoadModule fcgid_module libexec/apache22/mod_fcgid.so
Configure mod_fcgi


AddHandler fcgid-script .fcgi
FCGIWrapper /usr/local/bin/php-cgi .php


Find your DocumentRoot directory configuration option that read as follows:



Append following two lines:
SetHandler fcgid-script
FCGIWrapper /usr/local/bin/php-cgi .php
Options ExecCGI

At the end configuration should read as follows:

# This should be changed to whatever you set DocumentRoot to.

Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
SetHandler fcgid-script
FCGIWrapper /usr/local/bin/php-cgi .php
Options ExecCGI
Allow from all


Step # 4: Disable mod_php5

Find line that read as follows:
LoadModule php5_module libexec/apache22/libphp5.so
Comment out line:
#LoadModule php5_module libexec/apache22/libphp5.so
Also make sure following two line (mime type) exists:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

Save and close the file.
Step # 5: Restart Apache22

Finally, restart apache web server:
# /usr/local/etc/rc.d/apache22 restart
Step # 5: Test mod_fcgi

Use following small program to verify mod_fcgi is working properly:

phpinfo();
?>

You must see Server API as CGI/FastCGI as well as following screen:
FreeBSD PHP5 mod_fcgi
(Fig. 01: PHP5 Configured as FastCGI using mod_fcgi)
Further readings:

* mod_fcgid project
* FreeBSD project

Updated for accuracy.

Reference: http://www.cyberciti.biz/faq/freebsd-apache22-fastcgi-php-configuration/