Vagrant周り・コマンドなど

## mkdirをcd をまとめる方法。

### オプション
`-p` ：親ディレクトリが存在しない時、自動で作成します。また、既に存在するディレクトリを指定してもエラーになりません。

>```bash:bash
$ mkdir -p xxx/yyy && cd $_
```

>https://qiita.com/akokubu/items/d577d0d8ccc6464286c1

## VagrantでCentOS環境を作る方法

boxの確認

```bash:bash
$ vagrant box list
```

http://www.vagrantbox.es/
→様々なLinuxディストリビューションの立ち上げ情報などが載っている。

`centos7`という名前でCentOS 7.0 x64を追加する。

```bash:bash
$ vagrant box add centos7 https://github.com/tommy-muehle/puppet-vagrant-boxes/releases/download/1.1.0/centos-7.0-x86_64.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'centos7' (v0) for provider:
    box: Downloading: https://github.com/tommy-muehle/puppet-vagrant-boxes/releases/download/1.1.0/centos-7.0-x86_64.box
    box: Download redirected to host: github-production-release-asset-2e65be.s3.amazonaws.com
==> box: Successfully added box 'centos7' (v0) for 'virtualbox'!
```

ドットインストールにある**[コマンド](https://dotinstall.com/lessons/basic_localdev_mac_v2/38506)**を実行する。

```bash:bash
# Vagrantfileを編集して仮想マシンのIPアドレスを192.168.33.10にする
~/MyVagrant/MyCentOS
❯ sed -i '' -e 's/# config.vm.network "private_network", ip: "192.168.33.10"/config.vm.network "private_network", ip: "192.168.33.10"/' Vagrantfile
```

`sed`コマンド解説：
https://hydrocul.github.io/wiki/commands/sed.html


```bash:bash
~/MyVagrant/MyCentOS
❯ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'centos7'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: MyCentOS_default_1546175790306_13478
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    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 guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default:
    default: Guest Additions Version: 4.3.28
    default: VirtualBox Version: 6.0
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => /Users/koyowakebe/MyVagrant/MyCentOS
```