29

We just got new servers for our new system and I want to know what I should do to make my new code as efficient as possible, and how to organize it.

I want a good solution so I don't have to reorganize it one year from now on (for example) and I want the best practices and techniques to make sure my code will survive long enough to avoid redesigning it later. no framework use here

Here's my new environment:

  • 8 web servers LAMP (Apache 2, PHP 5.3.5, CentOS 5) - (Xeon E5645, 32 GB RAM, RAID 10 1 TB 15k RPM) - one load balancer to manage them
  • 12 database MySQL 5.5 servers (same as above) with replication (four masters and eight slaves)
  • one SVN server (an old server we use)

My idea was to mirror them (the web servers) and then push the code from the SVN to all servers. Is this good?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Gilbert Kakaz
  • 1,567
  • 9
  • 23
  • 2
    is the svn server on the same network as the web servers? or you have svn hosted on a separate domain that does not belong to you? – Book Of Zeus Dec 31 '11 at 02:41
  • the svn server is in the same ip range so yes on the same network as the servers but not accessible from outside – Gilbert Kakaz Dec 31 '11 at 02:44

1 Answers1

36

You can centralize your code in one common folder (either create a script that copies all the code to the eight servers or use NFS).

This centralized code can be in one or more repositories in your SVN installation. So when you push, you only push what you need to push.

For example, you can create one repository for your own PHP libraries (database class, XML, IMAP, etc.). In a simple structure and when you call these files, you simply do:

require('/web/lib/DatabaseMySQL.class.php');

This way, you know all your required files at in the same place and very easy to maintain. Specially if your code requires required files that requires files.

You can create as many repository as you want and repeat this if you don't want to mix up files - for example third-party (Smarty, PHPMailer) with the code you create.

The other thing is, don't reinvent the wheel. There's plenty of good code out there that probably do what you already need to do. Like sending email (PHPMailer or any others) or template system (Smarty or any others). This way you same development time and when an update if available, you simply download, copy (commit if you have it in a repository) and push.

Script VS NFS.

Create a script to push all your code in eight web servers is easy to make. The downside of this is you need to make sure all the folders and all the files you have on each servers are identical in order to avoid errors.

Also, if there's a lag on your network or the connection drop during the push some server won't have the same code. Again, more errors. This is a little faster to run versus the NFS solution.

Createing an NFS fixes the problem above since you only use one location, but if that location drops, all of your servers won't run correctly. So, when you push the code, you push only to one place and all the other servers automatically have the new code. Something you need to know also: this will be a little slower than if the code is directly on the hard drive.

Here's a sample script you can use:

You can create a .sh script that will copy the code from your repository (for example, code you checked out from the repository) to all server like this:

// file: pushcode.sh
#!/bin/bash
/usr/bin/rsync -avz --exclude='.svn' -e ssh /path/to/code/checkedout/ user@server1:/path/to/code
/usr/bin/rsync -avz --exclude='.svn' -e ssh /path/to/code/checkedout/ user@server2:/path/to/code

Make this script executable and run it:

./pushcode.sh

To make sure the code copy correctly without prompting the password each time, you will have to bypass the SSH login.

Here's a good one you might like: https://serverfault.com/questions/195035/linux-nfs-performance-vs-other-file-systems

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Book Of Zeus
  • 49,509
  • 18
  • 174
  • 171
  • thank you for this, very useful. i think ill go with the script one to start, seem easier at first then, any recommendation about the script? how can i do it? – Gilbert Kakaz Dec 31 '11 at 03:17