有没有简化的方法来从现有的CentOS 5.10服务器导出本地Vagrantconfiguration设置? (木偶,厨师,贝壳等)

我最近开始学习如何使用Vagrant来build立本地开发环境。 (对各种WAMP堆栈选项感到沮丧之后)stream浪者迄今为止是非常棒的…轻微的(ha)学习曲线,但长期看起来很有希望。

完成了试图让我的虚拟机看起来像我的在线服务器的乏味过程…在我看来,有一个失踪的stream浪者片。 现在的过程似乎或多或less像手动试错。 不是第一次快速build立或保持与上游服务器轻松同步的理想select。

诚然,我可能不知道我正在寻找什么…因此,这个问题。

有没有一种简化的方法来从现有的CentOS 5.10服务器导出本地Vagrantconfiguration设置? 木偶厨师,贝壳等)

像这样的东西是我想象的…

(连接到在线服务器…)

  1. 检测回购差异,并根据需要启用,禁用,添加本地。
  2. 检测软件包,并同步本地进行匹配。 (从本地安装或删除)
  3. 获取httpd.conf,调整本地(如果需要),并同步。
  4. 获取php.ini,调整本地(如果需要),并同步。
  5. 获取MySQL设置,调整本地(如果需要),并同步。
  6. 获取时区和同步。
  7. [你的build议,应该同步更多的东西在这里欢迎…]

理想情况下,这将在configuration期间运行,基本保持本地版本与在线版本同步。 这将消除需要不断调整您的本地设置手动保持同步。 如果在线(主机或内部)发生了变化,它会自动传播。 (当然,理想情况下,您可以标记设置来调整行为以满足您的需求)

另外,我想如果我能打包在线服务器,而不打包各种用户特定的数据,那也可以。 然而,从我所能说的看来,这似乎是不可能的,而且肯定不会很有效。

警告

在我个人的情况下,我在一个CentOS 5.10服务器与cPanel。 cPanel似乎做了很多东西,服务器端并不一定立即显而易见。 一个例子是许多包名称以cPanel开头,似乎是专有的,但同时与我可能想要同步的东西有关。 (如cPanel-php53)据我所知,这些不能轻易同步…因此,需要将变通方法置于适当的位置。 另一个例子可能是不同于预期的path,但我不太清楚,因为我对CentOS和cPanel默认安装不够熟悉,以确定任何特质。

我到目前为止所做的…

在做决定之前,我做了一些事情,是否有更好的方法与Vagrant更加配合。 这不是可怕的,但不是真正的“简化”或全面。 这里是细节…

  1. 我学会了如何在两台机器上运行yum repolist all ,以及如何使用cd /etc/yum.repos.d; ll;在文件系统中查看repos cd /etc/yum.repos.d; ll; cd /etc/yum.repos.d; ll; ,而不是如何使用这个信息自动同步回购。

  2. 我写了一个shell脚本来让本地的包非常接近远程的包。 然而,虽然它做得很公平,但并不完美,我想知道有没有更好的办法。 问题…

    • 我不确定是否允许删除本地特有的软件包。 (也会抛出一些错误)
    • 我还没有整理如何弥补包装“cPanel”似乎是我真正想要(PHP,MySQL等)的替代品,而不是完全从安装列表中删除每个包。
    • 这不能作为stream浪者提供者运行,因为它需要用户input的性质。 在同样的说明中,运行此操作并删除“本地特有的软件包”将会消除以前在configuration期间运行的yum安装。

 #!/usr/bin/env bash # This script is a helper for syncing local packages to match a remote server. # It is geared toward a remote CentOS server with cPanel thrown in the mix # and a local "server" managed by Vagrant. Regardless, the concepts are the # same for many kinds of set-ups and it's fairly tweakable. # To run this script from the command line... # Be root or become root by running 'sudo -i', # then run 'source /vagrant/.vagrant/sync-packages.sh' remote_host=1.1.1.1 destination=/vagrant/.vagrant/ echo -e '\nGetting packages from remote server...' ssh root@${remote_host} "rpm -qa --queryformat='%{NAME}\n' | sort" > ${destination}packages-remote.txt echo 'Getting packages from local server...' rpm -qa --queryformat='%{NAME}\n' | sort > ${destination}packages-local.txt echo 'Compiling package sets for comparison...' comm -23 ${destination}packages-remote.txt ${destination}packages-local.txt > ${destination}packages-remote-only.txt comm -23 ${destination}packages-local.txt ${destination}packages-remote.txt > ${destination}packages-local-only.txt sed -r '/^(cpanel|newrelic)/!d' ${destination}packages-remote-only.txt > ${destination}packages-remote-only-proprietary.txt comm -23 ${destination}packages-remote-only.txt ${destination}packages-remote-only-proprietary.txt > ${destination}packages-remote-only-non-proprietary.txt echo "Packages total on local $(cat ${destination}packages-local.txt | wc -l)" echo "Packages unique to local $(cat ${destination}packages-local-only.txt | wc -l)" echo "Packages total on remote $(cat ${destination}packages-remote.txt | wc -l)" echo "Packages unique to remote $(cat ${destination}packages-remote-only.txt | wc -l)" echo "Packages unique to remote *proprietary* $(cat ${destination}packages-remote-only-proprietary.txt | wc -l)" echo "Packages unique to remote *non-proprietary* $(cat ${destination}packages-remote-only-non-proprietary.txt | wc -l)" # If there are packages that are unique to local, prompt for removal if [[ -s ${destination}packages-local-only.txt ]]; then read -p 'Do you want to remove the packages that are unique to local? (y/n) ' -n 1 -r; echo if [[ $REPLY =~ ^[Yy]$ ]]; then echo 'Removing packages (this runs in quiet mode and may take some time)...' yum -y -q remove $(cat ${destination}packages-local-only.txt) fi fi # If there are *non-proprietary* packages that are unique to remote, prompt for install if [[ -s ${destination}packages-remote-only-non-proprietary.txt ]]; then read -p 'Do you want to install the *non-proprietary* packages that are unique to remote? (y/n) ' -n 1 -r; echo if [[ $REPLY =~ ^[Yy]$ ]]; then echo 'Installing packages (this runs in quiet mode and may take some time)...' yum -y -q install $(cat ${destination}packages-remote-only-non-proprietary.txt) fi fi # Wrap up echo 'Ensuring all packages are up to date (this runs in quiet mode and may take some time)...' yum -y -q update echo -e "\nWe're all done here. If you need to see a log of changes, please run 'nano /var/log/yum.log'\n" 

3.到7.我写了一个shell脚本来获得一些远程configuration文件,并将它们移到本地。 它表面上工作得很好,但我还没有深入地testing结果。 我确实运行了date以查看时区是否按需要同步,并检查了一些文件内容以validation是否成功。

同样,这不能作为stream浪者提供者来运行,因为它本质上需要用户input。 此外,没有对文件进行调整,以确保它们在本地运行没有问题。 (比如http.conf,以确保Apache不会偶然发现某些东西或将MySQL指向正确的数据目录)最后,我确定这些不是我应该移植的唯一文件…这些只是最明显的。

 #!/usr/bin/env bash # This script is a helper for syncing local settings to match a remote server. # It is geared toward a remote CentOS server with cPanel thrown in the mix # and a local "server" managed by Vagrant. Regardless, the concepts are the # same for many kinds of set-ups and it's fairly tweakable. # To run this script from the command line... # Be root or become root by running 'sudo -i', # then run 'source /vagrant/.vagrant/sync-settings.sh' remote_host=1.1.1.1 destination=/vagrant/.vagrant/ echo 'Getting config files from remote server...' scp root@${remote_host}:"\ /usr/local/apache/conf/httpd.conf \ /usr/local/lib/php.ini \ /etc/my.cnf \ /root/.my.cnf \ /etc/localtime \ " ${destination} echo 'Syncing files...' mv -f ${destination}httpd.conf /usr/local/apache/conf/httpd.conf mv -f ${destination}php.ini /usr/local/lib/php.ini mv -f ${destination}my.cnf /etc/my.cnf mv -f ${destination}.my.cnf /root/.my.cnf mv -f ${destination}localtime /etc/localtime echo 'All done!' 

你可能只想使用蓝图

生成木偶模块和厨师食谱

在尝试将其部署到其他服务器之前,您将能够编辑所产生的包。