成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

如何安裝并設(shè)置Vagrant?

系統(tǒng) Linux 虛擬化
Vagrant 對(duì)于虛擬機(jī)來說是一個(gè)強(qiáng)大的工具,在這里我們將研究如何在 Ubuntu 上設(shè)置和使用 Virtualbox 和 Vagrant 來提供可復(fù)制的虛擬機(jī)。

如何安裝并設(shè)置Vagrant?

Vagrant 對(duì)于虛擬機(jī)來說是一個(gè)強(qiáng)大的工具,在這里我們將研究如何在 Ubuntu 上設(shè)置和使用 Virtualbox 和 Vagrant 來提供可復(fù)制的虛擬機(jī)。

 

虛擬機(jī),并不復(fù)雜

多年來,開發(fā)人員一直使用虛擬機(jī)作為其工作流程的一部分,允許他們交換和更改運(yùn)行軟件的環(huán)境,這通常是為了防止項(xiàng)目之間的沖突,例如需要 php 5.3 的項(xiàng)目 A 和需要 php 5.4 的項(xiàng)目 B。

并且使用虛擬機(jī)意味著你只需要你正在使用的計(jì)算機(jī)就行,而不需要專用硬件來鏡像你的生產(chǎn)環(huán)境。

當(dāng)多個(gè)開發(fā)人員在一個(gè)項(xiàng)目上工作時(shí),它也很方便,他們都可以運(yùn)行一個(gè)包含所有需求的環(huán)境,但是維護(hù)多臺(tái)機(jī)器并確保所有的需求都具有相同的版本是非常困難的,這時(shí) Vagrant 就能派上用場(chǎng)了。

 

使用虛擬機(jī)的好處

  • 你的虛擬機(jī)與主機(jī)環(huán)境是分開的
  • 你可以根據(jù)你代碼的要求裁剪一個(gè)定制虛擬機(jī)
  • 不會(huì)影響其他虛擬機(jī)
  • 可以運(yùn)行在你的主機(jī)上無法運(yùn)行的程序,例如在 Ubuntu 中運(yùn)行一些只能在 Windows 運(yùn)行的軟件

 

什么是 Vagrant

簡(jiǎn)而言之,這是一個(gè)與虛擬機(jī)一起工作的工具,可以讓你自動(dòng)創(chuàng)建和刪除虛擬機(jī)。

它圍繞一個(gè)名為 VagrantFile 的配置文件而工作,這個(gè)配置文件告訴 Vagrant 你想要安裝的操作系統(tǒng),以及一些其他選項(xiàng),如 IP 和目錄同步。 你還可以在虛擬機(jī)上添加一個(gè)命令的配置腳本。

通過共享這個(gè) VagrantFile,項(xiàng)目的所有開發(fā)人員全可以使用完全相同的虛擬機(jī)。

 

安裝要求

 

安裝 VirtualBox

VirtualBox 是運(yùn)行虛擬機(jī)的程序,它可以從 Ubuntu 倉庫中安裝。

  1. sudo apt-get install virtualbox

 

安裝 Vagrant

對(duì)于 Vagrant 本身,你要前往 https://www.vagrantup.com/downloads.html 查看適用于你的操作系統(tǒng)的安裝軟件包。

 

安裝增強(qiáng)功能

如果你打算與虛擬機(jī)共享任何文件夾,則需要安裝以下插件。

  1. vagrant plugin install vagrant-vbguest

 

配置 Vagrant

首先我們需要為 Vagrant 創(chuàng)建一個(gè)文件夾。

  1. mkdir ~/Vagrant/test-vm
  2. cd ~/Vagrant/test-vm

創(chuàng)建 VagrantFile:

  1. vagrant init

開啟虛擬機(jī):

  1. vagrant up

登錄機(jī)器:

  1. vagrant-ssh

此時(shí),你將擁有一個(gè)基本的 vagrant 機(jī)器,以及一個(gè)名為 VagrantFile 的文件。

 

定制

在上面的步驟中創(chuàng)建的 VagrantFile 看起來類似于以下內(nèi)容

