Sunday Apr 26, 2009

Install libssh2 in a non-standard location on SXCE

Libssh2 is a php extension that allows ssh connections to a remote machine in order to execute shell commands or even access the remote shell. Subsequently, the output from these commands can be displayed in a browser, as required. Evidently, it can be convenient to use it in various scenarios, where such a need may arise.

It's official website defines Libssh2 as:

libssh2 is a library implementing the SSH2 protocol as defined by Internet Drafts: SECSH-TRANS, SECSH-USERAUTH, SECSH-CONNECTION, SECSH-ARCH, SECSH-FILEXFER, SECSH-DHGEX, SECSH-NUMBERS, and SECSH-PUBLICKEY.

Many a times, we are faced with situations where we do not have root privileges on a unix box, and hence we are unable to install tools in their default path (eg. /usr/local/bin, /usr/local/include). As a result, we have to customize the installation by providing a non-standard location (eg. ~/$HOME), and providing additional flags for procedures like configure, build and install.

In this article, we have listed the steps involved in installing the libssh2 library on Solaris Express Community Edition. However, the same set of steps will work on any other unix distro, with minor changes.

Install libssh2
cd /tmp
wget http://voxel.dl.sourceforge.net/sourceforge/libssh2/libssh2-0.18.tar.gz
tar xvf libssh2-0.18.tar.gz
cd libssh2-0.18

Since, the /usr/local directory is "read-only", we'll provide a prefix in the configure step

-bash-3.2# ./configure --prefix=/opt/install

 -bash-3.2# make all install

Install PECL ssh2

-bash-3.2# wget http://pecl.php.net/get/ssh2-0.10.tgz
-bash-3.2# tar xvf ssh2-0.10.tar
x package.xml, 3091 bytes, 7 tape blocks
x ssh2-0.10/config.m4, 2149 bytes, 5 tape blocks
x ssh2-0.10/ssh2.c, 43225 bytes, 85 tape blocks
x ssh2-0.10/php_ssh2.h, 5397 bytes, 11 tape blocks
x ssh2-0.10/ssh2_fopen_wrappers.c, 36414 bytes, 72 tape blocks
x ssh2-0.10/ssh2_sftp.c, 22321 bytes, 44 tape blocks

Patch the ssh2.c file
-bash-3.2# cd ssh2-0.10
-bash-3.2# vi ssh2.c

Seach for
#if LIBSSH2_APINO < 200412301450
Change it to as followings
#if LIBSSH2_VERSION_NUM < 0x001000
Save the file and run

From the ssh2-0.10 directory, run

-bash-3.2# /usr/php/5.2/bin/phpize
Configuring for:
PHP Api Version:         20041225
Zend Module Api No:      20060613
Zend Extension Api No:   220060519


-bash-3.2# env CPPFLAGS="-I/opt/install/include" LDFLAGS="-L/opt/install/lib" ./configure --with-ssh2=/opt/install/lib --with-php-config=/usr/php/5.2/bin/php-config --prefix=/opt/install

-bash-3.2# make

-bash-3.2# make install
Installing shared extensions:     /var/php/5.2/modules/

Add the entry for the ssh2 extension in php.ini
vi /etc/php/5.2/php.ini
under Dynamic Extension, add
extension=ssh2.sos

Restart the apache service
svcadm restart apache22

Check if the service started successfully
svcs apache22

Thursday Apr 23, 2009

Using EBS with OpenSolaris 2008 AMI on Amazon EC2

Amazon describes the functionality provided by EBS as follows:

“Amazon Elastic Block Store (EBS) provides block level storage volumes for use with
Amazon EC2 instances. Amazon EBS volumes are off-instance storage that persists
independently from the life of an instance. Amazon Elastic Block Store provides highly
available, highly reliable storage volumes that can be attached to a running Amazon EC2
instance and exposed as a device within the instance. Amazon EBS is particularly suited for
applications that require a database, file system, or access to raw block level storage.”

 In this article, we  will list all the necessary steps involved in creating new EBS volumes and attaching them to an existing instance. The following commands were run on an OpenSolaris 2008.11 instance. The disk device name may change in other AMIs.

Set the Environment Variables on local machine
export EC2_HOME=/opt/ec2
export PATH=$PATH:$EC2_HOME/bin
export EC2_PRIVATE_KEY=$EC2_HOME/keys/pk-\*\*\*\*\*\*\*\*\*\*\*\*.pem
export EC2_CERT=$EC2_HOME/keys/cert-\*\*\*\*\*\*\*\*\*\*\*\*.pem
export JAVA_HOME=/usr/jdk/latest
export EC2_URL=https://ec2.amazonaws.com

