Ubuntu 20.04下從源碼安裝Redmine

news/2024/7/9 22:49:03 标签: ruby, redmine, postgresql, linux, apache

Ubuntu 20.04下從源碼安裝Redmine

  • 前言
  • 安裝步驟
    • 安裝Apache2
    • 安裝Postgresql
    • 安裝rvm及ruby
    • 安裝Passenger
    • 安裝Redmine
    • Apache2設定
    • 成果
    • Host redmine in a sub-URI
    • Troubleshooting
      • find_spec_for_exe': can't find gem passenger (>= 0.a) with executable passenger-install-apache2-module (Gem::GemNotFoundException)
      • PG::ConnectionBad: FATAL: password authentication failed for user "postgres"
      • Your Ruby version is 2.7.2, but your Gemfile specified >= 2.3.0, < 2.7.0
      • bundle install --path --without deprecated
  • 修改Redmine源碼

前言

之前寫過一篇Ubuntu 20.04下使用apt安裝Redmine,但是如果使用apt,則只能安裝4.0.6版的Redmine。如果想要安裝更新版本的Redmine,就必須從源碼安裝。

本篇基於How To Install Redmine on Ubuntu 20.04 Linux,記錄在Ubuntu 20.04下從源碼安裝Redmine的步驟。

安裝步驟

安裝Apache2

安裝Apache2,以及ruby和Passenger的依賴:

# apt update -y # in docker
# apt install -y sudo # in docker
sudo apt install wget software-properties-common -y
sudo apt install apache2 apache2-dev libcurl4-openssl-dev -y
sudo apt install imagemagick libmagickwand-dev git build-essential automake libgmp-dev -y

安裝Postgresql

這部份已整理成獨立的文檔,詳見Ubuntu 20.04下安裝Postgresql。

ruby_21">安裝rvm及ruby

這部份已整理成獨立的文檔,詳見Ubuntu 20.04下使用rvm安裝Ruby。

安裝Passenger

gem install passenger
passenger-install-apache2-module

Passenger module的安裝涉及其C++源碼的編譯及安裝,整個過程大概要花十分鐘左右。

在結束前會出現以下提示,要求編輯Apache的設定檔,加入列出來的五行字:

Almost there!

Please edit your Apache configuration file, and add these lines:

   LoadModule passenger_module /usr/share/rvm/gems/ruby-2.6.5/gems/passenger-6.0.8/buildout/apache2/mod_passenger.so
   <IfModule mod_passenger.c>
     PassengerRoot /usr/share/rvm/gems/ruby-2.6.5/gems/passenger-6.0.8
     PassengerDefaultRuby /usr/share/rvm/gems/ruby-2.6.5/wrappers/ruby
   </IfModule>

After you restart Apache, you are ready to deploy any number of web
applications on Apache, with a minimum amount of configuration!

Press ENTER when you are done editing.

這裡先按Enter跳過,出現以下log:

--------------------------------------------

Validating installation...

 * Checking whether this Passenger install is in PATH... (!)

   Please add /usr/share/rvm/gems/ruby-2.6.5/gems/passenger-6.0.8/bin to PATH.
   Otherwise you will get "command not found" errors upon running
   any Passenger commands.

   Learn more at about PATH at:

     https://www.phusionpassenger.com/library/indepth/environment_variables.html#the-path-environment-variable

 * Checking whether there are no other Passenger installations... (!)

   You are currently validating against Phusion Passenger(R) 6.0.8, located in:

     /usr/share/rvm/gems/ruby-2.6.5/gems/passenger-6.0.8/bin/passenger

   Besides this Passenger installation, the following other
   Passenger installations have also been detected:

     /usr/share/rvm/gems/ruby-2.6.5/bin/passenger
     /usr/local/bin/passenger

   Please uninstall these other Passenger installations to avoid
   confusion or conflicts.

 * Checking whether Apache is installed... _
 * Checking whether the Passenger module is correctly configured in Apache... _

Detected 0 error(s), 2 warning(s).
Press ENTER to continue.

按Enter結束安裝,接著在/etc/apache2/apache2.conf加上剛剛出現的那一段字:

