Tag Archives: mysql

Migrate data using Amazon EBS to a new running instance in EC2.

Been running mysql server inside Amazon EC2 throught an Elastic Block store and needs to be migrated to a new instance.

The tasks include:

1. Stopping mysql server.

2. Assume /var/lib/mysql and /var/log/mysql are symbolic links to
/ebs1/MYSQLDB/var/lib/mysql and /ebs1/MYSQLDB/var/log/mysq respectively.
Create a snapshot of a volume which is attached to the running instance.

3. Create new Volume from generated snapshot.

4. Install mysql-server. Stop mysql-server first, then

5. Attach new volume to the the new running instance. /dev/sdh and mount to /ebs1 directory.

6. Configure the symlink to /var/log/mysql and /var/lib/mysql point to
/ebs1/MYSQLDB//var/log/mysql and /ebs1/MYSQLDB/var/lib/mysql repectively.

In some cases, I got the error in debian-sys-maint when starting mysql, which can easily fix
by checking the password at /etc/mysql/debian.cnf for Ubuntu machines and granting
admin permissions for this user.

I tried also attaching EBS Volumes with the same data inside and get the error:

   Filesystem "sdi": Disabling barriers, not supported by the underlying device
XFS: Filesystem sdi has duplicate UUID - can't mount
sdi: unknown partition table<br />   

Where my /etc/fstab says:

 # Legacy /etc/fstab
 # Supplied by: ec2-ami-tools-1.3-30748
 /dev/sda1 /     ext3    defaults 1 1
 /dev/sda2 /mnt  ext3    defaults 0 0
 /dev/sda3 swap  swap    defaults 0 0
none      /proc proc    defaults 0 0
none      /sys  sysfs   defaults 0 0
/dev/sdh /ebs1 xfs noatime 0 0
/dev/sdi /ebs2 xfs noatime 0 0

To get the /ebs2 work, I need to add nouuid to fstab options.

   /dev/sdi /ebs2 xfs noatime,nouuid 0 0

http://developer.amazonwebservices.com/connect/thread.jspa?messageID=114594
http://adumont.serveblog.net/2007/03/31/xfs-and-lvm-snapshots/

Using Puppet to install Tomcat,MySQL, SVN and Java

In the last blog which features creating a basic module in Puppet here and here, this is a sample init.pp I’ve created to install, tomcat,mysql,subversion,java1.5 and load a database from a dump file. Notice that JDK is installed while accepting the license by using debconf-utils package. Tested in Ubuntu hardy which is launch from Amazon EC2.

Hope this will help some of my friends in their Puppet configurations.

class hostmanager::server {
     file { "/root/db.sql":
         source=> "puppet://$servername/hostmanager/db.sql"
     }
     file { "/etc/init.d/tomcat5.5":
         source=> "puppet://$servername/hostmanager/tomcat5.5"
     }
     $wantedpackages = ["debconf-utils", "mysql-server", "subversion"]
     package { $wantedpackages: ensure => installed }
     package { ["sun-java5-jdk"] :
                   ensure => installed,
                   require => Exec ["accept-license"]
     }
     package { ["tomcat5.5"] :
                   ensure => installed,
                   require => Package["sun-java5-jdk"]
     }
     exec { "informdb-load":
                 command => "mysql < /root/db.sql",
                 path =>"/bin:/usr/bin",
                 subscribe => File["/root/db.sql"],
                 subscribe => Service["mysql"],
                 unless => "mysql informdb -e 'quit'"
                }
      exec { "accept-license":
               command => "echo 'sun-java5-bin   shared/accepted-sun-dlj-v1-1    boolean true<br /> sun-java5-jdk   shared/accepted-sun-dlj-v1-1    boolean true
               sun-java5-jre   shared/accepted-sun-dlj-v1-1    boolean true
               sun-java5-jre   sun-java5-jre/stopthread        boolean true
               sun-java5-jre   sun-java5-jre/jcepolicy note
               sun-java5-bin   shared/present-sun-dlj-v1-1     note
               sun-java5-jdk   shared/present-sun-dlj-v1-1     note
               sun-java5-jre   shared/present-sun-dlj-v1-1     note
               '|debconf-set-selections",

               path =>"/bin:/usr/bin",
               subscribe =>Package["debconf-utils"]
          }
          service { "tomcat5.5":
                ensure => running,
                hasstatus => true,
                hasrestart => true,
                require => Package["tomcat5.5"],
                require => File["/etc/init.d/tomcat5.5"],
               restart => true
         }
         service { "mysql":
               ensure => running,
               hasstatus => true,
               hasrestart => true,
               require => Package["mysql-server"],
               restart => true
        }
}

Let’s start learning more about puppet. 🙂