#author("2018-05-12T17:51:18+09:00","","") #author("2018-05-12T17:55:25+09:00","","") #nofollow #norelated 総数:&counter(total); 今日:&counter(today); 昨日:&counter(yesterday); * もくじ [#ccb09661] #contents 参考URL [[Ubuntu 16.04(またはRaspbian)にRedmineをインストールする>https://jyn.jp/ubuntu-redmine/]] *必要なパッケージのインストール [#i47440d0] ** Ruby系 [#fa1f28d5] ~$ sudo apt-get install ruby-dev ruby bundler ** Apache系 [#l0985bae] ~$ sudo apt-get install libapache2-mod-passenger ** ImageMagic系 [#e9ee573b] ~$ sudo apt-get install imagemagick libmagick++-dev ** バージョン管理系 [#s09c039b] ~$ sudo apt-get install subversion ** MySQL [#o23b6d0a] ~$ sudo apt-get install libmysqlclient-dev *MySQLの設定変更 [#t3ec0407] Redmineのデータベースの文字コードは「utf8mb4」を利用しようと思います。&br; /etc/mysql/conf.d/redmine.cnfを作成し、以下の内容を書き込んで下さい。&br; ~$ sudo bash ~# cat << EOF > /etc/mysql/conf.d/redmine.cnf [mysqld] innodb_file_format = Barracuda innodb_file_per_table = 1 innodb_large_prefix character-set-server = utf8mb4 skip-character-set-client-handshake collation-server = utf8mb4_general_ci init-connect = SET NAMES utf8mb4 [mysql] default-character-set = utf8mb4 [client] default-character-set = utf8mb4 [mysqldump] default-character-set = utf8mb4 EOF ~# exit ~$ sudo service mysql restart * Redmine用データベースの作成 [#b8c322c5] 「mysql -u root -p」でMySQLサーバにログインしましょう。 ~$ mysql -u root -p Enter password:redmine Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.22-0ubuntu0.16.04.1 (Ubuntu) Copyright (c) 2000, 2018, 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> ログイン出来たら以下のSQLを実行してデータベースの作成とユーザの追加を行いましょう。(db、userは好みに合わせて設定して下さい)&br; CREATE DATABASE db CHARACTER SET utf8mb4; CREATE USER 'user'@'localhost' IDENTIFIED BY 'Redmine用ユーザのパスワード'; GRANT ALL PRIVILEGES ON db.* TO 'user'@'localhost'; FLUSH PRIVILEGES; 入力例 |設定項目|設定内容|h |データベース名|redmine_db| |文字セット|utf8mb4| |ユーザー名|my_redmine_admin| |ドメイン名|localhost| |Redmine用ユーザのパスワード|my_redmine_admin| mysql> CREATE DATABASE redmine_db CHARACTER SET utf8mb4; Query OK, 1 row affected (0.02 sec) mysql> CREATE USER 'my_redmine_admin'@'localhost' IDENTIFIED BY 'my_redmine_admin'; Query OK, 0 rows affected (0.00 sec) mysql> GRANT ALL PRIVILEGES ON redmine_db.* TO 'my_redmine_admin'@'localhost'; Query OK, 0 rows affected (0.00 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) mysql> exit Bye *Redmineのインストール [#jd9f69d3] **Redmineのダウンロード [#a4d4eea2] ***とりあえず、/var/www/redmineを作成して、所有者をwww-dataに変更しましょう。&br; [#e8884016] ~$ sudo mkdir -p /var/www/redmine ~$ sudo chown www-data:www-data /var/www/redmine ***Subversion(svn)のcheckout(co)を利用してダウンロードします。 [#xc04d350] ~$ sudo -u www-data svn co http://svn.redmine.org/redmine/branches/3.2-stable /var/www/redmine **Redmineの設定ファイルを作成 [#efdbad07] ***Redmineの設定ファイルを作成しましょう、まずはデータベースの設定から [#pfbb5a1e] 「/var/www/redmine/config/database.yml」を作成して以下の内容を書き込みます。&br; (ここまでの手順通りならディレクトリの所有者が「www-data」になっているはずなので、&br; rootでないとファイルが作成出来ないと思われます)&br; ~$ sudo bash ~# cat << EOF > /var/www/redmine/config/database.yml production: adapter: mysql2 host: localhost # Redmine用のMySQLデータベース名 database: redmine_db # Redmine用のMySQLユーザ名 username: my_redmine_admin # Redmine用のMySQLパスワード password: my_redmine_admin encoding: utf8mb4 socket: /var/run/mysqld/mysqld.sock EOF ~# exit ~$ ~$ sudo chown www-data:www-data /var/www/redmine/config/database.yml ~$ ls -la /var/www/redmine/config/ 合計 80 drwxr-xr-x 5 www-data www-data 4096 5月 11 22:41 . drwxr-xr-x 18 www-data www-data 4096 5月 10 23:17 .. -rw-r--r-- 1 www-data www-data 219 5月 10 23:17 additional_environment.rb.example -rw-r--r-- 1 www-data www-data 3515 5月 10 23:17 application.rb -rw-r--r-- 1 www-data www-data 171 5月 10 23:17 boot.rb -rw-r--r-- 1 www-data www-data 8140 5月 10 23:17 configuration.yml.example -rw-r--r-- 1 www-data www-data 299 5月 11 22:41 database.yml -rw-r--r-- 1 www-data www-data 1137 5月 10 23:17 database.yml.example -rw-r--r-- 1 www-data www-data 586 5月 10 23:17 environment.rb drwxr-xr-x 2 www-data www-data 4096 5月 10 23:17 environments drwxr-xr-x 2 www-data www-data 4096 5月 10 23:17 initializers drwxr-xr-x 2 www-data www-data 4096 5月 10 23:17 locales -rw-r--r-- 1 www-data www-data 17323 5月 10 23:17 routes.rb -rw-r--r-- 1 www-data www-data 5526 5月 10 23:17 settings.yml ***次に「/var/www/redmine/config/configuration.yml」を作成して以下の内容を書き込みます。 [#i7631b5c] ~$ sudo bash ~# cat << EOF > /var/www/redmine/config/configuration.yml production: email_delivery: delivery_method: :smtp smtp_settings: address: smtp.example.jp port: 25 domain: redmine.example.jp enable_starttls_auto: false EOF ~# exit ~$ ~$ sudo chown www-data:www-data /var/www/redmine/config/configuration.yml ~$ ls -la /var/www/redmine/config/ 合計 84 drwxr-xr-x 5 www-data www-data 4096 5月 11 22:50 . drwxr-xr-x 18 www-data www-data 4096 5月 10 23:17 .. -rw-r--r-- 1 www-data www-data 219 5月 10 23:17 additional_environment.rb.example -rw-r--r-- 1 www-data www-data 3515 5月 10 23:17 application.rb -rw-r--r-- 1 www-data www-data 171 5月 10 23:17 boot.rb -rw-r--r-- 1 www-data www-data 189 5月 11 22:50 configuration.yml -rw-r--r-- 1 www-data www-data 8140 5月 10 23:17 configuration.yml.example -rw-r--r-- 1 www-data www-data 299 5月 11 22:41 database.yml -rw-r--r-- 1 www-data www-data 1137 5月 10 23:17 database.yml.example -rw-r--r-- 1 www-data www-data 586 5月 10 23:17 environment.rb drwxr-xr-x 2 www-data www-data 4096 5月 10 23:17 environments drwxr-xr-x 2 www-data www-data 4096 5月 10 23:17 initializers drwxr-xr-x 2 www-data www-data 4096 5月 10 23:17 locales -rw-r--r-- 1 www-data www-data 17323 5月 10 23:17 routes.rb -rw-r--r-- 1 www-data www-data 5526 5月 10 23:17 settings.yml メール通知は様々な方法があり、色々と面倒なので 「[[メール通知のためのconfiguration.ymlの設定>http://redmine.jp/faq/general/mail_notification/]]」をご覧下さい。&br; ***厳密には設定では無いのですが、MySQLをutf8mb4で利用するにあたって1つ、ファイルを追加する必要があります。 [#t0988676] 「/var/www/redmine/config/initializers/utf8mb4.rb」を作成して、以下の内容をコピペして下さい。&br; ~$ sudo bash ~# cat << EOF > /var/www/redmine/config/initializers/utf8mb4.rb ActiveSupport.on_load :active_record do module ActiveRecord::ConnectionAdapters class AbstractMysqlAdapter def create_table_with_innodb_row_format(table_name, options = {}) table_options = options.merge(:options => 'ENGINE=InnoDB ROW_FORMAT=DYNAMIC') create_table_without_innodb_row_format(table_name, table_options) do |td| yield td if block_given? end end alias_method_chain :create_table, :innodb_row_format end end end EOF ~# exit ~$ ~$ sudo chown www-data:www-data /var/www/redmine/config/initializers/utf8mb4.rb ~$ ls -la /var/www/redmine/config/initializers/ 合計 40 drwxr-xr-x 2 www-data www-data 4096 5月 11 23:10 . drwxr-xr-x 5 www-data www-data 4096 5月 11 22:50 .. -rw-r--r-- 1 www-data www-data 509 5月 10 23:17 00-core_plugins.rb -rw-r--r-- 1 www-data www-data 5665 5月 10 23:17 10-patches.rb -rw-r--r-- 1 www-data www-data 113 5月 10 23:17 20-mime_types.rb -rw-r--r-- 1 www-data www-data 908 5月 10 23:17 30-redmine.rb -rw-r--r-- 1 www-data www-data 574 5月 10 23:17 backtrace_silencers.rb -rw-r--r-- 1 www-data www-data 376 5月 10 23:17 inflections.rb -rw-r--r-- 1 www-data www-data 489 5月 11 23:10 utf8mb4.rb **Redmineの初期設定 [#v6b67fb7] まずはRedmineをインストールしたディレクトリに移動しましょう ~$ cd /var/www/redmine/ 今の段階だとwww-dataとrootのファイルが混在しているので、全てwww-dataの物にしてしまいましょう。 ~$ find | sudo xargs chown www-data:www-data 次に、Redmineが必要とする依存ライブラリを取得します。&br; 以下のコマンドを実行して、赤文字が出なければOKです。(手順通りに進んでいたら出ないはず)&br; ~$ sudo -u www-data bundle install -j$(nproc) --without development test postgresql sqlite --path vendor/bundle resql sqlite --path vendor/bundle [sudo] redmine のパスワード: Fetching gem metadata from https://rubygems.org/........... Fetching version metadata from https://rubygems.org/... Fetching dependency metadata from https://rubygems.org/.. Resolving dependencies...................................................................................................... Installing rake 12.3.1 Installing i18n 0.7.0 Installing json 1.8.6 with native extensions Installing minitest 5.11.3 Installing thread_safe 0.3.6 Installing builder 3.2.3 Installing erubis 2.7.0 Installing mini_portile2 2.1.0 Installing crass 1.0.4 Installing rack 1.6.10 Installing mime-types-data 3.2016.0521 Installing arel 6.0.4 Installing public_suffix 3.0.2 Using bundler 1.11.2 Installing coderay 1.1.2 Installing concurrent-ruby 1.0.5 Installing htmlentities 4.3.4 Installing thor 0.20.0 Installing mimemagic 0.3.2 Installing mysql2 0.4.10 with native extensions Installing net-ldap 0.12.1 Installing ruby-openid 2.3.0 Installing rbpdf-font 1.19.1 Installing redcarpet 3.3.4 with native extensions Installing request_store 1.0.5 Installing rmagick 2.16.0 with native extensions Installing tzinfo 1.2.5 Installing nokogiri 1.7.2 with native extensions Installing rack-test 0.6.3 Installing mime-types 3.1 Installing addressable 2.5.2 Installing sprockets 3.7.1 Installing rack-openid 1.4.2 Installing rbpdf 1.19.3 Installing activesupport 4.2.7.1 Installing loofah 2.2.2 Installing mail 2.6.6 Installing css_parser 1.6.0 Installing rails-deprecated_sanitizer 1.0.3 Installing globalid 0.4.1 Installing activemodel 4.2.7.1 Installing rails-html-sanitizer 1.0.4 Installing roadie 3.2.2 Installing rails-dom-testing 1.0.9 Installing activejob 4.2.7.1 Installing activerecord 4.2.7.1 Installing protected_attributes 1.1.4 Installing actionview 4.2.7.1 Installing actionpack 4.2.7.1 Installing actionmailer 4.2.7.1 Installing actionpack-action_caching 1.2.0 Installing actionpack-xml_parser 1.0.2 Installing railties 4.2.7.1 Installing sprockets-rails 3.2.1 Installing jquery-rails 3.1.5 Installing roadie-rails 1.1.1 Installing rails 4.2.7.1 Bundle complete! 34 Gemfile dependencies, 57 gems now installed. Gems in the groups development, test, postgresql and sqlite were not installed. Bundled gems are installed into ./vendor/bundle. 次に、シークレットトークンを作成して、テーブルを作成して、デフォルトのデータを読み込みましょう。&br; ~$ sudo -u www-data bundle exec rake generate_secret_token ~$ sudo -u www-data RAILS_ENV=production bundle exec rake db:migrate ~$ sudo -u www-data RAILS_ENV=production REDMINE_LANG=ja bundle exec rake redmine:load_default_data さぁ、これでRedmineを実行する準備が整いました……Apache以外はね。&br; *Apacheの設定 [#ea2ad02a] **Passengerの設定 [#q4689bf5] Redmine(と言うか、Passengerで動くもの)はアクセスされた時に初めて起動されます、初回起動時に色々読み込んだりアレしたりコレしたりと、応答がかなり遅いです。&br; そこで「PassengerPreStart」を指定すると、Apacheが起動した段階で自動的に自分自身にリクエストを送ってRedmineを起動しておくことが出来ます。&br; 「/etc/apache2/mods-available/passenger.conf」をエディタで開いて、以下の設定を追記しましょう。&br; PassengerPreStart http://redmineのアドレス/ 例: PassengerPreStart http://192.168.3.26/ ~$ cat /etc/apache2/mods-available/passenger.conf <IfModule mod_passenger.c> PassengerRoot /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini PassengerDefaultRuby /usr/bin/ruby PassengerPreStart http://192.168.3.26/ </IfModule> **Webサイトの設定(ルートに設置する場合) [#x21404eb] |設定ファイル名|/etc/apache2/sites-enabled/000-default.conf| |設定ファイル本体|/etc/apache2/sites-available/000-default.conf| ~$ ls -la /etc/apache2/sites-enabled/ 合計 8 drwxr-xr-x 2 root root 4096 5月 10 21:38 . drwxr-xr-x 9 root root 4096 5月 12 00:35 .. lrwxrwxrwx 1 root root 35 5月 10 21:38 000-default.conf -> ../sites-available/000-default.conf 変更前の状態 /etc/apache2/sites-available/000-default.conf ~$ cat /etc/apache2/sites-available/000-default.conf <VirtualHost *:80> # The ServerName directive sets the request scheme, hostname and port that # the server uses to identify itself. This is used when creating # redirection URLs. In the context of virtual hosts, the ServerName # specifies what hostname must appear in the request's Host: header to # match this virtual host. For the default virtual host (this file) this # value is not decisive as it is used as a last resort host regardless. # However, you must set it for any further virtual host explicitly. #ServerName www.example.com ServerAdmin webmaster@localhost DocumentRoot /var/www/html # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular # modules, e.g. #LogLevel info ssl:warn ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined # For most configuration files from conf-available/, which are # enabled or disabled at a global level, it is possible to # include a line for only one particular virtual host. For example the # following line enables the CGI configuration for this host only # after it has been globally disabled with "a2disconf". #Include conf-available/serve-cgi-bin.conf </VirtualHost> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet もし、RedmineをWebサイトのrootに設置(http://redmine.example.jp/ で見られるように)する場合は以下の様な設定になります。&br; <VirtualHost *:80> ServerName redmine.example.jp ServerAdmin redmine@example.jp # public/ディレクトリを指定する事に注意 DocumentRoot /var/www/redmine/public # 他のモジュールとの互換性を犠牲にPassengerの性能を底上げするオプションです。 # Directoryの中に移動させるとなぜか404になります。 PassengerHighPerformance on <Directory /var/www/redmine/public> # アクセス制限を掛けておくと安全!! Require ip ::1 127. 192.168. # .htaccessなどは利用しない方が(ほんの少しだけ)高性能になります。 AllowOverride None Options None </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> 設定が終わったら「sudo service apache2 restart」で再起動してやりましょう。&br; **Webサイトの設定(サブディレクトリに設置する場合) [#aaea9b58] |設定ファイル名|/etc/apache2/sites-enabled/000-default.conf| |設定ファイル本体|/etc/apache2/sites-available/000-default.conf| Redmineをサブディレクトリに設置(http://example.jp/redmine/ で見られるように)する場合は少し準備が必要です。&br; 現在のルートは「/var/www/html」にあると仮定します。&br; まず最初に、Redmineをインストールしたディレクトリへのシンボリックリンクを張ってやる必要があります。&br; ~$ sudo ln -s /var/www/redmine/public /var/www/html/redmine でもって、以下の様に設定します。&br; <VirtualHost *:80> ServerName example.jp ServerAdmin webmaster@example.jp # public/ディレクトリを指定する事に注意 DocumentRoot /var/www/html # これを指定する事でRedmineの場所が異なっていてもPassengerが正常に起動します。 RackBaseURI /redmine <Directory /var/www/html/redmine> # アクセス制限を掛けておくと安全!! Require ip ::1 127. 192.168. # .htaccessなどは利用しない方が(ほんの少しだけ)高性能になります。 AllowOverride None Options None </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> ~$ diff -uprN /etc/apache2/sites-available/000-default.conf.org /etc/apache2/sites-available/000-default.conf --- /etc/apache2/sites-available/000-default.conf.org 2018-05-12 17:38:14.327415519 +0900 +++ /etc/apache2/sites-available/000-default.conf 2018-05-12 17:43:11.655415519 +0900 @@ -11,6 +11,16 @@ ServerAdmin webmaster@localhost DocumentRoot /var/www/html + #これを指定する事でRedmineの場所が異なっていてもPassengerが正常に起動します。 + RackBaseURI /redmine + <Directory /var/www/html/redmine> + # アクセス制限を掛けておくと安全!! + Require ip ::1 127. 192.168. + # .htaccessなどは利用しない方が(ほんの少しだけ)高性能になります。 + AllowOverride None + Options None + </Directory> + # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular 設定が終わったら「sudo service apache2 restart」で再起動してやりましょう。&br; *出来上がり [#z9aecc65] 正常に起動しましたでしょうか?、&br; 初期ユーザはユーザ名「admin」パスワード「admin」でログイン出来ますよ(ルータみたい)&br; Redmineのインストールは色々と面倒な所がありますが、&br; インストールさえ出来てしまえばプラグインなどもあり、&br; とても幅広く便利に使いこなす事が出来ます。&br; * ここからつづき [#tdead98e]