2011/11/23

Redhat 安裝 Redmine

ssh root@server

cd /opt
wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm && rpm -i *.rpm

yum groupinstall "Development Tools"
yum install httpd httpd-devel
yum install libxml2 libxslt libxml2-devel libxslt-devel
yum install git
yum install openssl openssl-devel
yum install sqlite sqlite-devel 
yum install zlib zlib-devel 
yum install mysql++-devel mysql++ mysql-devel
yum install readline-devel compat-readline5 readline 
yum install libcurl libcurl-devel curl-devel 
yum install libstdc++ libstdc++-devel libstdc++-docs compat-libstdc++-33 
yum install apr-devel apr-util-devel

sudo https_proxy="YOUR_HTTPS_PROXY" bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)

logout && login

rvm install 1.8.7
rvm --default system 1.8.7

logout && login

gem update system

which ruby
which gem

gem install passenger
passenger-install-apache2-module

chkconfig httpd on
service httpd restart

cd /opt && wget http://rubyforge.org/frs/download.php/75520/redmine-1.2.2.zip
unzip redmine-1.2.2.zip && mv redmine-1.2.2 /var/www/html/redmine && cd /var/www/html
cd /var/www/html/redmine/

touch Gemfile

vim Gemfile
###
source "http://rubygems.org"
gem "rake", "0.8.7"
gem "rack", "1.1.1"
gem "i18n", "0.4.2"
gem "rubytree", "0.5.2", :require => "tree"
gem "RedCloth", "~>4.2.3", :require => "redcloth" # for CodeRay
gem "mysql"
gem "coderay", "~>0.9.7"
# gem "rails", "2.3.11"
###

gem install bundler
bundle install

mysql -u root -p -h YOUR_SERVER
###
create database redmine character set utf8;
create user 'redmine'@'localhost' identified by 'YOUR_PASSWORD';
grant all privileges on redmine.* to 'redmine'@'localhost';
###

cd /var/www/html/redmine

mv config/database.yml.example config/database.yml
vim config/database.yml
###
production:
  adapter: mysql
  database: redmine
  host: YOUR_SERVER
  username: redmine
  password: YOUR_PASSWORD
  encoding: utf8
###

vim config/environment.rb
###
ENV['RAILS_ENV'] ||= 'production'
###

cd /var/www/html/redmine
RAILS_ENV=production bundle exec rake generate_session_store
RAILS_ENV=production bundle exec rake db:migrate
# RAILS_ENV=production bundle exec rake redmine:load_default_data

cd /var/www/html/redmine
mv public/dispatch.cgi.example public/dispatch.cgi
mv public/dispatch.fcgi.example public/dispatch.fcgi
mv public/dispatch.rb.example public/dispatch.rb
mv public/htaccess.fcgi.example public/.htaccess

cd /var/www/html/
chown -R apache:apache redmine
chmod -R 755 redmine

vim /etc/httpd/conf.d/redmine.conf
###
LoadModule passenger_module /usr/local/rvm/gems/ruby-1.8.7-p352/gems/passenger-3.0.9/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/rvm/gems/ruby-1.8.7-p352/gems/passenger-3.0.9
PassengerRuby /usr/local/rvm/wrappers/ruby-1.8.7-p352/ruby

《Virtualhost *:80》
ServerName redmine
DocumentRoot /var/www/html/redmine/public
      《directory /var/www/html/redmine/public》
         AllowOverride all
         Options -MultiViews
      《/Directory》
《/VirtualHost》
###

service httpd restart

Upgrade

RAILS_ENV=production bundle exec rake generate_session_store
RAILS_ENV=production bundle exec rake db:migrate
RAILS_ENV=production bundle exec rake db:migrate:upgrade_plugin_migrations
RAILS_ENV=production bundle exec rake db:migrate_plugins
RAILS_ENV=production bundle exec rake tmp:cache:clear
RAILS_ENV=production bundle exec rake tmp:sessions:clear
service httpd restart

