0
votes

I have an AWS instance running CentOS 6.5. It has been updated, secured, and setup for web hosting (LAMP). I attached an EBS volume to the instance and mounted it under /data.

Two questions:

  1. How can I get MySQL to use the /data directory as its database storage location? (I don't want to run the program from the /data directory, just put the .sql file there.

  2. How can I do the same for my web site? I plan on running a wordpress site and its current location is in the /var/www/html directory. I want to change this to /data/site.

I want to keep the web site files and database on a separate volume: /data. If my instance was to get corrupt or inaccessible, I can attach the EBS volume to a new instance.

I have read dozens of tutorials and articles on how to get MySQL moved to a different directory, but nothing is working. MySQL refuses to start up after. Can I keep MySQL installed as is, but have it read/write the database on a different directory like /data which is a mounted EBS volume or is this not possible at all with linux?

Here are some of the tutorials and articles I been following/testing with:

aws.amazon.com/articles/1663?_encoding=UTF8&jiveRedirect=1

spruce.it/noise/setting-up-a-proper-lamp-stack-on-aws-ec2-ebs/

EDIT: This is what I am doing.

  1. Create a new instance using this ami: https://aws.amazon.com/marketplace/pp/B00IOYDTV6?ref=cns_srchrow

  2. Once the instance is up, I run updates using: sudo yum update -y

  3. One updated, I set it up as a LAMP web server using these instructions: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/install-LAMP.html In addition to the above steps, I allow port 80 tcp connections on the built-in firewall. I run these commands: sudo iptables -I INPUT -p tcp --dport 80 -j ACCEPT and sudo service iptables save Once this is done, I test my site at http://IP-ADDRESS (this shows me the Apache Test Page)

  4. Once LAMP is installed, I install the MySQL Server by running this: yum install mysql-server After that is installed, I proceed to the "To secure the MySQL server" instructions on the previous Amazon document.

  5. Next, I install PHPMyAdmin using these two tutorials: http://tecadmin.net/installing-apache-mysql-php-on-centos-redhat/# and http://tecadmin.net/how-to-install-phpmyadmin-on-centos-using-yum/

  6. At this point, I have a fully functioning web server. Now, I want to use the AWS EBS volume to store all the databases and website files. First, I attach the newly create AWS EBS volume. I use this tutorial to do this: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-using-volumes.html

THIS IS WHERE THE PROBLEMS START. Using the information in this tutorial: aws.amazon.com/articles/1663?_encoding=UTF8&jiveRedirect=1. It says FAILED.

1
What error messages are you seeing ? Can you elaborate a bit more ? - Rico
I added some more information about my procedure above. - mradarit

1 Answers

0
votes

So one thing you can do is the following that avoids copying all directories. You need to make sure that all permissions are setup correctly for it to work:

  • mysql dat dir:

    mv /var/lib/mysql /var/lib/mysql.orig
    mkdir -p /<your-new-ebs-mountpoint>/var/lib/mysql
    chown mysql.mysql /<your-new-ebs-mountpoint>/var/lib/mysql
    chmod 700 /<your-new-ebs-mountpoint>/var/lib/mysql
    
  • etc configs:

    mkdir -p /<your-new-ebs-mountpoint>/etc
    cp /etc/my.cnf /<your-new-ebs-mountpoint>/etc/my.cnf
    mv /etc/my.cnf /etc/my.cnf.orig
    ln -s /<your-new-ebs-mountpoint>/etc/my.cnf /etc/my.cnf
    
  • logs:

    mkdir -p /<your-new-ebs-mountpoint>/var/log
    mv /var/log/mysqld.log /var/log/mysqld.log.orig
    touch /<your-new-ebs-mountpoint>/var/log/mysqld.log
    chown mysql.mysql /<your-new-ebs-mountpoint>/var/log/mysqld.log
    chmod 640 /<your-new-ebs-mountpoint>/var/log/mysqld.log
    ln -s /<your-new-ebs-mountpoint>/var/log/mysqld.log /var/log/mysqld.log