使用docker环境搭建canvaslms

admin 发表了文章 • 0 个评论 • 1660 次浏览 • 2018-04-03 00:28 • 来自相关话题

转载自 Error250http://www.cnblogs.com/error250/p/8662522.html ...查看全部

转载自 Error250

http://www.cnblogs.com/error250/p/8662522.html


准备:  一台8G内存的服务器。安装好docker, pull一个ubuntu镜像下来, 可以是最新版也可以是官方支持的14/ 16

更新时间: 2018-04-03

Step 1: 启动docker容易加载ubuntu镜像。命令如下:

 

sudo docker run -it ubuntu # -it 是链接输入输出, 后面有一个command参数, 默认为/bin/bash

 

Step 2: 安装vim, sudo  (ubuntu镜像可能会非常精简, 没有sudo, 没有vim等文本编辑器)

apt-get update && apt-get install vim sudo  # 先update不然可能找不到软件

Step 3: 添加一个用户, 然后加入到sudo列表

useradd canvas_userpasswd canvas_user  # 修改密码vim /etc/sudoers

Step 4: 安装postgresql, 版本>=9.3

sudo apt-get install -y postgresql

Step 5: 配置postgresql

sudo -u postgres createuser canvas -D -S -R -P   # 给canvas用户设置登录密码
sudo -u postgres createdb canvas_production --owner=canvassudo -u postgres createdb canvas_queue_production --owner=canvas

验证数据库是否配置成功:

psql -h localhost -U canvas canvas_production
psql -h localhost -U canvas canvas_queue_production

Step 6: 安装git

sudo apt-get install git-core

Step 7: 获取canvas代码,切换分支

git clone https://github.com/instructure/canvas-lms.git canvascd canvasgit branch --set-upstream-to origin/stablesudo mkdir -p /opt/canvassudo chown -R $USER /opt/canvascp -rav /home/$USER/canvas/. /opt/canvas  # /opt/ 这个路径可以随意换到你认为合适的位置, 这里以此为例

Step 8: 安装ruby软件源

sudo apt-get install software-properties-common
sudo apt-add-repository ppa:brightbox/ruby-ng
sudo apt-get update

Step 9: 安装ruby2.4及其他依赖

sudo apt-get install ruby2.4 ruby2.4-dev zlib1g-dev libxml2-dev libsqlite3-dev postgresql libpq-dev libxmlsec1-dev curl make g++

Step 10: 安装Node 8.x (canvas 依赖node8.x)

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -sudo apt-get install nodejs

Step 11: 设置当前账户为Postgres的超级用户

sudo -u postgres createuser $USER
sudo -u postgres psql -c "alter user $USER with superuser" postgres

Step 12: 安装bundle及gems

安装bundler

sudo gem install bundler --version 1.13.6

 

可以切换gems源:

gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/
bundle config mirror.https://rubygems.org https://gems.ruby-china.org

安装gems(此步骤时间较长)

bundle install --path vendor/bundle

Step 13: 设置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

配置数据库文件,设置自己的数据库密码

cp ./config/databa

>>

production:
 adapter: postgresql
 encoding: utf8
 database: canvas_production
 host: localhost
 username: canvas
 password: password789  # Step 5设置的密码
 timeout:5000
 queue:
   adapter: postgresql
   encoding: utf8
   database: canvas_queue_production
   host: localhost
   username: canvas
   password: password789 # Step 5设置的密码
   timeout:5000

配置SMTP邮件服务器

 cp config/outgoing_mail.yml.example config/outgoing_mail.yml

这里呢可以选用公邮例如126邮箱,下面以126邮箱为例:

首先登录你的126邮箱 点击设置

选择 POP3/SMTP/IMAP  菜单

在此处打开 IMAP/SMTP和POP3/SMTP服务

此时会要求设置客户端授权密码, 该密码讲作为第三方登录密码,之后就可以退出126邮箱了。然后编辑config/outgoing_mail.yml

>>

production:
 address: "smtp.126.com"  # 126的地址
 port: "25"
 user_name: "user"  # 126邮箱的账号  不带@126.com
 password: "password"  # 设置的客户端授权密码
 authentication: "login" # plain, login, or cram_md5
 domain: "126.com"
 outgoing_address: "canvas@126.com"  # 邮箱名
 default_name: "Instructure Canvas"     # 随意设置一个显示名

 

