Posts

Showing posts from July, 2011

Change Security Groups on EC2

It is difficult to change the secuirty group which an EC2 instance is assigned once its running However one way to accomplish this is 1. Right click on instance and select "Create Image (EBS AMI). For example if the instance is called staging-srv. 2. Give the image a name and description and then create 3. Create your new security group and define required security measures e.g. inbound ports 4. Create a new EC2 instance based on the above created image. 5. If a elastic IP is assigned to staging-srv then disassoicate it 5. Launch the new instance 6. Associate the elastic IP with the new instance 6. Rename the old instance to e.g. staging-srv to staging-srv-old 7. Name the new instance staging-srv 8. Test your new instance with the new security group 9. Once happy it works delete the old ECS instance.

Mount an EBS Volume on CentOS

1. Create a new EBS Volume.  Note the device name returned by AMZ e.g. /dev/sdf 2. Login to your Amazon Instance 3. At the prompt type fdisk /dev/sdf 4. Create a new primary partition and accept all the default values. 5. Type (w) to write partition data to disk 6. At the command prompt type mkfs.ext3 /dev/sdf  to format as an ext3 file system. 7. mkdir /web 8.Type mount /dev/sdf /web

Change Storage Engine from INNODB to MyISAM for all tables

The following is a basic php script to change the storage engine used by all MySQL tables for a specified database to MyISAM from INNODB. <?php $conn = mysql_connect("localhost","username","password"); mysql_select_db("database-name",$conn); $sql = "SHOW tables"; $rs = mysql_query($sql); while($row = mysql_fetch_array($rs)) {   $tbl = $row[0];   $sql = "ALTER TABLE $tbl  ENGINE=myisam";   mysql_query($sql); } ?> To change all tables from MyISAM to INNODB <?php $conn = mysql_connect("localhost","username","password"); mysql_select_db("database-name",$conn); $sql = "SHOW tables"; $rs = mysql_query($sql); while($row = mysql_fetch_array($rs)) {   $tbl = $row[0];   $sql = "ALTER TABLE $tbl  ENGINE=INNODB";   mysql_query($sql); } ?>

Install PHP 5.3.6 on CentOS 64bit

Create Install folders and get rpms Login as root cd $HOME mkdir php-setup-packages cd $HOME/php-setup-packages wget http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm wget http://dl.iuscommunity.org/pub/ius/stable/Redhat/5/x86_64/ius-release-1.0-6.ius.el5.noarch.rpm Install Required RPMs cd $HOME/php-setup-packages rpm -Uvh *.rpm Remove Existing PHP Packages yum remove php php-* Install PHP 5.3.5 Packages yum install php53u-pear yum install php53u php53u-cli yum install php53u-common yum install php53u-devel yum install php53u-gd yum install php53u-mbstring yum install php53u-mcrypt yum install php53u-mysql yum install php53u-pdo yum install php53u-soap yum install php53u-xml yum install php53u-xmlrpc yum install php53u-bcmath yum install php53u-pecl-apc yum install php53u-pecl-memcache yum install php53u-snmp

Chroot Apache on CentOS 5 32bit

SECUREFOLDER=/securesystem mkdir $SECUREFOLDER mkdir -p $SECUREFOLDER/var/run chown -R root.root $SECUREFOLDER/var/run mkdir -p $SECUREFOLDER/home/httpd mkdir -p $SECUREFOLDER/var/www/html mkdir -p $SECUREFOLDER/tmp chmod 1777 $SECUREFOLDER/tmp mkdir -p $SECUREFOLDER/var/lib/php/session chown root.apache $SECUREFOLDER/var/lib/php/session cd /opt/ yum list | grep chroot wget http://core.segfault.pl/~hobbit/mod_chroot/dist/mod_chroot-0.5.tar.gz tar -zxvf mod_chroot-0.5.tar.gz cd mod_chroot-0.5 apxs -cia mod_chroot.c vi /etc/httpd/conf/httpd.conf setsebool httpd_disable_trans 1 vi /etc/init.d/httpd chattr +i /etc/init.d/httpd /etc/init.d/httpd start /etc/init.d/httpd start

Script to chroot MySQL on 32bit CentOS 5

#!/bin/bash # Set chroot location J=/securesystem/mysql /etc/init.d/mysqld stop # Creating directory structure mkdir -p $J/dev $J/etc $J/tmp $J/var/tmp $J/usr/libexec $J/usr/share/mysql/english \   $J/usr/share/mysql/norwegian $J/var/run/mysqld $J/var/log $J/var/lib $J/bin $J/lib $J/var/run/nscd chown -R root:sys $J chmod -R 755 $J chmod 1777 $J/tmp # Copy necessary files cp /usr/libexec/mysqld $J/usr/libexec/ cp /usr/share/mysql/english/errmsg.sys $J/usr/share/mysql/english/ cp /usr/share/mysql/norwegian/errmsg.sys $J/usr/share/mysql/norwegian/ cp -r /usr/share/mysql/charsets $J/usr/share/mysql/ cp /etc/hosts $J/etc/ cp /etc/host.conf $J/etc/ cp /etc/resolv.conf $J/etc/ cp /bin/bash $J/bin grep mysql /etc/group > $J/etc/group grep mysql /etc/passwd > $J/etc/passwd cp /etc/my.cnf $J/etc/ cp -R /var/lib/mysql $J/var/lib/ chown -R mysql:mysql $J/var cp /usr/lib/libkrb5.so.3 /lib/libdl.so.2 /lib/libc.so.6 /lib/ld-linux.so.2 \ /lib/librt.so.1 /usr/lib/libz.s