Canvas LMS 安装 Analytics 插件

发布于: 15 December, 2021
分享:

参考链接:https://github.com/instructure/analytics

安装 JDK

首先执行 java --version 查看系统知否已经安装过 Java JDK:

$ java --version

如从未安装过 Java,Ubuntu 系统会显示可通过哪些命令安装:

Command 'java' not found, but can be installed with:
sudo apt install openjdk-11-jre-headless  # version 11.0.16+8-0ubuntu1~20.04, or
sudo apt install default-jre              # version 2:1.11-72
sudo apt install openjdk-13-jre-headless  # version 13.0.7+5-0ubuntu1~20.04
sudo apt install openjdk-16-jre-headless  # version 16.0.1+9-1~20.04
sudo apt install openjdk-17-jre-headless  # version 17.0.4+8-1~20.04
sudo apt install openjdk-8-jre-headless   # version 8u342-b07-0ubuntu1~20.04

假设服务器系统中从未安装,开始安装:

$ sudo apt install openjdk-8-jdk

安装结束后,执行 java -version,注意这里的参数是 -version,而不是 --version,如成功安装 Java JDK 8 则返回:

openjdk version "1.8.0_342"
OpenJDK Runtime Environment (build 1.8.0_342-8u342-b07-0ubuntu1~20.04-b07)
OpenJDK 64-Bit Server VM (build 25.342-b07, mixed mode)

 

安装 Cassandra 数据库

$ wget -q -O - https://www.apache.org/dist/cassandra/KEYS | sudo apt-key add -
3.11.xx版本:
$ echo "deb http://www.apache.org/dist/cassandra/debian 311x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
40 版本:
$ echo "deb http://www.apache.org/dist/cassandra/debian 40x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
$ sudo apt update
$ sudo apt install cassandra
$ systemctl status cassandra

 

查看 Cassandra 运行状态

3.11.xx 版本需要修改配置文件,在结尾处添加 start_rpc: true

$ nodetool status

返回:

Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address    Load       Tokens  Owns (effective)  Host ID                               Rack 
UN  127.0.0.1  69.08 KiB  16      100.0%            94f7fbd9-05bc-409d-8104-94aee27a0314  rack1

如果 nodetools 执行,返回被拒绝,服务启动中,稍后再试。

登录 Cassandra

$ cqlsh

退出登录

$ exit 或 ctrl + d

 

配置 Cassandra(可跳过)

cqlsh> UPDATE system.local SET cluster_name = 'Cassandra for Canvas Analytics' WHERE KEY = 'local';
cqlsh> exit

 

修改 Cassandra 配置文件(可跳过)

$ sudo nano /etc/cassandra/cassandra.yaml

 

修改 Cluster Name:(可跳过)

# Cassandra storage config YAML
# NOTE:
#   See https://cassandra.apache.org/doc/latest/configuration/ for
#   full explanations of configuration directives
# /NOTE
# The name of the cluster. This is mainly used to prevent machines in
# one logical cluster from joining another.
cluster_name: 'Cassandra for Canvas Analytics'

 

重启 Cassandra:

$ sudo systemctl restart cassandra
$ sudo systemctl status cassandra

默认安装后没有监听9160端口,Canvas LMS 无法获取数据

编辑:/etc/cassandra/cassandra.yaml

末尾增加:start_rpc: true

重启 Cassandra 服务:

$ sudo systemctl restart cassandra

 

配置 Canvas LMS

$ su canvas
$ cd /path/canvas
$ cp config/cassandra.yml.example config/cassandra.yml
$ nano config/cassandra.yml

修改 config/cassandra.yml 文件时,留意文件中的说明:

To use Cassandra for page views:
1. Create the keyspace in Cassandra.
2. Enable and fill in the configuration below. You can specify as many "seed" servers as you'd like from the cluster.
3. Run rake db:migrate to create the tables in the specified Keyspace.
4. In a script/console, run Setting.set('enable_page_views', 'cassandra')
5. Restart all app/job processes.
You'll also need to have redis enabled and configured in redis.yml.
To migrate the page views already in your database to cassandra, run
rake db:migrate_pageviews_to_cassandra
This will migrate all page views from the last 52 weeks for non-deleted accounts.

根据 cassandra 版本,创建对应表结构。首先,默认情况下 cassandra.yml 文件中没有 production 节点,将 development 或 test 节点修改为 production,随后将 production 配置区块中的 # 符号删除,取消注释。

修改 cassandra.yml 权限

$ chmod 400 config/cassandra.yml

 

创建表空间

cqlsh> CREATE KEYSPACE page_views WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
cqlsh> CREATE KEYSPACE page_views_test WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
cqlsh> CREATE KEYSPACE auditors WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
cqlsh> CREATE KEYSPACE auditors_test WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };

 

查看表空间

cqlsh> desc keyspaces;

如表空间成功创建,返回:

auditors       page_views_test  system_distributed  system_views         
auditors_test  system           system_schema       system_virtual_schema
page_views     system_auth      system_traces 

 

克隆 Analytics 插件

$ su canvas
$ cd /path/canvas
$ git clone https://github.com/instructure/analytics.git gems/plugins/analytics
$ bundle update
$ RAILS_ENV=production bundle exec rake db:migrate
$ RAILS_ENV=production bundle exec rake canvas:compile_assets
$ RAILS_ENV=production bundle exec rake db:migrate_pageviews_to_cassandra

 

Rails Console

$ cd /path/canvas
$ nano script/rails

复制以下内容,并保存

#!/usr/bin/env ruby
require 'pathname'
expanded_path = Pathname.new(__FILE__).realpath
APP_PATH = File.expand_path('../../config/application', expanded_path)
require File.expand_path('../../config/boot', expanded_path)
require 'rails/commands'

执行 rails console 进入控制台:

$ RAILS_ENV=production script/rails console

设置 enable_page_views 参数:

irb(main):001:0> Setting.set('enable_page_views', 'cassandra')

回车后保存,Ctrl + D 退出。

 

重启服务

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

 

使用 Analytics 服务

上述安装及配置工作结束后,登录 Canvas,访问地址栏 https://canvas.example.com/accounts/self/settings,在 Featuers 面板下开启 Analytics,最后通过地址栏访问:https://canvas.example.com/accounts/self/analytics 查看是否成功开启。

0 留言

留言

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

您可能感兴趣

Canvas LTI 外部工具详解

Canvas LTI 集成是将第三方学习工具嵌入 Canvas 中,实现无缝整合和交互,提供更丰富的学习体验和功能扩展...

什么是 Canvas LMS 学习系统?

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