Note: Replace the values of the environment variables accordingly.


Start an OpenSolaris 2008 Instance 
ec2-run-instances ami-7db75014 -k prateek-keypair

Login to the Instance
ssh -i /PATH/TO/keypair-file root@ec2-XX-XXX-XXX-XXX.compute-1.amazonaws.com
Note: Replace the value of the public host name of the above instance accordingly.


Create a keys directory
mkdir /opt/ec2/keys

Transfer your Private key and certificate to the Instance from local machine
scp -i /PATH/TO/keypair-file /PATH/TO/KEYS/\*pem root@root@ec2-XX-XXX-XXX-XXX.compute-1.amazonaws.com:/opt/ec2/keys

Set the Environment Variables on the EC2 instance

export EC2_HOME=/home/EC2/ec2-api-tools-1.3-19403
export PATH=$PATH:$EC2_HOME/bin
export EC2_PRIVATE_KEY=/home/EC2/ec2-api-tools-1.3-19403/keys/pk-\*\*\*\*\*\*\*\*\*\*\*\*.pem
export EC2_CERT=/home//EC2/ec2-api-tools-1.3-19403/keys/cert-\*\*\*\*\*\*\*\*\*\*\*\*.pem
export JAVA_HOME=/usr/jdk/latest
export EC2_URL=https://ec2.amazonaws.com

Create a new EBS Volume
The following command can be repeated as needed to create additional volumes.
ec2-create-volume --size 128 --availability-zone us-east-1a
VOLUME  vol-b1dc3fd8    128             us-east-1a      creating        2009-04-22T01:23:00+0000

ec2-describe-volumes vol-b1dc3fd8
VOLUME  vol-b1dc3fd8    128             us-east-1a      available       2009-04-22T01:23:00+0000

You can list all the volumes along with their status as:
ec2-describe-volumes | cut -f2,3,5,6

vol-7208ed1b    2       us-east-1c      available
vol-99dc3ff0    128     us-east-1a      available
vol-0f2ecb66    1       us-east-1a      available
vol-b1dc3fd8    128     us-east-1a      available

Attaching Volumes to an OpenSolaris EC2 Instance
The command for attaching volumes to an instance is:
ec2-attach-volume -i <instance-id> -d <device-id> VOLUMENAME

In Solaris, devices are named from 0 to 23. Device number 0 and 1 are used for ephemeral storage. Therefore, we can use the devices starting from 2 until 23.
I have attached 2 volumes to the current instances below:

ec2-attach-volume -i i-ed573f84 -d 3 vol-6123c008
ec2-attach-volume -i i-ed573f84 -d 4 vol-b1dc3fd8

The list of the attached volumes can be displayed as:
ec2-describe-volumes | grep attached

ATTACHMENT      vol-99dc3ff0    i-ed573f84      2       attached        2009-04-22T02:46:24+0000
ATTACHMENT      vol-6123c008    i-ed573f84      3       attached        2009-04-22T02:47:22+0000
ATTACHMENT      vol-b1dc3fd8    i-ed573f84      4       attached        2009-04-22T02:47:57+0000
ATTACHMENT      vol-6e23c007    i-ed573f84      5       attached        2009-04-22T02:48:16+0000

Using EBS volumes from the Solaris Instance
You can view the mapping of the Solaris devices to the EBS volumes that we created earlier.

NOTE: Use c4d\*p0 for OpenSolaris 2008.05 (ami-41e70328 )and c0d\*p0 for SXCE Build 79 32 bit image (ami-eb7a9f82)

ls -l /dev/dsk/c3d\*p0
lrwxrwxrwx 1 root root 26 2008-12-14 23:32 c3d0p0 -> ../../devices/xpvd/xdf@0:q
lrwxrwxrwx 1 root root 26 2008-12-22 18:54 c3d1p0 -> ../../devices/xpvd/xdf@1:q
lrwxrwxrwx 1 root root 26 2009-04-22 02:46 c3d2p0 -> ../../devices/xpvd/xdf@2:q
lrwxrwxrwx 1 root root 26 2009-04-22 02:47 c3d3p0 -> ../../devices/xpvd/xdf@3:q
lrwxrwxrwx 1 root root 26 2009-04-22 02:47 c3d4p0 -> ../../devices/xpvd/xdf@4:q
lrwxrwxrwx 1 root root 26 2009-04-22 02:48 c3d5p0 -> ../../devices/xpvd/xdf@5:q
lrwxrwxrwx 1 root root 26 2008-12-14 23:32 c3d6p0 -> ../../devices/xpvd/xdf@6:q

Now, you can use these EBS volumes just like you would use any other attached storage device. 

About

Prateek Parekh

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today