Deploy Redmine on Debian12

2024-08-25 infra Redmine

環境

  • OS: Debain 12
  • DB:
    • 10.192.1.105
    • redmine_db

安裝步驟

sudo apt install -y gnupg2
gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
curl -sSL https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
sudo apt-get install ruby-full
wget https://www.redmine.org/releases/redmine-5.1.3.tar.gz
sudo tar -zxf redmine-5.1.3.tar.gz -C /opt/
cd /opt/
sudo ln -s redmine-5.1.3 redmine
cd /opt/redmine
sudo cp /opt/redmine/config/configuration.yml{.example,}
sudo cp /opt/redmine/public/dispatch.fcgi{.example,}
sudo cp /opt/redmine/config/database.yml{.example,}
  • config/database.yml
production:
  adapter: postgresql
  database: redmine_db
  host: 10.192.1.105
  username: redmineAp
  password: "pollo@redmine**2024%%0826"
sudo gem install bundler
sudo su - redmine
bundle config set --local path 'vendor/bundle'
bundle install
bundle update
gem install io-wait strscan webrick --user-install
bundle exec rake generate_secret_token
RAILS_ENV=production bundle exec rake db:migrate
RAILS_ENV=production REDMINE_LANG=en bundle exec rake redmine:load_default_data
for i in tmp tmp/pdf public/plugin_assets; do [ -d $i ] || mkdir -p $i; done
chown -R redmine:redmine files log tmp public/plugin_assets
chmod -R 755 /opt/redmine
echo 'gem "webrick"' >> Gemfile
bundle install
bundle exec rails server -u webrick -e production
sudo apt install ruby ruby-dev build-essential libpq-dev imagemagick ghostscript

sudo useradd -r -m -d /opt/redmine -s /usr/bin/bash redmine

cd /opt/redmine
sudo chown -R redmine: /opt/redmine-5.1.3
jameschang@lab-redmine-110:/opt/redmine$ sudo gem install bundler
Fetching bundler-2.4.22.gem
Successfully installed bundler-2.4.22
Parsing documentation for bundler-2.4.22
Installing ri documentation for bundler-2.4.22
Done installing documentation for bundler after 0 seconds
1 gem installed
  • /etc/systemd/system/redmine.service
[Unit]
Description=Rails-Puma Webserver

[Service]
Type=simple
User=deploy
WorkingDirectory=/opt/redmine
ExecStart=/bin/bash -lc 'bundle exec rails server -e production'
TimeoutSec=15
Restart=always

User=redmine
Group=redmine
UMask=0027
RestartSec=10
Restart=always

[Install]
WantedBy=multi-user.target
  • nginx
upstream redmine {
    server 127.0.0.1:3000;
}
server {
    listen       80;

    root /opt/redmine/public;

    location ~ /redmine/(stylesheets|javascripts|images|favicon)(.*)$
    {
        proxy_pass http://app/$1$2;
    }

    location /redmine {
        proxy_pass  http://redmine;
    }

    location @redmine {
        proxy_pass http://redmine;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
    }
}

參考資料