分类: 系统运维
2009-03-25 10:52:43
Remove the test database:
DROP DATABASE test;
Disable anonymous access:
DELETE FROM mysql.user WHERE user = ”;
FLUSH PRIVILEGES;
Then exit mySQL using quit.
Now it’s time to move apache to EBS:
First we need to stop the service:
/sbin/service httpd stop
Then we move httpd to EBS:
mv /etc/httpd /ebs1/httpd
And create a symbolic link to it:
ln -s /ebs1/httpd /etc
Also do this for the document root:
mv /var/www /ebs1/www
ln -s /ebs1/www /var/
And restart apache:
/sbin/service httpd start
Note: If you terminate and start a new instance simply remove the /etc/httpd and /var/www folders and just run the commands to create the symbolic links.
Then we do the same for mySQL:
/sbin/service mysqld stop
mv /var/lib/mysql /ebs1/mysql
ln -s /ebs1/mysql /var/lib
/sbin/service mysqld start
This only moves the mySQL data, not the logs. You can edit /etc/my.cnf to configure where logs are stored and also move the log directory to EBS if you want to.
So now you have a fully functioning server on EC2 that stores and retrieves data to and from and EBS volume. The EBS volume and be backed up almost instantly using a snapshot. If you don’t use innodb for your tables it is advised that you lock your tables while you take the snapshot.
Next steps / thoughts:
Some might want to create a hosting enviroment for many websites. What you can do for this is to edit your httpd.conf file (located on EBS /ebs1/httpd/conf/httpd.conf) and enable Virtual Hosts. What I did is to create a directory /ebs1/sites and then create users on fedora using the following command:
useradd -d /ebs1/sites/mysite1.com user-for-mysite1
Also don’t forget to specify a password for the user using:
passwd user-for-mysite1
Once you have created the user you can point the document root for that specific site to his home directory.
Also to enable the user to upload files to his/her website using SCP you need to allow password access through SSH (be careful on security issues though). To do this, edit /etc/ssh/sshd_config and change the line “PasswordAuthentication no” to “PasswordAuthentication yes”. Also restart sshd by running /etc/init.d/sshd restart.
The final step is to link real domains to your new server. We assume that you have already assigned one or more IPs to your server. To point a domain to a specific IP you need to edit its DNS records and add an “A record” that points to that IP. Once the domain resolves on your server you will be able to use it for your website. If you need to host multiple websites, create one VirtualHost record for each domain (using the appropriate servername and documentroot values) and off you go!
Special thanks to http://agiletesting.blogspot.com/ for the useful information that I found there for this tutorial.