配置域名  此处配置的域名将决定在邮件中的链接是否能正确链接到网站上

cp config/domain.yml.example config/domain.yml

配置安全字符串 不能少于20个字符

cp config/security.yml.example config/security.yml

Step 14: 安装js依赖

此步骤前可以生成本地一个镜像备份(因为这步骤出错的概率比较高, 如果错误了不会搞了 前面的步骤就白跑了):

退出docker后, 通过命令

sudo docker ps -a

找到刚才结束掉的容器id

然后执行

sudo docker commit [容器id] canvas:v1.0 # canvas为设置的镜像名 v1.0为设置的tag

之后再回到刚刚的容器中:

sudo docker start -ai [容器id]

这样就将之前所有更改保存到了一个本地镜像中, 名为canvas:v1.0。

接下来添加canvas用户

sudo adduser --disabled-password --gecos canvas canvasuser

配置缓存文件

cd /opt/canvasmkdir -p log tmp/pids public/assets public/stylesheets/compiledtouch Gemfile.locksudo chown -R canvasuser config/environment.rb log tmp public/assets public/stylesheets/compiled Gemfile.lock config.ru

安装yarn 1.3.2

sudo npm install -g yarn@1.3.2

可以修改yarn的安装源:

yarn config set registry https://registry.npm.taobao.org -g

安装js依赖 (此步骤耗时长)

yarn install

Step 15: 编译assets (容易出错)

首先检查本地默认系统编码:

locale

如果默认编码不是en_US.UTF-8, 那么修改一下

sudo vim /etc/enviorment  # 重新登陆后生效

编译assets

RAILS_ENV=production bundle exec rake canvas:compile_assets

Step 16: 初始化数据库

RAILS_ENV=production bundle exec rake db:initial_setup  # 此步骤会设置管理员账户, canvas刚刚部署好的时候不允许注册, 必须先用管理员账户登录后,设置开放注册

Step 17: 修改权限

