Help us understand the problem. What is going on with this article?

OSX(el capitan) + Vagrant + Centos7.2 + rails4.2 + ruby2.3.1 + mariadb5.5x 開発環境構築手順

More than 3 years have passed since last update.

概要

Macを新規購入やクリーンインストール後、極力速やかに
CentOS最新版でRails開発環境を構築する手順をまとめます。

バージョン(2016/05/04現在)
  • OSX El Capitan 10.11.3
  • vagrant 1.8.1
  • Virtualbox 5.0.14
  • CentOS 7.2
  • Rails 4.2.6
  • Ruby 2.3.1
  • MariaDB 5.5x

Vagrant & VirtualBoxインストール

brew install virtualbox
brew install vagrant

Centos7のBoxを追加する

http://www.vagrantbox.es/ から CentOS7.0 x86_64 minimalのURLをコピーする。
ここではcentos7miniという名前でboxを追加する

mkdir vagrant
cd vagrant 

vagrant box add centos7mini https://f0fff3908f081cb6461b407be80daf97f07ac418.googledrive.com/host/0BwtuV7VyVTSkUG1PM3pCeDJ4dVE/centos7.box

Vagrantfileの作成&&VM立ち上げ

vagrant init centos7mini
vagrant up

以下のようなエラーが出るが一旦無視する
数分このまま進まないので、待たずに別のターミナルを立ち上げて vagrant sshしても良い

==> default: Mounting shared folders...
    default: /vagrant => /Users/YOURFOLDER/devel/cent7.2

Failed to mount folders in Linux guest. This is usually because
the "vboxsf" file system is not available. Please verify that
the guest additions are properly installed in the guest and
can work properly. The command attempted was:

mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` vagrant /vagrant
mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` vagrant /vagrant

The error output from the last command was:

/sbin/mount.vboxsf: mounting failed with the error: No such device

VMへのログイン及びCent7.2へupdate

vagrant ssh
sudo yum -y update
sudo systemctl disable firewalld
sudo vi /etc/selinux/config

- 以下をdisabledに変更する
SELINUX=disabled

exit

アップデート後のBoxパッケージ化

vagrant package

パッケージが終わるとカレントディレクトリにpackage.boxが作成される(1GB程度のサイズ)

CentOS7.2 boxの追加&確認

vagrant box add cent7.2 package.box
vagrant box list
cent7.2     (virtualbox, 0)
centos7mini (virtualbox, 0)

# CentOS7.0のVMやその関連ファイルは削除する
vagrant destory
rm Vagrantfile
rm package.box

CentOS7.2 boxの立ち上げ

vagrant init cent7.2

任意でリソース、ポート番号やIp、共有フォルダ等を設定

vi Vagrantfile

  config.vm.provider "virtualbox" do |vb|
    vb.cpus = 4
    vb.memory = 1048
    config.vm.network "forwarded_port", guest: 3000, host: 3000
  end

   config.vm.network "private_network", ip: "192.168.33.10"

config.vm.synced_folder "~/devel", "/var/rails/"
等の記述でnfs,フォルダ共有などできますが、パーミッションやスピードの問題で嵌まるので使用しません。

vagrant up

/sbin/mount.vboxsf: mounting failed with the error: No such device のようなエラーが発生する場合はvboxをリビルドする

vagrant ssh
sudo /etc/init.d/vboxadd setup
exit

vagrant reload

ユーザー作成

以下を参照して必要なユーザー作成
http://qiita.com/takuchan9104/items/1abd31c05432d5e81bf8

Railsインストール

長くなるので、以下に分割しました。

http://qiita.com/takuchan9104/items/7afc8d1465f11c136183

MariaDBのインストール

sudo yum -y install mariadb-server mariadb-devel
sudo systemctl start mariadb
sudo systemctl enable mariadb

config/database.ymlの編集

config/database.yml
default: &default
  adapter: mysql2
  pool: 5
  timeout: 5000
  username: root
  password:
  socket: /var/lib/mysql/mysql.sock
  encoding: utf8

development:
  <<: *default
  database: db/development

databaseの作成

bin/rake db:create

Scaffoldで動作確認

bin/rails g scaffold User name:string email:string

bin/rake db:migrate
bin/rails s -b 0.0.0.0

ブラウザからhttp://192.168.33.10:3000/users にアクセスして
適当にデータが入力できれば完了!

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした