Artikel ini adalah hasil dari pekerjaan menginstal dan otonomisasi server berbasis OS Linux dengan Redmine dari berbagai sumber (termasuk instruksi resmi) , beberapa perintah dan urutan tindakan diambil dari sumber lain. Semua sumber yang digunakan ditunjukkan di akhir artikel.
pengantar
Secara umum, tugasnya terdengar seperti ini : instal Redmine di server dengan server web di nginx .
Karena Redmine ditulis dalam RoR , maka diperlukan lingkungan RoR, tetapi masalahnya adalah aplikasi RoR yang berbeda mungkin memerlukan versi lingkungan yang berbeda . Dalam kasus saya, itu perlu untuk menyediakan kemungkinan menginstal aplikasi RoR dengan lingkungan yang berbeda, yang berarti bahwa diperlukan pengelola versi yang akan menerapkan lingkungan yang diperlukan di tempat yang tepat.
RVM adalah pengelola versi lingkungan ruby, mulai dari versi penerjemah hingga kemacetan. Ini diperlukan untuk menjalankan aplikasi RoR yang berbeda di server yang sama , yang mungkin memerlukan lingkungan runtime yang berbeda.
Saya juga menginginkan versi klasik dari server web di nginx. Namun, nginx tidak tahu cara menjalankan aplikasi, dan dalam hal ini bertindak sebagai proxy untuk server web RoR yang menjalankan aplikasi.
Unicorn adalah server web untuk aplikasi Rack (dan termasuk RoR). Untuk beberapa alasan, saya tidak ingin menggunakan penumpang , mungkin karena nginx harus dikompilasi dengan penumpang , bukan nginx murni. Dan juga karena Unicorn dapat berbeda untuk setiap aplikasi RoR , dan bukan yang global.
Sekarang tugasnya menjadi lebih jelas: instal Redmine di server, terapkan tumpukan RoR + Unicorn + Nginx, dengan peluncuran otomatis .
Latihan
Nonaktifkan 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
-
-
-
-
-
Beberapa Lebih Banyak Tentang Otentikasi MySQL
Autentikasi Native Pluggable , Apa itu mysql_native_password? , Seperti di MySQL 8.0 untuk mengubah nilai variabel global default_authentication_plugin?