操作
如何在Ubuntu Server 10.04上使用Mercurial和Subversion安装Redmine 1.2.x¶
Redmine安装¶
- 安装LAMP堆栈
$ sudo tasksel install lamp-server
- 安装所需软件包
$ sudo apt-get install build-essential subversion llibmysqlclient15-dev libdigest-sha1-perl libgemplugin-ruby libgemplugin-ruby1.8 libruby-extras libruby1.8-extras rails rake ruby rubygems rubygems1.8 ruby1.8-dev libopenssl-ruby1.8
- 安装所需的Ruby gem
$ sudo gem install rails -v=2.3.11 --no-ri --no-rdoc $ sudo gem install rake -v=0.8.7 --no-ri --no-rdoc $ sudo gem uninstall rake -v=0.9.2 $ sudo gem install i18n -v=0.4.2 --no-ri --no-rdoc $ sudo gem install mysql --no-ri --no-rdoc
- 将Redmine下载到/user/share/redmine目录
$ sudo svn co http://redmine.rubyforge.org/svn/branches/1.2-stable /usr/share/redmine
- 创建一个空MySQL数据库和一个名为redmine的辅助用户,例如。
$ mysql -u root -p (enter the mysql root user password) > create database redmine character set utf8; > create user 'redmine'@'localhost' identified by '[password]'; > grant all privileges on redmine.* to 'redmine'@'localhost' identified by '[password]'; > exit
- 将config/database.yml.example复制到config/database.yml并编辑此文件以配置“生产”环境下的数据库设置。
$ sudo cp /usr/share/redmine/config/database.yml.example /usr/share/redmine/config/database.yml $ sudo nano /usr/share/redmine/config/database.yml Modify to the following and save (ctrl+x) production: adapter: mysql socket: /var/run/mysqld/mysqld.sock database: redmine host: localhost username: redmine password: [password] encoding: utf8
- 生成会话存储密钥。
$ cd /usr/share/redmine $ sudo rake generate_session_store
- 在应用根目录下运行以下命令以创建数据库结构
$ cd /usr/share/redmine $ sudo rake db:migrate RAILS_ENV="production"
- 运行以下命令在数据库中插入默认配置数据
$ sudo RAILS_ENV=production rake redmine:load_default_data
- 设置权限
$ cd /usr/share/redmine $ sudo chown -R www-data:www-data files log tmp public/plugin_assets $ sudo chmod -R 755 files log tmp public/plugin_assets
- 使用webrick网络服务器进行测试
$ cd /usr/share/redmine $ ruby script/server webrick -e production Point your web browser at http://[my server ip]:3000 You should now see the application welcome page.
Apache集成¶
- 安装所需软件包
$ sudo apt-get install libapache2-mod-passenger
- 将符号链接添加到public redmine网络目录
$ sudo ln -s /usr/share/redmine/public /var/www/redmine
- 配置Passanger以作为www-data运行
$ sudo nano /etc/apache2/mods-available/passenger.conf Add the follow line and save (ctrl+x) PassengerDefaultUser www-data
- 创建一个新的Apache站点文件
$ sudo nano /etc/apache2/sites-available/redmine
添加以下行并保存(ctrl+x)<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www ServerName myservername RewriteEngine on RewriteRule ^/$ /redmine [R] <Directory /var/www/redmine> RailsBaseURI /redmine PassengerResolveSymlinksInDocumentRoot on </Directory> ErrorLog /var/log/apache2/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog /var/log/apache2/access.log combined </VirtualHost>
对于SSL,请替换以下文本<VirtualHost *:443> ServerAdmin webmaster@localhost DocumentRoot /var/www ServerName myservername SSLEngine On SSLCertificateFile /etc/apache2/ssl/redmine.pem RewriteEngine on RewriteRule ^/$ /redmine [R] <Directory /var/www/redmine> RailsBaseURI /redmine PassengerResolveSymlinksInDocumentRoot on </Directory> ErrorLog /var/log/apache2/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog /var/log/apache2/access.log combined </VirtualHost>
- 启用Redmine网站
$ sudo a2dissite default $ sudo a2ensite redmine
- 启用Passenger和Rewrite模块并重新启动Apache
$ sudo a2enmod passenger $ sudo a2enmod rewrite $ sudo /etc/init.d/apache2 restart
- 测试设置
Open up your favorite web browser and goto http://[my site or ip]/redmine
Mercurial集成¶
- 安装最新的Mercurial发布版
$ sudo apt-get install python-software-properties $ sudo add-apt-repository ppa:mercurial-ppa/releases $ sudo apt-get update $ sudo apt-get install mercurial libapache-dbi-perl libapache2-mod-perl2
- 创建hg网络目录
$ sudo mkdir -p /var/hg/repos
- 创建网络CGI脚本文件
$ sudo nano /var/hg/hgwebdir.cgi Add the following and save #!/usr/bin/env python # from mercurial import demandimport; demandimport.enable() from mercurial.hgweb.hgwebdir_mod import hgwebdir import mercurial.hgweb.wsgicgi as wsgicgi application = hgwebdir('hgweb.config') wsgicgi.launch(application)
- 创建CGI网络配置文件
$ sudo nano /var/hg/hgweb.config Add the following and save [paths] /=/var/hg/repos/** [web] allow_push = * push_ssl = false allowbz2 = yes allowgz = yes allowzip = yes
- 设置权限
$ sudo chown -R www-data:www-data /var/hg $ sudo chmod gu+x /var/hg/hgwebdir.cgi
- 创建Apache配置文件
$ sudo nano /etc/apache2/conf.d/hg.config Add the following and save PerlLoadModule Apache::Redmine ScriptAlias /hg "/var/hg/hgwebdir.cgi" <Location /hg > AuthType Basic AuthName "Redmine Mercurial Repository" Require valid-user #Redmine auth PerlAccessHandler Apache::Authn::Redmine::access_handler PerlAuthenHandler Apache::Authn::Redmine::authen_handler RedmineDSN "DBI:mysql:database=redmine;host=localhost" RedmineDbUser "redmine" RedmineDbPass "password" </Location>
- 将符号链接添加到Redmine.pm
$ sudo ln -s /usr/share/redmine/extra/svn/Redmine.pm /usr/lib/perl5/Apache/Redmine.pm $ sudo ln -s /usr/share/redmine/extra/svn/Redmine.pm /usr/lib/perl5/Apache2/Redmine.pm
- 启用所需的Apache模块并重新启动Apache
$ sudo /etc/init.d/apache2 restart
- 在Redmine中创建一个新的测试仓库和项目
$ sudo hg init /var/hg/repos/test $ sudo chown -R www-data:www-data /var/hg/repos/test Create a new project with and identifier 'test' In the project Settings > Repository set SCM: Mercurial Path to repository: /var/hg/repos/test Press the 'Create' button Goto to the Repository tab of the test project
- 在网页浏览器中查看测试仓库
> http://[my site name]/hg/test
Subversion集成¶
- 安装最新的Mercurial发布版
$ sudo apt-get install subversion libapache2-svn libapache-dbi-perl libapache2-mod-perl2
- 创建svn仓库目录
$ sudo mkdir /var/svn
- 设置权限
$ sudo chown -R www-data:www-data /var/svn
- 将符号链接添加到Redmine.pm
$ sudo ln -s /usr/share/redmine/extra/svn/Redmine.pm /usr/lib/perl5/Apache/Redmine.pm $ sudo ln -s /usr/share/redmine/extra/svn/Redmine.pm /usr/lib/perl5/Apache2/Redmine.pm
- 创建Apache配置文件
$ sudo nano /etc/apache2/conf.d/svn.config
添加以下内容并保存PerlLoadModule Apache::Redmine <Location /svn> DAV svn SVNParentPath "/var/svn" Order deny,allow Deny from all Satisfy any PerlAccessHandler Apache::Authn::Redmine::access_handler PerlAuthenHandler Apache::Authn::Redmine::authen_handler AuthType Basic AuthName "Redmine Subversion Repository" #read-only access <Limit GET PROPFIND OPTIONS REPORT> Require valid-user Allow from [my server ip] # Allow from another-ip Satisfy any </Limit> # write access <LimitExcept GET PROPFIND OPTIONS REPORT> Require valid-user </LimitExcept> ## for mysql RedmineDSN "DBI:mysql:database=redmine;host=localhost" RedmineDbUser "redmine" RedmineDbPass "password" </Location>
- 启用所需的Apache模块并重新启动Apache
$ sudo a2enmod dav_svn $ sudo /etc/init.d/apache2 restart
- 创建一个新的测试仓库
$ sudo svnadmin create /var/svn/test $ sudo chown -R www-data:www-data /var/svn/test
自动化仓库创建¶
- 启用仓库管理WS并生成API密钥
* From the Redmine Administration menu select Settings * Click on the Repositories tab * Enable the 'Enable WS for repository management' checkbox * Click the 'Generate a key' link * Press the 'Save' button
- 修改reposman.rb
$ sudo nano /usr/share/extra/svn/reposman.rb Add the following to module SCM and save module Mercurial def self.create(path) Dir.mkdir path Dir.chdir(path) do system_or_raise "hg init" end end end
- 计划每分钟运行一次reposman.rb脚本
$ sudo nano /etc/cron.d/redmine
添加以下行之一并保存(不要同时添加两个)。
(注意:您需要将[我的API密钥]替换为在步骤1中生成的API密钥)
.
要创建Subversion仓库,请添加* * * * * root ruby /usr/share/redmine/extra/svn/reposman.rb --redmine localhost/redmine --scm Subversion --svn-dir /var/hg/repos --owner www-data --url file:///var/svn --key=[my API key] >> /var/log/reposman.log
或者要创建Mecurial仓库,请添加* * * * * root ruby /usr/share/redmine/extra/svn/reposman.rb --redmine localhost/redmine --scm Mercurial --svn-dir /var/hg/repos --owner www-data --url /var/hg/repos --key=[my API key] >> /var/log/reposman.log
Redmine中仓库的自动刷新¶
- 计划每15分钟运行一次fetch_changesets脚本
$ sudo nano /var/cron.d/redmine Add the following line and save */15 * * * * root ruby /usr/share/redmine/script/runner "Repository.fetch_changesets" -e production > /dev/null 2>&1
- 在Mercurial服务器上设置一个changegroup脚本来在每次推送到Mercurial仓库后运行fetch_changesets
$ sudo nano /var/hg/changegroup-hook
添加以下文本并保存
(注意:您需要将[您的API密钥]替换为在Redmine中生成的API密钥#!/bin/sh curl "https://127.0.0.1/redmine/sys/fetch_changesets?key=[your API key]" > /dev/null 2>&1
设置权限$ sudo chown www-data:www-data /var/hg/changegroup-hook $ sudo chmod ug+x /var/hg/changegroup-hook
修改hgweb.config文件$ sudo nano /var/hg/hgweb.config
添加以下部分并保存[hooks] changegroup = /var/hg/changegroup-hook
邮件集成¶
- 安装和配置Sendmail
$ sudo apt-get install sendmail $ sudo sendmailconfig (Answer Yes to all questions which you will be asked)
- 更新Redmine配置文件
$ sudo nano /usr/share/redmine/config/configuration.yml Add the following text and save production: email_delivery: delivery_method: :sendmail
备份到Amazon S3云存储¶
- 在http://aws.amazon.com/创建账户
- 使用aws管理控制台创建S3存储桶https://console.aws.amazon.com/ec2/home
- 在https://aws-portal.amazon.com/gp/aws/developer/account/index.html?action=access-key查看您的访问密钥
- 编译并安装fuse到2.8.4
$ sudo wget https://launchpad.net/ubuntu/+archive/primary/+files/fuse_2.8.4.orig.tar.gz $ cd fuse-2.8.4/ $ tar xzf fuse_2.8.4.orig.tar.gz $ sudo ./configure $ sudo make $ sudo make install
- 编译并安装s3fs 1.61
$ sudo apt-get install libxml2-dev $ wget http://s3fs.googlecode.com/files/s3fs-1.61.tar.gz $ tar xzf s3fs-1.61.tar.gz $ cd s3fs-1.61/ $ sudo ./configure $ sudo make $ sudo make install
- 创建s3fs密码文件
$ sudo nano /etc/passwd-s3fs
用冒号分隔,添加您的'访问密钥ID'和'秘密访问密钥'[accessKeyId]:[secretAccessKey]
设置权限sudo chmod 650 /etc/passwd-s3fs
- 创建挂载点
$ sudo mkdir /mnt/s3
- 挂载您的S3存储桶
$ sudo s3fs [your-s3-bucket-name] /mnt/s3 -ouse_cache=/tmp -o allow_other
- 测试是否成功并卸载
$ echo hello > /mnt/s3/welcome.txt $ ls /mnt/s3 $ sudo umount /mnt/s3
- 创建upstart任务,以便在启动时挂载s3文件系统
$ sudo nano /etc/init/s3.conf
添加以下文本并保存。description "Mount Amazon S3 file system on system start" start on (local-filesystems and net-device-up IFACE!=lo) stop on runlevel [016] respawn exec s3fs -f [your-s3-bucket-name] /mnt/s3 -ouse_cache=/tmp -o allow_other
- 启动s3任务
sudo start s3
- 测试是否成功
$ echo hello > /mnt/s3/welcome2.txt $ ls /mnt/s3
- 创建备份脚本文件
$ sudo apt-get install mailutils $ sudo nano /usr/local/bin/backup-redmine.sh
添加以下文本并保存。#!/bin/bash # Script to backup Redmine files to a mounted storage device # with daily, weekly, monthly backup rotation # Admin email address admin_email="[email protected]" # What to backup db_dump_file="/usr/share/redmine/db/redmine-database-dump.sql" backup_files="$db_dump_file /usr/share/redmine/files /var/hg /var/svn" backup_files="$backup_files /etc/apache2/conf.d/hg.conf /etc/apache2/sites-available/redmine" backup_files="$backup_files /etc/init/s3.conf /etc/cron.d/redmine /usr/local/bin/backup-redmine.sh" # Where to backup to backup_dir="/mnt/s3" # Set database access redmine_db_name="redmine" redmine_db_user="redmine" redmine_db_password="password" # Encryption encrypt="false" secret_passphrase="your_gpg_passphrase" # Set rotation in units of days daily_remove_older_than=6 weekly_remove_older_than=30 monthly_remove_older_than=62 # Redirect stderr to a log file error_log="/tmp/backup-redmine.log" exec 6>&2 exec 2>$error_log on_exit() { # Restore IO output exec 2>&6 6>$- # Check for errors if [ -s "$error_log" ]; then logger -t "$0" -s "#### Backup Failed ####" logger -t "$0" -s -f "$error_log" cat "$error_log" | mail -s "Backup failed!" $admin_email else logger -t "$0" -s "Backup Complete" fi # Clean up rm -f $error_log } trap on_exit EXIT SIGHUP SIGINT SIGQUIT SIGTERM # Setup variables for the archive filename. hostname=$(hostname -s) date_time_stamp=`date +%Y-%m-%d_%Hh%Mm` # Datestamp e.g 2011-12-31_23h59m date_stamp=`date +%Y-%m-%d` # Date p e.g 2011-12-31 date_day_of_week=`date +%A` # Day of the week e.g. Monday date_day_of_month=`date +%e` # Date of the Month e.g. 27 # Is the backup directory mounted? mount | grep -sq "$backup_dir" if [ $? != 0 ]; then echo "backup destination ${backup_dir} is not mounted" >&2 exit 1 fi # Make required directories [ -d "$backup_dir/monthly" ] || mkdir "$backup_dir/monthly" [ -d "$backup_dir/weekly" ] || mkdir "$backup_dir/weekly" [ -d "$backup_dir/daily" ] || mkdir "$backup_dir/daily" # Delete old archives find "${backup_dir}/monthly" -mtime +"$monthly_remove_older_than" -type f -name "${hostname}_*" -exec rm {} \; find "${backup_dir}/weekly" -mtime +"$weekly_remove_older_than" -type f -name "${hostname}_*" -exec rm {} \; find "${backup_dir}/daily" -mtime +"$daily_remove_older_than" -type f -name "${hostname}_*" -exec rm {} \; archive_file="${backup_dir}/daily/${hostname}_${date_time_stamp}.tgz" [ $encrypt == "true" ] && archive_file="${archive_file}.gpg" # Dump the redmine database rm -f "$db_dump_file" mysqldump --user="${redmine_db_name}" --password="${redmine_db_password}" "${redmine_db_name}" > $db_dump_file # Write the archive file to the backup directory if [ $encrypt == "true" ]; then tar czP $backup_files | gpg -c -z 0 --yes --no-use-agent --passphrase="${secret_passphrase}" -o "${archive_file}" else tar czfP "${archive_file}" $backup_files fi # Make a weekly backup on Saturday if [ $date_day_of_week == "Saturday" ]; then weekly_count=$(find "${backup_dir}/weekly" -type f -name "${hostname}_${date_stamp}*" | wc -l) [ $weekly_count == "0" ] && cp "${archive_file}" "${backup_dir}/weekly/" fi # Make a monthly backup on the first day of every month if [ $date_day_of_month == "1" ]; then monthly_count=$(find "${backup_dir}/monthly" -type f -name "${hostname}_${date_stamp}*" | wc -l) [ $monthly_count == "0" ] && cp "${archive_file}" "${backup_dir}/monthly/" fi if [ -s "$error_log" ]; then exit 1 else exit 0 fi
- 设置权限
sudo chmod ug+x /usr/local/bin/backup-redmine.sh sudo chmod o-r /usr/local/bin/backup-redmine.sh
- 安排每天午夜12点运行备份
$ sudo nano /etc/cron.d/redmine Add the following line and save 0 0 * * * root /usr/local/bin/backup-redmine.sh
- 测试脚本
$ sudo backup-redmine.sh $ ls -R /mnt/s3
由Dimitry Profus更新,大约13年前 1次修订 · 历史记录