Vagrant+node.jsインストールと初期設定(CentOS6編)

JavaScript

はじめに

今回は下記の環境をちゃちゃっと構築するための手順を記載します。

ホストOS : Windows10
ゲストOS : CentOS6.5(VagrantでBOX「puphpet/centos65-x64」を使用)
仮想化ソフト : VirtualBox、Vagrant

 

参考HP

VirtualBox公式HP : https://www.virtualbox.org/

Vagrant公式HP : https://www.vagrantup.com/

BOXファイル : https://app.vagrantup.com/boxes/search
※今回はBOX「puphpet/centos65-x64」を使用する

BOXファイル:http://www.vagrantbox.es/

BOXファイル:http://vccw.cc/

VirtualBoxのインストール

VirtualBoxインストール入門(Windows10)編[所要時間:5分]

 

Vagrantのインストール

特別な変更は無く、インストーラーに沿ってインストールする

 

Vagrantの初期設定

「default: Warning: Authentication failure. Retrying…」の対処

Vagrant 1.8.5のバグが原因で鍵認証がうまくいかなず、下記が出続ける場合の対処

default: Warning: Authentication failure. Retrying…
default: Warning: Authentication failure. Retrying…
default: Warning: Authentication failure. Retrying…
default: Warning: Authentication failure. Retrying…

下記ファイルの56行目に付近にある
[vagrantのインストール先パス]\embedded\gems\gems\vagrant-1.8.5\plugins\guests\linux\cap\public_key.rb

下記記載のすぐ下に
mv ~/.ssh/authorized_keys.tmp ~/.ssh/authorized_keys

下記を追加する
chmod 0600 ~/.ssh/authorized_keys

vagrantのプラグインをインストール

$ vagrant plugin install vagrant-hostsupdate

 

Vagrantfileの設定

指定のBOXファイルを決める

Vagrantfileを下記の通り変更する。
※今回はBOX「puphpet/centos65-x64」を設定する場合の例

config.vm.box = “puphpet/centos65-x64″   ←指定のBOXを設定

ポートとIPと共有フォルダの設定

Vagrantfileに下記を追加

config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.network "private_network", ip: "192.168.33.10", id:"http"

 

コマンドログイン後

「Error: Cannot retrieve repository metadata (repomd.xml) for repository:」の対処

sudo yum remove centos-release-SCL
sudo yum update

sudoコマンドのnpm、nodeコマンドを使用可能にする

sudo visudo

73行目 : Defaults    env_reset

Defaults    !env_reset

84行目 : # Defaults   env_keep += “HOME”

Defaults   env_keep += “HOME”

86行目 :  Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin

# Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin

nvmのインストール

GitHub - nvm-sh/nvm: Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions
Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions - nvm-sh/nvm
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash

nvm install v0.12.4
nvm alias default v0.12.4

gitのインストール

sudo yum install git

npmの確認

npm install request

or

npm install -g request

nodeの動作確認

node download-node.js

let url = "http://www.yahoo.co.jp/";
let savepath = "test.html";

let http = require('http');
let fs = require('fs');

let outfile = fs.createWriteStream(savepath);

http.get(url, function(res) {
  res.pipe(outfile);
  res.on('end', function() {
    outfile.close();
    console.log("OK");
  });
});

 

 

タイトルとURLをコピーしました