【KUSANAGI】Vagrantでwordpressを一般公開で構築する
KUSANAGI for Vagrant
皆さんこんにちわ、今回はKUSANAGIをvagrantで構築、WANつまりインターネット上に開放するまでを紹介。
今回使うホストOS(使うPC)はwindows10です、Linux等別のOSでも問題ないはずです。
準備(vagrant)
まずは公式の通りにVirtualBoxとvagrantをインストールしてください。
vagrantfileを作るところまで無事できたらvagrantfileを次のようにすべて書き換えてください。
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The “2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don’t change it unless you know what
# you’re doing.
Vagrant.configure(“2") do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://vagrantcloud.com/search.
config.vm.box = “primestrategy/kusanagi"
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = true
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing “localhost:8080" will access port 80 on the guest machine.
# NOTE: This will enable public access to the opened port
# config.vm.network “forwarded_port", guest: 80, host: 8080
config.vm.network “forwarded_port", guest: 22, host: 22, id: “ssh",host_ip: “empty"
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine and only allow access
# via 127.0.0.1 to disable public access
config.vm.network “forwarded_port", guest: 80, host: 80, host_ip: “empty", id: “www"
config.vm.network “forwarded_port", guest: 443, host: 443, host_ip: “empty", id: “ssl"
# Create a private network, which allows host-only access to the machine
# using a specific IP.
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
config.vm.network"public_network", type: “dhcp"
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
# 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 = “1024"
# 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
# apt-get update
# apt-get install -y apache2
# SHELL
end
SSHのポートに関しては任意のポートに書き換えてください。
そしたらコマンドプロンプトまたはpowershellでvagrant upしてください。
無事VirtualBoxにKUSANAGIが読み込まれたら、一旦閉じるからシャットダウンシグナルを送信を選択し、止まるまで待ちます。
準備(VirtualBox)
次はVirtualBoxでKUSANAGIの設定をします。
システム
まずはシステムからメモリの割当をします、任意の数値を割り当ててください。(なお最低4GB、最大16GBが上限です。16GB以上は非推奨)
起動順序は自由でいいと思いますが、自分はこのようにしています。
プロセッサー
割り当てるCPU数、使用率を設定します。
CPUのコア数は各自タスクマネージャーなどで調べて余裕のある分だけ設定してください、CPUは2コアは最低必要かと思います。
アクセラレーション
準仮想化インターフェースはhyper-vかデフォルトでいいと思います。
ネットワーク
KUSANAGIの設定上アダプタ1はnat固定です、デフォルトの通信はすべてNAT経由、つまりwinを通して通信されます。
アダプタ2はvagrantfileに記述したとおりブリッジアダプターが設定されます。
なおこのときホストPCにインターフェースは複数ある場合vagrant up時にどれを使用するか聞かれますので選択してください。
インターフェースの固定化は各自調べてください(vagrant interface bridged等)
再起動
あとはコマンドプロンプト等でvagrant upしてKUSANAGIを再起動してください。
無事起動したらSSHやブラウザなどでホストのIPまたはゲストのIP(ブリッジに割り当てられたIP)にアクセスして接続すれば成功です。
ホストIPで接続できない場合はwindowsの場合セキュリティにポート80、443、22(SSHのポート番号)を許可すると治るかもしれません。
ブリッジのIPで接続はほぼ成功すると思いますが、自分の環境ではローカルからでは接続できましたがWAN(インターネット経由)だとアクセスできませんでした。どうやらプロキシ関係が問題だと思いますが直し方がわからなかったのでルーターには80、443のポート接続はブリッジではなくホストのIPを指定しています。
余談ですがホストIPを通したNAT接続よりブリッジ接続からアクセスしたほうが早いそうなのでできる人はブリッジから接続できるよう頑張ってください。
(WAN(インターネット)からブリッジに接続するvagrantfileの記述を知ってる人は教えてくださるとありがたいです)
ディスカッション
コメント一覧
まだ、コメントがありません