0
1

More than 3 years have passed since last update.

[失敗談]railsの環境構築で休日を潰した件[ポエム]

Last updated at Posted at 2019-12-15

注意

本記事は、貴重な休日をrails環境構築で無駄にした男の2019/12/15の作業ログです。

得られた知見

  • 目的と手段をはき違えないようにしよう(アプリケーション制作の手段の一つが開発環境構築)
  • 変なところに凝るのは辞めよう(特に時間がないとき)
  • できるだけ環境は参考する記事のものに揃えよう(バージョンとか)
  • 開発環境構築に大きくハマったら、おとなしくcloudIDEを使おう(cloud9とか便利なものあるよね)

予告「クレジットカードなしでAWSに登録して、cloud9を使ってみた(2019年12月最新版)」みたいなタイトルで今年中に記事書きます。書きました。


一目で分かる今回のあらすじ

有名なアレ
              ,. -‐'''''""¨¨¨ヽ
         (.___,,,... -ァァフ|          あ…ありのまま 今 起こった事を話すぜ!
          |i i|    }! }} //|
         |l、{   j} /,,ィ//|       『おれはrailsの環境構築をし直そう
        i|:!ヾ、_ノ/ u {:}//ヘ        としていたらいつのまにか休日が終わっていた』
        |リ u' }  ,ノ _,!V,ハ |
       /´fト、_{ル{,ィ'eラ , タ人        な… 何を言ってるのか わからねーと思うが
     /'   ヾ|宀| {´,)⌒`/ |<ヽトiゝ        おれも何がどうなったかわからなかった…
    ,゙  / )ヽ iLレ  u' | | ヾlトハ〉
     |/_/  ハ !ニ⊇ '/:}  V:::::ヽ        頭がどうにかなりそうだった…
    // 二二二7'T'' /u' __ /:::::::/`ヽ
   /'´r -―一ァ‐゙T´ '"´ /::::/-‐  \    催眠術だとか超スピードだとか
   / //   广¨´  /'   /:::::/´ ̄`ヽ ⌒ヽ    そんなチャチなもんじゃあ 断じてねえ
  ノ ' /  ノ:::::`ー-、___/::::://       ヽ  }
_/`丶 /:::::::::::::::::::::::::: ̄`ー-{:::...       イ 

2019/12/14

「そうだ、rails環境構築し直そう」

ことの発端はこの発言だった。
その日の日中は用事(就活セミナー)があり、自宅に帰るバスの中でqiitaを眺めながら思ってしまった。
以前、ruby 2.6.5 + rails 6.0.1の環境でherokuを使ってサンプルアプリ(scaffolding機能で生成)をデプロイした
開発環境を作成した。しかし、偉大な先駆者の方々のrailsの記事を見ていると「アプリごとにgemファイルは作るべき」という意見が大多数であったので、システムのgemファイルに直にいろいろと詰め込んでいた以前の開発環境をどうするべきか悩んでしまった。
結局、新しく開発環境を作り直してgemファイルまわりを変更しようといった結論に至ってしまっ

こういった場合の正しい対応は、
そんなの気にせずアプリケーション制作する です。

Done is better than perfect. (マーク・ザッカーバーグ)

ある程度新しいqiitaの記事があるものから選ぼう

->VirtualBox + vagrant を使ってやってみよう

参考

Qiita / Windows + VirtualBox + vagrant + Ubuntu + Docker + Docker Compose で Ruby on Rails + PostgreSQL の開発環境を構築する手順

ゼロから始める開発環境構築(Rails MySQL) その1

2019/12/15

とりあえずやってみる

//VirtualBox-6.1-6.1.0_135406_el7-1.x86_64.rpm  vagrant_2.2.6_x86_64.rpm
をダウンロード

//ダウンロードしたファイルをworkspaceに移す
cp VirtualBox-6.1-6.1.0_135406_el7-1.x86_64.rpm /home/dev01/workspace
cp vagrant_2.2.6_x86_64.rpm /home/dev01/workspace

//workspaceに移したファイルをインストール
yum install -y SDL
rpm -ivh VirtualBox-6.1-6.1.0_135406_el7-1.x86_64.rpm
yum install bzip2 gcc make perl kernel-devel
reboot
rpm -ivh vagrant_2.2.6_x86_64.rpm
vagrant init bento/centos-7.5
vi Vagrantfile

vagrant up

参考

ゼロから始める開発環境構築(Rails MySQL) その1
Ken01のブログ / VirtualBoxのインストール
maruko2 note / CentOS/rpmコマンドの使い方
雑木林 / VitualBoxでGuest Addonをインストールする

立ち上がらない、なんで?

//エラーメッセージ
No usable default provider could be found for your system.

Vagrant relies on interactions with 3rd party systems, known as
"providers", to provide Vagrant with resources to run development
environments. Examples are VirtualBox, VMware, Hyper-V.

The easiest solution to this message is to install VirtualBox, which
is available for free on all major platforms.

If you believe you already have a provider available, make sure it
is properly installed and configured. You can see more details about
why a particular provider isn't working by forcing usage with
`vagrant up --provider=PROVIDER`, which should give you a more specific
error message for that particular provider.

//解決策
ほかにも似たような事例があった
->virtualboxのバージョンが高すぎるらしい?
-->探したらvagrantとvirtualboxのうまくいったver.の組み合わせがあった(Vagrant 2.2.4+VirtualBox 5.0.2.6)

参考

Qiita / 【Mac】vagrant upでエラー
Qiita / Windows + VirtualBox + vagrant + Ubuntu + Docker + Docker Compose で Ruby on Rails + PostgreSQL の開発環境を構築する手順
teratail / ローカル開発環境の構築

リトライ

yum -y update
mkdir workspace
cd workspace

VirtualBox 5.0.2.6をダウンロードするか...
->VirtualBox 5.0.x is no longer supported!(迫真)
->だめやん...
他の組み合わせを探す
->あった (Vagrant 2.2.2 + VirtualBox 6.0.0)

VirtualBox 6.0.0、Vagrant 2.2.2をダウンロード
wget  https://download.virtualbox.org/virtualbox/6.0.0/VirtualBox-6.0-6.0.0_127566_el7-1.x86_64.rpm
wget https://releases.hashicorp.com/vagrant/2.2.2/vagrant_2.2.2_x86_64.rpm

yum install -y SDL
yum install bzip2 gcc make perl kernel-devel
reboot
rpm -ivh VirtualBox-6.0-6.0.0_127566_el7-1.x86_64.rpm

参考

NOBODY:PLACE / 開発環境の整備(Vagrant+VirtualBox+CentOS7.6+PHP7.1)【#np2020】

エラー吐いた

This system is currently not set up to build kernel modules.
Please install the Linux kernel "header" files matching the current kernel
for adding new hardware support to the system.
The distribution packages containing the headers are probably:
    kernel-devel kernel-devel-3.10.0-1062.el7.x86_64
This system is currently not set up to build kernel modules.
Please install the Linux kernel "header" files matching the current kernel
for adding new hardware support to the system.
The distribution packages containing the headers are probably:
    kernel-devel kernel-devel-3.10.0-1062.el7.x86_64

There were problems setting up VirtualBox.  To re-start the set-up process, run
  /sbin/vboxconfig
as root.

対応

yum install kernel-devel kernel-devel-3.10.0-1062.el7.x86_64
/sbin/vboxconfig
(エラーが出なくなったので)ヨシッ(某現場猫)

続き

rpm -ivh vagrant_2.2.2_x86_64.rpm
mkdir test
cd test
vagrant init bento/centos-7.5

これ最新版じゃないからアップデートしたら?このURLから探してね(意訳)

==> vagrant: A new version of Vagrant is available: 2.2.6 (installed version: 2.2.2)!
==> vagrant: To upgrade visit: https://www.vagrantup.com/downloads.html

無視して続ける

vi Vagrantfile
(https://qiita.com/hirokisuganuma/items/6ef3334f8339f165e48b)
vagrant up

またエラーが出た

Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.

If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.

If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.

If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.

vagrantは動いてるか確認

vagrant status
↓
Current machine states:
default                   running (virtualbox)
The VM is running. To stop this VM, you can run `vagrant halt` to
shut it down forcefully, or you can run `vagrant suspend` to simply
suspend the virtual machine. In either case, to restart it again,
simply run `vagrant up`.

private key以降で詰まってるからVagrantが照会している鍵の場所を確認

確認
vagrant ssh-config
SSHの準備ができてないみたいだから,状況を確認してみ(意訳)
The provider for this Vagrant-managed machine is reporting that it
is not yet ready for SSH. Depending on your provider this can carry
different meanings. Make sure your machine is created and running and
try again. Additionally, check the output of `vagrant status` to verify
that the machine is in the state that you expect. If you continue to
get this error message, please view the documentation for the provider
you're using.

参考

[すごくねむい / vagrant upでprivate keyより先に進まない症状(10/25追記あり)](http://tauplank.hatenablog.com/entry/2016/10/23/153728)

vagrantを起動してからssh接続を試してみる

vagrant up
vagrant ssh

エラー?

ssh_exchange_identification: read: Connection reset by peer

どういうこと?

https://saba.omnioo.com/note/1396/sshエラー集/

このようなエラーが出て都度「Are you sure you want to continue connecting (yes/no)? yes」が立ち上がってしまう場合があります。これは接続先の対象ホストのIPアドレスが変わったりIPアドレスと紐づくドメインが変わったりした際に、古い接続情報がknown_hostsファイルに残っているということになります。該当の行数(ここでは2行目の情報)を削除します。最近はノートとwifiという感じで接続することもあって、wifiを切り替えるとこのエラーが出ることがあるんだけど、IP制限で弾かれていることが多い。またhosts.allowやhosts.denyの設定を間違ったりしてアクセスに障害が出るとこのエラーが出ることあります。

https://deep-blog.jp/engineer/5443/

サーバ側からすると接続相手側から接続を切られてしまったということを意味しているそうです。
つまり、お客様が使用されているPC側が何らかのトラブルにより強制的に接続を切ってしまったようです。

サーバ側(ホストOS)、接続相手側(ゲストOS)で読み替えると何となくわかった(根拠のない自信)。
しかし、対策がわからない
そこで似たような事例を探してみる
->あった

teratail / Vagrant+Virtualboxの開発環境で起動時に「default: Warning: Connection refused. Retrying...」の警告

前提条件
1. vagrantユーザが存在する
2. ~vagrant/.ssh/authorized_keysに公開鍵の登録がされていること
3. vagrantユーザはパスワードなしsudoができる

前提条件を満たすようにやってみよう

パスワードなしsudoができるvagrantユーザを作る
どこに?
->ゲストマシン上に
あらかじめboxの中に用意されているもんじゃないの?
->もしかしたらどこかで手順を勘違いしたかも
---> /(^o^)\
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1