Cet article est le résultat d'un travail d'installation et d'autonomisation d'un serveur basé sur Linux OS avec Redmine à partir de diverses sources (y compris les instructions officielles) , certaines des commandes et la séquence d'actions ont été prises à partir d'autres sources. Toutes les sources utilisées sont indiquées à la fin de l'article.
introduction
En général, la tâche ressemblait à ceci : installer Redmine sur un serveur avec un serveur Web sur nginx .
Puisque Redmine est écrit en RoR , il est nécessaire d'avoir un environnement RoR, mais le problème est que différentes applications RoR peuvent nécessiter différentes versions de l'environnement . Dans mon cas, il était nécessaire de prévoir la possibilité d'installer des applications RoR avec différents environnements, ce qui signifie qu'un gestionnaire de version est nécessaire pour déployer l'environnement requis au bon endroit.
RVM est un gestionnaire de versions d'environnements ruby, allant des versions d'interpréteurs aux jams. Il est nécessaire pour exécuter différentes applications RoR sur le même serveur , ce qui peut nécessiter différents environnements d'exécution.
Je voulais aussi une version classique d'un serveur web sur nginx. Cependant, nginx ne sait pas comment exécuter l'application et, dans ce cas, agit comme un proxy pour le serveur Web RoR en cours d'exécution de l'application.
Unicorn est un serveur Web pour les applications Rack (et y compris RoR). Pour une raison quelconque, je ne voulais pas utiliser de passager , probablement parce que nginx doit être compilé avec passager , c'est-à-dire pas du nginx pur. Et aussi parce que Unicorn peut être différent pour chaque application RoR , et non pour une application globale.
Maintenant, la tâche devient plus claire: installer Redmine sur le serveur, déployer la pile RoR + Unicorn + Nginx, avec lancement automatique .
Formation
Désactiver 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
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
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 - !
Ruby on Rails ruby (Nginx + Unicorn)
Rails- Unicorn Nginx Ubuntu 14.04
-
-
-
-
-
En savoir plus sur l'authentification MySQL
Authentification native enfichable , qu'est-ce que mysql_native_password? , Comme dans MySQL 8.0 pour changer la valeur d'une variable globale default_authentication_plugin?