- 追加された行はこの色です。
- 削除された行はこの色です。
[[Linuxめも]]
*VirtualBoxをインストール [#ze6527b3]
https://www.virtualbox.org/wiki/Downloads
*Vagrantをインストール [#q676a0a8]
ベイグラントと呼ぶようです。
https://www.vagrantup.com/downloads.html
*boxの登録 [#o5789751]
VirtualBox用boxファイルを指定して登録する。
http://www.vagrantbox.es
C:\Users\user>vagrant box add CentOS66 https://github.com/tommy-muehle/puppet-vagrant-boxes/releases/download/1.0.0/centos-6.6-x86_64.box
mkdir centos
cd centos
vagrant init CentOS66
フォルダ内に Vagrantfile ファイルが生成されていることを確認
Vargrantfileの以下のコメントを外す
config.vm.network "private_network", ip: "192.168.33.10"
CPU数を4個にしてメモリを4GB割り当てる場合
config.vm.provider "virtualbox" do |vb|
vb.cpus = 4
vb.memory = "4096"
end
起動
vargrant up
TeraTermで 192.168.33.10 へ接続
ID:vargrant~
PW:vagrant
サーバ停止は
vagrant halt
もしくはCentOS側で
shutdown -h now
*共有フォルダの設定 [#qf072333]
Vagrantfile ファイルを編集
config.vm.synced_folder "../home", "/home"
C\Users\user\home\vagrant フォルダを作成し、test.txt ファイルを作成
sshにて
cd /home/vagrant
ls -l
で test.txt ファイルが見えれば成功
$ cd
$ vi .bashrc
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# User specific aliases and functions
$ source ~/.bashrc
*日本語環境に変更 [#j27d2f10]
# vi /etc/sysconfig/i18n
LANG="ja_JP.UTF-8"
SYSFONT="latarcyrheb-sun16"
# source /etc/sysconfig/i18n
*日本時間に設定 [#t859ebb4]
# cp /usr/share/zoneinfo/Japan /etc/localtime
# vi /etc/sysconfig/clock
ZONE="Asia/Tokyo"
*ネットワークの改善 [#cdf74abd]
1行追加。
# vi /etc/resolv.conf
options single-request-reopen
*rsyncでファイル共有を行う [#ld1f4228]
自作のプログラムだと気になることはなかったが、EC-CUBE3系を入れたあたりからブラウザでのアクセスで画面が表示されるまでが極端に遅くなった。~
Magento2系を入れたらさらに遅く、使い物にならなくなってしまうほど。~
CPU数やメモリ割り当てを上げても解決せず。~
vagrantの共有ファイルシステムが遅いという問題が指摘されているのを見かけてこれが原因だと気がつく。~
ファイル数が多いシステムだと共有が遅いので、その分遅くなるのだと。~
nfsで共有するのが楽ちんぽいがWindowsなので不可。~
Sambaは信頼性に欠けるようなのでrsyncを使うのがベターな様子。
**MinGWをインストール [#w77b31e7]
以下からmingw-get-setup.exeをダウンロード~
https://sourceforge.net/projects/mingw/files/
何も考えずに C:\MinGW へデフォルトでインストールします。
**sshとrsyncをインストール [#v39b7f99]
コマンドラインにてインストールします。
> cd C:\MinGW\bin
> mingw-get.exe update
> mingw-get.exe install msys-openssh msys-rsync
**パスを通す [#l56b6a9a]
エクスプローラにてPCを右クリックし、プロパティ~
システムの詳細設定 - 環境変数 - システムの環境変数
Pathを編集して以下2つを追加
-C:\MinGW\bin
-C:\MinGW\msys\1.0\bin
**Vagrantfileファイルを変更 [#x82b5675]
共有設定をrsyncに書き換えます。
rsync__exclude は共有から除外したい場合、指定します。
config.vm.synced_folder "../home", "/home", type:"rsync", group:"apache", owner:"apache", rsync__chown:false, rsync__exclude: ["vagrant/", ".git/", ".svn/", "log/", "cache/", "vendor/", "var/", "etc/", "media/", "static/", "templates_c/"]
config.vm.synced_folder "../home", "/home", type:"rsync", group:"apache", owner:"apache", rsync__chown:false, rsync__exclude: ["vagrant/", ".git/", ".svn/", "log/", "cache/", "vendor/", "var/", "media/", "static/", "templates_c/"]
**rsync-autoを実行する [#o5d77cd9]
コマンドラインにて vagrant up したのちに vagrant rsync-auto を実行して共有フォルダを監視状態にします。~
これで共有フォルダ内を変更すると自動的にゲストOSへ反映されるようになるはずです。
**default: Warning: Authentication failure. Retrying... [#xb453c61]
rsyncで共有するようにしてから default: Warning: Authentication failure. Retrying... が連発してしまうようになりました。
エラーが連発している間に以下の鍵ファイルを削除します。~
centos\.vagrant\machines\default\virtualbox\private_key
sshでログインして作業します。
$ cd /home/vagrant
$ mkdir .ssh
$ chmod 700 .ssh
$ cd .ssh
$ wget https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub
$ mv vagrant.pub authorized_keys
$ chmod 600 authorized_keys
vagrant halt してから再度 vagrant up すると問題なく立ち上がるはずです。
*inaccessibleで立ち上がらなくなった [#y794456b]
vagrant up しても inaccessible と表示されて立ち上がらくなってしまった。
Bringing machine 'default' up with 'virtualbox' provider...
Your VM has become "inaccessible." Unfortunately, this is a critical error
with VirtualBox that Vagrant can not cleanly recover from. Please open VirtualBox
and clear out your inaccessible virtual machines or find a way to fix them.
Virtual Box VMs 以下のフォルダ内のファイル
centos_default_1456133417390_64892.vbox-prev
centos_default_1456133417390_64892.vbox-tmp
ができていたので、.vbox-tmp ファイルを .vbox に拡張子変更したら立ち上がりました。
*Windows updateすると立ち上がらなくなった [#pcc9933e]
Windows10でupdateがかかった後に vagrant up すると以下のようなエラーが途中で出力されてWEBアクセスできなくなってしまいました。
The guest machine entered an invalid state while waiting for it
to boot. Valid states are 'starting, running'. The machine is in the
'unknown' state. Please verify everything is configured
properly and try again.
If the provider you're using has a GUI that comes with it,
it is often helpful to open that and watch the machine, since the
GUI often has more helpful error messages than Vagrant can retrieve.
For example, if you're using VirtualBox, run `vagrant up` while the
VirtualBox GUI is open.
The primary issue for this error is that the provider you're using
is not properly configured. This is very rarely a Vagrant issue.
原因はよくわかりませんが、VirtualBoxがインストールされているフォルダで以下のファイルを右クリックしてインストールすれば無事に接続できるようになりました。
Oracle\VirtualBox\drivers\vboxdrv\VBoxDrv.inf
参考
-[[VirtualBoxとVagrantで開発環境を構築:http://www.webcyou.com/?p=4632]]
-[[Windows上でVirtualBox+Vagrant+CentOSによる仮想環境構築:http://qiita.com/hiroyasu55/items/11a4c996b0c62450940f]]
-[[Vagrant + VirtualBoxでアプリがやたら重い時に試した方が良いこと:http://qiita.com/yashikawa7/items/247df1439b2fa485f4e4]]