Redmine

来自 Alpine Linux
此材料正在制作中...

在此通知移除之前,请勿遵循此处的说明。
(最后编辑由 Sertonix 于 2023 年 11 月 17 日。)

注意:此页面的所有内容都已过时,新软件包是 ruby-unicorn,其中包括 redmine 示例文件。

注意:Alpine 2.5+ 安装需要遵循此页面底部的 2.1.2 版本的安装说明。

注意:这是我们 Redmine 安装指南的完整重写。以前,Redmine 需要的 Ruby 软件包需要使用 rubygems 手动安装。现在我们在我们的仓库中有了 Remine 需要的 Ruby 软件包。截至撰写本文时,ruby 软件包在测试仓库中维护。

一些假设

  • 对于本指南,我们假设您正在运行 Alpine Linux 的硬盘安装。如果您从 RAM 运行,请确保您使用 LBU。
  • Alpine Linux 使用 Lighttpd 作为默认 Web 服务器。Redmine 将在 Lighttpd 内使用 FastCGI 运行。如果您想使用任何其他 Web 服务器安装 Redmine,您将需要手动安装它。目前需要手动安装的包括:ruby-rails ruby-fcgi ruby-rmagick ruby-i18n ruby-openid rubygems
  • 我们使用 MySQL 作为 Redmine 安装的数据库。Redmine 也能够使用 PostgreSQL 或 SQLite 运行。
  • MySQL 在远程位置运行。请遵循其他关于如何设置 MySQL 的教程。(需要链接)。
  • 有关 Redmine 安装的详细信息,请访问: https://redmine.ruby-lang.org.cn/projects/redmine/wiki/RedmineInstall


安装 Redmine

apk add redmine

在 Alpine 基础安装上,这应该会拉取大约 50 个软件包,包括(几乎)所有 Ruby 依赖项和 Lighttpd。如果您想运行不同的 Web 服务器,您将需要跳过 redmine 软件包并使用 apk 手动安装所有依赖项。

数据库支持

Redmine 支持各种数据库后端。这里我们只介绍 MySQL 和 PostgreSQL。

选项 1 - MySQL

为了让 Redmine 与 MySQL 服务器通信,我们将需要 mysql ruby 软件包。(如果您想运行另一个数据库,只需安装相应的数据库软件包)。

apk add ruby-mysql

现在在我们继续之前,我们需要准备我们的数据库。根据 Redmine 网站,您需要执行以下操作

create database redmine character set utf8; create user 'redmine'@'localhost' identified by 'my_password'; grant all privileges on redmine.* to 'redmine'@'localhost';

如果您需要 mysql 客户端,您可以像这样安装它

apk add mysql-client

您当然也可以使用像 phpmyadmin 这样的工具来创建数据库和设置用户。

选项 2 - PostgreSQL

apk add ruby-pg postgresql

初始化并启动数据库引擎

rc-service postgresql setup rc-service postgresql start

创建 redmine 数据库用户,将“redminepw”替换为您自己的密码

psql -U postgres -c "CREATE ROLE redmine LOGIN ENCRYPTED PASSWORD 'redminepw' NOINHERIT VALID UNTIL 'infinity';"

创建 redmine 数据库(请注意,UTF8 需要 template0)

psql -U postgres -c "CREATE DATABASE redmine WITH ENCODING 'UTF8' OWNER=redmine TEMPLATE = template0;"

Redmine 配置文件

Redmine 默认配置文件位于 /etc/redmine 内。为了让 Redmine 找到您的数据库,请编辑 database.yml。我们已删除所有条目,仅保留默认的 production 条目。有关示例,请查看:/var/www/localhost/htdocs/redmine/config 如果您需要编辑其他配置文件,请将它们移动到 /etc/redmine 并将它们链接回原始位置。这样 apk 将使用 config protect,并且在更新时不会覆盖您的配置文件。不要忘记编辑其他文件,例如 configuration.yml 中的 SMTP 配置。

首先,我们需要生成会话存储密钥

su -pc "cd /var/www/localhost/htdocs/redmine; /usr/lib/ruby/gems/1.8/bin/rake generate_session_store" lighttpd

现在我们填充数据库

su -pc "cd /var/www/localhost/htdocs/redmine; RAILS_ENV=production /usr/lib/ruby/gems/1.8/bin/rake db:migrate" lighttpd

设置 Lighttpd

现在我们的数据库已准备就绪,我们需要配置 Lighttpd。我们包含了一个基于 FastCGI 的 Redmine/Ligghtpd 配置示例。您可以在 /etc/lighttpd 中找到它。当您完成设置 Ligghtpd 配置后,将其包含在 lighttpd.conf 中,我们就可以启动它了。

vi /etc/lighttpd/redmine-virtual.conf

vi /etc/lighttpd/lighttpd.conf

 ... 
 include "redmine-virtual.conf"
 ...

rc-service lighttpd start

如果您的服务器未运行,您可以在 /var/log/lighttpd 中找到信息。如果这没有提供线索,您也可以在前台运行 Lighttpd。它应该显示更多调试信息。

rc-service lighttpd stop lighttpd -f /etc/lighttpd/lighttpd.conf -D

启用邮件到工单

注意: 此配置不是很安全,因为它使用了开箱即用的 postfix 配置。假设将对 postfix 应用其他配置,但这不在本节的范围之内。

