Canvas LMS 安装攻略

T-Bot
发布于: 1年前
分享:

Canvas LMS 是一款功能强大,可全方位覆盖 K-12 学习资源管理,其安装过程比较复杂,特此全程记录并分享给大家。

安装、配置 Canvas LMS

官方使用指南:

https://guides.instructure.com

 

创建系统用户

root@canvas-demo:~# adduser canvas

修改 canvas 用户 sudo 权限

root@canvas-demo:~# visudo

root@canvas-demo:~# su canvas

创建工作区目录

canvas@canvas-demo:/root$ sudo mkdir -p /data

canvas@canvas-demo:/root$ sudo chown canvas:canvas /data

切换至工作区目录:

canvas@canvas-demo:/root$ cd /data

 

安装及配置 PostgreSQL 数据库

安装

传送门

为 Canvas 创建一个 PostgreSQL 数据库用户:

canvas@canvas-demo:/data$ sudo -u postgres createuser canvas --no-createdb --no-superuser --no-createrole --pwprompt

输入 2 次数据库用户密码

创建 Canvas 数据库:

canvas@canvas-demo:/data$ sudo -u postgres createdb canvas_production --owner=canvas

设置超级用户

canvas@canvas-demo:/data/canvas$ sudo -u postgres createuser $USER

canvas@canvas-demo:/data/canvas$ sudo -u postgres psql -c "alter user $USER with superuser" postgres

 

2. 安装 Git:

canvas@canvas-demo:/data$ sudo apt install git

 

3. 克隆 Canvas LMS:

canvas@canvas-demo:/data$ git clone https://github.com/instructure/canvas-lms.git canvas

canvas@canvas-demo:/data$ cd canvas

canvas@canvas-demo:/data$ git checkout prod

修改 canvas 文件夹权限:

canvas@canvas-demo:/data$ sudo chown -R canvas /data/canvas

再次确认切换至 canvas 安装目录:

canvas@canvas-demo:/data$ cd /data/canvas

 

4. 安装依赖

4.1 安装 Ruby

$ sudo apt install software-properties-common

$ sudo add-apt-repository ppa:brightbox/ruby-ng #此步骤需要回车确认

$ sudo apt update

$ sudo apt-get install ruby2.7 ruby2.7-dev zlib1g-dev libxml2-dev libsqlite3-dev libpq-dev libxmlsec1-dev libidn11-dev curl make g++

********************************************************************

尝试安装 ruby2.7 时,但 Bundler 在 Canvas init 时 会报错

$ sudo apt-get install ruby ruby-dev zlib1g-dev libxml2-dev libsqlite3-dev libpq-dev libxmlsec1-dev curl make g++

Ubuntu 20.04 在安装 libxmlsec1-dev 时遇到错误:

尝试:

$ sudo apt install libssl1.1=1.1.1f-1ubuntu2

再次安装:$ sudo apt install libxmlsec1-dev

否则 bundle _2.2.19_ install 报错

********************************************************************

 

4.2 安装 Node.js

$ curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -

$ sudo apt -y install nodejs

