專案

一般

個人檔案

動作

如何在 Ubuntu Server 10.04 上安裝 Redmine 1.3.x (含 Mercurial 和 Subversion)

安裝前準備

  1. 設定時區
    $ dpkg-reconfigure tzdata
    
    Select your timezone and exit.
    
  2. 設定主機名稱
    $ sudo nano /etc/hostname
    
    Enter your server name and save.
    
    eg.
    
    redmine
    
  3. 將您的完整網域名稱 (FQDN) 對應到 localhost
    $ sudo nano /etc/hosts
    
    Add a line mapping local host to your FQDN and hostname and save. 
    
    eg. 
    
    127.0.0.1 redmine.domain.com redmine
    

Redmine 安裝

  1. 安裝 LAMP 堆疊
    $ sudo tasksel install lamp-server
    
  2. 安裝必要的套件
    $ sudo apt-get install build-essential subversion libmysqlclient-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 
    

    -->更新 rubygems
    在某些情況下,您的系統可能仍在使用 rubygems 1.5,但您需要更新的版本。 您可以輸入以下指令來檢查安裝的版本:
    $ gem --version
    

    如果版本是 1.5:更新 rubygems
    gem install rubygems-update
    cd /var/lib/gems/1.8/bin
    sudo ./update_rubygems
    

    -->安裝必要的 gems
    $ sudo gem install rails -v=2.3.14 --no-ri --no-rdoc
    $ sudo gem install rake -v=0.8.7 --no-ri --no-rdoc
    $ sudo gem uninstall rake -v=0.9.2.2 
    $ sudo gem install i18n -v=0.4.2 --no-ri --no-rdoc
    $ sudo gem install mysql --no-ri --no-rdoc
    
  3. 將 Redmine 下載到 /user/share/redmine 目錄
    $ sudo svn co http://redmine.rubyforge.org/svn/branches/1.3-stable /usr/share/redmine
    
  4. 建立一個空的 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
    
  5. 將 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
    
  6. 產生一個工作階段儲存區密鑰。
    $ cd /usr/share/redmine
    
    $ sudo rake generate_session_store
    
  7. 在應用程式根目錄下執行以下指令來建立資料庫結構:
    $ cd /usr/share/redmine
    
    $ sudo rake db:migrate RAILS_ENV="production" 
    
  8. 執行以下指令將預設設定資料插入資料庫:
    $ sudo RAILS_ENV=production rake redmine:load_default_data
    
  9. 設定權限
    $ cd /usr/share/redmine
    $ sudo chown -R www-data:www-data files log tmp public/plugin_assets
    
  10. 使用 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 整合

  1. 安裝必要的套件
    $ sudo apt-get install libapache2-mod-passenger
    
  2. 新增一個指向公開 Redmine 網頁目錄的符號連結
    $ sudo ln -s /usr/share/redmine/public /var/www/redmine
    
  3. 將 Passanger 設定為以 www-data 身分執行
    $ sudo nano /etc/apache2/mods-available/passenger.conf
    
    Add the follow line and save (ctrl+x)
    
    PassengerDefaultUser www-data
    
  4. 建立新的 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>
    
  5. 啟用 Redmine 網站
    $ sudo a2dissite default
    $ sudo a2ensite redmine
    
  6. 啟用 Passenger 和 Rewite 模組,然後重新啟動 Apache
    $ sudo a2enmod passenger
    $ sudo a2enmod rewrite
    $ sudo /etc/init.d/apache2 restart
    
  7. 測試設定
    Open up your favorite web browser and goto
    
    http://[my site or ip]/redmine
    

Mercurial 整合

  1. 安裝最新版的 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
    
  2. 建立 hg 網頁目錄
    $ sudo mkdir -p /var/hg/repos
    
  3. 建立網頁 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)
    
  4. 建立 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
    
  5. 設定權限
    $ sudo chown -R www-data:www-data /var/hg
    $ sudo chmod gu+x /var/hg/hgwebdir.cgi
    
  6. 建立 Apache 設定檔
    $ sudo nano /etc/apache2/conf.d/hg.config
    
    Add the following and save
    # Use PerlLoadModule Apache2::Redmine when using apache2, or else you might get weird errors trying to authenticate.
    
    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>
    
  7. 新增一個指向 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  
    
  8. 啟用必要的 Apache 模組,然後重新啟動 Apache
    $ sudo /etc/init.d/apache2 restart
    
  9. 在 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
    
  10. 在網頁瀏覽器中檢視測試儲存庫
    > http://[my site name]/hg/test
    

Subversion 整合

  1. 安裝最新版的 Mercurial
    $ sudo apt-get install subversion libapache2-svn libapache-dbi-perl libapache2-mod-perl2
    
  2. 建立 svn 儲存庫目錄
    $ sudo mkdir /var/svn
    
  3. 設定權限
    $ sudo chown -R www-data:www-data /var/svn
    
  4. 新增一個指向 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  
    
  5. 建立 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>
    
  6. 啟用必要的 Apache 模組,然後重新啟動 Apache
    $ sudo a2enmod dav_svn
    $ sudo /etc/init.d/apache2 restart
    
  7. 建立新的測試儲存庫
    $ sudo svnadmin create /var/svn/test
    $ sudo chown -R www-data:www-data /var/svn/test
    

自動建立儲存庫

  1. 啟用儲存庫管理的 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
    
  2. 修改 reposman.rb
    $ sudo nano /usr/share/redmine/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
    
  3. 將 reposman.rb 指令碼排程為每分鐘執行一次
    $ sudo nano /etc/cron.d/redmine
    

    新增以下其中一行 (不要兩行都新增) 並儲存。
    (注意:您需要將 [my API key] 替換為您在步驟 1 中產生的 API 金鑰)
    .
    要建立 subversion 儲存庫,請新增
    * * * * * root ruby /usr/share/redmine/extra/svn/reposman.rb --redmine localhost/redmine --scm Subversion --svn-dir /var/svn --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 中儲存庫的自動重新整理

  1. 排程 fetch_changesets 指令碼每 15 分鐘執行一次
    $ sudo nano /etc/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
    
  2. 在 Mercurial 伺服器上設定一個 changegroup 指令碼,以便在每次推送至 Mercurial 儲存庫後執行 fetch_changesets
    $ sudo nano /var/hg/changegroup-hook
    

    新增以下文字並儲存
    (注意:您需要將 [your API key] 替換為您在 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
    

電子郵件整合

  1. 安裝並設定 Sendmail
    $ sudo apt-get install sendmail
    $ sudo sendmailconfig
    
    (Answer Yes to all questions which you will be asked)
    
  2. 更新 Redmine 設定檔
    $ sudo nano /usr/share/redmine/config/configuration.yml
    
    Add the following text and save
    
     production:
       email_delivery:
         delivery_method: :sendmail
    

備份至 Amazon S3 雲端儲存空間

  1. http://aws.amazon.com/ 建立帳戶
  2. 使用 aws 管理主控台建立 S3 儲存貯體 https://console.aws.amazon.com/ec2/home
  3. https://aws-portal.amazon.com/gp/aws/developer/account/index.html?action=access-key 查看您的存取金鑰
  4. 建置並安裝 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
    
  5. 建置並安裝 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
    
  6. 建立 s3fs 密碼檔案
    $ sudo nano /etc/passwd-s3fs
    

    新增您的「存取金鑰 ID」和「秘密存取金鑰」,以冒號分隔
    [accessKeyId]:[secretAccessKey]
    

    設定權限
    sudo chmod 640 /etc/passwd-s3fs
    
  7. 建立掛載點
    $ sudo mkdir /mnt/s3
    
  8. 掛載您的 S3 儲存貯體
    $ sudo s3fs [your-s3-bucket-name] /mnt/s3 -ouse_cache=/tmp -o allow_other
    
  9. 測試是否正常運作並卸載
    $ echo hello > /mnt/s3/welcome.txt
    $ ls /mnt/s3
    $ sudo umount /mnt/s3
    
  10. 建立 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
    
  11. 啟動 s3 作業
    sudo start s3
    
  12. 測試是否正常運作
    $ echo hello > /mnt/s3/welcome2.txt
    $ ls /mnt/s3
    
  13. 建立備份指令碼檔案
    $ 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
    
    # Sysadmin email address
    sysadmin_email="admin@domain.com" 
    
    # 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 /etc/apache2/conf.d/hg.conf" 
    backup_files="$backup_files /etc/apache2/sites-available/redmine /etc/init/s3.conf /etc/cron.d/redmine" 
    backup_files="$backup_files /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="true" 
    secret_passphrase="password" 
    
    # Set rotation schedule in units of days ( 0 = disabled )
    daily_remove_older_than=6
    weekly_remove_older_than=31
    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!"  $sysadmin_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_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
    
    # Delete old archives
    find "${backup_dir}" -mtime +"$monthly_remove_older_than" -type f -name "${hostname}_fullbackup_monthly*" -exec rm {} \;
    find "${backup_dir}" -mtime +"$weekly_remove_older_than" -type f -name "${hostname}_fullbackup_weekly*" -exec rm {} \;
    find "${backup_dir}" -mtime +"$daily_remove_older_than" -type f -name "${hostname}_fullbackup_daily*" -exec rm {} \;
    
    # Determine the backup schedule
    if [[ $monthly_remove_older_than -gt "0" && $date_day_of_month == "1" ]]; then
        schedule="monthly" 
    elif [[ $weekly_remove_older_than -gt "0" && $date_day_of_week == "Saturday" ]]; then
        schedule="weekly" 
    elif [[ $daily_remove_older_than -gt "0" ]]; then
        schedule="daily" 
    else
        echo "Invalid backup rotation schedule" >&2
        exit 1
    fi
    
    archive_file="${backup_dir}/${hostname}_fullbackup_${schedule}_${date_stamp}.tgz" 
    
    # 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}.gpg" 
    else
        tar czfP "${archive_file}" ${backup_files}
    fi
    
    if [ -s "$error_log" ]; then
        exit 1
    else
        exit 0
    fi
    
  14. 設定權限
    sudo chmod 770 /usr/local/bin/backup-redmine.sh
    
  15. 排程備份在每天凌晨 12 點執行一次
    $ sudo nano /etc/cron.d/redmine
    
    Add the following line and save
    
    0 0 * * * root /usr/local/bin/backup-redmine.sh
    
  16. 測試指令碼
    $ sudo backup-redmine.sh
    $ ls -R /mnt/s3
    

Alexey Porotnikov超過 11 年前 更新 · 23 個版本