2011/03/01

Setting up django: step 1, python 2.7.1

Just trying out some django in centos 5.5. So this should not been seen as a good solution. Just me trying to set it up properly

some pre preps
yum -y groupinstall 'Development Tools'
yum -y install openssl-devel* zlib*.x86_64
yum -y install httpd-devel
yum -y install mysql-devel
yum -y install wget

downloaded and untarred 2.7.1
cd /usr/local/src
wget http://www.python.org/ftp/python/2.7.1/Python-2.7.1.tgz
tar -xzvf Python-2.7.1.tgz


compiled it with embedded so we can use apache mod wsgi. Used a seperate path so that it is not conflicting with the internal python
./configure --prefix=/opt/python2.7 --with-threads --enable-shared
make
make install

added the new library to the dynamic loader
echo "/opt/python2.7/lib" > /etc/ld.so.conf.d/python27.conf
ldconfig

We can now test it
[root@django ld.so.conf.d]# /opt/python2.7/bin/python
Python 2.7.1 (r271:86832, Mar 1 2011, 21:14:38)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

ln -s /opt/python2.7/bin/python2.7 /usr/bin/python2.7
ln -s /opt/python2.7/lib/libpython2.7.so /usr/lib/libpython2.7.so

Installing the setup tools
cd /usr/local/src
wget http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg
sh setuptools-0.6c11-py2.7.egg --prefix=/opt/python2.7


Installing the mysql bindings
cd /usr/local/src
wget http://downloads.sourceforge.net/project/mysql-python/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz?r=&ts=1299013136&use_mirror=netcologne
tar -xzvf MySQL-python-1.2.3.tar.gz
python2.7 setup.py build
python2.7 setup.py install

Installing wsgi
cd /usr/local/src
wget http://modwsgi.googlecode.com/files/mod_wsgi-3.3.tar.gz
./configure --enable-shared --prefix=/opt/mod_wsgi-3.3 --with-python=/opt/python2.7/bin/python
make
make install

A mod should be made. You can find it in
Libraries have been installed in:
/usr/lib64/httpd/modules

The mod itself:
/usr/lib64/httpd/modules/mod_wsgi.so

echo "LoadModule wsgi_module /usr/lib64/httpd/modules/mod_wsgi.so" > /etc/httpd/conf.d/wsgi.conf
echo "AddHandler wsgi-script .wsgi" >> /etc/httpd/conf.d/wsgi.conf
chmod 755 /etc/httpd/conf.d/wsgi.conf
/etc/init.d/httpd restart

Installing django
wget http://www.djangoproject.com/download/1.2.5/tarball/
python2.7 setup.py install

cd /tmp
cat <<> test.py
#!/opt/python2.7/bin/python
import django
print django.get_version()
EOF
chmod +x test.py
[root@django html]# ./test.py
1.2.5

Symlinking the django admin so we can use it everywhere
ln -s /opt/python2.7/bin/django-admin.py /usr/local/bin/django-admin.py

Configuring apache to use django
cat <<> /etc/httpd/conf.d/django.conf
WSGIScriptAlias / /var/www/django/django.wsgi

Order allow,deny
Allow from all
EOF

creating the django handler
mkdir -p /var/www/django
cat <<> /var/www/django/django.wsgi
import os
import sys

path = '/var/www/django'
if path not in sys.path:
sys.path.append(path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
EOF
chmod 755 /var/www/django/django.wsgi

Now we can create a site
cd /var/www/django/
django-admin.py startproject mysite

Restart the webserver to activate everything
/etc/init.d/httpd restart

Surf to your http server ot see the result













2011/02/25

vcloud some more lessons learned: transfer volume

For my first vcloud cell I decided to make a seperate logical volume group that I could then export and share with other cloud cell. When I was done doing so I had the following result

A seperate logical volume in a seperate volume group
[root@abincloudhttp logs]# lvdisplay clouddata
--- Logical volume ---
LV Name /dev/clouddata/lvcloud
VG Name clouddata
LV UUID LCUjhy-vQxM-Taxn-0A2e-4ac7-F1UL-chl7dH
LV Write Access read/write
LV Status available
# open 1
LV Size 100.00 GB
Current LE 25599
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2

A new entry in fstab
[root@abincloudhttp logs]# cat /etc/fstab | grep clouddata
/dev/clouddata/lvcloud /opt/vmware/cloud-director/data/transfer/ ext3 defaults 1 2

And after everything was mounted via mount -a, a nice clean mount
[root@abincloudhttp logs]# df -h | grep transfer
99G 188M 94G 1% /opt/vmware/cloud-director/data/transfer

Also changed the export file
[root@abincloudhttp logs]# cat /etc/exports
/opt/vmware/cloud-director/data/transfer/ 0.0.0.0/0.0.0.0(rw,no_root_squash)

(This is poor security ofcourse as I should have used my local subnet/subnetmask and no_root_squash is not really good anyway :))

