質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Vagrant

Vagrantは、VirtualBox上の仮想マシンを コマンドラインから作成してくれるソフトウェアです。 ビルド環境など容易に構築が可能です。

Q&A

解決済

1回答

595閲覧

Vagrant プロビジョニングについて

xin

総合スコア17

Vagrant

Vagrantは、VirtualBox上の仮想マシンを コマンドラインから作成してくれるソフトウェアです。 ビルド環境など容易に構築が可能です。

0グッド

0クリップ

投稿2017/12/02 09:23

いつもお世話になっております。
オライリーの書籍に沿ってVagrantを勉強していたのですが、プロビジョニングの項で分からない箇所があったので質問させて頂きます。

macOS Sierra(10.12.6)
vagrant 2.0.0
virtual box 5.1.30
ゲストOS Ubuntu 12.04 LTS

//vagrantfile config.vm.box = "precise64" config.vm.box_url = "http://files.vagrantup.com/precise64.box" //ここの # を外してポートを開けました config.vm.network "forwarded_port", guest: 80, host: 8080
vagrant up vagrant ssh vagrant@precise64:~$ sudo apt-get update vagrant@precise64:~$ sudo apt-get install apache2

テキストでは次に

Ubuntuはシステムの起動時にApacheが立ち上がるように設定し、インストールしたままのApacheは、 /var/www/ にあるファイルを配信します。 設定を簡単にするために、 /var/www を、デフォルトの共有ファイルである/vagrantへのシンボリックリンクに変更しましょう。 vagrant@precise64:~$ sudo rm -rf /var/www vagrant@precise64:~$ sudo ln -fs /vagrant /var/www --Mitchell Hashimoto 著 玉川竜司 訳 「実践 Vagrant」

とあリます。
以下二点質問です。

1. ここで共有フォルダに置いたファイルがデフォルトでApacheから配信されるようになるので、ホストのエディタで作成した例えばhtmlなどのファイルが、共有フォルダに保存されればブラウザを更新すれば表示されるようにしている(ただしプロビジョニングの自動化はしていないのでvagrant upの度に共有ファイルの設定をしなければならない)、という理解で合っていますか?

