Meek Consulting

Just another WordPress weblog

Configuring Apache on CENTOS:
Just some random notes on what I had to do to get my Perferred tools installed on Apache under centos:

yum install php-Smarty php-pear php-pear-MDB2 php-mysql

To get pear configured I ran these commands:

pear upgrade MDB2
pear install ‘MDB2#mysql’
pear channel-discover pear.firephp.org
pear install firephp/FirePHPCore

After starting up mysqld I ran the script to set root password and lock down the mysql db:

service mysqld start

/usr/bin/mysql_secure_installation

=======

Other useful commands:

chcon -R -h -t httpd_sys_content_t www

service httpd restart

mkdir /usr2/apps/Smarty

cd /usr2/apps/Smarty

wget http://www.smarty.net/do_download.php?download_file=Smarty-2.6.26.tar.gz

tar xozvf Smarty-2.6.26.tar.gz

mkdir /usr/local/lib/php

mkdir /usr/local/lib/php/Smarty

cp -r Smarty-2.6.26/libs/* /usr/local/lib/php/Smarty

Set include path:

vi php.ini

AND MAKE FOLLOWING edit tot he include path line

include_path = “.:/usr/share/php:/usr/local/lib/php/Smarty:/usr/share/pear”

Restart Webserver

service httpd restart

Calculating the Fiscal Year in Excel

Jason came up with this nifty formula to calculate the fiscal year in excel based on a string in the YYYY-MM-DD format.
It could be adapted to support other formats by changing the MID substring values ( MID is the excel Substring function).

This example references a date in cell AB7 — you’ll have to change that to refer to your date field.

=IF(MID(AB7,6,2)=”10″,MID(AB7,1,4)+1,IF(MID(AB7,6,2)=”11″,MID(AB7,1,4)+1,IF(MID(AB7,6,2)=”12″,MID(AB7,1,4)+1,0+MID(AB7,1,4))))

[ad#Google Adsense]

Using CRL lists with PKI certificate of authorities

Notes from 3/8/2010  troubleshooting crl issues.

Users called and could not access the cobra web site.

They were using certificates issued by Verisign – specifically:

CN=VeriSign Client External Certification Authority – G2

I checked our page using the command:

openssl s_client -showcerts  -connect usecobra.com:443 -prexit

and we were not accepting verisign G2 cert on cobra

So I went to the DISA webpage: https://crl.chamb.disa.mil/

NOTE:  a quicker way to get the new cert is to cut and paste from the view screen after selecting a cert on the left and clicking view on the right side of the page.

This is an ascii representation of the cert known as PEM format.  ( as apposed to the .DER format  which is binary that you get when you use the download link.

For our purposes we want the PEM format ascii file to put in our ca-bundle.txt

I like to put the PEM cert in a file by itself to verify it.  I named this one verisign_ECA_G2.crt

Then I can run this to verify and get the issuer / subject to up in the comments.

openssl x509 -inform PEM -in verisign_ECA_G2.crt -issuer -subject –noout

issuer= /C=US/O=U.S. Government/OU=ECA/CN=ECA Root CA 2

subject= /C=US/O=U.S. Government/OU=ECA/OU=Certification Authorities/CN=VeriSign Client External Certification Authority – G2

I edited the ca-bundle.crt to add the comments at the top and the cert.

I add the code like this:

#############################################

#subject= /C=US/O=U.S. Government/OU=ECA/OU=Certification Authorities/CN=VeriSign Client External Certification Authority – G2

#issuer= /C=US/O=U.S. Government/OU=ECA/CN=ECA Root CA 2

—–BEGIN CERTIFICATE—–

MIIF7DCCBNSgAwIBAgIBCjANBgkqhkiG9w0BAQUFADBNMQswCQYDVQQGEwJVUzEY

MBYGA1UEChMPVS5TLiBHb3Zlcm5tZW50MQwwCgYDVQQLEwNFQ0ExFjAUBgNVBAMT

DUVDQSBSb290IENBIDIwHhcNMDgwNzAyMTQ0MTE4WhcNMTQwNzAxMTQ0MTE4WjCB

X158kXsnY2wvH2WdMMpHmj7GvikIw/tP/7w9/uwe6mE=

—–END CERTIFICATE—–

ON linux just restart the webserver to make it take affecte

service httpd restart

On oracle it is a little more complicated:

Log in as oracle

. formsset

cd /ora/wallets

## Save off the wallet.p12  for backup

cp wallet.p12 wallet.p12.100308

Edit ca-bundle.crt as described above.

Run ./import_cert which will “recomple” the wallet.p12 by running this command:

/ora/10ias/Apache/Apache/bin/ssl2ossl -cert /ora/wallets/usecobra.com.crt -key /ora/wallets/usecobra.com.key -cafile /ora/wallets/ca-bundle.crt -wallet /ora/wallets

You will need the password for the wallet as well as the key to complete this command.

Note – if it fails that means the cert you added is invalid – OR you do not have the cert for the all the parents up the chain of the issuer of that cert.

Then to restart the webserver on Oracle Solaris run the following commands

$ORACLE_HOME/opmn/bin/opmnctl status

$ORACLE_HOME/opmn/bin/opmnctl stopproc ias-component=HTTP_Server

$ORACLE_HOME/opmn/bin/opmnctl startproc ias-component=HTTP_Server

$ORACLE_HOME/opmn/bin/opmnctl status

Out of date CRL lists!!!

We found out today that the reason G2 certs from verisign were not being accepted was because the CRL file for Verisign we had in place was out of date.

All certs from an issuer whose CRL is expired are rejected until we get  a valid CRL list from that issuer – this is the concept that if my guest list is considered obsolete – no one from that source will get in.  Make sense.

openssl crl -inform DER -in /etc/httpd/crl/VERISIGNCLIENTEXTERNALCERTIFICATIONAUTHORITY_G2.crl -text | less

The command above will show the revoked certs by date and reason – as well as the “validitiy dates” for the list

Certificate Revocation List (CRL):

Version 2 (0×1)

Signature Algorithm: sha1WithRSAEncryption

Issuer: /C=US/O=U.S. Government/OU=ECA/OU=Certification Authorities/CN=VeriSign Client External Certification Authority – G2

Last Update: May 29 15:23:49 2009 GMT

Next Update: May 30 09:23:49 2009 GMT

In the above example has a Next Update date – after that time no one with a verisign G2 signed cert will be able to get in.

converting julian date to real date in mysql

We’ve got data that uses a funky date format — not a true julian date  but the Year followed by the DAY of the year.

i.e.

2010005 = January 5th, 2010

2010031 = January 31st 2010

2010365 = December 31st 2010

This little snippet of code will allow you to select it from the mysql database and convert it to a real date.

select date_sub(date_add(concat(substr(jdate,1,4),’-01-01′), interval substr(jdate,5,3) day ), interval 1 day)

so in this example below returns May 2 ( the 123rd day of 2004 is May 2 )

select date_sub(date_add(concat(substr(’2004123′,1,4),’-01-01′), interval substr(’2004123′,5,3) day ), interval 1 day)

Vim colorschemes

If you want to customize the colors you get in  VIM

Here is a gallery:   http://vimcolorschemetest.googlecode.com/svn/html/index-html.html

To try out different schemes you can type

:colorscheme XXXXX

in vi  where XXX is the scheme name  (without the .vim extension )

Once you find one you like you can put that command in your .vimrc in your home directory

I like :colorscheme darkblue

It looks for the files in /usr/share/vim/vim70/colors directory.

The only ones we have now on ccdev are listed below — if you pick one from that website we can download it and put it in that directory so everyone can choose it.

/usr/share/vim/vim70/colors/blue.vim

/usr/share/vim/vim70/colors/darkblue.vim

/usr/share/vim/vim70/colors/default.vim

/usr/share/vim/vim70/colors/delek.vim

/usr/share/vim/vim70/colors/desert.vim

/usr/share/vim/vim70/colors/elflord.vim

/usr/share/vim/vim70/colors/evening.vim

/usr/share/vim/vim70/colors/koehler.vim

/usr/share/vim/vim70/colors/morning.vim

/usr/share/vim/vim70/colors/murphy.vim

/usr/share/vim/vim70/colors/pablo.vim

/usr/share/vim/vim70/colors/peachpuff.vim

/usr/share/vim/vim70/colors/ron.vim

/usr/share/vim/vim70/colors/shine.vim

/usr/share/vim/vim70/colors/slate.vim

/usr/share/vim/vim70/colors/torte.vim

/usr/share/vim/vim70/colors/zellner.vim

[ad#Google_leaderboard]

Separating storage of mysql database files

We often have very large databases we want to create in mysql.

If we don’t have enough space in the /var/lib/mysql partition it is handy to be able to specify that a specific database be stored on another drive.

This can fairly easily be done by using innodb_file_per_table parameter in your my.cnf and using symbolic links.  The only tricky part is getting it to work under SELinux.  ( Don’t turn off SELINUX like other people say )  just follow these instructions to get it to allow what you want.

Steps to add new database that will use external storage:

Create the database using:

mysqladmin -uroot -p [pw] create newdbname

Shutdown mysql

/etc/init.d/mysqld stop

Edit /etc/my.cnf  adding line for innodb_file_per_table under the mysqld section

[mysqld]

innodb_file_per_table

While db is shut down — move the directory for the new database to a partition with space.

mv /var/lib/mysql/newdbname /bigpartition/mysql/newdbname

Create a symbolic link to the new location ( mysql looks only in /var/lib/mysql for databases on startup)

cd /var/lib/mysql

ln -s /bigpartition/mysql/newdbname newdbname

ls -l /bigpartition/mysql/newdbname

Fix the context on the newly created directories or you the database will not be visible when mysql restarts ( SELinux will prohibit mysql from using files in these directories )

chcon -c -t mysqld_db_t /bigpartition/mysql

chcon -c -t mysqld_db_t /bigpartition/mysql/newdbname

Re-start the MYSQL database

/etc/init.d/mysql start

Restore your database dump or create new tables.  The command I use is:

nohup time gunzip < backup.dmp.gz | mysql -uroot -p[dbpw] newdbname > restore.err 2>&1 &

Loading compressed file into mysql without uncompressing

If you have a compressed file from a mysqldump backup of your mysql database, and you don’t have space to uncompress it to load it on another machine.  You can load it directly from the compress file using this command:

zcat backupdump.sql.gz | mysql -uusername -p databasename

This will uncompress the file on the fly without using the space to hold the uncompressed file.

NOTE: You can create a compressed on the fly backup of a table by doing this command:

mysqldump -uuser -ppass dbname tablename | gzip – > backupdump.sql.gz

Leave out the tablename to dump the entire database..

I run this command in backup scripts for all my databases every night from cron.

These backup scripts typically look like this to name the file using todays date:

#!/bin/bash

cd /backupdirectory

DAY=`date ‘+%m%d%y’`

OUTFILE=”dataabasename.dmp.sql.$DAY.gz”

mysqldump -uuser -ppass dbname | gzip – > $OUTFILE

scp $OUTFILE remoteserverforsafekeeping.com:/backups

Fixing VIM to allow smart match finding using the percent key

Edited the file

/usr/share/vim/vim70/syntax/smarty.vim

Added the following code:

" HTML:  thanks to Johannes Zellner and Benji Fisher.
if exists("loaded_matchit")
let b:match_ignorecase = 1
let b:match_skip = 's:Comment'
let b:match_words = '<:>,' .
\ '<\@<=[ou]l\>[^>]*\%(>\|$\):<\@<=li\>:<\@<=/[ou]l>,' .
\ '<\@<=dl\>[^>]*\%(>\|$\):<\@<=d[td]\>:<\@<=/dl>,' .
\ '<\@<=\([^/][^ \t>]*\)[^>]*\%(>\|$\):<\@<=/\1>'
endif

This sets the HTML tag matching words for the matchit plug in when the filetype of Smarty is identified.

Then I edited the /etc/vimrc

Adding these lines to the bottom:

" CODE added to universally turn on the matchit plugin.
" added K. Meek 9/09
:source /usr/share/vim/vim70/macros/matchit.vim
:filetype plugin on

Now when you are editing a .tpl file the syntax is “SMARTY” for color coding, but the match words will match HTML tags


So you can position your cursor over say a <tr> tag and hit the % key and it will move cursor to the matching </tr> tag.  Same with <div> will find matching </div>

VERY COOL!

You may need the matchit.vim plugin.  You can download it here.

http://www.vim.org/scripts/script.php?script_id=39

Background Gradient Image Creation Tool

If you need to create a gradient image for a background you might try this tool.

It is pretty slick.

http://www.ogim.4u2ges.com/gradient-image-maker.asp

Faster MYSQL Index creation

Creating indexes in mysql on large tables can take a long time. Because it makes a temporary copy of the entire DB file first then creates the indexes.

So be sure you have enough free space for the complete DB ( MYI and MYD for MYISAM databases ) plus space for the new version.

If you need to create multiple indexes doing them all in one command saves the time of creating that copy of the DB each time ( many hours in some cases )

Also increasing the Sort buffer sizes will greatly speed things up.

Here is the SQL we used to reduce creation time from 4 days to 11 hours on a 400 Million record table (80Gig Size).

set myisam_sort_buffer_size=2000000000;
set sort_buffer_size=2000000000;
alter table schema.tablename
add index index1 using BTREE(field1,field2),
add index index2 using BTREE(field3,field4),
add index index3 using BTREE(field5);

Secured for spam by MLW and Associates, LLP's Super CAPTCHASecured by Super-CAPTCHA © 2009-2010 MLW & Associates, LLP. All rights reserved.