LoadModule passenger_module /usr/share/rvm/gems/ruby-2.6.5/gems/passenger-6.0.8/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
  PassengerRoot /usr/share/rvm/gems/ruby-2.6.5/gems/passenger-6.0.8
  PassengerDefaultRuby /usr/share/rvm/gems/ruby-2.6.5/wrappers/ruby
</IfModule>

Passenger的log路徑為/tmp/passenger-error-xxxxxx.html,如果啟動Redmine時出現We're sorry, but something went wrong.的錯誤,可以來這裡尋找線索。

另:Rails Passenger problem with Apache2裡有做一些額外的設定,沒有試過,但可能會有用。

安裝Redmine

此處安裝的是Redmine 4.1.1版,如果想要尋找其它的版本,可以到https://www.redmine.org/releases。

創建名為redmine的使用者並切換為該使用者:

sudo adduser --disabled-password --gecos "Redmine User" redmine
sudo su - redmine

下載redmine源碼並解壓:

wget https://www.redmine.org/releases/redmine-4.1.1.tar.gz
tar -xf redmine-*.tar.gz
mv redmine-4.1.1/ redmine

複製configuration.ymldatabase.yml兩份文件:

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

修改database.yml,將其中與mysql相關的mysql的都註釋掉,並取消註釋與postgresql相關的行:

vim database.yml # comment all mysql lines and uncomment postregsql lines

修改後的database.yml如下:

# Default setup is given for MySQL 5.7.7 or later.
# Examples for PostgreSQL, SQLite3 and SQL Server can be found at the end.
# Line indentation must be 2 spaces (no tabs).

# production:
#   adapter: mysql2
#   database: redmine
#   host: localhost
#   username: root
#   password: ""
#   # Use "utf8" instead of "utfmb4" for MySQL prior to 5.7.7
#   encoding: utf8mb4
#
# development:
#   adapter: mysql2
#   database: redmine_development
#   host: localhost
#   username: root
#   password: ""
#   # Use "utf8" instead of "utfmb4" for MySQL prior to 5.7.7
#   encoding: utf8mb4
#
# # Warning: The database defined as "test" will be erased and
# # re-generated from your development database when you run "rake".
# # Do not set this db to the same as development or production.
# test:
#   adapter: mysql2
#   database: redmine_test
#   host: localhost
#   username: root
#   password: ""
#   # Use "utf8" instead of "utfmb4" for MySQL prior to 5.7.7
#   encoding: utf8mb4

# PostgreSQL configuration example
production:
  adapter: postgresql
  database: redmine
  host: localhost
  username: postgres
  password: "postgres"

# SQLite3 configuration example
#production:
#  adapter: sqlite3
#  database: db/redmine.sqlite3

# SQL Server configuration example
#production:
#  adapter: sqlserver
#  database: redmine
#  host: localhost
#  username: jenkins
#  password: jenkins

注意設定檔中有個password欄位,必須與Ubuntu 20.04下安裝Postgresql - Redmine設定中設定的一致,也就是:

username: redmine
password: "DBPassword"

否則在使用RAILS_ENV=production bundle exec rake db:migrate做資料庫遷移時會出現PG::ConnectionBad: FATAL: password authentication failed for user "postgres"的問題。

讓rails application(即Redmine)使用postgresql的設定:

bundle config build.pg --with-pg-config=/usr/bin/pg_config

bundle做一些必要的設定:

bundle config set --local path 'vendor/bundle'

輸出:

You are replacing the current local value of path, which is currently "vendor/bundle --without developement test"
bundle config set --local without 'developement test'

輸出:

You are replacing the current local value of without, which is currently "developement:test"

使用以下指令檢查:

bundle config

輸出:

Settings are listed in order of priority. The top value will be used.
build.pg
Set for the current user (/home/redmine/.bundle/config): "--with-pg-config=/usr/bin/pg_config"

path
Set for your local app (/home/redmine/redmine/.bundle/config): "vendor/bundle"

without
Set for your local app (/home/redmine/redmine/.bundle/config): [:developement, :test]

安裝Redmine所需的dependencies:

bundle install

出現以下訊息:

HEADS UP! i18n 1.1 changed fallbacks to exclude default locale.
But that may break your application.

Please check your Rails app for 'config.i18n.fallbacks = true'.
If you're using I18n (>= 1.1.0) and Rails (< 5.2.2), this should be
'config.i18n.fallbacks = [I18n.default_locale]'.
If not, fallbacks will be broken in your app by I18n 1.1.x.