2. vagrant@precise64:$ sudo rm -rf /var/www の -rf オプションはどういった意味でしょうか?
googleで調べても出来ませんでした...
rmでリムーブするのもなぜでしょうか?
vagrant@precise64:
$ sudo ln -fs /vagrant /var/www
のみでリンクを貼れないのかな、と疑問に思いました。
(ちなみにvagrant@precise64:~$ sudo ln -fs /vagrant /var/wwwのみ実行すると
ln: `/vagrant': hard link not allowed for directory とエラーが返ってきました)

ご回答頂ければ有難いですm(_ _)m

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

1. ここで共有フォルダに置いたファイルがデフォルトでApacheから配信されるようになる

結果的にはそうなるのだろうとは思いますが、
何故/var/wwwの中身を配信し始めるのかに関して知っておきましょう。

UbuntuのApache設定ファイル、どうやるんだっけ? - Qiita
ubuntuの場合、/etc/apache2/apache2.confのファイルから辿っていけば、/var/wwwをドキュメントルートにするという記述があるはずです。
更に元を辿れはhttpdコマンドを利用して確認出来るのですが流石に割愛

2. vagrant@precise64:~$ sudo rm -rf /var/www の -rf オプションはどういった意味でしょうか?

googleで調べても出来ませんでした...

Googleにrm -rfと打ち込んだ場合、単語の先頭に-が設定されているので除外ワードとして認識されます。
rm "-rf"のように"(ダブルクォート)で囲みましょう。

因みにrm -rfはディレクトリを削除する時のよくあるコマンドです。
-dでもディレクトリを削除しますが、中のファイルが1個でも残っていれば不可能なので、再帰的(recursive)を冠する-rを利用します。
実際-rのみで実行すると「本当に○○を消してしまって大丈夫ですか?」の確認メッセージが滝のように出るので「うるさい、全部Yesださっさとしろ」の強制(force)を冠する-fもセットで利用されます。

詳細はぐぐるかman rm等で調べてみてください。

rmでリムーブするのもなぜでしょうか?

シンボリックリンクは既に存在しているファイルやディレクトリを押しのける事は出来ません。
/var/wwwが既に存在しているため新たなシンボリックリンクが作成できず、先にrm -rfで対象のディレクトリを削除してから張るという事を行っています。

投稿2017/12/03 02:22

miyabi-sun

総合スコア21158

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

xin

2017/12/03 03:25

ご回答有難うございます! 基本的な質問にも丁寧にお答え頂いて有難いです。 > ubuntuの場合、/etc/apache2/apache2.confのファイルから辿っていけば、/var/wwwをドキュメントルートにするという記述があるはずです。 なるほど、、実際にファイルを確認してみようとしまして、 vagrantでssh接続してから vagrant@precise64:~$ vi /etc/apache2/apache2.conf を実行しますと、 Based upon the NCSA server configuration files originally by Rob McCool. # # This is the main Apache server configuration file. It contains the # configuration directives that give the server its instructions. # See http://httpd.apache.org/docs/2.2/ for detailed information about # the directives. # # Do NOT simply read the instructions in here without understanding # what they do. They're here only as hints or reminders. If you are unsure # consult the online docs. You have been warned. # # The configuration directives are grouped into three basic sections: # 1. Directives that control the operation of the Apache server process as a # whole (the 'global environment'). # 2. Directives that define the parameters of the 'main' or 'default' server, # which responds to requests that aren't handled by a virtual host. # These directives also provide default values for the settings # of all virtual hosts. # 3. Settings for virtual hosts, which allow Web requests to be sent to # different IP addresses or hostnames and have them handled by the # same Apache server process. # # Configuration and logfile names: If the filenames you specify for many # of the server's control files begin with "/" (or "drive:/" for Win32), the # server will use that explicit path. If the filenames do *not* begin # with "/", the value of ServerRoot is prepended -- so "foo.log" # with ServerRoot set to "/etc/apache2" will be interpreted by the # server as "/etc/apache2/foo.log". # ### Section 1: Global Environment # # The directives in this section affect the overall operation of Apache, # such as the number of concurrent requests it can handle or where it # can find its configuration files. # # # ServerRoot: The top of the directory tree under which the server's # configuration, error, and log files are kept. # # NOTE! If you intend to place this on an NFS (or otherwise network) # mounted filesystem then please read the LockFile documentation (available # at <URL:http://httpd.apache.org/docs/2.2/mod/mpm_common.html#lockfile>); # you will save yourself a lot of trouble. # # Do NOT add a slash at the end of the directory path. # #ServerRoot "/etc/apache2" と出てきましたがドキュメントルートが見当たらず、一度ssh接続を切って場所を変えてみました。vagrantfileが入っている共有フォルダ内で open -a "Sublime Text" /etc をすると /etc/apache2/httpd.conf というファイルがあったのでみてみましたが、ここではDocument Rootの記載が DocumentRoot "/Library/WebServer/Documents" <Directory "/Library/WebServer/Documents"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.4/mod/core.html#options # for more information. # Options FollowSymLinks Multiviews MultiviewsMatch Any # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # AllowOverride FileInfo AuthConfig Limit # AllowOverride None # # Controls who can get stuff from this server. # Require all granted </Directory> となっていました。 検討違いのところを探してしまっていたら本当に申し訳ないのですが、お助言いただけたらと思います。
xin

2017/12/03 03:27

また、 >Googleにrm -rfと打ち込んだ場合、単語の先頭に-が設定されているので除外ワードとして認識されます。 rm "-rf"のように"(ダブルクォート)で囲みましょう。 なるほど、、!そうだったのですね、有難うございます! >シンボリックリンクは既に存在しているファイルやディレクトリを押しのける事は出来ません。 /var/wwwが既に存在しているため新たなシンボリックリンクが作成できず、先にrm -rfで対象のディレクトリを削除してから張るという事を行っています。 こちらもお陰様で理解出来ました!有難うございます!
miyabi-sun

2017/12/03 03:46

まず設定ファイル、httpd.confは別ファイルを読み込めるので、辿っていきましょう。 まぁ、暇な時にでもゆっくり目を通してくださいね。 私が貼り付けたQiitaの記事のリンク先では、○○のディレクトリの配下のファイルをまとめて読み込んでいるといった感じの記述があります
xin

2017/12/03 04:29

なるほど、、 あ、、!Qiitaの記事のここですね、 >そして、apache2.confはこのうち***-enabled内の.confや.loadファイルをすべて読み込むようになってます。 見逃しておりました。失礼いたしました。 別ファイルも読み込んでいたのですね、、。 取り急ぎ学習を進めて、時間が出来たらまた読み込んでみます。 迅速なご回答有難うございました!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問