Reference:
http://gembundler.com/rationale.html
http://www.redmine.org/projects/redmine/wiki/RedmineInstall
http://www.redmine.org/projects/redmine/wiki/HowTos
http://www.redmine.org/projects/redmine/wiki/HowTo_install_Redmine_on_CentOS_5
http://www.redmine.org/projects/redmine/wiki/HowTo_have_both_development_and_production_environment_available_from_Apache_with_VirtualHost

Ubuntu 安裝 Redmine

Redmine 是一套使用 Ruby 語言開發的專案管理系統,它非常好用!
在 Ubuntu 環境安裝 Redmin 專案管理系統,需要先佈置好 Ruby 環境。
可以參考:http://zx-1986.blogspot.com/2010/09/ruby-on-rails-in-ubuntu.html

[LAMP 環境]
架設 Ubuntu Web Server

[安裝 Ruby]
sudo apt-get install ruby
sudo apt-get install ruby-dev
sudo apt-get install irb libruby libopenssl-ruby ri rdoc
sudo apt-get update

[安裝 RubyGems]
sudo su -
cd /opt
wget http://production.cf.rubygems.org/rubygems/rubygems-1.8.10.tgz
tar zxvf rubygems*
cd rubygems*
ruby --version
ruby setup.rb --help
ruby setup.rb
ln -s /usr/bin/gem1.8 /usr/bin/gem
sudo apt-get install rubygems
# 註:如果可以,盡量使用 Ruby 來編譯安裝 RubyGems


[安裝需要的 Gems]
sudo su -
gem install -v=0.8.7 rake
gem install -v=1.1.1 rack
gem install -v=0.4.2 i18n

gem install -v=2.3.11 rails 
# 註:打包好的 Redmine 內(非原始碼包)已經自帶了 Rails(vendor/rails)

# Gems 預設會放在:/usr/lib/ruby/gems/1.8

[SQLite 資料庫]
假設是使用 sqlite3,需要補充必要套件:
sudo apt-get install sqlite3 sqlite3-doc
sudo apt-get install libsqlite3-ruby


[下載 Redmine 程式]
cd /var/www/
wget  http://rubyforge.org/frs/download.php/75099/redmine-1.2.1.zip
unzip redmine*.zip
mv redmine*.zip /tmp
mv redmine* redmine

使用 svn 直接同步 Redmine 的線上原始檔,所以先安裝 svn:
sudo apt-get install subversion

假設要將 Redmine 部署在 /var/www/ 底下,執行:
cd /var/www
svn checkout http://redmine.rubyforge.org/svn/branches/1.1-stable redmine-1.1


[Redmine 的資料庫設定]
修改 conf 資料夾下的 database.yml:
cd /var/www/redmine/config
cp database.yml.example database.yml
vim database.yml
將 database.yml 預設 MySQL (default setup) 內容全部註解起來。
檔案最開頭,補上:
production:
  adapter: sqlite3
  database: db/redmine.db
 
development:
  adapter: sqlite3
  database: db/redmine.db

[相關的資料夾設置]
cd /var/www/redmine
mkdir -p tmp public/plugin_assets
sudo chown -R www-data.www-data files log tmp public/plugin_assets
sudo chmod -R 755 files log tmp public/plugin_assets

[執行 Rake 進行部署]
chown -R www-data.www-data /var/www/redmine  # 避免權限問題,把 Redmine 給 HTTP Server 控制者
cd /var/www/redmine
ruby script/about
/var/lib/gems/1.8/bin/rake generate_session_store  # Ubuntu Desktop
RAILS_ENV=production /var/lib/gems/1.8/bin/rake db:migrate
RAILS_ENV=production /var/lib/gems/1.8/bin/rake redmine:load_default_data
Ubuntu 系統預設不會把 /var/lib/gems/1.8/bin 加到環境路徑。
所以呼叫 Rake 程式時,需要使用絕對路徑:/var/lib/gems/1.8/bin/rake
當然,你可以選擇把這個路徑加到系統的 PATH 變數 [Ref. 03]。
或者,直接使用 apt-get 安裝一個系統層級的 Rake 套件,但不建議 [Ref. 04]。

在 Ubuntu Server 版的環境中,Rake 的絕對路徑預設是:
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake

[測試 Redmine]
使用 Ruby 附帶的 WEBrick Web Server 測試啓動 Redmine:
cd /var/www/redmine
ruby script/server webrick -e production

預設的連結是本地端的 3000 埠:
http://localhost:3000

預設管理者的帳號密碼是:
admin/admin

Redmine 佈景主題安裝很簡單,推薦一個不錯的:Pixel Cookers
將佈景主題下載到 /var/www/redmine/public/themes 下,解壓縮就可以用了。

Redmine 主頁面的 html 可以修改這個檔案:
/var/www/redmine/app/views/layouts/base.rhtml



【run with Apache】

補充必要套件:
sudo apt-get install build-essential
sudo apt-get install apache2-prefork-dev libaprutil1-dev libapr1-dev libcurl4-openssl-dev

使用 RubyGems 安裝 Phusion Passenger 及其 Passenger Apache2 Module。
Passenger 也叫做 mod_rails 或 mod_rack,類似 mod_ruby 那種角色。
Passenger Apache2 Module 安裝過程會出現互動選項,請務必謹慎閱讀與選擇。
不同環境的執行結果或許有出入,以下僅記錄我個人環境執行的訊息:
sudo gem install passenger
sudo /var/lib/gems/1.8/bin/passenger-install-apache2-module

Passenger Apache2 Module 安裝開始時的貼心說明:
Here's what you can expect from the installation process:

 1. The Apache 2 module will be installed for you.
 2. You'll learn how to configure Apache.
 3. You'll learn how to deploy a Ruby on Rails application.
# 安裝會完成的三件事。

Don't worry if anything goes wrong. This installer will advise you on how to solve any problems.
# 都說 do not worry 了,那就 do not worry 吧!哈哈!
# 如果真的出現什麼問題,就照它指示的修正,然後再重新執行安裝。

編譯與佈置完成後出現的訊息:
The Apache 2 module was successfully installed.

Please edit your Apache configuration file, and add these lines:
# 下面這三行是要寫到 /etc/apache2/apache2.conf 的。
   LoadModule passenger_module /var/lib/gems/1.8/gems/passenger-3.0.2/ext/apache2/mod_passenger.so
   PassengerRoot /var/lib/gems/1.8/gems/passenger-3.0.2
   PassengerRuby /usr/bin/ruby1.8

After you restart Apache, you are ready to deploy any number of Ruby on Rails
applications on Apache, without any further Ruby on Rails-specific
configuration!
--------------------------------------------
Deploying a Ruby on Rails application: an example

Suppose you have a Rails application in /somewhere. Add a virtual host to your
Apache configuration file and set its DocumentRoot to /somewhere/public:
# 在 /etc/apache2/sites-available 底下新增一個檔案叫:redmine
# 並且把底下這段複製貼到 redmine 這個虛擬主機設定檔
  <virtualhost *:80>
      ServerName www.yourhost.com
      DocumentRoot /somewhere/public    # <-- be sure to point to 'public'!
      <directory /somewhere/public>
         AllowOverride all              # <-- relax Apache security settings
         Options -MultiViews            # <-- MultiViews must be turned off
      </Directory>
   </VirtualHost>
# 注意!裡面的 /somewhere/public 要改成 /var/www/redmine/public 的絕對路徑
# ServerName 可以設定成 localhost
# 因爲技術問題,請自行把上文全形的<>換成 <>

當 /etc/apache2/apache2.conf 與 /etc/apache2/site-available/redmine 都配置好。
執行:
sudo chown -R www-data:www-data /var/www/redmine
sudo a2ensite redmine
sudo service apache2 restart

連線 http://localhost:80 測試。

Reference:
01. http://www.redmine.org/projects/redmine/wiki/RedmineInstall
02. http://www.redmine.org/projects/redmine/wiki/RedmineRepositories
03. http://stackoverflow.com/questions/1664974/rake-command-not-found
04. http://fak3r.com/geek/ruby-on-rails-gem-install-versus-apt-get
05. http://www.redmine.org/issues/8325
06. http://www.redmine.org/boards/2/topics/26138
07. http://jugemchosuke.blogspot.com/2011/06/redmine-1.html

使用 apt-get 安裝 Redmine

*其實不推薦使用 apt-get 安裝,Redmine 或 Rails 的更新常會造成整個網站垮掉 ....

環境:Ubuntu Server 10.04

【快速安裝】

編輯 apt 來源:
sudo vim /etc/apt/source.list

在檔案最後加上:
deb http://ppa.launchpad.net/ondrej/redmine/ubuntu lucid main
deb-src http://ppa.launchpad.net/ondrej/redmine/ubuntu lucid main

執行:
sudo apt-get install apache2 sqlite3
sudo apt-get install redmine
sudo ln -s /usr/share/redmine/public /var/www/redmine

移除:
sudo apt-get autoremove redmine


【環境設定】

如果需要設定 apt-get 的 proxy:
vim /etc/apt/apt.conf.d/70debconf

加入:
Acquire::http::Proxy "http://YOUR_PROXY_SERVER:YOUR_PROXY_PROT";

先把 Redmine 的 PPA 加入 apt-get sources.list:
sudo add-apt-repository ppa:ondrej/redmine
如果以上步驟有問題,則手動 import GPG Public Key。
下載 Redmine PPA 的 Public Key。
(http://keyserver.ubuntu.com:11371/pks/lookup?op=get&search=0x4F4EA0AAE5267A6C)
把內容復制存成文字檔 redmine.public.key,然後:
sudo apt-key add redmine.public.key

sudo apt-get install python-software-properties
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install apparmor-profiles
sudo apt-get install tasksel
sudo tasksel install lamp-server
sudo aa-complain /usr/sbin/mysqld
sudo apt-get install redmine redmine-mysql subversion
sudo aa-enforce /usr/sbin/mysqld
sudo ln -s /usr/share/redmine/public /var/www/redmine
sudo apt-get install libapache2-mod-passenger

vim /etc/apache2/mods-available/passenger.conf 加入:
PassengerDefaultUser www-data 

vim /etc/apache2/sites-available/redmine
<directory/var/www/redmine>
    RailsBaseURI /redmine
    PassengerResolveSymlinksInDocumentRoot on
</Directory>

sudo chmod a+x /usr/share/redmine/public
sudo a2enmod passenger
sudo a2ensite redmine
sudo /etc/init.d/apache2 restart

檢查 http://localhost/redmine

預設的資料庫名稱:redmine_default
預設的資料庫帳號:redmine
預設的資料庫密碼:安裝過程中使用者設定
預設的資料庫設定:/etc/redmine/default/database.yml
預設檔案儲存路徑:/var/lib/redmine/default/files/
Redmine 安裝路徑:/usr/share/redmine

Reference:
http://zx-1986.blogspot.com/2011/02/redmind.html
https://help.ubuntu.com/community/AppArmor
https://help.ubuntu.com/community/Tasksel
www.redmine.org/projects/redmine/wiki/HowTo_Install_Redmine_in_Ubuntu

2011/11/20

vsftpd

Very Secure FTP Daemon

yum install vsftpd
yum install libdb3-util

/etc/vsftpd/vsftpd.conf

Reference:
http://ubuntuforums.org/showthread.php?t=518293
http://ubuntuforums.org/showthread.php?p=3497743
http://www.linuxfocus.org/English/July2004/article341.shtml