15分でRedmineをインストール(RVM + RoR + Unicorn + Nginx)

この記事は、さまざまなソース (公式の指示を含む)からのRedmineを使用したLinux OSに基づくサーバーのインストールと自動化に関する作業の結果であり、いくつかのコマンドと一連のアクションは他のソースから取得されました。使用されているすべてのソースは、記事の最後に示されています。





前書き

一般的に、タスクは次のように聞こえました:  nginx上のWebサーバーを備えたサーバーにRedmineをインストールします





以来 Redmineのがさ で書かれ RoRのは、RoRの環境を持っていることが必要であるが、問題があることを 別のRoRのアプリケーションは、環境の異なるバージョンを必要とするかもしれません私の場合、異なる環境でRoRアプリケーションをインストールする可能性を提供する必要がありました。つまり、必要な環境を適切な場所にデプロイするバージョンマネージャーが必要 です。





RVM は、インタプリタバージョンからジャムに至るまで、ルビー環境のバージョンマネージャーです。同じサーバー上で異なるRoRアプリケーション実行するために必要で あり、異なるランタイム環境が必要になる場合があります。





また、nginx上のWebサーバーのクラシックバージョンも必要でした。ただし、nginxはアプリケーションの実行方法を認識しておらず、この場合、アプリケーションの実行中のRoRWebサーバーへのプロキシとして機能します。





Unicorn は、Rack  (およびRoRを含む)アプリケーション用のWebサーバー です。何らかの理由で、私はpassengerを使いたくありませんでした 。おそらくnginxはpassengerコンパイルする必要があるため 、つまり純粋なnginxではありません。また、UnicornはRoRアプリケーションごとに異なる可能性があり、1つのグローバルアプリケーションでは異なる可能性があるため です。





これで、 タスク がより明確 になります。サーバーにRedmineをインストールし、RoR + Unicorn + Nginxスタックをデプロイして、自動起動します。





トレーニング

ipv6を無効にする

: ,  :)





VPS Ubuntu 16.04  apt-get install



   ipv6



:





0% [Connecting to archive.ubuntu.com (2001:67c:1562::15)]
      
      



: ipv6   /etc/sysctl.conf:





echo '' >> /etc/sysctl.conf
echo 'net.ipv6.conf.all.disable_ipv6 = 1' >> /etc/sysctl.conf
echo 'net.ipv6.conf.default.disable_ipv6 = 1' >> /etc/sysctl.conf
echo 'net.ipv6.conf.lo.disable_ipv6 = 1' >> /etc/sysctl.conf
sysctl -p
      
      



curl   RVM (Ruby Version Manager):





apt-get install curl
      
      



:  :)





Midnight Commander ( ):





apt-get install mc
      
      



Nano ( ):





apt-get install nano
      
      



Redmine

  Redmine 4.1.1.  /opt/



    redmine   :





wget --no-check-certificate https://www.redmine.org/releases/redmine-4.1.1.tar.gz
tar xvzf redmine-4.1.1.tar.gz
mv redmine-4.1.1 redmine
rm redmine-4.1.1.tar.gz
      
      



Redmine: /opt/redmine/







 1000



,  www-data



 (  www-data



):





chown -R www-data /opt/redmine/
      
      



PostgreSQL

PostgreSQL!





, redmine -  PostgreSQL >9.2.





:





apt policy postgresql
      
      



:





postgresql:
  Installed: (none)
  Candidate: 9.5+173ubuntu0.3
  Version table:
     9.5+173ubuntu0.3 500
        500 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages
        500 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages
     9.5+173 500
        500 http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages
      
      



, .





apt install postgresql
      
      



PostgreSQL ( , postgres psql), :





sudo -i -u postgres
# su postgres
psql
      
      



CREATE ROLE redmine LOGIN ENCRYPTED PASSWORD 'password' NOINHERIT VALID UNTIL 'infinity';
CREATE DATABASE redmine WITH ENCODING='UTF8' OWNER=redmine;
ALTER DATABASE "redmine" SET datestyle="ISO,MDY";
      
      



 \q







PostgreSQL, GitLab ( PostgreSQL), .