For more info see:
https://github.com/svenfuchs/i18n/releases/tag/v1.1.0

根據HEADS UP! i18n 1.1 changed fallbacks to exclude default locale,上面的訊息只是警告,不用特別處理。

生成用於加密session data的secret token:

bundle exec rake generate_secret_token

資料庫遷移:

RAILS_ENV=production bundle exec rake db:migrate

在資料庫中寫入預設的資料:

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] zh-TW
====================================
Default configuration data loaded.

修改部份目錄的擁有者及權限:

mkdir -p tmp tmp/pdf public/plugin_assets
# switch to sudo user
chown -R redmine:redmine files log tmp public/plugin_assets
chmod -R 755 files log tmp public/plugin_assets

Apache2設定

passenger-install-apache2-module時出現的LoadModule passenger_module ...那一行字貼到/etc/apache2/apache2.conf中,讓Apache2能自動載入passenger module:

echo "LoadModule passenger_module /usr/share/rvm/gems/ruby-2.6.5/gems/passenger-6.0.8/buildout/apache2/mod_passenger.so" | sudo tee -a /etc/apache2/apache2.conf

為Redmine創建一個virtual host file:

sudo vim /etc/apache2/sites-available/redmine.conf

內容如下:

<VirtualHost *:80>
    #ServerName redmine.example.com

    DocumentRoot /home/redmine/redmine/public

    PassengerRoot /usr/share/rvm/gems/ruby-2.6.5/gems/passenger-6.0.8
    PassengerDefaultRuby /usr/share/rvm/gems/ruby-2.6.5/wrappers/ruby
    PassengerUser redmine

    <Directory /home/redmine/redmine/public>
      Allow from all
      Options -MultiViews
      Require all granted
    </Directory>
</VirtualHost>

注意PassengerRootPassengerDefaultRuby的值需與passenger-install-apache2-module時出現的提示一致。可用以下指令檢查:

passenger-config about ruby-command

輸出如下:

passenger-config was invoked through the following Ruby interpreter:
  Command: /usr/share/rvm/gems/ruby-2.6.5/wrappers/ruby
  Version: ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux]
  To use in Apache: PassengerRuby /usr/share/rvm/gems/ruby-2.6.5/wrappers/ruby
  To use in Nginx : passenger_ruby /usr/share/rvm/gems/ruby-2.6.5/wrappers/ruby
  To use with Standalone: /usr/share/rvm/gems/ruby-2.6.5/wrappers/ruby /usr/share/rvm/gems/ruby-2.6.5/gems/passenger-6.0.8/bin/passenger start


## Notes for RVM users
Do you want to know which command to use for a different Ruby interpreter? 'rvm use' that Ruby interpreter, then re-run 'passenger-config about ruby-command'.

停用000-default,啟用redmine,並重啟Apache2:

sudo a2ensite redmine.conf # sudo a2ensite redmine
sudo a2dissite 000-default.conf
systemctl start apache2
systemctl reload apache2
# systemctl restart apache2

注:如果是在docker container中,可改用service apache2 startservice apache2 reload

關於Apache2 virtual host的概念,可以參考How To Set Up Apache Virtual Hosts on Ubuntu 16.04。

可用以下指令查看有哪些site是被啟用的:

a2query -s

輸出:

redmine (enabled by site administrator)

Apache2的重要路徑:

/etc/apache2                  #apache2.conf, ports.conf
/etc/apache2/sites-available  # 000-default.conf
/var/www/html                 # index.html
/etc/ssl                      #certs, private
/var/log/apache2              #access.log  error.log  other_vhosts_access.log

成果

上述步驟完成後,在瀏覽器中前往127.0.0.1:80,就能看到如下頁面:
<a class=redmine_init" />
點擊右上角登入,輸入默認帳號密碼admin/admin
在这里插入图片描述
登入後系統會要求變更密碼:
在这里插入图片描述
變更完成後會自動進到我的帳戶頁面:
在这里插入图片描述

可以暫時先保持默認的設定,之後隨時可以再更改。

redmine_in_a_subURI_380">Host redmine in a sub-URI

可參考將Redmine架在sub-URI。

Troubleshooting