VagrantFile:

  1. # -*- mode: ruby -*-
  2. # vi: set ft=ruby :
  3. # All Vagrant configuration is done below. The "2" in Vagrant.configure
  4. # configures the configuration version (we support older styles for
  5. # backwards compatibility). Please don't change it unless you know what
  6. # you're doing.
  7. Vagrant.configure("2") do |config|
  8. # The most common configuration options are documented and commented below.
  9. # For a complete reference, please see the online documentation at
  10. # https://docs.vagrantup.com.
  11.  
  12. # Every Vagrant development environment requires a box. You can search for
  13. # boxes at https://vagrantcloud.com/search.
  14. config.vm.box = "base"
  15.  
  16. # Disable automatic box update checking. If you disable this, then
  17. # boxes will only be checked for updates when the user runs
  18. # `vagrant box outdated`. This is not recommended.
  19. # config.vm.box_check_update = false
  20.  
  21. # Create a forwarded port mapping which allows access to a specific port
  22. # within the machine from a port on the host machine. In the example below,
  23. # accessing "localhost:8080" will access port 80 on the guest machine.
  24. # NOTE: This will enable public access to the opened port
  25. # config.vm.network "forwarded_port", guest: 80, host: 8080
  26.  
  27. # Create a forwarded port mapping which allows access to a specific port
  28. # within the machine from a port on the host machine and only allow access
  29. # via 127.0.0.1 to disable public access
  30. # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
  31.  
  32. # Create a private network, which allows host-only access to the machine
  33. # using a specific IP.
  34. # config.vm.network "private_network", ip: "192.168.33.10"
  35.  
  36. # Create a public network, which generally matched to bridged network.
  37. # Bridged networks make the machine appear as another physical device on
  38. # your network.
  39. # config.vm.network "public_network"
  40.  
  41. # Share an additional folder to the guest VM. The first argument is
  42. # the path on the host to the actual folder. The second argument is
  43. # the path on the guest to mount the folder. And the optional third
  44. # argument is a set of non-required options.
  45. # config.vm.synced_folder "../data", "/vagrant_data"
  46.  
  47. # Provider-specific configuration so you can fine-tune various
  48. # backing providers for Vagrant. These expose provider-specific options.
  49. # Example for VirtualBox:
  50. #
  51. # config.vm.provider "virtualbox" do |vb|
  52. # # Display the VirtualBox GUI when booting the machine
  53. # vb.gui = true
  54. #
  55. # # Customize the amount of memory on the VM:
  56. # vb.memory = "1024"
  57. # end
  58. #
  59. # View the documentation for the provider you are using for more
  60. # information on available options.
  61.  
  62. # Enable provisioning with a shell script. Additional provisioners such as
  63. # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
  64. # documentation for more information about their specific syntax and use.
  65. # config.vm.provision "shell", inline: <<-SHELL
  66. # apt-get update
  67. # apt-get install -y apache2
  68. # SHELL
  69. end

現(xiàn)在這個(gè) VagrantFile 將創(chuàng)建基本的虛擬機(jī)。但 Vagrant 背后的理念是讓虛擬機(jī)為我們的特定任務(wù)而配置,所以我們刪除注釋和調(diào)整配置。

VagrantFile:

  1. # -*- mode: ruby -*-
  2. # vi: set ft=ruby :
  3.  
  4. Vagrant.configure("2") do |config|
  5. # Set the Linux Version to Debian Jessie
  6. config.vm.box = "debian/jessie64"
  7. # Set the IP of the Box
  8. config.vm.network "private_network", ip: "192.168.33.10"
  9. # Sync Our Projects Directory with the WWW directory
  10. config.vm.synced_folder "~/Projects", "/var/www/"
  11. # Run the following to Provision
  12. config.vm.provision "shell", path: "install.sh"
  13. end

現(xiàn)在我們有一個(gè)簡(jiǎn)單的 VagrantFile,它將 Linux 版本設(shè)置為 debian jessie,設(shè)置一個(gè) IP 給我們使用,同步我們感興趣的文件夾,并最后運(yùn)行 install.sh,這是我們可以運(yùn)行 shell 命令的地方。

install.sh:

  1. #! /usr/bin/env bash
  2. # Variables
  3. DBHOST=localhost
  4. DBNAME=dbname
  5. DBUSER=dbuser
  6. DBPASSWD=test123
  7.  
  8. echo "[ Provisioning machine ]"
  9. echo "1) Update APT..."
  10. apt-get -qq update
  11.  
  12. echo "1) Install Utilities..."
  13. apt-get install -y tidy pdftk curl xpdf imagemagick openssl vim git
  14.  
  15. echo "2) Installing Apache..."
  16. apt-get install -y apache2
  17.  
  18. echo "3) Installing PHP and packages..."
  19. apt-get install -y php5 libapache2-mod-php5 libssh2-php php-pear php5-cli php5-common php5-curl php5-dev php5-gd php5-imagick php5-imap php5-intl php5-mcrypt php5-memcached php5-mysql php5-pspell php5-xdebug php5-xmlrpc
  20. #php5-suhosin-extension, php5-mysqlnd
  21.  
  22. echo "4) Installing MySQL..."
  23. debconf-set-selections <<< "mysql-server mysql-server/root_password password secret"
  24. debconf-set-selections <<< "mysql-server mysql-server/root_password_again password secret"
  25. apt-get install -y mysql-server
  26. mysql -uroot -p$DBPASSWD -e "CREATE DATABASE $DBNAME"
  27. mysql -uroot -p$DBPASSWD -e "grant all privileges on $DBNAME.* to '$DBUSER'@'localhost' identified by '$DBPASSWD'"
  28.  
  29. echo "5) Generating self signed certificate..."
  30. mkdir -p /etc/ssl/localcerts
  31. openssl req -new -x509 -days 365 -nodes -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" -out /etc/ssl/localcerts/apache.pem -keyout /etc/ssl/localcerts/apache.key
  32. chmod 600 /etc/ssl/localcerts/apache*
  33.  
  34. echo "6) Setup Apache..."
  35. a2enmod rewrite
  36. > /etc/apache2/sites-enabled/000-default.conf
  37. echo "
  38. <VirtualHost *:80>
  39. ServerAdmin webmaster@localhost
  40. DocumentRoot /var/www/
  41. ErrorLog ${APACHE_LOG_DIR}/error.log
  42. CustomLog ${APACHE_LOG_DIR}/access.log combined
  43. </VirtualHost>
  44.  
  45. " >> /etc/apache2/sites-enabled/000-default.conf
  46. service apache2 restart
  47.  
  48. echo "7) Composer Install..."
  49. curl --silent https://getcomposer.org/installer | php
  50. mv composer.phar /usr/local/bin/composer
  51.  
  52. echo "8) Install NodeJS..."
  53. curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
  54. apt-get -qq update
  55. apt-get -y install nodejs
  56.  
  57. echo "9) Install NPM Packages..."
  58. npm install -g gulp gulp-cli
  59.  
  60. echo "Provisioning Completed"

