天天看點

centos8 安裝nginx_如何在 CentOS 8 上安裝和配置 Redmine

centos8 安裝nginx_如何在 CentOS 8 上安裝和配置 Redmine

本文最先釋出在:

如何在 CentOS 8 上安裝和配置 Redmine​www.itcoder.tech

Redmine 是一個開源的項目管理和問題跟蹤應用。它是一個跨平台并且跨資料庫的應用,建構于 Ruby on Rails 架構之上。

Redmine 包括多項目支援,wiki,問題跟蹤系統,論壇,月曆,郵件提醒等等。

這個指南講解如何在 CentOS 8 上安裝和配置最新版本的 Redmine。 我們将會使用MariaDB作為資料庫 和 Passenger + Apache 作為 Ruby 應用伺服器。

一、前提條件

確定你滿足下面的條件:

  • 指向你伺服器公網 IP 的域名
  • 以 root 或者其他有 sudo 權限的使用者身份登入

二、建立一個 MySQL資料庫

Redmine 支援MySQL/MariaDB, Microsoft SQL Server, SQLite 3, 和 PostgreSQL。我們将會選擇 MariaDB 作為資料庫後端。

如果你沒有在你的 CentOS 系統上安裝 MariaDB 或者 MySQL,你可以按照下面的指令安裝它. https://linuxize.com/post/how-to-install-mariadb-on-centos-8/

使用下面的指令,登入 MySQL shell:

sudo mysql
           

在MySQL shell,運作下面的SQL 表達式來建立資料庫,建立使用者,并且給使用者授權:

CREATE DATABASE redmine CHARACTER SET utf8;
GRANT ALL ON redmine.* TO 'redmine'@'localhost' IDENTIFIED BY 'change-with-strong-password';
確定你将 change-with-strong-password 替換成一個強密碼。
           

一旦完成,退出 MySQL shell:

EXIT;
           

三、 安裝 Passenger, Apache and Ruby

Passenger 是一個很快速,輕量的網絡應用伺服器,适用于Ruby, Node.js, and Python,它還可以與Apache 、 Nginx內建。

我們将會安裝 Passenger 作為一個 Apache 子產品。

啟用 EPEL repository:

sudo dnf install epel-release
sudo dnf config-manager --enable epel
           

一旦源被啟用,更新軟體包清單,并且安裝 Ruby,Apache 和 Passenger:

sudo dnf install httpd mod_passenger passenger passenger-devel ruby
           

開啟 Apache 服務并且啟用開機啟動:

sudo systemctl enable httpd --now
           

四、 建立新系統使用者

建立一個新的使用者和使用者組,主目錄為

/opt/redmine

,用于運作 Redmine 執行個體:

sudo useradd -m -U -r -d /opt/redmine redmine
           

添加

apache

使用者到 redmine使用者組,并且修改

/opt/redmine

目錄權限以便 Apache 能夠通路它:

sudo usermod -a -G redmine apache
sudo chmod 750 /opt/redmine
           

五、安裝 Redmine

在寫作的時候,Redmine最新穩定版本是 4.1.0

在繼續下一步之前,浏覽 Redmine下載下傳頁面,看看有沒有更新的版本可用。

安裝 建構 Redmine 所需要的 GCC 編譯器和庫:

sudo dnf group install "Development Tools"
sudo dnf install zlib-devel curl-devel openssl-devel mariadb-devel ruby-devel
           

确定你使用

redmine

使用者運作下面的步驟:

sudo su - redmine
           

5.1 下載下傳 Redmine

使用

curl

下載下傳 Redmine 壓縮包:

curl -L http://www.redmine.org/releases/redmine-4.1.0.tar.gz -o redmine.tar.gz
           

一旦下載下傳完成,解壓這個壓縮包:

tar -xvf redmine.tar.gz
           

5.2 配置 Redmine 資料庫

拷貝 Redmine 示例資料庫配置檔案:

cp /opt/redmine/redmine-4.1.0/config/database.yml.example /opt/redmine/redmine-4.1.0/config/database.yml
           

使用文本編輯器打開檔案:

nano /opt/redmine/redmine-4.1.0/config/database.yml
           

