Redmine is a flexible project management web application. Written using the Ruby on Rails framework, it is cross-platform and cross-database.
Redmine是基於Ruby on Rails框架支持跨平臺、跨數據庫的一款靈活的項目管理web應用程序。
特性
- 支持多項目管理;
- 靈活的基於角色的訪問控制;
- 靈活的問題跟蹤系統;
- 通過甘特圖和日曆追蹤事務;
- 新聞、文檔和文件管理;
- feeds和郵件通知;
- 依附於項目的wiki;
- 項目論壇;
- 簡單實時跟蹤功能;
- 自定義字段的問題,時間項,項目和用戶;
- SCM in集成 (SVN, CVS, Git, Mercurial, Bazaar and Darcs)
- 多個 LDAP認證支持;
- 用戶自注冊支持;
- 多語言支持;
- 多數據庫支持。
爲什麼使用Redmine?
基於上面的多種特性,在項目管理工作中,如任務分配、任務跟蹤、項目權限管理等等帶來很大的便捷性,使得工作進度、質量更加可控。春雨在使用Redmine時集成了ldap,並以此對外部員工(toh、合作方)和內部員工做了區分,同時Redmine對用戶分配了四種角色(超級管理員、管理人員、開發人員、報告人員),而且還可以配置用戶組,如此一來對於項目權限管理更加便捷。更重要的一點是日常工作中所有工作內容的申請和交接都通過Redmine和email來操作,這樣所有工作的開展都有據可依,也符合等保3的考覈要求。
安裝配置
環境
環境 | 版本 | Ip | Hostname |
---|---|---|---|
系統環境 | centos7 | 192.168.228.130 | host3 |
Redmine | 3.4.6 | - | host3 |
ruby | 2.0.0 | - | host3 |
數據庫(mysql) | 5.6 | 192.168.228.129 | host2 |
安裝
-
安裝依賴:ruby、rake、rails
centos7.3 可以使用yum直接安裝ruby,也可以使用rvm安裝。在此使用rvm管理ruby,rvm 是一個命令行工具,可以提供一個便捷的多版本 Ruby 環境的管理和切換,如果你打算學習 Ruby / Rails, RVM 是必不可少的工具之一。
# 安裝rvm $ gpg --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3 $ curl -L https://get.rvm.io | bash -s stable $ source /etc/profile.d/rvm.sh #set up system environment for Ruby, 這步不可少 $ rvm reload $ rvm install 2.3.3 # rvm的簡單用法:安裝ruby $ rvm list 查看ruby $ rvm use 2.2.0 使用ruby $ rvm install xxxx 安裝一個版本的ruby $ rvm remove xxxx 卸載一個版本的ruby # 安裝rake和rails ## 如果嫌默認的ruby源慢,可以使用以下方法進行替換 $ gem source -r https://rubygems.org/ # 刪除默認ruby源 $ gem source -a http://mirrors.aliyun.com/rubygems/ # 配置阿里的源 ## 安裝 $ gem install rake -v 12.0.0 $ gem install rails -v 4.2.6
- 關於rvm更多介紹可參考:
-
安裝Redmine:
$ wget http://www.redmine.org/releases/redmine-3.4.6.tar.gz $ tar zxvf redmine-3.4.6.tar.gz
-
創建數據庫(使用單獨的數據庫服務器:192.168.228.129):
$ mysql -uroot -p123456 mysql> CREATE DATABASE redmine CHARACTER SET utf8mb4; mysql> CREATE USER 'redmine'@'192.168.228.130' IDENTIFIED BY '123456'; mysql> GRANT ALL PRIVILEGES ON redmine.* TO 'redmine'@'192.168.228.130'; # 在host3測試連通性,保證數據庫能正常訪問 $ mysql -uredmine -h192.168.228.129 -P3306 -p123456 MySQL [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | redmine | | test | +--------------------+ 3 rows in set (0.00 sec)
-
配置數據庫:
# 進入Redmine配置文件目錄 $ cd /usr/local/src/redmine-3.4.6/config # 創建數據庫配置文件 $ cp database.yml.example database.yml $ vim database.yml production: adapter: mysql2 database: redmine # 數據庫 host: 192.168.228.129 # 數據庫服務器 # port: 3307 # 數據庫運行端口不是3306時使用該變量指定對應端口 username: redmine # 數據庫用戶 password: "123456" # 密碼 encoding: utf8 # 字符集
-
安裝依賴: Redmine通過Bundler管理gems的依賴項。
# 安裝bundler $ gem install bundler # 安裝Redmine所依賴的gems相關包 $ bundle install --without development test
-
Note: 可選依賴項 && 數據庫適配器
RMagick :允許通過ImageMagick操作PDF和PNG導出的圖像。如果系統沒有安裝ImageMagick,在安裝Redmine依賴包時需要跳過該項
bundle install --without development test rmagick
。 -
衝突處理:
# 衝突1: An error occurred while installing nokogiri (1.6.8.1), and Bundler cannot continue. # 解決辦法: $ yum install -y gcc ruby-devel zlib-devel # 根據輸出信息判斷,之前沒有安裝ruby-devel包 # 詳情參考:http://www.nokogiri.org/tutorials/installing_nokogiri.html # 衝突2: An error occurred while installing mysql2 (0.4.10), and Bundler cannot continue. # 解決辦法: $ yum install -y mysql-devel # 衝突3: An error occurred while installing rmagick (2.16.0), and Bundler cannot continue. # 解決辦法: $ yum install ImageMagick-devel # 處理完以上衝突後直接執行 bundle install --without development test 安裝完成!
-
-
session加密處理: 創建隨機key對session加密,防止被篡改
$ bundle exec rake generate_secret_token
-
初始化數據庫字段:
$ RAILS_ENV=production bundle exec rake db:migrate
-
衝突解決(首先確保數據庫字符集爲utf8mb4):
# 衝突1:key太長 Mysql2::Error: Specified key was too long; max key length is 767 bytes: CREATE INDEX `wiki_pages_wiki_id_title` ON `wiki_pages` (`wiki_id`, `title`) # 解決辦法: $ vim config/initializers/ar_innodb_row_format.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.reverse_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 # 更改mysql配置: $ mysql -uroot -p123456 set global innodb_large_prefix = 1 set global innodb_file_format = barracuda set global innodb_file_per_table = 1 # 然後重新導入數據即可!!! # 參考: # http://www.redmine.org/issues/23586 (個人使用方法1) # 類似問題:http://www.redmine.org/boards/2/topics/54308?r=54309
Note: 數據庫相關配置寫入/etc/my.cnf下,避免服務重啓後配置被還原。
-
-
數據初始化:
$ RAILS_ENV=production bundle exec rake redmine:load_default_data ## 該過程會以交互形式讓用戶選擇語言環境變量,也可以在執行該命令時直接指定環境變量,如下: $ RAILS_ENV=production REDMINE_LANG=zh bundle exec rake redmine:load_default_data
-
文件系統授權: 運行Redmine的用戶需要對以下目錄文件有寫權限。出於安全考慮,app使用普通用戶運行,所以在此需要先創建redmine用戶。授權目錄如下:
- files:存儲附件文件
- log:存放應用日誌
- tmp 和 tmp/pdf:如果目錄文件不存在需要手動創建,用於創建PDF文件
- public/plugin_assets:存放插件
$ mkdir -p /usr/local/src/tmp/pdf /usr/local/src/public/plugin_assets $ chown -R redmine:redmine /usr/local/src/redmine-3.4.6 $ cd /usr/local/src/redmine-3.4.6 # 執行以下操作前請先備份/usr/local/src/redmine-3.4.6 $ chmod -R 755 files log tmp public/plugin_assets # 官方Note: If you have files in these directories (e.g. restore files from backup), make sure these files are not executable.(如果這些目錄下有文件,需要去除其執行權限!!!) $ find files log tmp public/plugin_assets -type f -exec chmod -x {} +
-
測試(該測試不支持生產環境):
$ bundle exec rails server webrick -e production
-
啓動Redmine:
/usr/local/rvm/rubies/ruby-2.3.3/bin/ruby /usr/local/src/redmine-3.4.6/bin/rails server webrick -e production -d
-
加入systemctl管理:
$ vim /usr/lib/systemd/system/redmine.service [Unit] Description=Redmine Control After=syslog.target After=network.target [Service] User=redmine Group=redmine WorkingDirectory=/usr/local/src/redmine-3.4.6/ ExecStart=/usr/local/rvm/rubies/ruby-2.3.3/bin/ruby /usr/local/src/redmine-3.4.6/bin/rails server webrick -e production server webrick -e production Restart=on-failure RestartSec=10 [Install] WantedBy=multi-user.target # 啓動Redmine: $ systemctl start redmine
-
衝突解決:
# 衝突: Sep 26 00:06:24 host3 ruby: /usr/local/rvm/rubies/ruby-2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.5/lib/bundler/spec_set.rb:91:in `block in material ize': Could not find rmagick-2.16.0 in any of the sources (Bundler::GemNotFound) # 原因:在本地找不到gem文件 # 解決辦法: $ bundle install --path vendor/cache # 將gem緩存到本地
-
-
檢查Redmine運行狀態:
Note: Due to a change in Rack,
rails server
now listens onlocalhost
instead of0.0.0.0
by default. Thisshould have minimal impact on the standard development workflow as both
http://127.0.0.1:3000 and http://localhost:3000 will continue to work as before
on your own machine.
However, with this change you will no longer be able to access the Rails
server from a different machine, for example if your development environment
is in a virtual machine and you would like to access it from the host machine.
In such cases, please start the server with
rails server -b 0.0.0.0
torestore the old behavior.
即, 新版本的Redmine啓動後默認監聽localhost,如果要通過外網訪問,需要在啓動時指定其監聽的ip。如果不指定,需要在本機配置代理(nginx/httpd)。
本文來源: vendor/cache/ruby/2.3.0/gems/rails-4.2.8/guides/source/4_2_release_notes.md
# 檢測方法1: $ curl http://192.168.228.130:3000 -I # 返回200狀態碼 # 檢測方法2:配置代理,通過瀏覽器訪問 ## nginx相關配置如下: $ cat /usr/local/nginx/conf/servers/redmine/upstream.conf upstream backserver { server 127.0.0.1:3000; } $ cat /usr/local/nginx/conf/servers/redmine/site.conf server { listen 80; server_name redmine.localhost.com; location / { #配置代理 proxy_pass http://backserver; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } # 在瀏覽器訪問192.168.228.130 (注意,在測試環境使用該方法測試的前提是保證該虛擬主機爲當前nginx服務器的默認虛擬主機,否則需要配置獨立域名),結果如下:
至此,Redmine安裝完成!
配置及使用
登錄
初始管理員用戶名:admin 密碼:admin
首次登陸後會要求更改管理員密碼:
更改密碼(12345678)後可以看到管理員用戶的相關信息:
功能介紹
管理員可以通過web界面直接管理Redmine大部分配置:
-
基礎配置:
-
郵件服務:
-
Note: 郵件通知功能需要登錄服務器編輯配置文件
config/configuration.yml
開啓配置後方可在此編輯。email_delivery: delivery_method: :sendmail # 在此使用sendmail作爲郵件服務器 # ==== Simple SMTP server at localhost (使用本地郵件服務器) # # email_delivery: # delivery_method: :smtp # smtp_settings: # address: "localhost" # port: 25 # # ==== SMTP server at example.com using LOGIN authentication and checking HELO for foo.com (使用指定的郵件服務器) # # email_delivery: # delivery_method: :smtp # smtp_settings: # address: "example.com" # port: 25 # authentication: :login # domain: 'foo.com' # user_name: 'myaccount' # password: 'password'
參考: http://www.redmine.org/projects/redmine/wiki/EmailConfiguration
配置完成後,重啓服務,web訪問如下:
-
-
ldap認證: 如果公司使用ldap管理員工賬號,Redmine內置了ldap集成功能,配置方法如下。
-
數據備份及恢復:
- 數據庫備份(stored in your redmine database)
- 附件備份 (stored in the
files
directory of your Redmine install) - 參考: http://www.redmine.org/projects/redmine/wiki/RedmineBackupRestore
忘記管理員密碼
因爲長時間不用,忘記了管理員密碼,且部署時更改初始密碼後沒記錄,所以需要通過後臺來重置密碼,方法如下:
# 進入部署目錄
$ cd /usr/local/src/redmine-3.4.6/
# 進入ruby
$ ./bin/rails console production
進入ruby後操作:
# 獲取要修改的用戶
2.3.0 :001 > admin_user = User.find_by_login('admin')
# 設置新密碼
2.3.0 :005 > admin_user.password='12345678' # 注:此處密碼最小8位
# 保存
2.3.0 :006 > admin_user.save!
=> true
# 退出
2.3.0 :007 > quit
然後再web端重新登錄即可!
Redmine安裝插件
往往隨着需求的不斷調整,對於功能的要求也就越來越多,所以作爲運維,隨時都面臨着對已有工具升級、打補丁、裝插件等工作。
- Redmineg官方插件 下載地址 ,更多的插件可以到github查找並下載, 示例 。
- 安裝插件(以插件redmine_angile爲例):
- 下載插件到
$(REDMINE_ROOT)/plugins/
下,並解壓; - 安裝依賴的gems包(需要先切換至Redmine運行目錄):
cd $(REDMINE_ROOT) && bundle install --without development test --no-deployment --path vendor/cache
; - 切換至redmine用戶 (必須有該操作,否則將因文件權限問題導致服務不可用);
- 更新數據庫
bundle exec rake redmine:plugins NAME=redmine_agile RAILS_ENV=production
;- 衝突: 如果出現“找不到“.bundle/ ”文件”的錯誤信息,原因是執行命令時所在路徑不對,切換至
/usr/local/src/redmine
重新執行即可!
- 衝突: 如果出現“找不到“.bundle/ ”文件”的錯誤信息,原因是執行命令時所在路徑不對,切換至
- 重啓Redmine服務
systemctl restart redmine
;
- 下載插件到
- 配置插件:
- 查看插件功能:
- 參考: