Dieser Artikel ist das Ergebnis der Arbeit an der Installation und Autonomisierung eines auf Linux basierenden Servers mit Redmine aus verschiedenen Quellen (einschließlich der offiziellen Anweisungen) . Einige der Befehle und die Reihenfolge der Aktionen wurden aus anderen Quellen übernommen. Alle verwendeten Quellen sind am Ende des Artikels angegeben.
Einführung
Im Allgemeinen klang die Aufgabe folgendermaßen : Installieren Sie Redmine auf einem Server mit einem Webserver unter Nginx .
Da Redmine in RoR geschrieben ist, ist eine RoR-Umgebung erforderlich. Das Problem besteht jedoch darin, dass für unterschiedliche RoR-Anwendungen möglicherweise unterschiedliche Versionen der Umgebung erforderlich sind . In meinem Fall musste die Möglichkeit zur Installation von RoR-Anwendungen in verschiedenen Umgebungen vorgesehen werden. Dies bedeutet, dass ein Versionsmanager erforderlich ist , der die erforderliche Umgebung am richtigen Ort bereitstellt.
RVM ist ein Versionsmanager für Ruby-Umgebungen, der von Interpreter-Versionen bis zu Staus reicht. Es wird benötigt, um verschiedene RoR-Anwendungen auf demselben Server auszuführen , was möglicherweise unterschiedliche Laufzeitumgebungen erfordert.
Ich wollte auch eine klassische Version eines Webservers auf Nginx. Nginx weiß jedoch nicht, wie die Anwendung ausgeführt werden soll, und fungiert in diesem Fall als Proxy für den ausführenden RoR-Webserver der Anwendung.
Unicorn ist ein Webserver für Rack- Anwendungen (einschließlich RoR-Anwendungen). Aus irgendeinem Grund wollte ich keinen Passagier verwenden , wahrscheinlich weil Nginx mit Passagier kompiliert werden muss, dh nicht reinem Nginx. Und auch, weil Unicorn für jede RoR-Anwendung unterschiedlich sein kann und nicht für eine globale.
Jetzt wird die Aufgabe klarer: Installieren Sie Redmine auf dem Server und stellen Sie den RoR + Unicorn + Nginx-Stack mit automatischem Start bereit .
Ausbildung
Deaktivieren Sie 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
-
-
-
-
-
Weitere Informationen zur MySQL-Authentifizierung
Native Pluggable-Authentifizierung , Was ist mysql_native_password? , Wie in MySQL 8.0, um den Wert einer globalen Variablen default_authentication_plugin zu ändern?