VagrantをMacOSで動かす!しかもParallelsで(^^;

くまかけは普段はMacで開発をしています。

で、LinuxやWindowsのときはParallels使って、起動してます。

以前からVagrantは興味を持ってたんですが、VirtualBoxってのが引っかかってたんですよ。。

で、今回、Parallelsを利用する方法があったので構築しました(^^)

目次

Parallelsってなんですか?

一応このあたりから説明を。。。

仮想マシン、VMとしてはWindowsの世界ではVMwareが有名かと思います。

てか、ほとんど一択ですよね。

それと同様に、MacではParallelsが昔から提供されていました。

公式サイトはこちら。。。

2017/03現在での最新バージョンはVer.12となっています。

いつの間にか色々とバージョンができていますが(^^;

今使っているのはVer.12 Pro Editsionです。

結構以前にVMwareFusionも使ってみたんですが、ネットワーク周りがなんかしっくりせず、Parallelsを使い続けています。

いよいよセットアップ

ParallelsをProvidorとしてVagrantをセットアップします。

公式サイトとしては、こちらに説明が掲載されています。(英語ですが(^^;))

利用できるのは

  • Parallels Desktop 10 for Mac
  • Parallels Desktop 11 for Mac – 「Pro」および「Business」エディションのみ
  • Parallels Desktop 12 for Mac – 「Pro」および「Business」エディションのみ

となっていますので、Standard Editionはどうやらダメみたいです。ご注意下さい。

インストール方法としては、vagrantをインストールして、プラグインをインストールして、環境を作成するって手順になります。

今回は、vagrant自体始めてだったことも有り、「Vagrant+Parallels上でCentOSを動かす」を参考にさせていただきました。

1)vagrantをインストールする

vagrantのサイトから、Mac用のイメージをダウンロードしてインストールします。

※今回はVer.1.9.2でした。

2)プラグインをインストールする

$ vagrant plugin install vagrant-parallels

※更新する時は下記になります。

3)Vargrantfileを準備します。

適当なディレクトリを作成し、そちらに移動します。

$mkdir vagrant

$mkdir centos7.1

$cd centos7.1

 

4)vagrantを起動します

$vagrant init parallels/centos-7.1

A Vagrantfile has been placed in this directory. You are now
ready to vagrant up your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
vagrantup.com for more information on using Vagrant.
Macintosh-3:centos7.1 toshisan$ ls
Vagrantfile

$ vagrant up –provider=parallels
Bringing machine ‘default’ up with ‘parallels’ provider…
==> default: Registering VM image from the base box ‘parallels/centos-7.1’…
==> default: Cloning new virtual machine…
==> default: Unregistering the box VM image…
==> default: Setting the default configuration for VM…
==> default: Checking if box ‘parallels/centos-7.1’ is up to date…
==> default: Setting the name of the VM: centos71_default_1488820673878_57976
==> default: Preparing network interfaces based on configuration…
default: Adapter 0: shared
==> default: Clearing any previously set network interfaces…
==> default: Booting VM…
==> default: Waiting for machine to boot. This may take a few minutes…
default: SSH address: 10.211.55.39:22
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Connection refused. Retrying…
default:
default: Vagrant insecure key detected. Vagrant will automatically replace
default: this with a newly generated keypair for better security.
default:
default: Inserting generated public key within guest…
default: Removing insecure key from the guest if it’s present…
default: Key inserted! Disconnecting and reconnecting using new SSH key…
==> default: Machine booted and ready!
==> default: Checking for Parallels Tools installed on the VM…
==> default: Parallels Tools installed on this VM are outdated! In most cases
==> default: this is fine but in rare cases it can cause things such as shared
==> default: folders to not work properly. If you see shared folder errors,
==> default: please update Parallels Tools within the virtual machine and
==> default: reload your VM.
==> default: Mounting shared folders…
default: /vagrant => /Users/toshisan/vagrant/centos7.1

5)vagrantに接続します

ここで、vagrant sshってやればosとつながるんですが、下記のエラーが出ました。

Parallels DHCP leases file is not accessible. The Parallels provider
uses it to detect an IP address of virtual machine. This file must be
readable for the user that is running Vagrant.

Parallels DHCP leases file: /Library/Preferences/Parallels/parallels_dhcp_leases

どうやらDHCPの設定ファイルが読み込めないとの模様。

$ ls -al /Library/Preferences/Parallels/parallels_dhcp_leases
-rw——- 1 root admin 2137 3 6 18:42 /Library/Preferences/Parallels/parallels_dhcp_leases

あ、そりゃそうですよね。

対処方法を調べてみたんですが、見つけられず、取り敢えずは下記のように対処しました(^^;

$ sudo chmod 644 /Library/Preferences/Parallels/parallels_dhcp_leases
Password:
$ ls -al /Library/Preferences/Parallels/parallels_dhcp_leases
-rw-r–r– 1 root admin 2137 3 6 18:42 /Library/Preferences/Parallels/parallels_dhcp_leases

このあと

vagrant ssh

で無事接続できました。やれやれ。。。

$ vagrant ssh
Last login: Mon Mar 6 16:02:19 2017
[vagrant@centos-7 ~]$

6)仮想環境とPCのディレクトリを同期させる

これが便利。

仮想環境内のファイルを外から編集ができます。

・仮想環境

[vagrant@centos-7 ~]$ ls -al /

drwxr-xr-x. 1 vagrant nfsnobody 238 3月 6 17:17 vagrant

[vagrant@centos-7 ~]$ echo “hello” > /vagrant/hello.txt

・ホスト環境

$ ls -al vagrant/centos7.1

-rw-rw-r– 1 hoge hoge  6 3 7 02:23 hello.txt

 

別のディレクトリ指定なんかもできます。

こちらを参考にして下さい。

今回の最後に一つ。。

Parallels Toolの自動アップデートを組み込んだら共有フォルダのオーナーさんがrootになっちゃいます。

[vagrant@centos-7 ~]$ ls -al /

drwxr-xr-x. 1 vagrant nfsnobody 272 3月 6 17:44 vagrant

これが下記のようにして起動させると

config.vm.provider “parallels” do |vb|
 vb.update_guest_tools = true
end

まず

==> default: Mounting shared folders…
default: /vagrant => /Users/toshisan/vagrant/centos7.1

が表示されなくて

[vagrant@centos-7 ~]$ ls -al /

drwxr-xr-x. 1 root root 272 3月 6 17:44 vagrant

ってなってしまうんです。。

これではチョット使いにくいので、今回はToolの自動アップデートは無しにしました。

さて、まだこれからですが、ココで一旦終了です(^^)

追記 2018/05/03

久々にインストールしました。結構ハマりました(^^;

・Vagrant 2.0.4にしました。

これでCentOS7.3をインストールしました

$vagrant init parallels/centos-7.3

Vagrantfileが作成されました。

$ vagrant up

インストールされる。。。

Parallels Toolが古いかもだからUpdateして、VMを再起動しないさよ!

ってメッセージが。。

で、Vargrantfileに自動アップデートを追加。(内容は上記を参照して下さい)

これで一旦再起動。

$ vagrant reload

こうすると、どうも「Kernelのバージョンアップが必要です」ってメッセージがでます。

VM自体は動いているので、vagrant sshでログインして、yum updateしました。

[vagrant@centos7 ~]$ sudo yum update

それと、kernel-developもインストールが必要らしんで、yum install kernel-deveopしときました。

これでVMを再起動すると、起動して、共用フォルダも使えるようになりました。

Follow me!

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA