美文网首页
ubuntu上安装redmine

ubuntu上安装redmine

作者: 一粟沧海 | 来源:发表于2018-02-01 00:15 被阅读420次

    1 预备工作

    redmine source code

    两个途径

    需要一种数据库,这里以mysql为例

    sudo apt-get install mysql-server mysql-client
    

    2 创建数据库

    mysql -u root -p
    
    CREATE DATABASE redmine CHARACTER SET utf8;
    CREATE USER 'redmine'@'localhost' IDENTIFIED BY 'my_password';
    GRANT ALL PRIVILEGES ON redmine.* TO 'redmine'@'localhost';
    

    当mysql version大于5.5.2时,可将字符集改为SET utf8mb4,即可以设置为 CREATE DATABASE redmine CHARACTER SET utf8mb4;

    3 建立数据库和redmine的链接

    将./redmine/config/database.yml.example 复制一份并改名为 ./redmine/config/database.yml

    cd redmine
    cp config/database.yml.example config/database.yml
    

    打开database.yml,将production段参考刚才创建数据库的参数修改为如下内容:

    production:
      adapter: mysql2
      database: redmine
      host: localhost
      username: redmine
      password: "my_password"
      encoding: utf8
    

    这里需要注意 adapter处是mysql2,一些老的教程写为mysql

    4 下载依赖

    ruby gem

    sudo apt-get install ruby ruby-dev rubygems  libmysqlclient-dev imagemagick libmagickwand-dev
    

    bundler

    使用gem下载bundler,这里需要将gem的源文件路径修改为国内的仓库,可以使用如下命令修改,也可以直接打开Gemfile编辑,

    gem sources -r http://rubygems.org/
    gem source -a http://ruby.taobao.org
    

    然后下载bundler

    sudo gem install bundler -V
    

    使用bundle来下载依赖

    依赖文件的描述见Gemfile

    bundle install --without development test
    

    5 配置

    生成一个加密

    bundle exec rake generate_secret_token
    

    数据库创建和设置

    RAILS_ENV=production bundle exec rake db:migrate
    RAILS_ENV=production bundle exec rake redmine:load_default_data
    

    这个过程中可能会遇到一个问题,见后面的问题记录

    6 设置权限

    sudo find files log tmp public/plugin_assets -type f -exec chmod -x {} +
    

    7 测试运行

    bundle exec rails server webrick -e production
    

    访问http://localhost:3000/

    然后以admin登陆,密码同为admin

    8 遇到的一个问题

    在执行如下命令时

    RAILS_ENV=production bundle exec rake db:migrate
    

    提示如下

    -- create_table(:email_addresses, {:id=>:integer})
    rake aborted!
    StandardError: An error has occurred, all later migrations canceled:
    
    Mysql2::Error: Invalid default value for 'updated_on': CREATE TABLE `email_addresses` (`id` int NOT NULL AUTO_INCREMENT PRIMARY KEY, `user_id` int NOT NULL, `address` varchar(255) NOT NULL, `is_default` tinyint(1) DEFAULT 0 NOT NULL, `notify` tinyint(1) DEFAULT 1 NOT NULL, `created_on` timestamp NOT NULL, `updated_on` timestamp NOT NULL) ENGINE=InnoDB
    

    详细提示

    
    -- create_table(:email_addresses, {:id=>:integer})
    rake aborted!
    StandardError: An error has occurred, all later migrations canceled:
    
    Mysql2::Error: Invalid default value for 'updated_on': CREATE TABLE `email_addresses` (`id` int NOT NULL AUTO_INCREMENT PRIMARY KEY, `user_id` int NOT NULL, `address` varchar(255) NOT NULL, `is_default` tinyint(1) DEFAULT 0 NOT NULL, `notify` tinyint(1) DEFAULT 1 NOT NULL, `created_on` timestamp NOT NULL, `updated_on` timestamp NOT NULL) ENGINE=InnoDB
    > /var/lib/gems/2.3.0/gems/mysql2-0.4.10/lib/mysql2/client.rb:120:in `_query'
    > /var/lib/gems/2.3.0/gems/mysql2-0.4.10/lib/mysql2/client.rb:120:in `block in query'
    > /var/lib/gems/2.3.0/gems/mysql2-0.4.10/lib/mysql2/client.rb:119:in `handle_interrupt'
    > /var/lib/gems/2.3.0/gems/mysql2-0.4.10/lib/mysql2/client.rb:119:in `query'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:214:in `block (2 levels) in execute'
    > /var/lib/gems/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies/interlock.rb:46:in `block in permit_concurrent_loads'
    > /var/lib/gems/2.3.0/gems/activesupport-5.1.4/lib/active_support/concurrency/share_lock.rb:185:in `yield_shares'
    > /var/lib/gems/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies/interlock.rb:45:in `permit_concurrent_loads'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:213:in `block in execute'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:612:in `block (2 levels) in log'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:611:in `block in log'
    > /var/lib/gems/2.3.0/gems/activesupport-5.1.4/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:603:in `log'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:212:in `execute'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/mysql/database_statements.rb:26:in `execute'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/schema_statements.rb:288:in `create_table'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:363:in `create_table'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:849:in `block in method_missing'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:818:in `block in say_with_time'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:818:in `say_with_time'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:838:in `method_missing'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration/compatibility.rb:45:in `create_table'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration/compatibility.rb:91:in `create_table'
    > /home/amtili/tools/redmine/db/migrate/20150113194759_create_email_addresses.rb:3:in `change'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:792:in `exec_migration'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:776:in `block (2 levels) in migrate'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:775:in `block in migrate'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:408:in `with_connection'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:774:in `migrate'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:953:in `migrate'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1230:in `block in execute_migration_in_transaction'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1300:in `ddl_transaction'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1229:in `execute_migration_in_transaction'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1201:in `block in migrate_without_lock'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1200:in `each'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1200:in `migrate_without_lock'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1148:in `block in migrate'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1317:in `with_advisory_lock'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1148:in `migrate'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1007:in `up'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:985:in `migrate'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:171:in `migrate'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/railties/databases.rake:58:in `block (2 levels) in <top (required)>'
    > /var/lib/gems/2.3.0/gems/rake-12.3.0/exe/rake:27:in `<top (required)>'
    > 
    > Caused by:
    > ActiveRecord::StatementInvalid: Mysql2::Error: Invalid default value for 'updated_on': CREATE TABLE `email_addresses` (`id` int NOT NULL AUTO_INCREMENT PRIMARY KEY, `user_id` int NOT NULL, `address` varchar(255) NOT NULL, `is_default` tinyint(1) DEFAULT 0 NOT NULL, `notify` tinyint(1) DEFAULT 1 NOT NULL, `created_on` timestamp NOT NULL, `updated_on` timestamp NOT NULL) ENGINE=InnoDB
    > /var/lib/gems/2.3.0/gems/mysql2-0.4.10/lib/mysql2/client.rb:120:in `_query'
    > /var/lib/gems/2.3.0/gems/mysql2-0.4.10/lib/mysql2/client.rb:120:in `block in query'
    > /var/lib/gems/2.3.0/gems/mysql2-0.4.10/lib/mysql2/client.rb:119:in `handle_interrupt'
    > /var/lib/gems/2.3.0/gems/mysql2-0.4.10/lib/mysql2/client.rb:119:in `query'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:214:in `block (2 levels) in execute'
    > /var/lib/gems/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies/interlock.rb:46:in `block in permit_concurrent_loads'
    > /var/lib/gems/2.3.0/gems/activesupport-5.1.4/lib/active_support/concurrency/share_lock.rb:185:in `yield_shares'
    > /var/lib/gems/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies/interlock.rb:45:in `permit_concurrent_loads'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:213:in `block in execute'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:612:in `block (2 levels) in log'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:611:in `block in log'
    > /var/lib/gems/2.3.0/gems/activesupport-5.1.4/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:603:in `log'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:212:in `execute'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/mysql/database_statements.rb:26:in `execute'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/schema_statements.rb:288:in `create_table'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:363:in `create_table'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:849:in `block in method_missing'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:818:in `block in say_with_time'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:818:in `say_with_time'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:838:in `method_missing'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration/compatibility.rb:45:in `create_table'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration/compatibility.rb:91:in `create_table'
    > /home/amtili/tools/redmine/db/migrate/20150113194759_create_email_addresses.rb:3:in `change'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:792:in `exec_migration'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:776:in `block (2 levels) in migrate'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:775:in `block in migrate'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:408:in `with_connection'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:774:in `migrate'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:953:in `migrate'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1230:in `block in execute_migration_in_transaction'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1300:in `ddl_transaction'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1229:in `execute_migration_in_transaction'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1201:in `block in migrate_without_lock'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1200:in `each'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1200:in `migrate_without_lock'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1148:in `block in migrate'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1317:in `with_advisory_lock'tis
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1148:in `migrate'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1007:in `up'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:985:in `migrate'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:171:in `migrate'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/railties/databases.rake:58:in `block (2 levels) in <top (required)>'
    > /var/lib/gems/2.3.0/gems/rake-12.3.0/tisexe/rake:27:in `<top (required)>'
    > 
    > Caused by:
    > Mysql2::Error: Invalid default value for 'updated_on'
    > /var/lib/gems/2.3.0/gems/mysql2-0.4.10/lib/mysql2/client.rb:120:in `_query'
    > /var/lib/gems/2.3.0/gems/mysql2-0.4.10/lib/mysql2/client.rb:120:in `block in query'
    > /var/lib/gems/2.3.0/gems/mysql2-0.4.10/lib/mysql2/client.rb:119:in `handle_interrupt'
    > /var/lib/gems/2.3.0/gems/mysql2-0.4.10/lib/mysql2/client.rb:119:in `query'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/atisbstract_mysql_adapter.rb:214:in `block (2 levels) in execute'
    > /var/lib/gems/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies/interlock.rb:46:in `block in permit_concurrent_loads'
    > /var/lib/gems/2.3.0/gems/activesupport-5.1.4/lib/active_support/concurrency/share_lock.rb:185:in `yield_shares'
    > /var/lib/gems/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies/interlock.rb:45:in `permit_concurrent_loads'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:213:in `block in execute'
    > /var/lib/gems/2.3.0/gems/activerecordtis-5.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:612:in `block (2 levels) in log'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:611:in `block in log'
    > /var/lib/gems/2.3.0/gems/activesupport-5.1.4/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:603:in `log'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:212:in `execute'
    > /var/lib/gems/2.3.0/gems/activerecordtis-5.1.4/lib/active_record/connection_adapters/mysql/database_statements.rb:26:in `execute'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/schema_statements.rb:288:in `create_table'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:363:in `create_table'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:849:in `block in method_missing'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:818:in `block in say_with_time'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:818:in `say_with_time'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:838:in `method_missing'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration/compatibility.rb:45:in `create_table'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration/compatibility.rb:91:in `create_table'
    > /home/amtili/tools/redmine/db/migrate/20150113194759_create_email_addresses.rb:3:in `change'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:792:in `exec_migration'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:776:in `block (2 levels) in migrate'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:775:in `block in migrate'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:408:in `with_connection'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:774:in `migrate'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:953:in `migrate'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1230:in `block in execute_migration_in_transaction'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1300:in `ddl_transaction'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1229:in `execute_migration_in_transaction'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1201:in `block in migrate_without_lock'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1200:in `each'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1200:in `migrate_without_lock'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1148:in `block in migrate'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1317:in `with_advisory_lock'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1148:in `migrate'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1007:in `up'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:985:in `migrate'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:171:in `migrate'
    > /var/lib/gems/2.3.0/gems/activerecord-5.1.4/lib/active_record/railties/databases.rake:58:in `block (2 levels) in <top (required)>'
    > /var/lib/gems/2.3.0/gems/rake-12.3.0/exe/rake:27:in `<top (required)>'
    > Tasks: TOP => db:migrate
    > (See full trace by running task with --trace)
    >
    

    解决方案

    参考文档
    改动如下

    ~/tools/redmine$ git diff db/migrate/20150113194759_create_email_addresses.rb
    diff --git a/db/migrate/20150113194759_create_email_addresses.rb b/db/migrate/20150113194759_create_email_addresses.rb
    index 22ad19e94..fd497226b 100644
    --- a/db/migrate/20150113194759_create_email_addresses.rb
    +++ b/db/migrate/20150113194759_create_email_addresses.rb
    @@ -6,7 +6,7 @@ class CreateEmailAddresses < ActiveRecord::Migration[4.2]
           t.column :is_default, :boolean, :null => false, :default => false
           t.column :notify, :boolean, :null => false, :default => true
           t.column :created_on, :timestamp, :null => false
    -      t.column :updated_on, :timestamp, :null => false
    +      t.column :updated_on, :timestamp
         end
       end
     end
    
    

    相关文章

      网友评论

          本文标题:ubuntu上安装redmine

          本文链接:https://www.haomeiwen.com/subject/nisrzxtx.html