IT練習ノート

IT関連で調べたこと(実際は嵌ったこと)を書いています。

Redmineインストール練習

今更ながらRedmineを使うことになったので、手元で弄れる環境を作ってみた。というかそもそもRailsわかってない。

  • Rubyのバージョン確認
(root)MacBook-Air-2:redmine foo$ ruby -v
ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14]
  • MySQLのバージョン確認
(root)MacBook-Air-2:redmine foo$ mysql --version
mysql  Ver 14.14 Distrib 5.7.16, for osx10.10 (x86_64) using  EditLine wrapper
  • MySQLのrootユーザのパスワードを忘れたので再設定
(root)MacBook-Air-2:redmine foo$ mysql.server stop
Shutting down MySQL
.. SUCCESS! 
(root)MacBook-Air-2:redmine foo$ mysqld_safe --skip-grant-tables &
[1] 25012
(root)MacBook-Air-2:redmine foo$ 2016-01-01T11:13:30.6NZ mysqld_safe Logging to '/usr/local/var/mysql/MacBook-Air-2.local.err'.
2016-01-01T11:13:30.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql

(root)MacBook-Air-2:redmine foo$ mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.16 Homebrew

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> UPDATE user SET authentication_string=password('root') WHERE user='root';
Query OK, 1 row affected, 1 warning (0.02 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> quit
Bye
  • Redmine用のデータベース用意
(root)MacBook-Air-2:redmine foo$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.7.16 Homebrew

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database redmine character set utf8;
Query OK, 1 row affected (0.01 sec)

mysql> create user 'redmine'@'localhost' identified by 'my_password';
Query OK, 0 rows affected (0.02 sec)

mysql> grant all privileges on redmine.* to 'redmine'@'localhost';
Query OK, 0 rows affected (0.01 sec)

mysql> quit
Bye
  • Redmineのソース取得 (gitから取ってくればよかった、、、。)
(root)MacBook-Air-2:redmine foo$ svn checkout http://svn.redmine.org/redmine/branches/3.3-stable redmine
A    redmine/test
A    redmine/test/unit
A    redmine/test/unit/document_test.rb
A    redmine/test/unit/issue_import_test.rb
A    redmine/test/unit/repository_git_test.rb
A    redmine/test/unit/version_test.rb
A    redmine/test/unit/project_members_inheritance_test.rb
A    redmine/test/unit/attachment_transaction_test.rb
途中省略
A    redmine/public/stylesheets/rtl.css
A    redmine/public/stylesheets/scm.css
A    redmine/public/stylesheets/application.css
A    redmine/public/favicon.ico
A    redmine/public/htaccess.fcgi.example
 U   redmine
Checked out revision 16052.
  • Redmineアプリケーションフォルダに移動
(root)MacBook-Air-2:redmine foo$ cd redmine/
(root)MacBook-Air-2:redmine foo$ ls
CONTRIBUTING.md README.rdoc app     bin     config.ru   doc     files       log     public      test      vendor
Gemfile     Rakefile    appveyor.yml    config      db      extra       lib     plugins     script      tmp
  • データベースファイルを作成
(root)MacBook-Air-2:redmine foo$ vim ./config/
additional_environment.rb.example  configuration.yml.example          environments/                      routes.rb                          
application.rb                     database.yml.example               initializers/                      settings.yml                       
boot.rb                            environment.rb                     locales/                           
(root)MacBook-Air-2:redmine foo$ cp ./config/database.yml.example ./config/database.yml 
  • データベース設定に、データベース名、ユーザ名、パスワードを設定する
  1 # Default setup is given for MySQL with ruby1.9.
  2 # Examples for PostgreSQL, SQLite3 and SQL Server can be found at the end.
  3 # Line indentation must be 2 spaces (no tabs).
  4 
  5 production:
  6   adapter: mysql2
  7   database: redmine
  8   host: localhost
  9   username: redmine
 10   password: my_password
 11   encoding: utf8
 12 
 13 development:
 14   adapter: mysql2
 15   database: redmine_development
 16   host: localhost
 17   username: redmine
 18   password: my_password
 19   encoding: utf8
 20 
 21 # Warning: The database defined as "test" will be erased and
 22 # re-generated from your development database when you run "rake".
 23 # Do not set this db to the same as development or production.
 24 test:
 25   adapter: mysql2
 26   database: redmine_test
 27   host: localhost
 28   username: my_password
 29   password: my_password
 30   encoding: utf8
  • bundlerをインストール (意味がわかってない、後で調べる)
(root)MacBook-Air-2:redmine foo$ gem install bundler
Fetching: bundler-1.13.6.gem (100%)
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
(root)MacBook-Air-2:redmine foo$ sudo gem install bundler
Password:
Fetching: bundler-1.13.6.gem (100%)
Successfully installed bundler-1.13.6
Parsing documentation for bundler-1.13.6
Installing ri documentation for bundler-1.13.6
1 gem installed
  • redmineの依存関係のあるモジュールのインストール (pdf機能は使わないつもりなのでrmagicは入れないことにした)
(root)MacBook-Air-2:redmine foo$ bundle install --without development test rmagick
Fetching gem metadata from https://rubygems.org/..........
Fetching version metadata from https://rubygems.org/..
Fetching dependency metadata from https://rubygems.org/.
Resolving dependencies.....
Rubygems 2.0.14 is not threadsafe, so your gems will be installed one at a time. Upgrade to Rubygems 2.1.0 or higher to enable parallel gem installation.
Using rake 12.0.0
Using i18n 0.7.0
Using json 1.8.3
Using minitest 5.10.1
Using thread_safe 0.3.5
Using builder 3.2.2
Using erubis 2.7.0
Using mini_portile2 2.1.0
Using rack 1.6.5
Using mime-types-data 3.2016.0521
Using arel 6.0.3
Using public_suffix 2.0.4
Using bundler 1.13.6
Using coderay 1.1.1
Using concurrent-ruby 1.0.2
Using htmlentities 4.3.1
Using thor 0.19.4
Using mimemagic 0.3.2
Using mysql2 0.3.21
Using net-ldap 0.12.1
Using ruby-openid 2.3.0
Using rbpdf-font 1.19.0
Using redcarpet 3.3.4
Using request_store 1.0.5
Using tzinfo 1.2.2
Using nokogiri 1.6.8.1
Using rack-test 0.6.3
Using mime-types 3.1
Using addressable 2.5.0
Using sprockets 3.7.0
Using rack-openid 1.4.2
Using rbpdf 1.19.0
Installing activesupport 4.2.7.1
Installing loofah 2.0.3
Installing mail 2.6.4
Installing css_parser 1.4.7
Installing rails-deprecated_sanitizer 1.0.3
Installing globalid 0.3.7
Installing activemodel 4.2.7.1
Installing rails-html-sanitizer 1.0.3
Installing roadie 3.2.0
Installing rails-dom-testing 1.0.7
Installing activejob 4.2.7.1
Installing activerecord 4.2.7.1
Installing protected_attributes 1.1.3
Installing actionview 4.2.7.1
Installing actionpack 4.2.7.1
Installing actionmailer 4.2.7.1
Installing actionpack-action_caching 1.1.1
Installing actionpack-xml_parser 1.0.2
Installing railties 4.2.7.1
Installing sprockets-rails 3.2.0
Installing jquery-rails 3.1.4
Installing roadie-rails 1.1.1
Installing rails 4.2.7.1
Bundle complete! 31 Gemfile dependencies, 55 gems now installed.
Gems in the groups development, test and rmagick were not installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.
  • セキュリティトークン作成 (意味がわかってないので後で調べる)
(root)MacBook-Air-2:redmine foo$ bundle exec rake generate_secret_token
(root)MacBook-Air-2:redmine foo$ RAILS_ENV=production bundle exec rake db:migrate
== 1 Setup: migrating =========================================================
-- create_table("attachments", {:force=>true})
   -> 0.0133s
-- create_table("auth_sources", {:force=>true})
   -> 0.0135s
-- create_table("custom_fields", {:force=>true})
   -> 0.0123s
-- create_table("custom_fields_projects", {:id=>false, :force=>true})
途中省略
== 20160416072926 RemovePositionDefaults: migrating ===========================
-- change_column("boards", :position, :integer, {:default=>nil})
   -> 0.0095s
-- change_column("custom_fields", :position, :integer, {:default=>nil})
   -> 0.0133s
-- change_column("enumerations", :position, :integer, {:default=>nil})
   -> 0.0107s
-- change_column("issue_statuses", :position, :integer, {:default=>nil})
   -> 0.0082s
-- change_column("roles", :position, :integer, {:default=>nil})
   -> 0.0084s
-- change_column("trackers", :position, :integer, {:default=>nil})
   -> 0.0091s
== 20160416072926 RemovePositionDefaults: migrated (0.0601s) ==================

== 20160529063352 AddRolesSettings: migrating =================================
-- add_column(:roles, :settings, :text)
   -> 0.0430s
== 20160529063352 AddRolesSettings: migrated (0.0432s) ========================
  • 初期データ作成
(root)MacBook-Air-2:redmine foo$ RAILS_ENV=production bundle exec rake redmine:load_default_data

Select language: ar, az, bg, bs, ca, cs, da, de, el, en, en-GB, es, es-PA, et, eu, fa, fi, fr, gl, he, hr, hu, id, it, ja, ko, lt, lv, mk, mn, nl, no, pl, pt, pt-BR, ro, ru, sk, sl, sq, sr, sr-YU, sv, th, tr, uk, vi, zh, zh-TW [en] ja
====================================
Default configuration data loaded.
(root)MacBook-Air-2:redmine foo$ bundle exec rails server webrick -e production
=> Booting WEBrick
=> Rails 4.2.7.1 application starting in production on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2016-01-01 20:55:35] INFO  WEBrick 1.3.1
[2016-01-01 20:55:35] INFO  ruby 2.0.0 (2014-05-08) [universal.x86_64-darwin14]
[2016-01-01 20:55:35] INFO  WEBrick::HTTPServer#start: pid=44346 port=3000
  • admin / admin でログインすると、パスワード変更を要求される。

