Linux:将文件上传到实时服务器 - 如何自动化流程?
我正在本地计算机上进行开发(apache2、php、mysql)。当我想将文件上传到我的实时服务器(nginx、mysql、php5-fpm)时,我首先备份我的 www 文件夹,提取数据库,将所有内容 scp 到我的服务器(这很乏味,因为它受 opiekey 保护),自己登录将文件从服务器上的主目录复制到我的 www 目录,如果幸运的话,文件权限和其他一切都正常,我可以在线查看更改。如果我运气不好,我就必须研究到底出了什么问题。
今天,我只更改了一个文件,并且只为了这个文件就必须完成整个过程。你可以想象这有多烦人。有没有更快的方法来做到这一点?一种使这一切自动化的方法?也许像 SVN 中的“提交”之类的东西就可以起飞了?
你们如何处理这些类型的事情?
PS:我对这一切都非常陌生,所以请耐心等待!例如,我总是将文件复制到服务器上的主目录中,因为 scp 似乎无法将它们直接复制到 /var/www 文件夹中?!
I'm developing on my local machine (apache2, php, mysql). When I want to upload files to my live server (nginx, mysql, php5-fpm), I first backup my www folder, extract the databases, scp everything to my server (which is tedious, because it's protected with opiekey), log myself in, copy the files from my home directory on the server to my www directory and if I'm lucky and the file permissions and everything else works out, I can view the changes online. If I'm unlucky I'll have to research what went wrong.
Today, I changed only one file, and had to go through the entire process just for this file. You can imagine how annoying that is. Is there a faster way to do this? A way to automate it all? Maybe something like "commit" in SVN and off you fly?
How do you guys handle these types of things?
PS: I'm very very new to all this, so bear with me! For example I'm always copying files into my home directory on the server, because scp cannot seem to copy them directly into the /var/www folder?!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有许多实用程序可以为您做到这一点。如果您了解 python,请尝试 fabric。如果您了解 ruby,您可能更喜欢 capistrano。它们允许您编写本地和远程操作的脚本。
如果您有一个服务器场需要管理,那么这两个服务器可能无法按您想要的规模运行。对于超过 10 个服务器,请查看 chef 或 puppet 来完全管理您的服务器。
无论您是从本地结帐、打包源(我的首选解决方案)、远程存储库还是完全不同的东西进行部署,都取决于您。任何对你有用的都可以。只要确保您的部署是可重现的(也就是说,您总是可以说“5 分钟前它没有损坏,我想要现在拥有 5 分钟前拥有的东西”)。无论您使用什么版本控制方式都比没有版本控制好(标记版本可能是最舒服的)。
There are many utilities which will do that for you. If you know python, try fabric. If you know ruby, you may prefer capistrano. They allow you to script both local and remote operations.
If you have a farm of servers to take care of, those two might not work at the scale you want. For over 10 servers, have a look at chef or puppet to manage your servers completely.
Whether you deploy from local checkout, packaged source (my preferred solution), remote repository, or something entirely different is up to you. Whatever works for you is ok. Just make sure your deployments are reproducible (that is you can always say "5 minutes ago it wasn't broken, I want to have what now what I had 5 minutes ago"). Whatever way of versioning you use is better than no versioning (tagged releases are probably the most comfortable).
我认为“SVN”方法非常接近您真正想要的。您创建一个 cron 作业,每隔几分钟运行一次“svn update”(如果使用 Mercurial,则运行 hg pull -u,与 git 类似)。另一种选择是使用 dropbox(我们有时将它用于我们的网络服务器)——这个选项非常容易设置并与非开发人员(如 UI 设计师)共享...
I think the "SVN" approach is very close to what you really want. You make a cron job that will run "svn update" every few minutes (or hg pull -u if using mercurial, similar with git). Another option is to use dropbox (we use it for our web servers sometimes) - this one is very easy to setyp and share with non-developers (like UI designers)...
rsync 将仅发送本地计算机和远程计算机之间的更改。这将是 scp 的替代品。您可以研究如何设置它来执行您需要的操作。
您无法复制到 /var/www,因为您用于登录复制会话的凭据无权在 /var/www 上写入。假设您具有 root 访问权限,请将 /var/www(或者更好的是子目录)上的组 (chown) 更改为您的组,并更改权限以允许您的组写入访问权限 (chmod g+w)。
rsync 是相当轻量级的,所以它应该很容易上手。
rsync will send only the changes between your local machine and the remote machine. It would be an alternative to scp. You can look into how to set it up to do what you need.
You can't copy to /var/www because the credentials you're using to log in for the copy session doesn't have access to write on /var/www. Assuming you have root access, change the group (chown) on /var/www (or better yet, a sub directory) to your group and change the permissions to allow your group write access (chmod g+w).
rsync is fairly lightweight, so it should be simple to get going.