[RUBY] Launch multiple Redmine instances on one server

Redmine is crowded

Since Redmine is convenient, we set up a server for each project in-house. Before I knew it, there were more than 30 redmine servers. Of course, we do not set up a physical server for each Redmine, but most create virtual servers on the physical server machine in the company. Even so, if you start up this many virtual servers on one server, it becomes unstable, so the Redmine server of the completed project is turned off. You may think that you can create multiple projects in Redmine without making Redmine so crowded, but since you can not set the permissions of Redmine users in detail and you can not group projects, after all, for each project I have launched Redmine. Furthermore, although Redmine is constantly being upgraded, there are risks associated with upgrading to a running Redmine. The reason (excuse) for avoiding version upgrades is that version dependence such as Redmine / ruby / rails / gem is also intense.

Let's accommodate multiple Redmine on one server

We haven't accommodated multiple Redmines on a single server so far, partly because the official documentation doesn't explain how to do that. Surprisingly, there are few cases where multiple Redmines live together. However, I am prepared that both Redmine and ruby will be stable soon, so I will operate multiple Redmine instances on one server in the future.

First install Redmine

Install Redmine according to the official documentation. Although the official document and old description such as version are included, the OS of the installation environment is CentOS 7, Redmine version is 4.0, Apache + Passenger environment, MariaDB5.5 (MySQL compatible).

http://redmine.jp/install/

I also tried batch installation with BitNami package, but since Apache was a different startup method from CentOS standard, I did not adopt it this time and installed it manually.

Up to this point, ** immediately after Redmine is newly installed with Passanger **, we will proceed. The prerequisite for the following operations is to log in with root privileges and install Redmine in / var / lib / redmine.

Copy the second Redmine

First of all, stop Apache just in case.

# systemctl stop httpd.service

Save the current installed Redmine as a template.

# mv /var/lib/redmine /var/lib/redmine.template

Copy the first Redmine and the second Redmine from the template.

# cp -p -r /var/lib/redmine.template /var/lib/redmine1
# cp -p -r /var/lib/redmine.template /var/lib/redmine2

Create a second Redmine user and database.

# mysql -u root -p 
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 180
Server version: 5.5.64-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> CREATE DATABASE redmine2 CHARACTER SET utf8;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> CREATE USER 'redmine2'@'localhost' IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON redmine2.* TO 'redmine2'@'localhost';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> quit;
Bye

Modify the /var/lib/redmine2/config/database.yml file to match the settings of the second Redmine database.

database.yml


production:
    adapter: mysql2
    database: redmine2
    host: localhost
    username: redmine2
    password: password
    encoding: utf8

Generate a new session protection private key for the second Redmine.

# cd /var/lib/redmine2
# bundle exec rake generate_secret_token

Migrate the second Redmine database (? = Data initialization?). The last line of the third line below seems to be necessary if the plugin is installed. (I didn't do it because I didn't add the plugin)

# cd /var/lib/redmine2
# bundle exec rake db:migrate RAILS_ENV=production
# bundle exec rake redmine:plugins:migrate RAILS_ENV=production

A running message will be played, but if there is no error message at the end, it is complete. If you get an error, make sure you can access the database you just added.

Redmine1 / Redmine2 test