My SQL

MySQL!





MySQL:





apt-get install mysql-server
      
      



mysql:





mysql -u root -p
      
      



MySQL < 8.0   redmine, , :





CREATE DATABASE redmine CHARACTER SET utf8mb4;
CREATE USER 'redmine'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON redmine.* TO 'redmine'@'localhost';
      
      



, MySQL >= 8.0  mysqlnativepassword (  ):





ALTER USER 'redmine'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
      
      



MySQL 8, MySQL.





RVM

 gnupg2  RVM:





apt install gnupg2
gpg2 --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
      
      



 /opt/



  rvm :





curl -sSL https://get.rvm.io -o rvm.sh
      
      



:





wget --output-document=rvm.sh https://get.rvm.io
      
      



RVM (  /opt/



):





cat rvm.sh | bash -s stable --rails
      
      



RVM  rvm



,  www-data



 ( RVM):





usermod -a -G rvm www-data
      
      



Ruby On Rails  (   ):





source /usr/local/rvm/scripts/rvm
      
      



Redmine 4.1.1, Ruby [2.3, 2.6]



. RVM:





rvm list known
      
      



, :





[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p648]
[ruby-]2.1[.10]
[ruby-]2.2[.10]
[ruby-]2.3[.8]
[ruby-]2.4[.9]
[ruby-]2.5[.7]
[ruby-]2.6[.5]
[ruby-]2.7[.0]
      
      



 Ruby 2.6.5



, :





rvm install 2.6.5
rvm use 2.6.5
      
      



  Redmine:





rvm gemset create redmine
echo "rvm use ruby-2.6.5@redmine" > /opt/redmine/.rvmrc
      
      



 /opt/redmine/



  ,  ruby-2.6.5@redmine



:





Using /usr/local/rvm/gems/ruby-2.6.5 with gemset redmine
      
      



Redmine

 /opt/redmine/config/database.yml.sample



    . :





touch /opt/redmine/config/database.yml
      
      



:





production:
  adapter: postgresql
  database: redmine
  host: localhost
  username: redmine
  password: password
      
      



RoR :





bundle
      
      



RoR .





PostgreSQL  bundle



   pg



:





Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
...
Gem files will remain installed in /usr/local/rvm/gems/ruby-2.6.5/gems/pg-1.1.4
for inspection.
Results logged to
/usr/local/rvm/gems/ruby-2.6.5/extensions/x86_64-linux/2.6.0/pg-1.1.4/gem_make.out
 
An error occurred while installing pg (1.1.4), and Bundler cannot
continue.
Make sure that gem install pg -v '1.1.4' --source 'https://rubygems.org/'
succeeds before bundling.
      
      



 , :





apt-get install libpq-dev
      
      



MySQL mysql2 ( PostgreSQL).  , :





apt-get install build-essential ruby-dev libmysqlclient-dev
      
      



 nokogiri,  , :





apt-get install build-essential patch ruby-dev zlib1g-dev liblzma-dev
gem install nokogiri
      
      



 bundle







 5-, 6- 7-    :





bundle exec rake generate_secret_token
RAILS_ENV=production bundle exec rake db:migrate
RAILS_ENV=production REDMINE_LANG=ru bundle exec rake redmine:load_default_data
      
      







Redmine  webrick:





bundle exec rails server webrick -e production
      
      



, 3000  (localhost:3000



  ip:3000



).





webrick, .





Unicorn

 /opt/redmine/GemFile



  :





gem 'unicorn'
      
      



unicorn:





touch /opt/redmine/config/unicorn.rb
      
      



:





#    
app_dir = File.expand_path("../..", __FILE__)
shared_dir = "#{app_dir}/shared"
working_directory app_dir
 
#    unicorn
worker_processes 2
preload_app true
timeout 30
 
#     nginx
listen "#{shared_dir}/sockets/unicorn.sock", :backlog => 64
 
#   
stderr_path "#{shared_dir}/log/unicorn.stderr.log"
stdout_path "#{shared_dir}/log/unicorn.stdout.log"
 
#  pid ,      unicorn (    )
pid "#{shared_dir}/pids/unicorn.pid"
 