切换至国内 NPM 镜像:(原始地址:https://registry.npmjs.org/)

$ npm config set registry https://r.npm.taobao.org

验证 NPM 镜像地址:

$ npm config get registry

4.3 安装 NPM

$ sudo npm install -g npm@latest

 

6. Bundler 和 Canvas 依赖

此步骤可能会因为网络问题出错,多尝试几次即可。替换镜像可跳过,从 6.2 继续。

6.1 替换 Ruby gems 国内镜像:

使用 Ruby China 源:

canvas@canvas-demo:/data/canvas$ gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/

使用清华源:

canvas@canvas-demo:/data/canvas$ gem sources --add https://mirrors.tuna.tsinghua.edu.cn/rubygems/ --remove https://rubygems.org/ 

查看当前源:

canvas@canvas-demo:/data/canvas$ gem sources -l

 

6.2 安装 bundler 包管理器

canvas@canvas-demo:/data/canvas$ sudo gem install bundler --version 2.2.19 --default

6.3 通过 bundler 管理器安装 bundle

canvas@canvas-demo:/data/canvas$ bundle config set --local path 'vendor/bundle'

canvas@canvas-demo:/data/canvas$ bundle config set --local without 'pulsar'

canvas@canvas-demo:/data/canvas$ bundle _2.2.19_ install

 

7.安装 Yarn

canvas@canvas-demo:/data/canvas$ curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -

canvas@canvas-demo:/data/canvas$ echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

canvas@canvas-demo:/data/canvas$ sudo apt-get update && sudo apt-get install yarn=1.19.1-1

如需切换 Yarn 镜像,可安装 yrm 切换镜像,具体可参考其他网站资料

Yarn 防超时执行参数:yarn install --network-timeout 600000

 

8. 安装 Python

contextify 包需要用到 Python,通过 apt 安装:

canvas@canvas-demo:/data/canvas$ sudo apt install python

 

9. 通过 Yarn 安装依赖

canvas@canvas-demo:/data/canvas$ sudo yarn install

 

10. Canvas 配置文件

canvas@canvas-demo:/data/canvas$ for config in amazon_s3 database delayed_jobs domain file_store outgoing_mail security external_migration; do cp config/$config.yml.example config/$config.yml; done

 

10.1 动态配置文件

canvas@canvas-demo:/data/canvas$ cp config/dynamic_settings.yml.example config/dynamic_settings.yml

canvas@canvas-demo:/data/canvas$ nano config/dynamic_settings.yml

10.2 数据库配置文件

canvas@canvas-demo:/data/canvas$ cp config/database.yml.example config/database.yml

canvas@canvas-demo:/data/canvas$ nano config/database.yml

10.3 发送邮件配置文件

canvas@canvas-demo:/data/canvas$ cp config/outgoing_mail.yml.example config/outgoing_mail.yml

canvas@canvas-demo:/data/canvas$ nano config/outgoing_mail.yml

10.4 URL 配置文件

canvas@canvas-demo:/data/canvas$ cp config/domain.yml.example config/domain.yml

canvas@canvas-demo:/data/canvas$ nano config/domain.yml

10.5 安全配置文件

canvas@canvas-demo:/data/canvas$ cp config/security.yml.example config/security.yml

修改 security.yml 文件,替换加密密钥,长度为至少20个字符随机字符串

canvas@canvas-demo:/data/canvas$ nano config/security.yml

 

11. 生成素材库

canvas@canvas-demo:/data/canvas$ mkdir -p log tmp/pids public/assets app/stylesheets/brandable_css_brands

canvas@canvas-demo:/data/canvas$ touch app/stylesheets/_brandable_variables_defaults_autogenerated.scss

canvas@canvas-demo:/data/canvas$ touch Gemfile.lock

canvas@canvas-demo:/data/canvas$ touch log/production.log

canvas@canvas-demo:/data/canvas$ yarn install

canvas@canvas-demo:/data/canvas$ RAILS_ENV=production bundle exec rake canvas:compile_assets

 

12. 初始化数据库

canvas@canvas-demo:/data/canvas$ RAILS_ENV=production bundle exec rake db:initial_setup

12.1 数据库初始化出错:

2022-AUG-04 版本后,执行 db:initial_setup 报错,可尝试如下步骤:

$ su canvas
$ cd /data/canvas
$ mv db/migrate/20210823222355_change_immersive_reader_allowed_on_to_on.rb .
$ mv db/migrate/20210812210129_add_singleton_column.rb db/migrate/20111111214311_add_singleton_column.rb
$ RAILS_ENV=production bundle exec rake db:initial_setup
$ mv 20210823222355_change_immersive_reader_allowed_on_to_on.rb db/migrate/.
$ RAILS_ENV=production bundle exec rake db:migrate

 

13. 修改配置文件权限

canvas@canvas-demo:/data/canvas$ sudo chmod 400 config/*.yml

 

14. 安装 Apache 和 Passenger

14.1 安装

canvas@canvas-demo:/data/canvas$ sudo apt-get install passenger libapache2-mod-passenger apache2

如 Passenger 遇阻,可尝试 Passenger 安装:

$ sudo apt-get install -y dirmngr gnupg

$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7

$ sudo apt-get install -y apt-transport-https ca-certificates

# Add our APT repository

$ sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger bionic main > /etc/apt/sources.list.d/passenger.list'

$ sudo apt-get update

# Install Passenger + Apache module

$ sudo apt-get install -y libapache2-mod-passenger

 

启用 Apache 相关模块:

canvas@canvas-demo:/data/canvas$ sudo a2enmod rewrite
canvas@canvas-demo:/data/canvas$ sudo a2enmod passenger
canvas@canvas-demo:/data/canvas$ sudo a2enmod ssl

 

编辑 Passenger 模块配置文件:

canvas@canvas-demo:/data/canvas$ sudo nano /etc/apache2/mods-enabled/passenger.conf

添加 PassengerDefaultUser canvas,如下:

 

PassengerRoot /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini

 PassengerDefaultRuby /usr/bin/passenger_free_ruby

 PassengerDefaultUser canvas

 

14.2 安装XSendFile

$ sudo apt-get install libapache2-mod-xsendfile

开启 XSendFile 模块:

$ sudo a2enmod xsendfile

为了避免今后更新 Canvas 程序时覆盖环境配置,可创建另外一个 production-local.rb 增加 Canvas 环境配置:

canvas@canvas-demo:/data/canvas$ nano ./config/environments/production-local.rb

添加一行:config.action_dispatch.x_sendfile_header = 'X-Sendfile'

保存,退出编辑。

 

配置 VHOST  

Apache Vhost

   

安装 Redis 缓存服务

$ sudo add-apt-repository ppa:chris-lea/redis-server
$ sudo apt-get update
$ sudo apt-get install -y redis-server
$ sudo nano /etc/redis/redis.conf
$ sudo systemctl enable redis-server
$ sudo systemctl start redis.service
$ cd /data/canvas/

增加缓存存储配置文件:

canvas@canvas-demo:/data/canvas$ cp config/cache_store.yml.example config/cache_store.yml
canvas@canvas-demo:/data/canvas$ nano config/cache_store.yml

写入:


production:
  cache_store: redis_cache_store
  url:
  - localhost
  db: 0

保存退出编辑后,修改cache_store.yml 所有者及权限:

canvas@canvas-demo:/data/canvas$ sudo chmod 400 config/cache_store.yml

增加 Canvas 缓存配置文件:(新版本可跳过)

canvas@canvas-demo:/data/canvas$ cp config/redis.yml.example config/redis.yml
canvas@canvas-demo:/data/canvas$ nano config/redis.yml

写入:

production:
  servers:
    - redis://password@localhost
  db: 1

修改 redis.yml 权限:

canvas@canvas-demo:/data/canvas$ sudo chown canvas:canvas config/redis.yml
canvas@canvas-demo:/data/canvas$ sudo chmod 400 config/redis.yml

 

配置 Canvas 自动化任务

canvas@canvas-demo:/data/canvas$ sudo ln -s /data/canvas/script/canvas_init /etc/init.d/canvas_init
canvas@canvas-demo:/data/canvas$ sudo update-rc.d canvas_init defaults
canvas@canvas-demo:/data/canvas$ sudo /etc/init.d/canvas_init start

返回:Daemonizing... 表示成功!

 

重启 Canvas

$ sudo /etc/init.d/apache2 restart
$ sudo /etc/init.d/canvas_init restart
$ /data/canvas/script/delayed_job restart

 

安装 QTI Migration Tool

当用户操作复制、导入测验(Quiz)内容时,需要 QTI Migration Tool 支持,具体安装步骤如下:

安装 Python 3 和依赖:

$ pip3 install lxml

克隆 QTIMigration Tool

$ cd /data/canvas/vendor
$ git clone https://github.com/instructure/QTIMigrationTool.git QTIMigrationTool
$ cd QTIMigrationTool
$ chmod +x migrate.py

完成上述步骤后,重启 delayed_job:

$ cd /data/canvas
$ script/delayed_job restart

安装完成后,Site Admin -> Plugins -> QTI Converter 开启支持,如果 QTI Migration 工具安装成功,Canvas 会自动识别并开启该插件。

 

 

0 留言

留言

您的留言将被人工审核,请勿发表色情、反动言论。

您可能感兴趣

如何为 Canvas 学习系统配置 Microsoft Azure AD 登录

学校在部署 Canvas 学习系统时,大多会希望其与现有账户系统集成,实现单点登录(SSO),这样可以方便用户...

什么是 Canvas LMS 学习系统?

Canvas 是一个基于网络的学习管理系统或 LMS。学习机构、教育工作者和学生使用它来访问和管理在线课程学习...