通過上面的步驟,在你的目錄中會(huì)有 VagrantFileinstall.sh,運(yùn)行 vagrant 會(huì)做下面的事情:

  • 采用 Debian Jessie 來創(chuàng)建虛擬機(jī)
  • 將機(jī)器的 IP 設(shè)置為 192.168.33.10
  • 同步 ~/Projects/var/www/ 目錄
  • 安裝并設(shè)置 Apache、Mysql、PHP、Git、Vim
  • 安裝并運(yùn)行 Composer
  • 安裝 Nodejs 和 gulp
  • 創(chuàng)建一個(gè) MySQL 數(shù)據(jù)庫
  • 創(chuàng)建自簽名證書

通過與其他人共享 VagrantFileinstall.sh,你可以在兩臺(tái)不同的機(jī)器上使用完全相同的環(huán)境。 

責(zé)任編輯:龐桂玉 來源: Linux中國(guó)
相關(guān)推薦

2016-10-24 09:09:48

AnsibleVagrantFedora

2010-06-08 16:39:31

如何安裝OpenSUS

2018-12-26 09:00:07

VirtualBoxFreeDOSLinux

2011-03-25 09:16:37

Solaris

2011-03-25 10:38:49

邏輯域來賓域

2012-05-22 15:34:43

Oracle Sola

2010-02-03 13:03:36

Fedora mysq

2013-04-07 15:14:41

2019-04-22 11:50:38

LinuxFlatpak

2024-08-29 16:06:26

前端Vue開發(fā)

2020-10-26 09:00:00

LinuxVagrant操作系統(tǒng)

2013-10-21 10:19:30

Windows 8.1ISO安裝盤

2021-07-12 11:41:55

鴻蒙HarmonyOS應(yīng)用

2019-11-18 14:00:40

開發(fā)工具環(huán)境搭建vagrant

2012-05-15 09:31:57

puppet vagrVirtualBox

2013-11-05 10:16:07

軟路由安裝設(shè)置

2015-08-03 17:28:04

Windows 10安裝

2011-09-22 09:27:02

虛擬機(jī)windows8虛擬化

2021-10-25 22:35:10

Windows 7Windows微軟

2021-10-26 22:36:56

Windows微軟工具
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)

主站蜘蛛池模板: 午夜久久久久久久久久一区二区 | 免费视频99| 91福利网 | 亚洲精品 在线播放 | 久久久久成人精品亚洲国产 | 日韩av一区在线观看 | 欧美 日韩 国产 成人 在线 | 一区二区视频在线 | 欧美日韩电影一区二区 | 久久国| 成人精品一区二区三区 | 久久免费视频2 | 国产成人福利在线观看 | 波多野结衣在线观看一区二区三区 | 国产精品视频免费观看 | 欧美一区二区在线观看视频 | 亚洲精品一区在线 | 日韩在线资源 | 伊人影院99 | 男人天堂社区 | 日本一本在线 | 日韩成人免费在线视频 | 国产高清一区二区 | 一区二区在线免费观看视频 | 久久a久久 | 国产欧美精品一区二区三区 | 亚洲精品久久久久久久久久久 | 婷婷激情综合 | 91视频.| 伊人操| 欧美一级二级在线观看 | 欧美日在线 | 情侣酒店偷拍一区二区在线播放 | 日本a∨精品中文字幕在线 亚洲91视频 | a级黄色片在线观看 | 91精品国产91 | 一区二区三区国产精品 | 成年人免费网站 | 久久久久久九九九九九九 | 国产情侣啪啪 | 蜜桃免费一区二区三区 |