LoginSignup
21
31

More than 5 years have passed since last update.

CentOSにLMS(学習管理システム)のCanvasをインストールする(Development Ver)

Last updated at Posted at 2015-07-29

Vagrant上のCentOS7.1にCanvasをインストールする手順を以下に記載します.
ここでは公式手順のQuick-Startをベースにし、商用運用するための手順は別途書く予定です

参考) 公式手順

前提

CentOSはMac上にVagrantでsetupしたものを利用しています.
Vagrant自体はsetup済みとして話を進めていきます

またcanvasはrails上で動くのでruby、及びcssのcompileにnodeを使っています。
それぞれanyenvを利用してsetupするので、以下を参照にしてanyenvをcentosOSにinstallして下さい.
anyenvで開発環境を整える

Version

  • Centos7.1
    使ったVagrantfileはこれ
  • anyenv
    • ruby 2.2.1
    • node v0.12.7

install概要

  1. vagrantでcentos7setup
    • centOS setup
    • firewalldの設定をいじる
  2. 事前作業
    • PostgreSQLインストール
    • redisインストール(必須ではない)
  3. canvasインストール
    • nokogiriのコンパイルエラー対応
    • bundle/npm install
  4. canvas環境設定
  5. データベースセットップ
  6. 起動

CentOS7 setup

$ cd ~/vagrant
$ mkdir canvas
$ cd canvas

これをVagrantfileとしてcanvasフォルダにコピー

起動とログイン

$ vagrant up
# ssh canvasでお手軽にログインできるように、ssh_configをupdate
$ vagrant ssh-config --host canvas >> ~/.ssh/config
$ ssh canvas

後は環境に合わせてOSを色々変更する.
やったのは以下

  $ rbenv install 2.1.6
  $ rbenv global 2.1.6
  $ rbenv rehash
  $ ndenv install v0.12.7
  $ ndenv global v0.12.7
  $ ndenv rehash

firewalldの設定追加

初期設定でcanvasは3000ポートで起動するので、firewalldで穴あけをしておく.
(macから http://192.168.33.10:3000 のような形でアクセスしたいので)

$ sudo firewall-cmd --permanent --add-port=3000/tcp
$ sudo firewall-cmd --reload
$ firewall-cmd --list-all
public (default, active)
  interfaces: enp0s3 enp0s8
  sources:
  services: dhcpv6-client ssh
  ports: 3000/tcp
  masquerade: no
  forward-ports:
  icmp-blocks:
  rich rules:

canvas事前作業

postgresインストール

MySQLも利用できそうだけど、とりあえずQuick-Startの手順をベースにPostgreSQLをインストール

$ sudo yum install -y postgresql-server postgresql-devel
$ sudo mkdir -p /var/lib/pgsql/data
$ sudo chown postgres:postgres /var/lib/pgsql/data
# ユーザーをpostgresに切り替え
$ sudo -i -u postgres
$ initdb  -D '/var/lib/pgsql/data'
$ exit

PostgreSQL起動と確認

$ sudo systemctl start postgresql.service
# 動作確認 activeになっていればOK
$ sudo systemctl status postgresql.service
postgresql.service - PostgreSQL database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql.service; disabled)
   Active: active (running) since 火 2015-07-28 11:26:16 JST; 23h ago

redisのインストール

必須では無いが、cacheサーバとして合ったほうが早いのでインストールしておく.
今回商用ベースではないので、設定はデフォルトのまま進む

$ sudo yum -y install redis
$ sudo systemctl start redis.service
# 起動しているか確認
$ sudo systemctl status redis.server
$ redis-cli ping
PONG -> PONGが返ってくればOK

canvasのインストール

canvasのソースを取得

事前準備ができたら、canvasのソースを取得してインストールする

$ cd $HOME
$ git clone https://github.com/instructure/canvas-lms.git canvas
$ cd canvas
$ git branch --set-upstream-to origin/stable

nokogiriがうまく入らない問題対応

このまま公式手順通りに行くと、bundle installのnokogiriインストール時につまります.
以下のコマンドを参考に、Gemfileを編集した後、次のbundle installを行う.

参考)nokogiri インストール時のエラー Running ‘patch’ for libxml2 2.8.0… ERROR

# nokogiriに必要なpackageをyumでインストールしておく
$ sudo yum install -y libxml2-devel libxslt-devel
$ vi Gemfile

# 以下のようになるよう、ENV['NOKOGIRI_USE_SYSTEM_LIBRRIES']を追加する.

$ git diff
diff --git a/Gemfile b/Gemfile
index 6480fbe..3802bc9 100644
--- a/Gemfile
+++ b/Gemfile
@@ -12,8 +12,9 @@
 # these gems to prevent regression, and the indentation serves to alert us to the relationship betw
 source 'https://rubygems.org/'