apache2module_GemGemNotFoundException_384">find_spec_for_exe’: can’t find gem passenger (>= 0.a) with executable passenger-install-apache2-module (Gem::GemNotFoundException)

如果在執行passenger-install-apache2-module時出現以下錯誤:

Traceback (most recent call last):
        4: from /usr/share/rvm/gems/ruby-2.6.6/bin/ruby_executable_hooks:22:in `<main>'
        3: from /usr/share/rvm/gems/ruby-2.6.6/bin/ruby_executable_hooks:22:in `eval'
        2: from /usr/share/rvm/gems/ruby-2.6.6/bin/passenger-install-apache2-module:23:in `<main>'
        1: from /usr/share/rvm/rubies/ruby-2.6.6/lib/ruby/site_ruby/2.6.0/rubygems.rb:303:in `activate_bin_path'
/usr/share/rvm/rubies/ruby-2.6.6/lib/ruby/site_ruby/2.6.0/rubygems.rb:284:in `find_spec_for_exe': can't find gem passenger (>= 0.a) with executable passenger-install-apache2-module (Gem::GemNotFoundException)

參考’find_spec_for_exe’: can’t find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException),可以嘗試卸載bundler 2.2.16,並安裝bundler 1.17.3。

參考find_spec_for_exe’: can’t find gem bundler (>= 0.a) (Gem::GemNotFoundException),使用以下指令解決:

gem update --system

PG::ConnectionBad: FATAL: password authentication failed for user “postgres”

如果RAILS_ENV=production bundle exec rake db:migrate時出現以下錯誤:

rake aborted!
PG::ConnectionBad: FATAL:  password authentication failed for user "postgres"
FATAL:  password authentication failed for user "postgres"
/home/redmine/redmine/vendor/bundle/ruby/2.6.0/gems/pg-1.1.4/lib/pg.rb:56:in `initialize'
/home/redmine/redmine/vendor/bundle/ruby/2.6.0/gems/pg-1.1.4/lib/pg.rb:56:in `new'
/home/redmine/redmine/vendor/bundle/ruby/2.6.0/gems/pg-1.1.4/lib/pg.rb:56:in `connect'
/home/redmine/redmine/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.5/lib/active_record/connection_adapters/postgresql_adapter.rb:692:in `connect'
/home/redmine/redmine/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.5/lib/active_record/connection_adapters/postgresql_adapter.rb:223:in `initialize'
/home/redmine/redmine/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.5/lib/active_record/connection_adapters/postgresql_adapter.rb:48:in `new'
/home/redmine/redmine/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.5/lib/active_record/connection_adapters/postgresql_adapter.rb:48:in `postgresql_connection'
/home/redmine/redmine/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:830:in `new_connection'
/home/redmine/redmine/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:874:in `checkout_new_connection'
/home/redmine/redmine/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:853:in `try_to_checkout_new_connection'
/home/redmine/redmine/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:814:in `acquire_connection'
/home/redmine/redmine/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:538:in `checkout'
/home/redmine/redmine/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:382:in `connection'
/home/redmine/redmine/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:1033:in `retrieve_connection'
/home/redmine/redmine/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.5/lib/active_record/connection_handling.rb:118:in `retrieve_connection'
/home/redmine/redmine/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.5/lib/active_record/connection_handling.rb:90:in `connection'
/home/redmine/redmine/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.5/lib/active_record/tasks/database_tasks.rb:172:in `migrate'
/home/redmine/redmine/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.5/lib/active_record/railties/databases.rake:60:in `block (2 levels) in <top (required)>'
/home/redmine/redmine/vendor/bundle/ruby/2.6.0/gems/rake-13.0.3/exe/rake:27:in `<top (required)>'
/usr/share/rvm/gems/ruby-2.6.6/bin/ruby_executable_hooks:22:in `eval'
/usr/share/rvm/gems/ruby-2.6.6/bin/ruby_executable_hooks:22:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

代表資料庫的使用者postgres的密碼與設定檔裡寫的不一致。
可以直接修正設定檔裡的密碼,或重新設定postgres使用者的密碼。

參考Postgresql: password authentication failed for user “postgres”,進入postgres shell後:

ALTER USER postgres PASSWORD 'postgres'; --same as that in config/database.yml

Your Ruby version is 2.7.2, but your Gemfile specified >= 2.3.0, < 2.7.0

如果下bundle install時出現以下錯誤,需重裝舊版ruby

Your Ruby version is 2.7.2, but your Gemfile specified >= 2.3.0, < 2.7.0

bundle install --path --without deprecated

教學中使用的指令如下:

bundle install --path vendor/bundle --without developement test

但是實測後發現會出現以下訊息:

[DEPRECATED] The `--path` flag is deprecated because it relies on being remembered across bundler invocations, which bundler will no longer do in future versions. Instead please use `bundle config set --local path 'vendor/bundle'`, and stop using this flag
[DEPRECATED] The `--without` flag is deprecated because it relies on being remembered across bundler invocations, which bundler will no longer do in future versions. Instead please use `bundle config set --local without 'developement test'`, and stop using this flag

需要將它用以下三條指令替代:

bundle config set --local path 'vendor/bundle'
bundle config set --local without 'developement test'
bundle install

修改Redmine源碼

修改redmine code後使它生效:

RAILS_ENV=production bundle exec rake db:migrate

http://www.niftyadmin.cn/n/778430.html

相关文章

Redmine plugin redmine_xapian安裝

Redmine插件redmine_xapian安裝前言安裝步驟安裝xapian-core,omega,xapian-bindings安裝xapian-core安裝pcre安裝omega安裝xapian-bindings安裝其它required packages安裝redmine_xapian pluginTroubleshootinginstall omega時make出錯bundle install的位置Your Gemfile has no…

Ubuntu下使用CIFS掛載Windows共享資源

Ubuntu下使用CIFS掛載Windows共享資源前言方法一&#xff1a;mount方法二&#xff1a;/etc/fstab設定開機自動掛載修改權限TroubleshootingUnable to apply new capability setbad option; for several filesystems (e.g. nfs, cifs) you might need a /sbin/mountCouldnt chdi…

Redmine plugin redmine_2fa安裝

Redmine plugin redmine_2fa安裝 前言安裝步驟安裝redis安裝redmine_sidekiq安裝redmine_bots安裝redmine_2faTroubleshootingNoMethodError (undefined method tr for nil:NilClass使用方式重設2fa otp secret key)前言 redmine_2fa是redmine的一個plugin&#xff0c;提供了登…

將Redmine架在sub-URI

將Redmine架在sub-URI參考HowTo Install Redmine in a sub-URI及Defect #32318&#xff0c;在config/environment.rb檔案的最底下加上&#xff1a; ActionController::Base.relative_url_root RedmineApp::Application.routes.default_scope Redmine::Utils::relative_url_ro…

Windows 10下安裝OpenSSL 1.1.1

Windows 10下安裝OpenSSL 1.1.1前言透過installer安裝OpenSSL在Visual Studio 2019中使用範例程式使用命令直接加解密參考連結前言 OpenSSL官網為OpenSSL&#xff0c;可以從上面下載openssl-1.1.1k.tar.gz後按照NOTES-WINDOWS.md的說明手動編譯安裝。但是看起來OpenSSL的依賴並…

PCL - MLS代碼研讀(一)- MLS測試

PCL - MLS代碼研讀&#xff08;一&#xff09;- MLS測試前言測試曲面重建測試SAMPLE_LOCAL_PLANE上採樣方法測試VOXEL_GRID_DILATION上採樣方法主程序MLS module結構前言 PCL的MLS模塊用於對點雲做平滑處理&#xff08;或說曲面重建&#xff09;及上採樣&#xff0c;其中MLS的…

PCL - MLS代碼研讀(二)- MLSResult

PCL - MLS代碼研讀&#xff08;二&#xff09;- MLSResult前言pcl::MLSResultProjectionMethodPolynomialPartialDerivativeMLSProjectionResults成員變量computeMLSWeight成員函數兩個constructor坐標計算函數偏微分計算函數曲率計算函數各式投影函數擬合曲面計算函數前言 PC…

PCL - MLS代碼研讀(三)- 坐標計算函數

PCL - MLS代碼研讀&#xff08;三&#xff09;- 坐標計算函數前言三維getMLSCoordinates二維getMLSCoordinatesgetPolynomialValue前言 本篇延續PCL - MLS代碼研讀&#xff08;二&#xff09;&#xff0c;繼續介紹坐標計算函數。 三維getMLSCoordinates 此函數計算全局坐標系…