sudo chown canvasuser ./config/*.yml
sudo chown canvasuser ./config/environment.rb
sudo chmod 400 ./config/*.yml
sudo chown -R canvasuser ./log/ ./tmp/ ./public/javascripts/ ./public/assets/ ./public/stylesheets/compiled/ ./Gemfile.lock ./config.ru

Step 18: 配置Passenger 的apt源

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7
sudo apt-get install -y apt-transport-https ca-certificatessudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger trusty main > /etc/apt/sources.list.d/passenger.list'sudo apt-get update

Step 19: 安装Passenger 及Apache (官方推荐使用)

sudo apt-get install passenger libapache2-mod-passenger apache2

Step 20: 配置passenger, apache2

sudo a2enmod rewritesudo a2enmod passengersudo a2enmod sslsudo a2dissite 000-default.confsudo vim /etc/apache2/sites-available/canvas.conf

>>

<VirtualHost *:80>
  ServerName canvas.example.com
  ServerAlias files.canvas.example.com
  ServerAdmin youremail@example.com
  DocumentRoot /opt/canvas/public
  RewriteEngine On  # 与https相关
  RewriteCond %{HTTP:X-Forwarded-Proto} !=https # 与https相关
  RewriteCond %{REQUEST_URI} !^/health_check # 与https相关
  RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L]   # 与https相关
  ErrorLog /var/log/apache2/canvas_errors.log
  LogLevel warn
  CustomLog /var/log/apache2/canvas_access.log combined
  SetEnv RAILS_ENV production  
    #Allow from all
    AllowOverride all
    Require all granted
    Options -MultiViews  # 与https相关<VirtualHost *:443>
  ServerName canvas.example.com
  ServerAlias files.canvas.example.com
  ServerAdmin youremail@example.com
  DocumentRoot /opt/canvas/public
  ErrorLog /var/log/apache2/canvas_errors.log
  LogLevel warn
  CustomLog /var/log/apache2/canvas_ssl_access.log combined
  SSLEngine on
  BrowserMatch "MSIE [2-6]" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0
  BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
  # the following ssl certificate files are generated for you from the ssl-cert package.
  #SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
  #SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
  SetEnv RAILS_ENV production
  #XSendFile On
  #XSendFilePath /opt/canvas
  PassengerDefaultUser canvasuser
  PassengerFriendlyErrorPages on#open error log 
    Options All
    AllowOverride All
    Require all granted

如果你的网站不支持https, 建议注释掉跟https有关的配置

启动canvas站点

sudo a2ensite canvas.conf

本地存储  如果你的文件想要存在本地 则需要设置本地存储。教程暂时没有配置s3服务器的教程。

>>

sudo chmod -R 1777 tmp/
sudo chmod -R 1777 /tmp/

配置使用apache

sudo vim ./config/environments/production-local.rb

config.action_dispatch.x_sendfile_header = 'X-Sendfile' 这一行的注释去掉

Step 21: 安装redis服务器

sudo add-apt-repository ppa:chris-lea/redis-server
sudo apt-get updatesudo apt-get install redis-server

配置站点缓存文件

cp config/cache_store.yml.example config/cache_store.yml
sudo vim config/cache_store.yml
sudo chown canvasuser config/cache_store.yml
sudo chmod 400 config/cache_store.yml

>>

test:
    cache_store: redis_store
development:
    cache_store: redis_store
production:
    cache_store: redis_store

配置redis文件

cp config/redis.yml.example config/redis.ymlnano config/redis.ymlsudo chown canvasuser config/redis.ymlsudo chmod 400 config/redis.yml
production:
  servers:    - redis://localhost

Step 22: 重启apache2就可以启动canvas了!

sudo ln -s /opt/canvas/sc

Step 23: 添加canvas启动脚本

>>

service redis-server start
service canvas_init start  # 该服务主要负责一切延时任务, 如发送邮件等
service apache2 starttail -f /dev/null  # 保证前台shell不退出

Step 24: 提交修改,生成镜像, 启动服务!

sudo docker ps -a  # 查看刚刚的容器id
sudo docker commit [容器id] canvas:v1.1
sudo docker run -d -p 4567:80 canvas:v1.1 bash /opt/canvas/canvas-start.sh

检查容器是否再运行:

sudo docker ps -a

如果刚刚跑的容器还在运行, 没有Exited。那么,代开浏览器,访问服务器域名 samle.com:4567, 出现canvas的登录页面则canvas部署成功!

Debug:

1. 检查/var/log/apache2/canvas_errors.log 错误日志

2. 检查/var/log/apache2/canvas_access.log 访问日志

3. 检查/var/log/apache2/error.log  apache2的错误日志

4. 检查$canvas_install_path/log/production.log # canvas 日志

5. 访问 http://domain/error_reports 查看canvas详细错误

任何问题你可以尝试在github的issue中搜索答案或者加入canvas交流群:46465366询问。

后续:这里续写本部署还缺少的两个步骤。1. 把postgresql数据库的数据拉出来。2. 配置文件服务器

 

Ubuntu14.04/16.04 Canvas LMS的Production版安装教程

admin 发表了文章 • 0 个评论 • 3329 次浏览 • 2016-11-08 15:31 • 来自相关话题

修正于 2018.7.6官方安装教程地址:https://github.com/instructure/canvas-lms/wiki/Production-Start大家可以按照官方的地址一步一步安装。 ...查看全部

修正于 2018.7.6

官方安装教程地址:https://github.com/instructure/canvas-lms/wiki/Production-Start

大家可以按照官方的地址一步一步安装。

Canvas被Black Duck标榜为"唯一的一款商业开源学习管理系统,而且是唯一的一款部署在云端的学习管理系统LMS"。

Canvas的确是一款优秀的lms,界面美观/功能完备/丰富的API,尤其适合校内教学使用,有班级/小组/学期的概念。

下面是安装过程

首先,要安装一台干净的Ubuntu14.04或者16.04都可以,只安装open ssh,建议安装成纯英文系统。

接下来可以安装官方的教程一步一步安装

#adduser master

然后得把它加入到sudoer里面去

#nano /etc/sudoers

  1. 安装Postgres数据库,命令如下,9.5版本以上的都可以

    ~$ sudo apt-get update && sudo apt-get -y upgrade && sudo apt-get -y autoremove
    ~$ sudo apt-get update && sudo apt-get install -y postgresql

  2. 配置Postgres,命令如下

    ~$ sudo -u postgres createuser canvas -D -S -R -P
    ~$ sudo -u postgres createdb canvas_production --owner=canvas
    ~$ sudo -u postgres createdb canvas_queue_production --owner=canvas

    验证数据库

  3. ~$ psql -h localhost -U canvas canvas_production
  4. ~$ psql -h localhost -U canvas canvas_queue_production

  5. 安装Git软件,命令如下

    sudo apt-get install git-core

  6. 通过GitHub获取Canvas-LMS代码并设置分支,本地放在/var下面,命令如下

  7. ~$ sudo apt-get -y install git-core
    ~$ cd $HOME
    ~/home/$USER$ git clone https://github.com/instructure/canvas-lms.git canvas
    ~/home/$USER$ cd canvas
    ~/home/$USER$ git checkout stable
    ~/home/$USER/canvas$ git branch --set-upstream-to origin/stable
    ~/home/$USER/canvas$ sudo mkdir -p /opt/canvas
    ~/home/$USER/canvas$ sudo chown -R $USER /opt/canvas
    ~/home/$USER/canvas$ cp -rav /home/$USER/canvas/. /opt/canvas
  8. 从这里开始,要进入/opt/canvas目录中

  9. cd /opt/canvas

  10. 安装Ruby2.4的apt源,命令如下

     sudo apt-get install software-properties-common
     sudo apt-add-repository ppa:brightbox/ruby-ng
     sudo apt-get update

  11. 安装Ruby2.4,命令如下

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

  12. 安装Node.js,命令如下

    curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
    sudo apt-get install nodejs

  13. 设置系统账户为Postgres的超级用户,命令如下

    sudo -u postgres createuser $USER
    sudo -u postgres psql -c "alter user $USER with superuser" postgres

  14. 使用gem安装bundler,命令如下

    sudo gem install bundler --version 1.13.6
    bundle install --path vendor/bundle

  15. 安装yarn

  16. ~/opt/canvas$  curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -

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

    ~/opt/canvas$  sudo apt-get update && sudo apt-get install yarn=1.10.0-1

检测一下有没有python

sudo apt-get install python

  1. 从这里结束,如果你是用的云服务器,需要创建一个快照。以免反复的安装,此处比较耗时间。

  1. 设置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

  2. 配置数据库文件,修改为自己设置的数据库密码,命令如下

     cp ./config/database.yml.example ./config/database.yml
     nano ./config/database.yml

production:
 adapter: postgresql
 encoding: utf8
 database: canvas_production
 host: localhost
 username: canvas
 password: password789
 timeout: 5000

  1. 配置SMTP邮件服务器,命令如下

     cp config/outgoing_mail.yml.example config/outgoing_mail.yml

    nano config/outgoing_mail.yml
    production:
     address: "smtp.example.com"
     port: "25"
     user_name: "user"
     password: "password"
     authentication: "plain" # plain, login, or cram_md5
     domain: "example.com"
     outgoing_address: "canvas@example.com"
     default_name: "Instructure Canvas"
  2. 配置域名,命令如下

    cp config/domain.yml.example config/domain.yml

    nano config/domain.yml

  3. 配置安全字符串文件,安全字符串不能少于20个字符,命令如下

    cp config/security.yml.example config/security.yml

    nano config/security.yml

  4. 添加Canvas用户,命令如下

    sudo adduser --disabled-password --gecos canvas canvasuser

  5. 配置缓存文件,命令如下

    ~/opt/canvas$ mkdir -p log tmp/pids public/assets public/stylesheets/compiled
    ~/opt/canvas$ touch Gemfile.lock
    ~/opt/canvas$ sudo chown -R canvasuser config/environment.rb log tmp public/assets public/stylesheets/compiled Gemfile.lock config.ru

  6. 生产缓存文件
  7. sudo RAILS_ENV=production bundle exec rake canvas:compile_assets
  8. 初始化数据库,命令如下

    cd /opt/canvas

    RAILS_ENV=production bundle exec rake db:initial_setup

  9. 修改配置文件权限,命令如下

    ~/opt/canvas$ sudo chown canvasuser ./config/*.yml
    ~/opt/canvas$ sudo chown canvasuser ./config/environment.rb
    ~/opt/canvas$ sudo chmod 400 ./config/*.yml
    ~/opt/canvas$ sudo chown -R canvasuser ./log/ ./tmp/ ./public/javascripts/ ./public/assets/ ./public/stylesheets/compiled/ ./Gemfile.lock ./config.ru

  10. 配置Passenger 的apt源,命令如下

    sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7
    sudo apt-get install -y apt-transport-https ca-certificates
    sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger trusty main > /etc/apt/sources.list.d/passenger.list'
    sudo apt-get update

  11. 安装Passenger 及Apache,命令如下

    sudo apt-get install passenger libapache2-mod-passenger apache2

  12. 启用mod_rewrite模块,命令如下

    ~$ sudo a2enmod rewrite

    配置Passenger

  13. ~$ sudo a2enmod passenger
  14. 启用Apache的SSL服务,命令如下

    ~/opt/canvas$ sudo a2enmod ssl

  15. 删除Apache默认站点,命令如下

    ~$ sudo a2dissite 000-default.conf

  16. 创建新的站点配置文件并写入一下信息,命令如下

    sudo nano /etc/apache2/sites-available/canvas.conf

    内容:可以对应修改一下域名等信息

    ServerName canvas.example.com
      ServerAlias files.canvas.example.com
      ServerAdmin youremail@example.com
      DocumentRoot /opt/canvas/public
      RewriteEngine On
      RewriteCond %{HTTP:X-Forwarded-Proto} !=https
      RewriteCond %{REQUEST_URI} !^/health_check
      RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L]  
      ErrorLog /var/log/apache2/canvas_errors.log
      LogLevel warn
      CustomLog /var/log/apache2/canvas_access.log combined
      SetEnv RAILS_ENV productionOptions All
        AllowOverride All
        Require all grantedServerName canvas.example.com
      ServerAlias files.canvas.example.com
      ServerAdmin youremail@example.com
      DocumentRoot /opt/canvas/public
      ErrorLog /var/log/apache2/canvas_errors.log
      LogLevel warn
      CustomLog /var/log/apache2/canvas_ssl_access.log combined
      SSLEngine on
      BrowserMatch "MSIE [2-6]" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0
      BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
      # the following ssl certificate files are generated for you from the ssl-cert package.
      #SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
      #SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
      SetEnv RAILS_ENV production
      #XSendFile On
      #XSendFilePath /opt/canvas
      PassengerDefaultUser canvasuser
      PassengerFriendlyErrorPages on#open error logOptions All
        AllowOverride All
        Require all granted

  17. 启用canvas站点,命令如下

    ~/opt/canvas$ sudo a2ensite canvas.conf
  18. 配置本地存储,安装XSendFile

  19. ~$ sudo apt-get update && sudo apt-get install -y libapache2-mod-xsendfile
    ~$ sudo a2enmod xsendfile

  20. 创建新的配置文件,以避免未来的合并冲突

  21. ~/var/canvas$ cp ./config/environments/production.rb ./config/environments/production-local.rb
  22. ~/var/canvas$ vi ./config/environments/production-local.rb
    config.action_dispatch.x_sendfile_header = 'X-Sendfile'

  23. 安装redis服务器的apt源及软件,命令如下

    sudo add-apt-repository ppa:chris-lea/redis-server
    sudo apt-get update
    sudo apt-get install redis-server

  24. 配置站点缓存文件,命令如下

    cd /opt/canvas/
    cp config/cache_store.yml.example config/cache_store.yml
    nano config/cache_store.yml
    sudo chown canvasuser config/cache_store.yml
    sudo chmod 400 config/cache_store.yml

    配置内容如下

    test:
        cache_store: redis_store
    development:
        cache_store: redis_store
    production:
        cache_store: redis_store

  25. 配置redis文件,命令如下

    cd /opt/canvas/
    cp config/redis.yml.example config/redis.yml
    nano config/redis.yml
    sudo chown canvasuser config/redis.yml
    sudo chmod 400 config/redis.yml

    配置内容如下:

    production:
      servers:
        - redis://localhost

  26. 设置canvas服务自动启动并重启Apache,命令如下

    sudo ln -s /opt/canvas/script/canvas_init /etc/init.d/canvas_init
    sudo update-rc.d canvas_init defaults
    sudo /etc/init.d/canvas_init start
    sudo /etc/init.d/apache2 restart

到这里就可以访问设置的域名或者直接访问IP,如果看到登陆界面,恭喜您完成了Canvas安装了!