搜尋

production

章節,并且輸入我們之前建立的 MySQL 資料庫 和 使用者資訊:

/opt/redmine/redmine-4.1.0/config/database.yml

production:
  adapter: mysql2
  database: redmine
  host: localhost
  username: redmine
  password: "change-with-strong-password"
  encoding: utf8mb4
           

一旦完成,儲存你的檔案,并且退出編輯器。

5.3 安裝 Ruby 依賴

切換到

redmine-4.1.0

目錄并且安裝 Ruby 依賴包:

cd ~/redmine-4.1.0
gem install bundler --no-rdoc --no-ri
bundle install --without development test postgresql sqlite --path vendor/bundle
           

5.4 生成密鑰,并且遷移資料庫

運作下面的指令來生成密鑰,并且遷移資料庫:

bundle exec rake generate_secret_token
RAILS_ENV=production bundle exec rake db:migrate
           

六、配置 Apache

切換回你的 sudo 使用者,并且建立 Apache Vhost檔案:

exit
sudo nano /etc/httpd/conf.d/example.com.conf
           

/etc/httpd/conf.d/example.com.conf

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /opt/redmine/redmine-4.1.0/public

    <Directory /opt/redmine/redmine-4.1.0/public>
        Options Indexes ExecCGI FollowSymLinks
        Require all granted
        AllowOverride all
    </Directory>

    ErrorLog /var/log/httpd/example.com-error.log
    CustomLog /var/log/httpd/example.com-access.log combined
</VirtualHost>
不要忘記将example.com替換成你的 Redmine 域名。
           

重新開機 Apache 服務,輸入:

sudo systemctl restart httpd
           

6.1 配置 Apache SSL

如果你沒有一個可信任的 SSL 證書,你可以按照這些指令,生成一個免費的Let’s Encrypt證書。https://linuxize.com/post/secure-apache-with-let-s-encrypt-on-centos-8/

一旦證書被生成,編輯類似下面的 Apache 配置檔案:

sudo nano /etc/httpd/conf.d/example.com.conf
           

/etc/httpd/conf.d/example.com.conf

<VirtualHost *:80>
  ServerName example.com
  ServerAlias www.example.com

  Redirect permanent / https://example.com/
</VirtualHost>

<VirtualHost *:443>
  ServerName example.com
  ServerAlias www.example.com

  Protocols h2 http:/1.1

  <If "%{HTTP_HOST} == 'www.example.com'">
    Redirect permanent / https://example.com/
  </If>

  DocumentRoot /opt/redmine/redmine-4.1.0/public
  ErrorLog /var/log/httpd/example.com-error.log
  CustomLog /var/log/httpd/example.com-access.log combined

  SSLEngine On
  SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
  SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem

  <Directory /opt/redmine/redmine-4.1.0/public>
    Options Indexes ExecCGI FollowSymLinks
    Require all granted
    AllowOverride all
  </Directory>

</VirtualHost>
不要忘記将example.com替換成你的Redmine域名,設定正确的 SSL 證書檔案路徑。所有的 HTTP 請求都轉向 HTTPS。
           

七、 通路 Redmine

打開你的浏覽器,輸入你的域名,并且如果安裝過程很成功,那麼一個類似下面的界面将會出現:

centos8 安裝nginx_如何在 CentOS 8 上安裝和配置 Redmine

預設的登入憑據如下:

  • 使用者名: admin
  • 密碼: admin

當你第一次登入時,你将會被提示修改密碼,類似下面:

centos8 安裝nginx_如何在 CentOS 8 上安裝和配置 Redmine

一旦你修改了密碼,你将會被轉向使用者頁面。

如果你無法通路頁面,那很可能是你的防火牆阻止了 Apache 端口。

使用下面的指令,來打開必要的端口:

sudo firewall-cmd --permanent --zone=public --add-port=443/tcp
sudo firewall-cmd --permanent --zone=public --add-port=80/tcp
sudo firewall-cmd --reload
           

八、總結

你已經在你的 CentOS 系統上成功地安裝了 Redmine。你現在應該檢視 Redmine 文檔,并且學習如何配置和使用 Redmine。