When I tried to start up my cloud cell, I got a 404 warnings that the application was not available. Not knowing where to look I started to google and found that the logs are kept on a straightforward location
/opt/vmware/cloud-director/logs/

In my cell.log I saw some errors about the transfer directory. I then realised that vcloud, made a seperate user vcloud. However by manually creating another volume group, I overwritten the default ownerships a shown below
[root@abincloudhttp data]# ls -alh
total 44K
drwxr-xr-x 6 vcloud vcloud 4.0K Feb 25 10:45 .
drwxr-xr-x 19 vcloud vcloud 4.0K Feb 25 10:31 ..
drwx------ 3 vcloud vcloud 4.0K Feb 25 10:45 activemq
drwx------ 2 vcloud vcloud 4.0K Feb 25 10:31 generated-bundles
drwxr-xr-x 3 root root 4.0K Feb 24 10:51 transfer
drwx------ 2 vcloud vcloud 4.0K Feb 25 10:45 txlog

a simple chown vcloud:vcloud transfer and service vmware-vcd restart solved the problem :)


2011/02/24

cloud director: some quick reminders

centos packages
  • yum install -y alsa-lib bash chkconfig compat-libcom_err coreutils findutils glibc grep initscripts krb5-libs libgcc libICE libSM libstdc libX11 libXau libXdmcp libXext libXi libXt libXtst module-init-tools net-tools pciutils procps redhat-lsb sed tar which libstdc++
post install certificates generation
  • cd /opt/vmware/cloud-director/
  • cd jre/bin/
  • mkdir /opt/vmware/cloud-director/keys
  • ./keytool -keystore /opt/vmware/cloud-director/certificates.ks -storetype JCEKS -storepass mysupersecretpass987654321 -genkey -keyalg RSA -alias http
  • ./keytool -keystore /opt/vmware/cloud-director/certificates.ks -storetype JCEKS -storepass mysupersecretpass987654321 -genkey -keyalg RSA -alias consoleproxy
  • ./keytool -keystore /opt/vmware/cloud-director/certificates.ks -storetype JCEKS -storepass mysupersecretpass987654321 -list

2011/02/19

Cheap Host Profiles Remake

I realised that setting up the host profiles before was complex. Since I was playing around with google app engine I thought to myself, lets do a remake. The result can be found here . Since I'm using GAE, I am using google API's to authenticate. Hence you can login with your gmail account. Notice that the acode part is an activation code. Please do not bookmark this url, is it just to activate your google account. Instead use this url once your account is "activated".

Basically it is the same syntax (a complete example is available in the "help" section) but better output :). Planning on doing some better error catching but basically if you don't do anything wrong, everything should work. Also thinking about maybe generating some documentation from the XML... we will see :)

2011/02/17

More vMA fun

Show the states of a path for every lun

for disk in $(esxcfg-scsidevs -m | sed 's/^\([^:]*\).*/\1/g'); do echo "Device $disk";esxcfg-mpath -l -d $disk | grep -e "State:" -e "Target Transport Details:"; done;

2011/01/06

Another oneliner : using esxcli to change to roundrobin

for disk in $(esxcli nmp device list | grep -B2 -e "Storage Array Type: VMW_SATP_SVC" | grep -e "^naa"); do echo "esxcli nmp device setpolicy --device $disk --psp VMW_PSP_RR";done;

Should find all SVC luns and echo the command to change the disk to round robin path policy. If you have identical ESX configs (like most clusters do), you can copy past the output to every esx host. For example

~ # for disk in $(esxcli nmp device list | grep -B2 -e "Storage Array Type: VMW_SATP_SVC" | grep -e "^naa"); do echo "esxcli nmp device setpolicy --device $disk --psp VMW_PSP_RR";done;
esxcli nmp device setpolicy --device naa.600507680181055b18000000000000f6 --psp VMW_PSP_RR
esxcli nmp device setpolicy --device naa.600507680181055b18000000000000f7 --psp VMW_PSP_RR
esxcli nmp device setpolicy --device naa.600507680181055b18000000000000f8 --psp VMW_PSP_RR
esxcli nmp device setpolicy --device naa.600507680181055b18000000000000f9 --psp VMW_PSP_RR
esxcli nmp device setpolicy --device naa.600507680181055b18000000000000fb --psp VMW_PSP_RR
~ #

Just a fastliner

interfaceips=$(ifconfig -a| grep "inet addr" | sed 's/\s\+/ /g;s/^\s\+//;s/^inet addr://' | cut -f1 -d" ")
for ip in $interfaceips
do
echo "scp $(whoami)@$ip:$(pwd)/$1"
done