Redmine là một công cụ quản lý dự án dựa trên web miễn phí và mã nguồn mở. Nó được viết bằng Ruby on Rails và hỗ trợ nhiều máy chủ cơ sở dữ liệu để lưu trữ cơ sở dữ liệu. Nó là một ứng dụng giàu tính năng hỗ trợ nhiều dự án, ACL dựa trên vai trò và hệ thống theo dõi vấn đề. Nó cũng có biểu đồ và hỗ trợ lịch Gantt, quản lý tệp, theo wiki và diễn đàn dự án, cũng như nhiều tính năng khác. Nó hỗ trợ các hệ thống kiểm soát phiên bản như Git, SVN hoặc CVS. Nó cũng là đa ngôn ngữ, hỗ trợ tới 49 ngôn ngữ.
Điều kiện tiên quyết
- Một phiên bản máy chủ Vultr Ubuntu 16.04.
- Một người dùng sudo .
- Một tên miền chỉ về phía máy chủ.
Đối với hướng dẫn này, chúng tôi sẽ sử dụng 192.168.1.1làm địa chỉ IP công cộng và redmine.example.com làm tên miền được chỉ vào đối tượng Vultr. Vui lòng đảm bảo thay thế tất cả các lần xuất hiện của tên miền và địa chỉ IP mẫu bằng tên thực tế.
Cập nhật hệ thống cơ sở của bạn bằng hướng dẫn Cách cập nhật Ubuntu 16.04 . Khi hệ thống của bạn đã được cập nhật, hãy tiến hành cài đặt các phụ thuộc.
Cài đặt Apache
Redmine được viết bằng Ruby on Rails, do đó chúng tôi sẽ yêu cầu Phusion Pasbah tích hợp với máy chủ web Apache để phục vụ ứng dụng.
Cài đặt Apache.
sudo apt -y install apache2 apache2-dev libcurl4-openssl-dev
Để xây dựng Ruby và Hành khách, chúng ta cũng sẽ cần một số công cụ phát triển. Cài đặt các công cụ cần thiết.
sudo apt -y install imagemagick libmagickwand-dev git build-essential automake libgmp-dev
Cài đặt PostgreSQL
Redmine hỗ trợ nhiều loại máy chủ cơ sở dữ liệu như MySQL, PostgreSQL và MSSQL. Trong hướng dẫn này, chúng tôi sẽ sử dụng PostgreSQL để lưu trữ máy chủ cơ sở dữ liệu Redmine.
PostgreSQL là một hệ thống cơ sở dữ liệu quan hệ đối tượng. Kho lưu trữ Ubuntu mặc định chứa phiên bản cũ của PostgreSQL, vì vậy hãy thêm kho lưu trữ PostgreQuery vào hệ thống.
echo "deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt update
Cài đặt máy chủ cơ sở dữ liệu PostgreSQL.
sudo apt -y install postgresql
Khởi động máy chủ PostgreSQL và cho phép nó khởi động tự động khi khởi động.
sudo systemctl start postgresql
sudo systemctl enable postgresql
Thay đổi mật khẩu cho người dùng PostgreSQL mặc định.
sudo passwd postgres
Đăng nhập với tư cách người dùng PostgreSQL.
sudo su - postgres
Tạo một người dùng PostgreSQL mới cho Redmine.
createuser redmine
Bạn được phép sử dụng bất kỳ tên người dùng thay vì redmine. PostgreSQL cung cấp psql shell để chạy các truy vấn trên cơ sở dữ liệu. Chuyển sang trình bao PostgreSQL.
psql
Đặt mật khẩu cho người dùng mới được tạo cho cơ sở dữ liệu Redmine.
ALTER USER redmine WITH ENCRYPTED password 'DBPassword';
Thay thế DBPassword bằng mật khẩu an toàn. Tạo một cơ sở dữ liệu mới để cài đặt Redmine.
CREATE DATABASE redmine WITH ENCODING='UTF8' OWNER=redmine;
Thoát khỏi psql vỏ.
\q
Chuyển sang sudo người dùng.
exit
Cài đặt thêm một vài phụ thuộc PostgreSQL cần thiết.
sudo apt -y install libpqxx-dev protobuf-compiler
Cài đặt Ruby
Chúng tôi sẽ cài đặt phiên bản mới nhất của Ruby bằng RVM. Nó được sử dụng để cài đặt và quản lý nhiều phiên bản của Ruby.
Thêm kho RVM.
sudo apt-add-repository -y ppa:rael-gc/rvm
sudo apt update
Cài đặt RVM.
sudo apt -y install rvm
Khi chúng tôi cần cài đặt hệ thống Ruby rộng, chúng tôi sẽ tạm thời chuyển sang người dùng root.
sudo -i
Cập nhật các biến môi trường.
echo "source /etc/profile.d/rvm.sh" | tee -a /etc/profile
source /etc/profile.d/rvm.sh
Cài đặt phiên bản mới nhất của Ruby.
rvm install 2.5.1
Lưu ý: Nếu bạn đang sử dụng một phiên bản Ruby khác, hãy đảm bảo cập nhật đường dẫn Ruby phù hợp.
Sử dụng phiên bản cài đặt của Ruby.
rvm use 2.5.1 --default
Bạn có thể xác minh phiên bản của nó.
ruby -v
Bạn sẽ thấy một đầu ra tương tự.
root@vultr:~# ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
Cài đặt bundler, là trình quản lý phụ thuộc cho ứng dụng Ruby.
gem install bundler
Ruby is now installed. Before we install Redmine, we will need to install Phusion Passenger.
Install Passenger
Run the following command to install Passenger.
gem install passenger
Install the Apache module for Passenger.
passenger-install-apache2-module
The installer script will ask you some questions. First, it will provide you information about the installation process. Then, it will ask you to select the language which you will be using. Since our application is written in Ruby on Rails, select Ruby from the menu and press ENTER to proceed further.
Which languages are you interested in?
Use <space> to select.
If the menu doesn't display correctly, press '!'
‣ ⬢ Ruby
⬢ Python
⬡ Node.js
⬡ Meteor
The installer will now check for requirements. The installer will not encounter any missing dependencies and will automatically proceed to compile and install the module.
Once the module is installed, it will prompt you to add the module to the Apache configuration file.
Almost there!
Please edit your Apache configuration file, and add these lines:
LoadModule passenger_module /usr/share/rvm/gems/ruby-2.5.1/gems/passenger-5.2.3/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /usr/share/rvm/gems/ruby-2.5.1/gems/passenger-5.2.3
PassengerDefaultRuby /usr/share/rvm/gems/ruby-2.5.1/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.
We will skip this for now and will complete it later in the tutorial. Press ENTER to skip this step.
Finally, the installer script will validate the installation and you will see a warning saying the Passenger module is not specified in Apache configuration.
Validating installation...
* Checking whether this Passenger install is in PATH... ✓
* Checking whether there are no other Passenger installations... ✓
* Checking whether Apache is installed... ✓
* Checking whether the Passenger module is correctly configured in Apache... (!)
You did not specify 'LoadModule passenger_module' in any of your Apache
configuration files. Please paste the configuration snippet that this
installer printed earlier, into one of your Apache configuration files, such
as /etc/apache2/apache2.conf.
Detected 0 error(s), 1 warning(s).
Press ENTER to continue.
Now that we have installed the Passenger module for Apache, proceed to download and install Redmine. Switch to the sudo user again since we do not need to run any more commands using root user.
exit
Install Redmine
It is recommended to use an unprivileged user to run the application to keep it isolated from rest of the system. Create a new user for Redmine and switch to the newly created user.
sudo adduser --disabled-password --gecos "Redmine User" redmine
sudo su - redmine
Download the latest version of Redmine from the official Redmine download page.
cd ~
wget http://www.redmine.org/releases/redmine-3.4.4.tar.gz
Extract the archive and rename the directory for the sake of convenience.
tar -xf redmine-*.tar.gz
mv redmine-*/ redmine/
Copy the example configuration files to its production location.
cd redmine
cp config/configuration.yml.example config/configuration.yml
cp config/database.yml.example config/database.yml
Open the database configuration file we just copied to enter the database details.
nano config/database.yml
By default, the database file is configured for MySQL. Find the configurations for production and development, and test which uses the MySQL adapter. Comment out all of these lines.
#production:
# adapter: mysql2
# database: redmine
# host: localhost
# username: root
# password: ""
# encoding: utf8
#development:
# adapter: mysql2
# database: redmine_development
# host: localhost
# username: root
# password: ""
# encoding: utf8
#test:
# adapter: mysql2
# database: redmine_test
# host: localhost
# username: root
# password: ""
# encoding: utf8
Furthur, find the lines which are commented, having production configuration for the postgresql adapter. Uncomment those lines and update the database name and user credentials. Make sure to use the correct indentation, which is two spaces.
production:
adapter: postgresql
database: redmine
host: localhost
username: redmine
password: "DBPassword"
Configure the application to use the PostgreSQL configuration.
bundle config build.pg --with-pg-config=/usr/bin/pg_config
Install the dependencies required by the application.
bundle install --path vendor/bundle --without development test
You will see the following message at the end of the installation.
Installing roadie-rails 1.1.1
Bundle complete! 31 Gemfile dependencies, 55 gems now installed.
Gems in the groups development and test were not installed.
Bundled gems are installed into `./vendor/bundle`
The following command generates secret tokens that are used to encode the session data.
bundle exec rake generate_secret_token
Write the PostgreSQL database.
RAILS_ENV=production bundle exec rake db:migrate
Run the following command, which writes the default data into PostgreSQL database.
RAILS_ENV=production bundle exec rake redmine:load_default_data
The above command will ask you to choose the default language to be used with the application. The default choice is English; choose according to your preference.
[redmine@vultr redmine]$ 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]
====================================
Default configuration data loaded.
Installation of the Redmine application is now finished. Change ownership and permissions of the directories and files.
mkdir -p tmp tmp/pdf public/plugin_assets
chown -R redmine:redmine files log tmp public/plugin_assets
chmod -R 755 files log tmp public/plugin_assets
We have configured everything we need from the non-privileged user. Switch back to the sudo user by running su - <username>.
Add the Passenger module for Apache into the Apache configuration file. This will automatically load the Passenger module.
echo "LoadModule passenger_module /usr/share/rvm/gems/ruby-2.5.1/gems/passenger-5.2.3/buildout/apache2/mod_passenger.so" | sudo tee -a /etc/apache2/apache2.conf
Note: The path to the Passenger module may change when there is a new release of Passenger. To find the path to the module, use the sudo find / -name mod_passenger.so command.
Create a new virtual host file for your Redmine application.
sudo nano /etc/apache2/sites-available/redmine.conf
Populate the file with the following content.
<VirtualHost *:80>
ServerName redmine.example.com
DocumentRoot /home/redmine/redmine/public
PassengerRoot /usr/share/rvm/gems/ruby-2.5.1/gems/passenger-5.2.3
PassengerDefaultRuby /usr/share/rvm/gems/ruby-2.5.1/wrappers/ruby
PassengerUser redmine
<Directory /home/redmine/redmine/public>
Allow from all
Options -MultiViews
Require all granted
</Directory>
</VirtualHost>
Make sure to replace redmine.example.com with your actual domain name. Also, make sure that the path to the PassengerRoot and PassengerDefaultRuby are correct. The path to the binaries may change when there is a new release of Ruby or Passenger. To find these paths, run the following command.
passenger-config about ruby-command
You will get following output.
user@vultr:~$ passenger-config about ruby-command
passenger-config was invoked through the following Ruby interpreter:
Command: /usr/share/rvm/gems/ruby-2.5.1/wrappers/ruby
Version: ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
To use in Apache: PassengerRuby /usr/share/rvm/gems/ruby-2.5.1/wrappers/ruby
To use in Nginx : passenger_ruby /usr/share/rvm/gems/ruby-2.5.1/wrappers/ruby
To use with Standalone: /usr/share/rvm/gems/ruby-2.5.1/wrappers/ruby /usr/share/rvm/gems/ruby-2.5.1/gems/passenger-5.2.3/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'.
Once the Virtual host file is created. Activate the configuration.
sudo a2ensite redmine
Restart the Apache web server.
sudo systemctl restart apache2
You can now access your Redmine interface on http://redmine.example.com. Login with the username admin, and the password admin. On your first login, Redmine will prompt you to update the password.
Securing Apache with Let's Encrypt SSL
Since our Redmine installation is on a public facing server, it is recommended to use SSL to secure the exchange of the data from the server.
Add the Certbot repository.
sudo add-apt-repository --yes ppa:certbot/certbot
sudo apt-get update
Install Certbot, which is the client application for Let's Encrypt CA.
sudo apt -y install certbot
Note: To obtain certificates from Let's Encrypt CA, the domain for which the certificates are to be generated must be pointed towards the server. If not, make the necessary changes to the DNS records of the domain and wait for the DNS to propagate before making the certificate request again. Certbot checks the domain authority before providing the certificates.
Generate the SSL certificates.
sudo certbot certonly --webroot -w /home/redmine/redmine/public -d redmine.example.com
The generated certificates are likely to be stored in /etc/letsencrypt/live/redmine.example.com/. The SSL certificate will be stored as cert.pem and private key will be stored as privkey.pem.
Let's Encrypt certificates expire in 90 days, hence it is recommended to set up auto-renewal of the certificates using Cron jobs.
Open the Cron job file for the root user.
sudo crontab -e
Add the following line at the end of the file.
30 5 * * * /usr/bin/certbot renew --quiet
The above Cron job will run every day at 5:30 AM. If the certificate is due for expiration, it will automatically be renewed.
Enable the SSL module for Apache.
sudo a2enmod ssl
Edit the virtual host file we created earlier for Redmine.
sudo nano /etc/apache2/sites-available/redmine.conf
Modify the Virtual host file to be similar to the following.
<VirtualHost *:80>
ServerName redmine.example.com
Redirect permanent / https://redmine.example.com/
</VirtualHost>
<VirtualHost *:443>
ServerAdmin [email protected]
ServerName redmine.example.com
DocumentRoot "/home/redmine/redmine/public"
<Directory "/home/redmine/redmine/public">
Options None
Require all granted
</Directory>
PassengerAppEnv production
PassengerRoot /usr/share/rvm/gems/ruby-2.5.1/gems/passenger-5.2.3
PassengerDefaultRuby /usr/share/rvm/gems/ruby-2.5.1/wrappers/ruby
PassengerUser redmine
PassengerHighPerformance on
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/redmine.example.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/redmine.example.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/redmine.example.com/chain.pem
SSLProtocol all -SSLv2 -SSLv3
SSLHonorCipherOrder on
SSLCipherSuite ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS
<IfModule headers_module>
Header always edit Set-Cookie ^(.*)$ $1;HttpOnly;Secure
Header always set Strict-Transport-Security "max-age=15768000; includeSubDomains"
</IfModule>
</VirtualHost>
Save the file and exit from the editor.
Restart Apache so that the changes can take effect.
sudo systemctl restart apache2
You can now access Redmine over HTTPS at https://redmine.example.com.
Congratulations, you have successfully installed Redmine on your Ubuntu 16.04 instance. Start developing your project either by creating or importing your project.