Mic*_*l X 4 shell centos puppet chef vagrant
我最近开始学习如何使用 Vagrant 来启动本地开发环境。(在对各种 WAMP 堆栈选项感到沮丧之后)到目前为止,Vagrant 很棒……学习曲线很小,但从长远来看看起来很有希望。
在尝试使我的 VM 看起来像我的在线服务器的乏味过程之后……在我看来,Vagrant 缺少了一个部分。现在的过程似乎或多或少像手动试错。第一次快速设置或轻松保持与上游服务器同步的理想选择。
诚然,我可能不确切知道我在寻找什么......因此问题。
是否有一种简化的方法可以从现有的 CentOS 5.10 服务器导出设置以进行本地 Vagrant 配置?(人偶、厨师、贝壳或其他)
这样的事情是我所设想的......
(连接到在线服务器...)
理想情况下,这将在配置期间运行,并且基本上保持本地版本与在线版本同步。这将消除不断手动调整本地设置以保持同步的需要。如果某些内容在线更改(由主机或内部)......它会自动传播。(当然,理想情况下,您可以标记设置以根据您的需要调整行为)
或者,我想如果我可以在不打包各种用户特定数据的情况下打包在线服务器,那也可以。但是,据我所知,这似乎不太可能……而且效率肯定不会很高。
警告
就我个人而言,我使用的是带有 cPanel 的 CentOS 5.10 服务器。cPanel 似乎在服务器端做了很多不一定立即显而易见的事情。一个例子是许多包名称以 cPanel 开头,看起来是专有的,但同时与我可能想要同步的内容相关。(例如cpanel-php53)据我目前所知,这些不能轻易同步......因此需要采取变通办法。另一个例子可能与预期的路径不同,但我不太确定,因为我对 CentOS 和 cPanel 的默认安装不够熟悉,无法确定任何特性。
到目前为止我所做的...
在我决定询问是否有更好的方法可以与 Vagrant 更紧密地合作之前,我做了一些事情。这并不可怕,但并不真正“精简”或全面。以下是详细信息...
我学会了如何yum repolist all在两台机器上运行以及如何使用 来查看文件系统中的 repos cd /etc/yum.repos.d; ll;,但没有学习如何使用此信息自动同步 repos。
我写了一个 shell 脚本来让本地的包与远程的包非常接近。然而,虽然它做得很好,但它并不完美,我想知道是否有更好的方法。问题...
#!/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"
Run Code Online (Sandbox Code Playgroud)
3. 到 7. 我写了一个 shell 脚本来获取一些远程配置文件并将它们移动到本地。它在表面上工作得相当好,但我还没有深入测试结果。我确实运行date以查看时区是否按需要同步并检查了一些文件内容以验证成功。
同样,这不能作为 Vagrant 供应商运行,因为它本质上需要用户输入。此外,没有对文件进行任何调整以确保它们可以在本地运行而不会出现问题。(例如 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!'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
222 次 |
| 最近记录: |