首先,添加 postfix。

apk add postfix

将别名添加到 /etc/postfix/aliases(将 url 替换为您的 URL,并将 InsertKeyHere 替换为您的 Redmine 密钥)

test: "|ruby /var/www/localhost/htdocs/redmine/extra/mail_handler/rdm-mailhandler.rb --url https://bugs.alpinelinux.org --key InsertKeyHere --project=test --unknown-user=accept --no-permission-check"

创建别名数据库

newaliases

启动 Postfix

rc-service postfix start
rc-update add postfix

可选:为未知用户启用邮件到工单

注意:要在 Redmine 中为“myproject”项目启用来自未知用户/电子邮件地址的邮件到工单创建(在 Redmine UI 中允许匿名问题创建之后),请创建以下脚本并让您的电子邮件服务器将新邮件管道传输到此脚本

 #!/usr/bin/perl
 # Author: Jeff Bilyk
 # March 2, 2011
 #Script to take email from stdin, then:
 # - Check redmine database to see if the user exists
 #   - If user doesn't exist, create the user
 # - Pass the email on the redmine utility:
 #   - echo "email contents" | rake redmine:email:read RAILS_ENV="production" project=myproject
 
 use strict;
 use DBI;
 # global variables
 my $DbName = 'redmine';
 my $DbUser = 'redmine';
 my $DbPassword = 'Secur3P@ass';
 my @fields;
 my @address;
 my $existinguser;
 
 # Get email from stdin
 my @email = <STDIN>;
 
 # Parse field for "for"
 foreach (@email)
 {
 	if ($_ =~ /From/)
 	{
 		@fields = (split /</,$_);
 		@address = (split />/,$fields[1]);
 	}
 }
 
 my $dbh = DBI->connect('dbi:mysql:' . $DbName, $DbUser, $DbPassword, { PrintError => 0 }) or die "SQL Connect Error:" . DBI->errstr;
 
 # Find out if there're any existing users with the specified email address
 my $sqlStatement = "SELECT * from users where mail = '$address[0]';";
 
 my $sqlCommand = $dbh->prepare($sqlStatement);
 
 $sqlCommand->execute or die "SQL Error: " . DBI->errstr;
 
 my @sqlRecordset;
 $existinguser = 'maybe';
 
 @sqlRecordset = $sqlCommand->fetchrow_array;
 
 if ($sqlRecordset[0] == ) {
 	printf "@sqlRecordset \n";
 	$existinguser = 'no';
 }
 else {
 	$existinguser = 'yes';
 }
 
 # If there isn't a user already, then create one
 if ($existinguser == 'no')
 {
 	my @name = (split /@/,$address[0]);
 	printf "Current variables: $name[0]  $address[0]  \n";
 	$sqlStatement = "INSERT INTO users (login, firstname, lastname, mail, mail_notification, admin, status, language, type) values (\"$name[0]\", \"$name[0]\", \" \", \"$address[0]\", 0, 0, 1, \"en\", \"User\");";
 	$sqlCommand = $dbh->prepare($sqlStatement);
 	$sqlCommand->execute or die "SQL Error: " .DBI->errstr;
 	printf "User created";
 }
 
 my $timeinsec = `date +%s`;
 open (MYFILE, ">>/var/tmp/$timeinsec");
 print MYFILE "@email";
 close (MYFILE);
 
 system("sed -i 's/^  //' /var/tmp/$timeinsec");
 system("sed -i 's/^ //' /var/tmp/$timeinsec");
 
 `cd /usr/share/webapps/redmine && rake redmine:email:read RAILS_ENV="production" project=myproject < /var/tmp/$timeinsec`;
 exit 0

本文档是一个正在进行中的工作。


安装 Redmine 2.1.2 及更高版本

Alpine 中的 Redmine 已从 lighttpd 切换到 unicorn httpd(ruby-fcgi 当前存在问题,根据 redmine 开发人员的说法,这是运行 redmine 的首选方式)。

此基本指南基于 sqlite,并且仅在 sqlite 上进行了测试。我们需要安装以下软件包

apk add ruby-sqlite ruby-unicorn redmine

将示例配置文件复制到 /etc/unicorn 中

cp /etc/unicorn/redmine.conf.rb.sample /etc/unicorn/redmine.conf.rb

编辑 unicorn conf.d 文件,并将配置文件设置为 /etc/unicorn/redmine.conf.rb

vim /etc/conf.d/unicorn

编辑 redmine 数据库配置,并将 sqlite 设置为数据库

vim /etc/redmine/database.yml

确保数据库目录存在并将所有者更改为 redmine

cd /usr/share/webapps/redmine

sudo -u redmine rake generate_secret_token

sudo -u redmine RAILS_ENV=production rake db:migrate

确保 redmine.conf.rb 正确并运行

rc-service unicorn start

这将启动 unicorn httpd 并默认监听 0.0.0.0:8080。

Unicorn 是一个非常基本的 httpd,建议在其前面使用反向代理,如 nginx、pound 或任何其他反向代理。

安装其他插件

  • 将插件目录复制到 vendor/plugins 目录中。
  • 执行迁移任务。(例如 rake db:migrate_plugins RAILS_ENV=production)
  • (重新)启动 Unicorn。

确保插件与您的 redmine 兼容。安装步骤可能因插件而异。