before_fork do |server, worker|
    defined?(ActiveRecord::Base) and
        ActiveRecord::Base.connection.disconnect!
end
 
after_fork do |server, worker|
    defined?(ActiveRecord::Base) and
        ActiveRecord::Base.establish_connection
end
      
      



:





bundle
      
      



:





mkdir -p /opt/redmine/shared/pids /opt/redmine/shared/sockets /opt/redmine/shared/log
chown -R www-data:rvm shared
      
      



 bundle



 ( ), unicorn (  /opt/redmine/



):





unicorn_rails -c config/unicorn.rb -E production -D
      
      



unicorn  pid



:





pkill -QUIT --pidfile /opt/redmine/shared/pids/unicorn.pid
      
      



  Unicorn.





Nginx

nginx:





apt-get install nginx
      
      



nginx (  /etc/nginx/nginx.conf



),  http



 ( ):





upstream redmine {
    server unix:/opt/redmine/shared/sockets/unicorn.sock fail_timeout=0;
}
 
server {
    listen 80;
    root /opt/redmine/public;
    try_files $uri/index.html $uri @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;
    }
}
      
      



( Redmine ip ):





user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
 
events {
  worker_connections 768;
}
 
http {
  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;
  keepalive_timeout 65;
  types_hash_max_size 2048;
 
  server_names_hash_bucket_size 64;
 
  include /etc/nginx/mime.types;
  default_type application/octet-stream;
 
  # Logging Settings
  access_log /var/log/nginx/access.log;
  error_log /var/log/nginx/error.log;
 
  # Gzip Settings
  gzip on;
 
  upstream redmine {
    server unix:/opt/redmine/shared/sockets/unicorn.sock fail_timeout=0;
  }
 
  server {
    listen 80;
    root /opt/redmine/public;
    try_files $uri/index.html $uri @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;
    }
  }
}
      
      



nginx:





service nginx restart
      
      



nginx ,  ip



  (  localhost



), Redmine .





 ( Unicorn), Unicorn , .





,    .





 /etc/systemd/system/



   redmine.service



:





touch /etc/systemd/system/redmine.service
      
      



:





[Unit]
Description=redminerun
After=syslog.target network.target
 
[Service]
Type=forking
PIDFile=/opt/redmine/shared/pids/unicorn.pid
WorkingDirectory=/opt/redmine/
User=www-data
Group=rvm
Environment=RAILS_ENV=production
ExecStart=/opt/redmine/config/unicorn_start
ExecReload=/opt/redmine/config/unicorn_reload
ExecStop=/opt/redmine/config/unicorn_stop
OOMScoreAdjust=-100
TimeoutSec=30
Restart=always
RestartSec=20s
 
[Install]
WantedBy=multi-user.target
      
      



:





  • PIDFile - pid



    ,





  • User Group - ,





  • ExecStart -





  • ExecReload -





  • ExecStop -





  • RestartSec - N





ExecStart



ExecReload



ExecStop



  bash .  ( / , :))





 /opt/redmine/config/



  , :





cd /opt/redmine/config/
touch unicorn_start unicorn_reload unicorn_stop
chown www-data:rvm unicorn_*
chmod +x unicorn_*
      
      



unicorn_start



  unicorn ( rvm



, redmine - , unicorn):





#!/bin/bash -
 
source /usr/local/rvm/scripts/rvm
cd /opt/redmine/
unicorn_rails -c config/unicorn.rb -E production -D
      
      



unicorn_stop



  :





#!/bin/bash -
 
pkill -QUIT --pidfile /opt/redmine/shared/pids/unicorn.pid
      
      



unicorn_reload



   ( ):





#!/bin/bash -
 
/opt/redmine/config/unicorn_stop
/opt/redmine/config/unicorn_start
      
      



:





systemctl status redmine
 
● redmine.service - redminerun
   Loaded: loaded (/etc/systemd/system/redmine.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
      
      



:





systemctl enable redmine
      
      



 start



/reload



/stop



.





:





systemctl start redmine
      
      



, ,   Unicorn - !









著者:Vitaly Buturlin








All Articles