您可以将代码集中放置在一个公共文件夹中(可以创建一个脚本将所有代码复制到八个服务器上,或使用
NFS)。这个集中的代码可以在SVN安装中的一个或多个仓库中。因此,当您推送时,只需推送所需的内容。例如,您可以为自己的PHP库(数据库类、XML、IMAP等)创建一个仓库。在一个简单的结构中,当您调用这些文件时,只需要简单地这样做:
require('/web/lib/DatabaseMySQL.class.php');
This way, you know all your required files are in the same place and very easy to maintain. Especially if your code requires files that require files.
You can create as many repositories 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 does what you already need to do. Like sending email (PHPMailer or any others) or template system (Smarty or any others). This way you save development time and when an update is available, you simply download, copy (commit if you have it in a repository) and push.
Script VS
NFS.
Creating a script to push all your code to 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 server are identical in order to avoid errors.
另外,如果您的网络延迟或连接在推送过程中断开,则某些服务器将没有相同的代码。这会导致更多错误。与NFS解决方案相比,这种方法运行速度稍快。
创建一个NFS可以解决上述问题,因为您只使用一个位置,但如果该位置下线,则所有服务器都无法正确运行。因此,当您推送代码时,只需推送到一个位置,所有其他服务器将自动拥有新代码。您还需要知道的是:这种方法比直接放在硬盘上慢一点。
以下是您可以使用的示例脚本:
您可以创建一个.sh脚本,将代码从存储库(例如,您从存储库检出的代码)复制到所有服务器,如下所示:
// file: pushcode.sh
/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
将此脚本设为可执行并运行:
./pushcode.sh
为了确保代码复制时不需要每次提示密码,您需要
绕过SSH登录。
这是一个不错的问题,您可能会喜欢:
https://serverfault.com/questions/195035/linux-nfs-performance-vs-other-file-systems。