f:id:naotoogawa:20161207215015p:plain

f:id:naotoogawa:20161207215007p:plain

  • データベーステーブル一覧
mysql> show tables;
+-------------------------------------+
| Tables_in_redmine                   |
+-------------------------------------+
| attachments                         |
| auth_sources                        |
| boards                              |
| changes                             |
| changeset_parents                   |
| changesets                          |
| changesets_issues                   |
| comments                            |
| custom_field_enumerations           |
| custom_fields                       |
| custom_fields_projects              |
| custom_fields_roles                 |
| custom_fields_trackers              |
| custom_values                       |
| documents                           |
| email_addresses                     |
| enabled_modules                     |
| enumerations                        |
| groups_users                        |
| import_items                        |
| imports                             |
| issue_categories                    |
| issue_relations                     |
| issue_statuses                      |
| issues                              |
| journal_details                     |
| journals                            |
| member_roles                        |
| members                             |
| messages                            |
| news                                |
| open_id_authentication_associations |
| open_id_authentication_nonces       |
| projects                            |
| projects_trackers                   |
| queries                             |
| queries_roles                       |
| repositories                        |
| roles                               |
| roles_managed_roles                 |
| schema_migrations                   |
| settings                            |
| time_entries                        |
| tokens                              |
| trackers                            |
| user_preferences                    |
| users                               |
| versions                            |
| watchers                            |
| wiki_content_versions               |
| wiki_contents                       |
| wiki_pages                          |
| wiki_redirects                      |
| wikis                               |
| workflows                           |
+-------------------------------------+
55 rows in set (0.00 sec)

mysql> 
  • データの状況
mysql> select table_name, table_rows from information_schema.tables where table_schema = 'redmine' order by 2 desc;
+-------------------------------------+------------+
| table_name                          | table_rows |
+-------------------------------------+------------+
| schema_migrations                   |        268 |
| workflows                           |        144 |
| enumerations                        |          9 |
| issue_statuses                      |          6 |
| roles                               |          5 |
| users                               |          4 |
| trackers                            |          3 |
| email_addresses                     |          1 |
| tokens                              |          1 |
| user_preferences                    |          1 |
| custom_fields_trackers              |          0 |
| journals                            |          0 |
  • ユーザデータ
mysql> select id, login, hashed_password, firstname, lastname, admin, status, last_login_on from users;
+----+-------+------------------------------------------+-----------+------------------+-------+--------+---------------------+
| id | login | hashed_password                          | firstname | lastname         | admin | status | last_login_on       |
+----+-------+------------------------------------------+-----------+------------------+-------+--------+---------------------+
|  1 | admin | a99fe2fb647cb2a5e059e095c93d2ccc0588f76d | Redmine   | Admin            |     1 |      1 | 2016-12-07 21:38:41 |
|  2 |       |                                          |           | Anonymous users  |     0 |      1 | NULL                |
|  3 |       |                                          |           | Non member users |     0 |      1 | NULL                |
|  4 |       |                                          |           | Anonymous        |     0 |      0 | NULL                |
+----+-------+------------------------------------------+-----------+------------------+-------+--------+---------------------+
4 rows in set (0.00 sec)
  • ロールのpermissionはtext属性になっている。
mysql> select permissions from roles where id = 3;
| permissions                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
- :add_project
- :edit_project
- :close_project
- :select_project_modules
- :manage_members
- :manage_versions
- :add_subprojects
- :view_issues
- :add_issues
- :edit_issues
- :copy_issues
- :manage_issue_relations
- :manage_subtasks
- :set_issues_private
- :set_own_issues_private
- :add_issue_notes
- :edit_issue_notes
- :edit_own_issue_notes
- :view_private_notes
- :set_notes_private
- :delete_issues
- :manage_public_queries
- :save_queries
- :view_issue_watchers
- :add_issue_watchers
- :delete_issue_watchers
- :import_issues
- :manage_categories
- :view_time_entries
- :log_time
- :edit_time_entries
- :edit_own_time_entries
- :manage_project_activities
- :manage_news
- :comment_news
- :view_documents
- :add_documents
- :edit_documents
- :delete_documents
- :view_files
- :manage_files
- :view_wiki_pages
- :view_wiki_edits
- :export_wiki_pages
- :edit_wiki_pages
- :rename_wiki_pages
- :delete_wiki_pages
- :delete_wiki_pages_attachments
- :protect_wiki_pages
- :manage_wiki
- :view_changesets
- :browse_repository
- :commit_access
- :manage_related_issues
- :manage_repository
- :add_messages
- :edit_messages
- :edit_own_messages
- :delete_messages
- :delete_own_messages
- :manage_boards
- :view_calendar
- :view_gantt
 |
1 row in set (0.00 sec)

mysql>