Windows Server 2019/2022 部署 Redmine 5.0.0 生产环境指南:从安装到邮件通知全搞定
Windows Server 2019/2022 企业级 Redmine 5.0.0 生产环境部署实战在企业级项目管理工具的选择中Redmine以其开源灵活的特性成为许多技术团队的首选。不同于个人开发环境的简易部署生产环境下的Redmine需要更高的稳定性、安全性和可维护性。本文将带您从零开始在Windows Server 2019/2022上构建一个真正可用于生产环境的Redmine系统。1. 生产环境规划与准备部署前的规划往往比安装过程更重要。对于企业级Redmine部署我们需要考虑以下几个关键因素服务器规格建议至少4核CPU、8GB内存和100GB存储空间特别是当项目数量超过50个或用户数超过100人时数据库选择生产环境推荐使用MySQL或PostgreSQL而非SQLite前者更适合高并发场景网络拓扑考虑将数据库服务器与应用服务器分离提升系统整体性能备份策略制定定期备份计划包括数据库备份和附件文件备份1.1 系统环境检查在开始安装前请确保您的Windows Server满足以下条件# 检查系统版本 Get-ComputerInfo | Select-Object WindowsProductName, WindowsVersion, OsHardwareAbstractionLayer # 检查.NET Framework版本 Get-ChildItem HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP -Recurse | Get-ItemProperty -Name Version -EA 0 | Where { $_.PSChildName -Match ^(?!S)\p{L}} | Select PSChildName, Version提示Redmine 5.0.0需要至少.NET Framework 4.8和Windows Server 2016及以上版本1.2 必要组件安装生产环境需要安装以下组件RubyDevkit推荐使用Ruby 2.7.x版本MySQL Server建议使用5.7或8.0版本ImageMagick用于附件图片处理Git用于版本控制集成使用Chocolatey包管理器可以快速安装这些组件choco install ruby -y --version2.7.6 choco install mysql --version8.0.31 -y choco install imagemagick -y choco install git -y2. Redmine核心安装与配置2.1 数据库准备为Redmine创建专用数据库账户和数据库CREATE DATABASE redmine CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; CREATE USER redminelocalhost IDENTIFIED BY 复杂密码应包含大小写字母数字和特殊符号; GRANT ALL PRIVILEGES ON redmine.* TO redminelocalhost; FLUSH PRIVILEGES;2.2 Redmine安装与基础配置下载Redmine 5.0.0稳定版并解压到合适位置$redminePath D:\Applications\Redmine mkdir $redminePath Invoke-WebRequest -Uri https://www.redmine.org/releases/redmine-5.0.0.zip -OutFile $env:TEMP\redmine-5.0.0.zip Expand-Archive -Path $env:TEMP\redmine-5.0.0.zip -DestinationPath $redminePath配置数据库连接信息编辑config/database.ymlproduction: adapter: mysql2 database: redmine host: localhost username: redmine password: 您的数据库密码 encoding: utf8mb4安装依赖并初始化数据库bundle install --without development test bundle exec rake db:migrate RAILS_ENVproduction bundle exec rake redmine:load_default_data RAILS_ENVproduction REDMINE_LANGzh3. 生产环境优化配置3.1 服务化部署将Redmine配置为Windows服务确保系统重启后自动恢复# 安装NSSM服务管理器 choco install nssm -y # 创建Redmine应用服务 nssm install Redmine C:\ruby27\bin\ruby.exe D:\Applications\Redmine\bin\rails server -e production -p 3000 nssm set Redmine AppDirectory D:\Applications\Redmine nssm set Redmine DisplayName Redmine项目管理平台 nssm set Redmine Description 企业级项目管理和问题跟踪系统 nssm set Redmine Start SERVICE_AUTO_START Start-Service Redmine3.2 安全加固生产环境必须考虑的安全措施防火墙配置仅开放必要的3000端口或自定义端口New-NetFirewallRule -DisplayName Redmine HTTP -Direction Inbound -Protocol TCP -LocalPort 3000 -Action AllowHTTPS配置使用Lets Encrypt获取免费SSL证书定期备份脚本$backupDir D:\Backups\Redmine $date Get-Date -Format yyyyMMdd mysqldump -u redmine -p redmine $backupDir\redmine_db_$date.sql Compress-Archive -Path D:\Applications\Redmine\files -DestinationPath $backupDir\redmine_files_$date.zip3.3 性能优化通过以下配置提升Redmine响应速度启用缓存修改config/environments/production.rbconfig.cache_store :mem_cache_store, localhost:11211 config.action_controller.perform_caching true配置Passenger或Puma替代默认WEBrick服务器数据库优化定期执行ANALYZE TABLE和OPTIMIZE TABLE4. 企业级邮件通知集成生产环境应使用专业邮件服务而非个人邮箱。以下是Exchange Server集成示例编辑config/configuration.ymlproduction: email_delivery: delivery_method: :smtp smtp_settings: address: mail.company.com port: 587 domain: company.com authentication: :ntlm user_name: redminecompany.com password: 强密码 enable_starttls_auto: true openssl_verify_mode: none测试邮件配置rails console production ActionMailer::Base.mail(from: redminecompany.com, to: admincompany.com, subject: Redmine邮件测试, body: 这是一封测试邮件).deliver_now5. 高可用与扩展方案对于大型企业部署考虑以下高级配置5.1 IIS反向代理配置configuration system.webServer rewrite rules rule nameReverseProxyInboundRule1 stopProcessingtrue match url(.*) / action typeRewrite urlhttp://localhost:3000/{R:1} / /rule /rules /rewrite /system.webServer /configuration5.2 负载均衡配置方案优点缺点Nginx多节点高并发能力强配置复杂Azure负载均衡器云原生集成成本较高Windows NLB无需额外软件功能有限5.3 插件生态系统推荐安装的生产环境必备插件Redmine Upgrades简化升级过程Easy Gantt增强甘特图功能Agile敏捷开发支持Knowledge Base知识库管理Monitoring系统监控告警安装插件步骤bundle exec rake redmine:plugins NAMEredmine_agile RAILS_ENVproduction