vagrant鎼缓centos鐜
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vagrant鎼缓centos鐜相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/org' title='org'>org htm 鐩稿悓 form cti reload vagrant 杩炴帴
vagrant鎼缓centos鐜
鍓嶈█
macos浣滀负寮€鍙戠幆澧冨凡缁忕浉褰撴柟渚匡紝鏈夊緢涓板瘜鐨勫伐鍏凤紝濡?code>homebrew绫讳技浜巙buntu鐨?code>apt-get鍜宑entos鐨?code>yum锛屽緢鏂逛究鍦板畨瑁呭悇绉嶅紑鍙戝伐鍏枫€備絾缁堢┒涓庣嚎涓婄敓浜х幆澧冧笉鍚岋紝鍗充究瀹夎鐨勬槸鐩稿悓鐨勮蒋浠讹紝瀹夎鐩綍锛岀鐞嗘柟寮忛兘鏈夋墍涓嶅悓銆傚綋椤圭洰寰堝鏉傦紝鎴栬€呮湁澶氫釜椤圭洰鏃讹紝寰堝鏄撳皢mac鏈湴鐜寮勫緱涔变竷鍏碂銆?/p>
涓轰簡鑳戒笌绾夸笂鐢熶骇鐜涓€鑷达紝灏濊瘯杩囩敤docker, 骞舵病鏈夋兂璞′腑鐨勬柟渚匡紝鍙兘鏄垜瀵筪okcer鐨勪簡瑙eお灏戙€備笖瑙夊緱docker鐨勯棬妲涜緝楂樸€?/p>
琛¢噺鍚勭鏂规鍚庯紝鏈€缁堥€夋嫨鐢╲agrant涓巚irtualBox鎼缓涓€涓畬鏁寸殑linux绯荤粺锛岃繖鏍疯兘澶熶笌绾夸笂鐢熶骇鐜涓€鑷达紝涔熻兘寰堟柟渚垮湴杩涜绉绘銆?/p>
鐜鍑嗗
- 涓嬭浇瀹夎 virtualBox
- 涓嬭浇瀹夎 vagrant
- 浣跨敤杩呴浄涓嬭浇 瀹樻柟闀滃儚
鎴戦€夋嫨鐨勬槸 centos7.2 鐨勯暅鍍?/p>
瀹夎
鏂板缓鐩綍centos
锛屼綔涓簐agrant鐨勬牴鐩綍
- 瀵煎叆涓嬭浇鐨勯暅鍍?/li>
? centos vagrant box add centos ~/Downloads/vagrant-centos-7.2.box
# 灏哹ox鍛藉悕涓篶entos
- 鍒濆鍖?/li>
? centos vagrant init
浼氳嚜鍔ㄧ敓鎴?code>Vagrantfile閰嶇疆鏂囦欢
淇敼閰嶇疆鏂囦欢
璁剧疆box鍚嶇О
box鍚嶇О椤讳笌涓婇潰鍛戒护鎸囧畾鐨刡ox鍚嶄竴鑷?/p>
config.vm.box = "centos"
绔彛杞彂
config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
macos涓嶅厑璁稿皢鏈満鐨?0绔彛杞彂, 瑙e喅鏂规鍙傜収锛?mac璁剧疆绔彛杞彂
寮€鍚痭fs
榛樿鐨剉irtualBox鍏变韩鏂囦欢閫熷害澶參锛岄渶瑕佸惎鐢╪fs榛樿
Vagrantfile 璁剧疆锛?/p>
config.vm.network "private_network", type: "dhcp"
config.vm.synced_folder "/Users/airmb/Downloads/work", "/home/wwwroot/work", :nfs => true, :mount_options => ['actimeo=2']
璁剧疆鍐呭瓨
鍐呭瓨澶у皬鏍规嵁鐗╃悊鏈哄唴瀛樿缃紝鎴戠殑mac鐗╃悊鏈烘槸8G鍐呭瓨锛屽垎閰嶄簡3G缁欒櫄鎷熸満
濡傛灉瑕佸畨瑁卪ysql5.7锛屽唴瀛樹笉鑳戒綆浜?G
config.vm.provider "virtualbox" do |vb|
vb.memory = "3072"
end
鏌ョ湅ssh-config
鍙互鐢╲agrant榛樿鐢熸垚鐨刱ey,涔熷彲浠ュ皢鑷繁鐨勭閽ユ浛鎹㈠埌 IdentityFile 鎸囧畾鐨勬枃浠讹紝杩炴帴铏氭嫙鏈哄悗鍐嶅皢鍏挜鏀惧埌铏氭嫙鏈轰腑鐨?
~/.ssh/authorized_keys
鍚姩铏氭嫙鏈?/p>
? centos vagrant up
杩炴帴杩涘叆铏氭嫙鏈?/p>
? centos vagrant ssh
榛樿鐨勫叡浜寕杞界洰褰曪細/home/vagrant
甯哥敤vagrant鍛戒护
- vagrant up 鍚姩
- vagrant ssh 杩涘叆铏氭嫙鏈?/li>
- vagrant halt 鍏虫満
- vagrant reload 閲嶅惎
- 瀵煎嚭涓庡鍏?/li>
? centos vagrant package --base centos_default_1533259579120_24934 --out centos7.2.box # 瀵煎嚭box
? centos vagrant box add centos ./centos7.2.box # 瀵煎叆box
娓呯┖閲嶆柊瀵煎叆闀滃儚
褰撻渶瑕侀噸鏂板鍏ラ暅鍍忔椂锛屼负閬垮厤鍑虹幇鍚勭濂囧鎬€殑闂锛屾竻绌轰互涓嬪唴瀹癸細
# 灏嗙幇鏈夌殑box鍒犻櫎
? centos vagrant box list
centos (virtualbox, 0)
? centos vagrant box remove centos
? centos vagrant global-status --prune
? centos rm -rf .vagrant
? centos rm -rf Vagrantfile
? centos cd ~/VirtualBox\ VMs
? VirtualBox VMs ls
centos_default_1534145188471_82398
? VirtualBox VMs rm -rf ./*
閰嶇疆鏂囦欢 Vagrantfile
绔彛杞彂
config.vm.network "forwarded_port", guest: 80, host: 8080
鍐呭瓨鍒嗛厤
config.vm.provider "virtualbox" do |vb|
# # Display the VirtualBox GUI when booting the machine
# vb.gui = true
#
# # Customize the amount of memory on the VM:
vb.memory = "3072"
end
鐩綍鎸傝浇
config.vm.synced_folder "~/code", "/home/wwwroot/code", :owner=> 'vagrant', :group=>'www', :mount_options => ['dmode=775', 'fmode=775']