摘要:簡(jiǎn)介是一個(gè)基于的工具,用于創(chuàng)建和部署虛擬化開(kāi)發(fā)環(huán)境。本教程不安裝可選。
Vagrant 簡(jiǎn)介
Vagrant是一個(gè)基于Ruby的工具,用于創(chuàng)建和部署虛擬化開(kāi)發(fā)環(huán)境。 它的主要意義是讓所有開(kāi)發(fā)人員都使用和線上服務(wù)器一樣的環(huán)境,本質(zhì)上和你新建一個(gè)虛擬機(jī)安裝
# https://www.vagrantup.com/downloads.html # vagrant 下載, 自行安裝 # https://www.virtualbox.org/wiki/Downloads # virtualbox 下載, 自行安裝常用命令
vagrant init # 初始化,生成Vagrantfile vagrant up # 啟動(dòng)虛擬機(jī) vagrant halt # 關(guān)閉虛擬機(jī) vagrant reload # 重啟虛擬機(jī) vagrant ssh # SSH 至虛擬機(jī) vagrant suspend # 掛起虛擬機(jī) vagrant resume # 喚醒虛擬機(jī) vagrant status # 查看虛擬機(jī)運(yùn)行狀態(tài) vagrant destroy # 銷毀當(dāng)前虛擬機(jī) #box管理命令 vagrant box list # 查看本地box列表 vagrant box add # 添加box到列表 vagrant box remove # 從box列表移除 # 修改了配置需要啟動(dòng)或重啟 vagrant provision vagrant reload --provisionhomestead
站在巨人的肩膀上,快速部署PHP開(kāi)發(fā)環(huán)境 homestead是laravel官方的一個(gè)php開(kāi)發(fā)環(huán)境 (本教程采用homestead box6.1.0) 內(nèi)置: Ubuntu 18.04 Git PHP 7.2 PHP 7.1 PHP 7.0 PHP 5.6 Nginx Apache (可選。本教程不安裝) MySQL MariaDB (可選。本教程不安裝) Sqlite3 PostgreSQL Composer Node (With Yarn, Bower, Grunt, and Gulp) Redis Memcached Beanstalkd Mailhog Neo4j (可選。本教程不安裝) MongoDB (可選。本教程不安裝) Elasticsearch (可選。本教程不安裝,以免過(guò)大) ngrok wp-cli Zend Z-Ray Go Minio下載box(homestead)
# wget https://vagrantcloud.com/laravel/boxes/homestead/versions/6.1.0/providers/virtualbox.box # 網(wǎng)盤:box鏡像
# metadata.json { "name": "laravel/homestead", "versions": [ { "version": "6.1.0", "providers": [ { "name": "virtualbox", "url": "X:/path/homestead-6.1.0.box" } ] } ] } vagrant add box metadata.json or vagrant add box laravel/homestead X:/path/homestead-6.1.0.box --box-version=6.1.0 vagrant box list # laravel/homestead (virtualbox, 6.1.0) vagrant init laravel/homestead --box-version=6.1.0 # 生成了Vagrantfile文件調(diào)整后的Vagrantfile配置
# -*- mode: ruby -*- # vi: set ft=ruby : ENV["VAGRANT_DEFAULT_PROVIDER"] = "virtualbox" Vagrant.configure("2") do |config| # 虛擬機(jī)名 # config.vm.define = "sxx_v1" # 鏡像名 config.vm.box = "laravel/homestead" # 鏡像版本要求 config.vm.box_version = "6.1.0" # config.vm.box_version = ">= 6.1.0" # 服務(wù)名 這里注意不能用下劃線"_" config.vm.hostname = "sxx-dev-server" # 虛擬機(jī)的私有網(wǎng)絡(luò)ip config.vm.network "private_network", ip: "192.168.10.10" # 共享同步的數(shù)據(jù)目錄 config.vm.synced_folder "D:/qkl/sxx/docker", "/home/share", create:false config.vm.synced_folder "D:/qkl/sxx/sxx_admin3", "/web/www/sxx_admin3", create:false config.vm.synced_folder "D:/qkl/sxx/vagrant/nginx/conf", "/etc/nginx/sites-custom/", create:false # 端口轉(zhuǎn)發(fā) # guest->虛擬機(jī) # host->宿主 config.vm.network "forwarded_port", guest: 22, host: 2222 config.vm.network "forwarded_port", guest: 80, host: 8000 # VirtualBox 虛擬機(jī)配置: config.vm.provider "virtualbox" do |vb| vb.gui = false vb.name = "sxx_v1" vb.memory = "2048" vb.cpus = "2" end # # View the documentation for the provider you are using for more # information on available options. # Enable provisioning with a shell script. Additional provisioners such as # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the # documentation for more information about their specific syntax and use. #config.vm.provision "shell", inline: <<-SHELL # sudo apt-get update #SHELL end啟動(dòng)
vagrant up # output ==> default: Attempting graceful shutdown of VM... ==> default: Checking if box "laravel/homestead" is up to date... ==> default: Clearing any previously set forwarded ports... ==> default: Clearing any previously set network interfaces... ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat default: Adapter 2: hostonly ==> default: Forwarding ports... default: 22 (guest) => 2222 (host) (adapter 1) default: 80 (guest) => 8000 (host) (adapter 1) default: 22 (guest) => 2222 (host) (adapter 1) ==> default: Running "pre-boot" VM customizations... ==> default: Booting VM... ==> default: Waiting for machine to boot. This may take a few minutes... default: SSH address: 127.0.0.1:2222 default: SSH username: vagrant default: SSH auth method: private key ==> default: Machine booted and ready! ==> default: Checking for guest additions in VM... ==> default: Setting hostname... ==> default: Configuring and enabling network interfaces... The following SSH command responded with a non-zero exit status. Vagrant assumes that this means the command failed! /sbin/ifdown "eth1" || true /sbin/ip addr flush dev "eth1" # Remove any previous network modifications from the interfaces file sed -e "/^#VAGRANT-BEGIN/,$ d" /etc/network/interfaces > /tmp/vagrant-network-interfaces.pre sed -ne "/^#VAGRANT-END/,$ p" /etc/network/interfaces | tac | sed -e "/^#VAGRANT-END/,$ d" | tac > /tmp/vagrant-network-interfaces.post cat /tmp/vagrant-network-interfaces.pre /tmp/vagrant-network-entry /tmp/vagrant-network-interfaces.post > /etc/network/interfaces rm -f /tmp/vagrant-network-interfaces.pre rm -f /tmp/vagrant-network-entry rm -f /tmp/vagrant-network-interfaces.post /sbin/ifup "eth1" Stdout from the command: Stderr from the command: bash: line 4: /sbin/ifdown: No such file or directory bash: line 20: /sbin/ifup: No such file or directory # 這提示出錯(cuò)了,應(yīng)該是官方的打包沒(méi)安裝ifupdown時(shí)候的問(wèn)題解決錯(cuò)誤
# 這里的ip,我們上面設(shè)置為192.168.10.10 ssh -p 2222 vagrant@ip or 直接打開(kāi)virtualbox的虛擬機(jī)進(jìn)入 # 輸入密碼 sudo apt-get install -y ifupdown # 重新啟動(dòng) vagrant reload # output初始化工作
# 重置/設(shè)置root密碼 su passwd root # 輸入新密碼 這里我是Vagrant123 # 解決homestead6.1.0里沒(méi)有phpize的問(wèn)題 安裝過(guò)程會(huì)提示操作,默認(rèn)選擇即可 sudo apt-get install -y php7.2-dev sudo apt-get install -y php7.1-dev sudo apt-get install -y php7.0-dev sudo apt-get install -y php5.6-dev # 如果需要更換linux下默認(rèn)版本 # ubunut update-alternavtives --config php # 選擇自己需要的版本前的序列即可 # nginx配置里可以直接指定版本,具體查看分享的nginx配置即可安裝擴(kuò)展
# 這我就不演示怎么安裝了基本都是phpize -> configure -> make && make install redis mongodb rdkafka(安裝前先安裝librdkafka-https://github.com/edenhill/librdkafka) zookeeper(安裝前線安裝zookeeker的C庫(kù)支持)建議后續(xù)安裝的擴(kuò)展
swoole # https://wiki.swoole.com/wiki/index/prid-1查看常用服務(wù)
vagrant package --output sxx_v1 # output 項(xiàng)目下生成了sxx_v1分享和使用
1. 安裝vagrant 2. 安裝virtualbox 3. copy 分享的box 4. 添加box: vagrant add box qklin/sxx_v1 box_file -box-version=6.1.0 或者上面的metadata.json添加 5. 設(shè)置復(fù)制一份Vagrantfile,調(diào)整成自己所需的共享目錄 6. 添加nginx的虛擬主機(jī)配置 7. vagrant up 8. 如果nginx有問(wèn)題,你可以ssh到虛擬機(jī),然后重啟下nginx,因?yàn)楣蚕砟夸浛赡苓t于nginx,所以nginx啟動(dòng)除了問(wèn)題,重啟nginx即可(/usr/sbin/nginx -s reload)分享本教程的vagrantbox和部分配置
# sxx_v1 box 鏈接: https://pan.baidu.com/s/1vkU5PTt856Ru7eCiqU3KpQ 密碼: 6666 # sxx_v1配置(nginx, vagrantfile等) 鏈接: https://pan.baidu.com/s/1z7MfT2pIYMGqq_tBwmfDNA 密碼: 8888 # homestead 官方的7.14.2配置(僅做參考,可以快速增加其他服務(wù),參考scripts里的腳本) 鏈接: https://pan.baidu.com/s/1qZ29r3w41PZ2tLDguzULAw 密碼: 9999總結(jié)
vagrant 本質(zhì)還是虛擬機(jī),不過(guò)是通過(guò)vagrant快速部署和管理虛擬機(jī) 本教程只是演示了一個(gè)配置配置一臺(tái)虛擬機(jī),vagrant通過(guò)vagrantfile快速部署分布式虛擬機(jī) 這個(gè)不是本教程的目的,具體更多你可以翻閱官方或百度搜索相關(guān)教程自行學(xué)習(xí)
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/29213.html
摘要:簡(jiǎn)介是一個(gè)基于的工具,用于創(chuàng)建和部署虛擬化開(kāi)發(fā)環(huán)境。本教程不安裝可選。 Vagrant 簡(jiǎn)介 Vagrant是一個(gè)基于Ruby的工具,用于創(chuàng)建和部署虛擬化開(kāi)發(fā)環(huán)境。 它的主要意義是讓所有開(kāi)發(fā)人員都使用和線上服務(wù)器一樣的環(huán)境,本質(zhì)上和你新建一個(gè)虛擬機(jī) 安裝 # https://www.vagrantup.com/downloads.html # vagrant 下載, 自行安裝 # h...
摘要:前言使用搭建開(kāi)發(fā)環(huán)境可以避免團(tuán)隊(duì)開(kāi)發(fā)帶來(lái)的開(kāi)發(fā)環(huán)境不一致問(wèn)題,避免了很多不必要的麻煩,同時(shí)其分發(fā)機(jī)制也也有利于新來(lái)的同事立即部署適合于公司的開(kāi)發(fā)環(huán)境,非常便利,是很多互聯(lián)網(wǎng)公司的首選。因此,學(xué)習(xí)如何搭建基于的開(kāi)發(fā)環(huán)境是很有必要的。 前言 使用vagrant搭建開(kāi)發(fā)環(huán)境可以避免團(tuán)隊(duì)開(kāi)發(fā)帶來(lái)的開(kāi)發(fā)環(huán)境不一致問(wèn)題,避免了很多不必要的麻煩,同時(shí)其分發(fā)機(jī)制也也有利于新來(lái)的同事立即部署適合于公司的...
摘要:準(zhǔn)備開(kāi)發(fā)所需工具系統(tǒng)環(huán)境搭建系統(tǒng)搭建環(huán)境以及環(huán)境為啥不用因?yàn)楹芏喙居玫?,然而才能正常支持,在下安裝一大堆東西不行,折騰了好些下,決定不躺著個(gè)坑。 準(zhǔn)備 開(kāi)發(fā)所需工具: Vagrant Oneinstack Virtualbox Vagrant box 系統(tǒng)環(huán)境:macOS Sierra 10.12.5搭建系統(tǒng):CentOS 7搭建環(huán)境:Oneinstack(PHP以及Java環(huán)境...
閱讀 3750·2021-09-22 10:57
閱讀 1921·2019-08-30 15:55
閱讀 2711·2019-08-30 15:44
閱讀 1740·2019-08-30 15:44
閱讀 1885·2019-08-30 15:44
閱讀 2256·2019-08-30 12:49
閱讀 1060·2019-08-29 18:47
閱讀 3144·2019-08-29 16:15