+ENV['NOKOGIRI_USE_SYSTEM_LIBRARIES'] = 'YES'
 require File.expand_path("../config/canvas_rails4", __FILE__)

 Dir.glob(File.join(File.dirname(__FILE__), 'Gemfile.d', '*.rb')).sort.each do |file|
   eval_gemfile(file)

bundle install

canvasに必要なrubyのpackageをbundleを使ってインストール.

# bundlerのバージョンは指定されているので合わせる
$ gem install bundler -v 1.10.3
# 今回mysqlは使わないのでinstallから外す
$ bundle install --without mysql sqlite

npm install

同じくcanvasに必要なnodeのpackageをnpmを使ってインストール

$ npm install
$ npm install coffee-script@1.6.2

環境設定

canvasのconfig類をexampleをベースに書き換えていく

今回利用するconfig一覧

config 概要
database.yml 使用するデータベース/データベース名等を定義
delayed_jobs.yml backgroundで実行するworkerの数等を定義
domain.yml canvasのドメイン名を定義
file_store.yml ファイルの保存先. amazon s3にも可能
outgoing_mail.yml 送信元となるsmtpサーバを定義
security.yml 暗号鍵定義。(どこで使う?
external_migration.yml 移行時にfaileを一時的に置く場所を定義
cache_store.yml canvasで使用するcacheサーバを定義
redis.yml cacheでredisを使う場合に定義

configの設定

基本今回は上記ファイルを使うが、exampleがconfigに色々あって邪魔なので、一旦exmpleは退避させておく

$ cd canvas/config/
$ mkdir example
$ mv *.example example/

設定するファイルだけ、config配下にコピーして変更していく

$ for config in database delayed_jobs domain file_store outgoing_mail outgoing_mail security external_migration cache_store redis;
do cp -v config/example/$config.yml.example config/$config.yml; done

変更点した点は以下のとおり

  • database.yml
    developmentなので、今回はそのまま.商用だとpasswdとか変更要
  • delayed_jobs.yml
    これも特に今回は変更無し.商用だとメモリ等状況に従ってworker数などを変更する
  • domain.yml domainがlocalhostになっていて、macからアクセスすると色々面倒なので、ここは修正する
  # vagrantの起動設定に合わせてIPアドレスを設定
  development: 
      domain: "192.168.33.10:3000"
  • file_store.yml 保存先はtmpで問題ないのでそのまま.
  • outgoing_mail.yml gmailだったら以下のように修正
  development:
    address: "smtp.gmail.com"
    port: "587"
    user_name: "you@gmail.com"
    password: "gmail-password"
    authentication: "plain" # plain, login, or cram_md5
    domain: "gmail.com"
    outgoing_address: "you@gmail.com"
    default_name: "Your Name"
    tls: true
  • security.yml とりあえず今回はイジらない
  • external_migration.yml migrationは今回無視するので変更無し
  • cache_store.yml デフォルトだとdevelopmentのcacheはコメントアウトされているので、以下のようにコメントアウトを外しておく
   development:
     cache_store: redis_store
  • redis.yml developmentの設定は無いので、以下を最下行に追加する.
  development:
      servers:
        - redis://localhost

補足

おこのみで以下の設定をしても良い。性能は上がるが、設定変更時に再起動が必要になりそうなので要注意.

$ echo -n 'config.cache_classes = true
config.action_controller.perform_caching = true
config.action_view.cache_template_loading = true
' > config/environments/development-local.rb

データベースセットアップ

データベースを作成する

$ sudo -u postgres createuser canvas --no-createdb --no-superuser --no-createrole --pwprompt
$ sudo -u postgres createdb canvas_development --owner=canvas
$ sudo -u postgres createdb canvas_queue_development --owner=canvas

データベースのイニシャライズ

rake db:initial_setupを実行してDBの初期化を行う.
途中で初期ユーザー名(email)とパスワードを聞かれるので設定していく.
また最後に利用データを採取してよいかと聞かれるので、嫌だったら3にする

$ bundle exec rake db:initial_setup
What email address will the site administrator account use? > hogehoge@fuga.com
Please confirm > hogefuga@fuga.com
What password will the site administrator use? > *******
Please confirm > *******
What do you want users to see as the account name? This should probably be the name of your organization. > fugafuga

To help our developers better serve you, Instructure would like to collect some usage data about your Canvas installation. You can change this setting at any time.:
1. Opt in
2. Only send anonymized data
3. Opt out completely
>3
You have opted out.
(中略)
Initial data loaded

File Generation

最後に、各種ファイル等のコンパイルを実施

$ bundle exec rake canvas:compile_assets

起動

以下のコマンドを実行してサーバを起動する。

$ bundle exec rails server

Vagrantfileの設定しだいですが、後は以下のようなURLをブラウザでアクセスすれば完了.

ハマった所

  • firewalld cent7で入ったfirewalldの仕組みがわからなかった…
21
31
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
21
31