You should now have two Redmines installed independently. To test (but you don't have to), go to each Redmine directory and run Redmine as follows:

# cd /var/lib/redmine1
# bundle exec rails server webrick -e production

You can check the operation of Redmine by setting "http: // * IP address *: 3000" on your PC browser. When you access it, the access status log will be displayed on the server screen on the Redmine side. To exit, press "CTRL + C" on the Redmine side to stop.

Similarly, check the operation of the second Redmine.

# cd /var/lib/redmine2
# bundle exec rails server webrick -e production 

Since it is the same Redmine that is being copied, neither Redmine1 nor Redmine2 can actually be determined. After logging in, rewrite the welcome message to make it easier to identify. This also stops by pressing "CTRL + C" on the Redmine side.

I tested and switched between two Redmines, but they are using the same port, so I can't start them at the same time. To start at the same time, you can start by changing the port, but I will try two methods, Apache's virtual host function and changing the subdirectory to access.

Please select either Case 1 or Case 2 below.

Case 1: Set multiple redmine with virtual host function

Up to this point, independent Redmine1 / Redmine2 can be installed and executed separately. Here, with the virtual host function of Apache,

のアクセスとなるよう設定します。もちろん、DNSサーバーの設定で、redmine1.hogehoge.com/redmine2.hogehoge.comとも同じサーバーを指すようにAレコードまたはCNAMEの設定が必要です。

After confirming the DNS settings and reflection, change the Apache configuration file. Add the following changes to the end of httpd.conf.

/etc/httpd/conf/httpd.conf


・
・
##Additions and changes from here

#Server default document root settings
<VirtualHost *:80>
 ServerName 127.0.0.1
 DocumentRoot /var/www/html
</VirtualHost>

# Redmine1(redmine1.hogehoge.com)settings of

<Directory "/var/lib/redmine1/public">
  Require all granted
</Directory>

<VirtualHost *:80>
 ServerName redmine1.hogehoge.com
 DocumentRoot "/var/lib/redmine1/public"
 PassengerAppRoot /var/lib/redmine1
 RailsBaseURI /
</VirtualHost>

# Redmine2(redmine2.hogehoge.com)settings of

<Directory "/var/lib/redmine2/public">
  Require all granted
</Directory>

<VirtualHost *:80>
 ServerName redmine2.hogehoge.com
 DocumentRoot "/var/lib/redmine2/public"
 PassengerAppRoot /var/lib/redmine2
 RailsBaseURI /
</VirtualHost>

Since it is assumed that Passennger has already been set, it is necessary to add directory permissions and virtual host settings for each Redmine.

Start Apache after changing the settings.

# systemctl start httpd.service

If Apache starts without any errors,

Please confirm that redmine1 / redmine2 can be started and operated respectively.

After accessing each Redmine, it should also be displayed in the Passenger process for a while as shown below.


# ps ax | grep Passenger
19815 ?        Sl     0:03 Passenger AppPreloader: /var/lib/redmine1
19865 ?        Sl     0:01 Passenger AppPreloader: /var/lib/redmine1 (forking...)
19920 pts/0    S+     0:00 grep --color=auto Passenger
22015 ?        Ssl    0:00 Passenger watchdog
22018 ?        Sl     0:33 Passenger core
27829 ?        Sl     0:04 Passenger AppPreloader: /var/lib/redmine2
27877 ?        Sl     0:01 Passenger AppPreloader: /var/lib/redmine2 (forking...)
#

From Passenger, you can see that each of Redmine1 / Redmine2 is running. If there is no access for a while, the Passenger process will also disappear.

With this procedure, you can launch multiple Redmines with different host names on one server.

Case 2: Set multiple redmine in subdirectory

The following is the setting of multiple Redmine in the subdirectory.

Set to access. You can use the IP address instead of the host name.

Modify the Apache configuration file. Add the following changes to the end of httpd.conf.

/etc/httpd/conf/httpd.conf


・
・
##Additions and changes from here

# Redmine1(/redmine1)settings of

<Directory "/var/lib/redmine1/public">
  Require all granted
</Directory>
Alias /redmine1 /var/lib/redmine1/public
<Location /redmine1>
  PassengerBaseURI /redmine1
  PassengerAppRoot /var/lib/redmine1
</Location>

# Redmine2(/redmine2)settings of

<Directory "/var/lib/redmine2/public">
  Require all granted
</Directory>
Alias /redmine2 /var/lib/redmine2/public
<Location /redmine2>
  PassengerBaseURI /redmine2
  PassengerAppRoot /var/lib/redmine2
</Location>

Start Apache after changing the settings.

# systemctl start httpd.service

If Apache starts without any errors,

Please confirm that redmine1 / redmine2 can be started and operated respectively.

After accessing each Redmine, it should also be displayed in the Passenger process for a while as shown below.

# ps ax | grep Passenger
30318 ?        Ssl    0:00 Passenger watchdog
30323 ?        Sl     0:00 Passenger core
30349 ?        Sl     0:03 Passenger AppPreloader: /var/lib/redmine1
30396 ?        Sl     0:00 Passenger AppPreloader: /var/lib/redmine1 (forking...)
30429 ?        Sl     0:03 Passenger AppPreloader: /var/lib/redmine2
30477 ?        Sl     0:00 Passenger AppPreloader: /var/lib/redmine2 (forking...)
30517 pts/0    R+     0:00 grep --color=auto Passenger
# 

From Passenger, you can see that each of Redmine1 / Redmine2 is running. If there is no access for a while, the Passenger process will also disappear.

With this procedure, you can launch multiple Redmines on one server with different subdirectory names.

Summary

I was able to set it more smoothly than I expected. You can access multiple Redmines with either host name or subdirectory name. If you apply it, you can also set it with https. I've been using it for a while and haven't had any problems, but I'm not sure if this is completely correct, so please take your own risk. Let's not think about future version upgrades of Redminem (laughs)

Recommended Posts

Launch multiple Redmine instances on one server
Redmine on Docker
Launch Rails on EC2
Notes on multiple inheritance
Install Redmine 4.1.1 on CentOS 7