顯示具有 redhat 標籤的文章。 顯示所有文章
顯示具有 redhat 標籤的文章。 顯示所有文章

2013/06/03

RHEL 5 安裝 Indefero

http://www.indefero.net

Indefero 是一個 Web 介面 Git 的前端工具,類似 Gitorious。
簡單說,它就是類似 Google Code 那樣的原始碼管理系統。
其實它可以接管 Git、Subversion、Mercurial、Monotone 等 SCM 軟體。
Indefero 是使用 PHP 撰寫的,搭配 Pluf 框架。



【Setup Indefero with Git in RHEL 5.x】

[修改 /etc/hosts]

127.0.0.1    indefero

[MySQL 資料庫]
資料庫版本:MySQL 5.x
資料庫帳號:indefero
資料庫密碼:indefero
資料庫名稱:indefero

mysql -u root -p
mysql> create database indefero;
mysql> ALTER DATABASE indefero CHARACTER SET utf8 COLLATE utf8_general_ci;
mysql> grant all privileges on indefero.* to indefero@localhost identified by 'indefero';

[相關使用者]

手動新增的使用者:git
httpd 預設的使用者:apache

[相關路徑]
/home/git/repositories
/home/git/.ssh
/var/www/html/indefero
/var/www/html/pluf

[1]安裝 Pluf 框架

Pluf:http://www.pluf.org

Pluf 需要至少 5.2.4 版本以上的 PHP,RHEL 5.x 附帶的通常都很舊。
RHEL 5.x 需要的 rpm 套件可以去這找:http://rpms.famillecollet.com

先使用 yum 安裝必須的 PHP 套件:

yum install php-pear
yum install php-pear-Mail php-pear-Mail-Mime php-pear-mail_mime

下載 Pluf 原始檔到 /var/www/html 并解壓縮,完成。

[2]安裝 Indefero

前往:http://projects.ceondo.com/p/indefero/

下載 Indefero 原始檔到 /var/www/html,解壓縮,然後執行:

cd /var/www/html/indefero
cp src/IDF/conf/idf.php-dist src/IDF/conf/idf.php
cp src/IDF/conf/path.php-dist src/IDF/conf/path.php

確認 MySQL 資料庫與資料庫使用者。

修改 src/IDF/conf/idf.php:

$cfg['git_repositories'] = '/home/git/repositories/%s.git';
$cfg['git_remote_url'] = 'git://indefero/%s.git';
$cfg['git_write_remote_url'] = 'git@indefero:%s.git';
$cfg['send_emails'] = false;
$cfg['mail_backend'] = 'smtp';
$cfg['mail_host'] = 'localhost';
$cfg['mail_port'] = 25;
$cfg['url_base'] = 'http://indefero';
$cfg['url_media'] = 'http://indefero/media';
$cfg['url_upload'] = 'http://indefero/media/upload';
$cfg['upload_path'] = '/var/www/html/indefero/www/media/upload';
$cfg['upload_issue_path'] = '/var/www/html/indefero/attachments';
# 超過 40 個字元就可以
$cfg['secret_key'] = 'abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd';
# Database configuration
$cfg['db_login'] = 'indefero';
$cfg['db_password'] = 'indefero';
$cfg['db_database'] = 'indefero';
$cfg['db_server'] = 'localhost';
$cfg['db_version'] = '5.1';
$cfg['db_table_prefix'] = 'indefero_';
$cfg['db_engine'] = 'MySQL';
# 如果有碰到 open_basedir restriction error,
# 執行 cp /etc/mime.types /home,并開啟以下設定:
#$cfg['idf_mimetypes_db'] = '/home/mime.types';

修改 src/IDF/conf/path.php:

# 如果沒有特殊修改,使用預設的相對路徑即可。

開始安裝:

cd /var/www/html/indefero/src
# 以下命令進行測試安裝
php /var/www/html/pluf/src/migrate.php --conf=IDF/conf/idf.php -a -i -d -u
# 以下命令進行實際安裝
php /var/www/html/pluf/src/migrate.php --conf=IDF/conf/idf.php -a -i -d

建立 /var/www/html/indefero/www/bootstrap.php:

require '/var/www/html/indefero/src/IDF/conf/path.php';
require 'Pluf.php';
Pluf::start('/var/www/html/indefero/src/IDF/conf/idf.php');
Pluf_Dispatcher::loadControllers(Pluf::f('idf_views'));

$user = new Pluf_User();
$user->first_name = '管理者姓氏';
$user->last_name = '管理者名字'; // Required! 必須!
$user->login = '管理者帳號'; // must be lowercase! 全部小寫!
$user->email = '管理者信箱';
$user->password = '管理者密碼';
$user->administrator = true;
$user->active = true;
$user->create();
print "Bootstrap ok\n";


建立管理者:

php /var/www/html/indefero/www/bootstrap.php

順利執行完成後,可以刪除或改名 bootstrap.php 檔。

建立 /etc/httpd/conf.d/indefero:

# 請自行把 [ ] 換成 < >
[virtualhost *:80]
    ServerName indefero
    DocumentRoot /var/www/html/indefero/www
    ErrorLog logs/indefero-error_log
    CustomLog logs/indefero-access_log common
[/VirtualHost]
[directory /var/www/html/indefero/www]  
    AllowOverride All
[/Directory]

在 /var/www/html/indefero/www 內補一個 .htaccess:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /index.php/$1

重新啟動 Apache:

service httpd restart

連到 http://indefero 登入看看。

[3]設定 Git Repositories

Indefero 原始檔的 doc 資料夾下,有完整的設定說明檔(doc/syncgit.mdtext)。

建立使用者用以控制 Indefero 的 Git Repositories:

useradd git
mkdir /home/git/repositories
mkdir -p /home/git/.ssh
touch /home/git/.ssh/authorized_keys
chown -R git.git /home/git
chmod 0700 /home/git/.ssh
chmod 0600 /home/git/.ssh/authorized_keys

把 httpd 的控制者加到 Git Repositories 控制者的群組:

usermod -a -G git apache

確認系統可以執行 python 程式,因為後面需要執行 scripts/gitserver.py。

python -v

重新修改 src/IDF/conf/idf.php 內的設定:

$cfg['git_repositories'] = '/home/git/repositories/%s.git';
$cfg['git_remote_url'] = 'git://indefero/%s.git';
$cfg['idf_plugin_syncgit_path_gitserve'] = '/var/www/html/indefero/scripts/gitserve.py';
$cfg['idf_plugin_syncgit_path_authorized_keys'] = '/home/git/.ssh/authorized_keys';
$cfg['idf_plugin_syncgit_sync_file'] = '/tmp/SYNC-GIT';

# Remove the git repositories which do not have a corresponding project
# This is run at cron time
$cfg['idf_plugin_syncgit_remove_orphans'] = false;

# git account home dir
$cfg['idf_plugin_syncgit_git_home_dir'] = '/home/git'; 

# where are going to be the git repositories
$cfg['idf_plugin_syncgit_base_repositories'] = '/home/git/repositories'; 

使用 git 的身份加入一下 Cron job:

* * * * * php /var/www/html/indefero/scripts/gitcron.php


安裝 git-daemon:
yum install git-daemon

制作一個 Git Daemon 寫在 /etc/event.d/local-git-daemon:
start on startup
stop on shutdown
exec /usr/bin/git-daemon \
--user=git --group=git \
--verbose \
--reuseaddr \
--base-path=/home/git/repositories/ \
/home/git/repositories/
respawn

啟動:
start local-git-daemon


使用網友寫的 git-daemon,編寫到 /etc/init.d/git-daemon:
(http://projects.ceondo.com/p/indefero/page/git-daemon-sysV-InitScript/)

#!/bin/sh
### BEGIN INIT INFO
# Provides: git-daemon
# Required-Start: $network $remote_fs $syslog
# Required-Stop: $network $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: git-daemon service
# Description: git-daemon makes git repositories available via the git
# protocol.
### END INIT INFO

# Author: Benjamin Graham "bman@duuit.com"

# Do NOT "set -e"

# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/lib/git-core
DESC="git-daemon service"
NAME=git-daemon
DAEMON=/usr/bin/$NAME
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

# Fallback options values, we use these when
# the /etc/default/git-daemon file does not exist
RUN=no
USER=git
GROUP=git
REPOSITORIES="/home/git/repositories/"

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# If ADVANCED_OPTS is empty, use a default setting
if [ "x$ADVANCED_OPTS" == "x" ];
then
    ADVANCED_OPTS="--base-path=$REPOSITORIES $REPOSITORIES"
fi

DAEMON_ARGS="--syslog --reuseaddr \
$ADVANCED_OPTS"

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

#
# Function that starts the daemon/service
#
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null || return 1
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --background --make-pidfile -- $DAEMON_ARGS || return 2

return 0
}

#
# Function that stops the daemon/service
#
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
# Wait for children to finish too if this is a daemon that forks
# and if the daemon is only ever run from this initscript.
# If the above conditions are not satisfied then add some other code
# that waits for the process to drop all resources that could be
# needed by services started subsequently. A last resort is to
# sleep for some time.
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
[ "$?" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
return "$RETVAL"
}

case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
status)
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
;;
restart|force-reload)
#
# If the "reload" option is implemented then remove the
# 'force-reload' alias
#
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
exit 3
;;

esac
/etc/default/git-daemon

# Defaults for the git-daemon initscript

# Set to yes to start git-daemon
RUN=yes

# Set to the user and group git-daemon should run as
USER=git
GROUP=git

# Set the base path and the directory where the repositories are.
REPOSITORIES="/home/git/repositories/"

# Provide a way to have custom setup.
#
# Note, when ADVANCED_OPTS is defined the REPOSITORIES setting is ignored,
# so take good care to specify exactly what git-daemon have to do.
#
# Here is an example from the man page:
#ADVANCED_OPTS="--verbose --export-all \
# --interpolated-path=/pub/%IP/%D \
# /pub/192.168.1.200/software \
# /pub/10.10.220.23/software"
ADVANCED_OPTS="/usr/lib/git-core/git-daemon \ 
--verbose --base-path=/home/git/repositories \
 /home/git/repositories"

啟動:

chmo a+x /etc/init.d/git-daemon
/etc/init.d/git-daemon start
service httpd restart



【關于 /home/git/repositories】

Git 其實可以 init 一個 bare repository(裸倉儲庫),bare repository 預設允許任何人 push。
實際的 Git 命令是:
cd some_directory && git init --bare

Indefero(大部分相似的系統)正是利用這個 Git 命令幫助使用者建立專案的 Repository。
Indefero 會根據使用者 create project 時給的 project name,
到 /home/git/repositories 內,建立 project_name.git 這種類型的資料夾,
再切換到該資料夾內,使用 git init --bare 初始化這個 Repository。



【版本升級】

備份舊的 Pluf 與 Indefero 資料夾:

cp -r pluf pluf_backup
cp -r indefero indefero_backup

備份舊的 Indefero 資料庫:

mysqldump -u indefero -p --databases indefero > indefero_backup.sql

下載最新的 Pluf 與 Indefero 原始檔,並解壓縮取代掉原本的資料夾。
然後執行資料庫升級:

cd /home/git/public_html/indefero/src
# 測試升級動作
$ php /home/git/public_html/pluf/src/migrate.php --conf=IDF/conf/idf.php -a -d -u
# 執行升級動作
$ php /home/git/public_html/pluf/src/migrate.php --conf=IDF/conf/idf.php -a -d 

重啟 Apache 檢查:
service httpd restart 



【錯誤修正】

[idf_plugin_syncgit_base_repositories]
http://projects.ceondo.com/p/indefero/issues/198/

[Getting Write Access to Git Repositories]
http://www.openflow.org/wk/index.php/Git

Reference:
01. http://projects.ceondo.com/p/indefero/page/Installation/
02. http://code.google.com/hosting/
03. https://git.wiki.kernel.org/index.php/InterfacesFrontendsAndTools
04. http://www.pluf.org/doc/install.html
05. http://zx-1986.blogspot.com/2010/08/git-manual.html

2013/06/02

RHEL 6 安裝 Gitlab [Old]

Gitlab(a.k.a. Gitlabhq)

Gitlab 是一套以 gitolite 爲基礎的 Git Hosting Website,
Gitlab 是用 Ruby on Rails 框架開發的,需要合適的 Ruby 環境。

作業系統:RHEL 6.0 i386

[前置安裝]

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

# yum remove gitosis

yum groupinstall "Development Tools"
yum install libxml2-devel libxslt-devel  libxml2 libxslt
yum install git openssl zlib subversion
yum install sqlite sqlite-devel 
yum install mysql++-devel mysql++ 
yum install readline readline-devel compat-readline5 
yum install libcurl libcurl-devel libstdc++ libstdc++-devel libstdc++-docs compat-libstdc++-33 curl
yum install gcc-c++ patch zlib zlib-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison iconv-devel sudo
yum install libicu 

# http://pkgs.org/download/libicu-devel
wget http://mirror.centos.org/centos/6/os/i386/Packages/libicu-devel-4.2.1-9.el6.i686.rpm
rpm -ivh libicu-devel-4.2.1-9.el6.i686.rpm

yum install python-pip
pip-python install pygments

yum install redis
chkconfig redis on
service redis start

[安裝 Ruby]

# using RVM to install Ruby
# install RVM in system wide

su - 

curl -L get.rvm.io | bash -s stable
source ~/.bash_profile
rvm requirements
rvm install 1.9.2
rvm use 1.9.2 --default

which ruby
which gem

[設定 Gitolite]

adduser -r -s /bin/sh -c 'git version control' -U -m git
adduser -c 'gitlab system' -U -m gitlab

usermod -a -G git gitlab
usermod -a -G rvm gitlab
usermod -a -G rvm git

chmod 755 /home/git
chmod 755 /home/gitlab

logout & login

sudo -H -u gitlab ssh-keygen -q -N '' -t rsa -f /home/gitlab/.ssh/id_rsa
sudo -H -u git git clone http://github.com/gitlabhq/gitolite /home/git/gitolite

sudo -u git sh -c 'echo -e "PATH=\$PATH:/home/git/bin\nexport PATH" > /home/git/.profile'
sudo -u git -i -H /home/git/gitolite/src/gl-system-install
cp /home/gitlab/.ssh/id_rsa.pub /home/git/gitlab.pub
chmod 777 /home/git/gitlab.pub

sudo -u git -H sed -i 's/0077/0007/g' /home/git/share/gitolite/conf/example.gitolite.rc
sudo -u git -H sh -c "PATH=/home/git/bin:$PATH; gl-setup -q /home/git/gitlab.pub"

chmod -R g+rwX /home/git/repositories/
chown -R git:git /home/git/repositories/

# check if gitolite works
# If you CAN NOT clone gitolite-admin repository - DONT PROCEED INSTALLATION
su - gitlab
git clone git@localhost:gitolite-admin.git /tmp/gitolite-admin
rm -rf /tmp/gitolite-admin 
exit

http://sitaramc.github.com/gitolite/
http://sitaramc.github.com/gitolite/rpmdeb.html
http://sitaramc.github.com/gitolite/add.html

[設定 Gitlab]

gem install charlock_holmes
gem install bundler

su - gitlab

cd /home/gitlab
git clone http://github.com/gitlabhq/gitlabhq.git gitlab

cd gitlab
cp config/gitlab.yml.example config/gitlab.yml # using default website setting
cp config/database.yml.sqlite config/database.yml # using SQLite as database

bundle install --without development test --deployment

bundle exec rake gitlab:app:setup RAILS_ENV=production
bundle exec rake gitlab:app:status RAILS_ENV=production

bundle exec rake environment resque:work QUEUE=* RAILS_ENV=production BACKGROUND=yes
bash /home/gitlab/gitlab/resque.sh

bundle exec rails s -e production # test running
bundle exec rails s -e production -d # test running as a daemon

測試網址
http://localhost:3000

預設的帳號密碼
admin@local.host / 5iveL!fe

https://github.com/gitlabhq/gitlabhq/blob/stable/doc/installation.md
http://dl.dropbox.com/u/936096/debian_ubuntu.sh

[設定 Nginx]

yum install nginx

su - gitlab
cd ~/gitlab
cp config/unicorn.rb.orig config/unicorn.rb
bundle exec unicorn_rails -c config/unicorn.rb -E production -D

exit

編輯 /etc/nginx/nginx.conf,在 http { 後加入以下內容:

# 注意修改 YOUR_SERVER_IP 與 YOUR_SUBDOMAIN

upstream gitlab {
    server unix:/home/gitlab/gitlab/tmp/sockets/gitlab.socket;
}

server {
    listen YOUR_SERVER_IP:80;
    server_name YOUR_DOMAIN;
    root /home/gitlab/gitlab/public;

    # individual nginx logs for this gitlab vhost
    access_log  /var/log/nginx/gitlab_access.log;
    error_log   /var/log/nginx/gitlab_error.log;

    location / {
    # serve static files from defined root folder;.
    # @gitlab is a named location for the upstream fallback, see below
    try_files $uri $uri/index.html $uri.html @gitlab;
    }

    # if a file, which is not found in the root folder is requested, 
    # then the proxy pass the request to the upsteam (gitlab unicorn)
    location @gitlab {
      proxy_redirect     off;
      # you need to change this to "https", if you set "ssl" directive to "on"
      proxy_set_header   X-FORWARDED_PROTO http;
      proxy_set_header   Host              YOUR_SUBDOMAIN:80;
      proxy_set_header   X-Real-IP         $remote_addr;

      proxy_pass http://gitlab;
    }

}

編輯 /etc/init.d/gitlab

#! /bin/bash
### BEGIN INIT INFO
# Provides:          gitlab
# Required-Start:    $local_fs $remote_fs $network $syslog redis-server
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: GitLab git repository management
# Description:       GitLab git repository management
### END INIT INFO

DAEMON_OPTS="-c /home/gitlab/gitlab/config/unicorn.rb -E production -D"
NAME=unicorn
DESC="Gitlab service"
PID=/home/gitlab/gitlab/tmp/pids/unicorn.pid
RESQUE_PID=/home/gitlab/gitlab/tmp/pids/resque_worker.pid

case "$1" in
  start)
        CD_TO_APP_DIR="cd /home/gitlab/gitlab"
        START_DAEMON_PROCESS="bundle exec unicorn_rails $DAEMON_OPTS"
        START_RESQUE_PROCESS="./resque.sh"

        echo -n "Starting $DESC: "
        if [ `whoami` = root ]; then
          sudo -u gitlab sh -l -c "$CD_TO_APP_DIR > /dev/null 2>&1 && $START_DAEMON_PROCESS && $START_RESQUE_PROCESS"
        else
          $CD_TO_APP_DIR > /dev/null 2>&1 && $START_DAEMON_PROCESS && $START_RESQUE_PROCESS
        fi
        echo "$NAME."
        ;;
  stop)
        echo -n "Stopping $DESC: "
        kill -QUIT `cat $PID`
        kill -QUIT `cat $RESQUE_PID`
        echo "$NAME."
        ;;
  restart)
        echo -n "Restarting $DESC: "
        kill -USR2 `cat $PID`
        kill -USR2 `cat $RESQUE_PID`
        echo "$NAME."
        ;;
  reload)
        echo -n "Reloading $DESC configuration: "
        kill -HUP `cat $PID`
        kill -HUP `cat $RESQUE_PID`
        echo "$NAME."
        ;;
  *)
        echo "Usage: $NAME {start|stop|restart|reload}" >&2
        exit 1
        ;;
esac

exit 0

避免 SSH 主機信任問題

su - gitlab
ssh git@YOUR_DOMAIN

The authenticity of host 'YOUR_DOMAIN (YOUR_IP)' can't be established.  
RSA key fingerprint is 98:2e:d7:e0:de:9f:ac:67:28:c2:42:2d:37:16:58:4d.
Are you sure you want to continue connecting (yes/no)? 

# 回答 yes 表示信任該主機

注意!目前 Gitlab 有一個 README 顯示 utf8 的 bug
https://github.com/gitlabhq/gitlabhq/issues/725#issuecomment-5669823

測試啓動

chmod +x /etc/init.d/gitlab
/etc/init.d/nginx restart
/etc/init.d/gitlab restart

設定開機啓動

yum install postfix
chkconfig postfix on
chkconfig nginx on
echo "/etc/init.d/gitlab start" >> /etc/rc.local

Reference:
http://zx-1986.blogspot.com/2011/11/gitlabhq.html
http://zx-1986.blogspot.com/2011/11/gitlabhq-in-redhat.html

Redhat 安裝 Gitlabhq [Old]

這是舊的筆記,請前往:
http://zx-1986.blogspot.com/2012/03/setup-gitlab-in-rhel-6.html

this note was out of date! please check the update version:
http://zx-1986.blogspot.com/2012/03/setup-gitlab-in-rhel-6.html

作業系統:RHEL 6.0 i386

cd /opt 

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

yum groupinstall "Development Tools" # thanks for http://dejant.blogspot.com
yum install libxml2-devel libxslt-devel # thanks for http://dejant.blogspot.com
yum install git libxml2 libxslt sqlite sqlite-devel openssl zlib mysql++-devel mysql++ readline-devel compat-readline5 readline libcurl libcurl-devel libstdc++ libstdc++-devel libstdc++-docs compat-libstdc++-33

yum install python-pip
pip-python install pygments
# yum install python-setuptools
# easy_install pygments

adduser gitlabhq
passwd gitlabhq
visudo
#  gitlabhq    ALL=(ALL)    NOPASSWD: ALL

sudo bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
# using sudo for multi-users installed!
# logout, then login as root again

rvm install 1.9.2  
rvm --default use 1.9.2
ruby --version

echo "gem: --no-rdoc --no-ri" > ~/.gemrc
gem update --system  
gem install bundler

echo $rvm_path/src/$(rvm tools strings) 
rvm @global gem install ruby-debug19 -- --with-ruby-include=$rvm_path/src/$(rvm tools strings)
exit

su - gitlabhq
ssh-keygen -t rsa

sudo yum install gitosis

sudo adduser -r -s /bin/sh -c 'git version control' -U -m git
sudo usermod -a -G git gitlabhq
sudo usermod -a -G rvm gitlabhq

sudo -H -u git gitosis-init < /home/gitlabhq/.ssh/id_rsa.pub

sudo chmod 755 /home/git
sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update

cd ~
git clone https://github.com/gitlabhq/gitlabhq.git

cd gitlabhq
vim Gemfile # :%s/git:/https:/g
vim Gemfile.lock # :%s/git:/https:/g

sudo su -

cd /home/gitlabhq/gitlabhq
bundle install # run the "bundle install" as "root" to avoid the permission issue at first time

cd /usr/local/rvm/gems/ruby-1.9.2-p290/bundler/gems
mv ./* /tmp

exit

bundle install # run the "bundle install" as "gitlabhq" to make sure all gems in gitlabhq/ grant to "gitlabhq"
bundle exec rake db:setup RAILS_ENV=production
bundle exec rake db:seed_fu RAILS_ENV=production

vim config/gitosis.yml  # 檢查內容與路徑
rails s -e production # 啟動測試服務器

測試網址
http://localhost:3000

預設的帳號密碼
admin@local.host / 5iveL!fe

# 設定 Nginx

sudo su -
yum remove httpd
gem install passenger
passenger-install-nginx-module

# 選擇 1. Yes: download, compile and install Nginx for me. (recommended)
# passenger-install-nginx-module 會自動下載并編譯安裝 Nginx,預設裝到 /opt/nginx

vim /opt/nginx/conf/nginx.conf

---
user gitlabhq;
 
server {
  listen 80;
  server_name YOUR_IP_ADDRESS;
  root /home/gitlabhq/gitlabhq/public;
  passenger_enabled on;
}
---

/opt/nginx/sbin/nginx # start Nginx server
/opt/nginx/sbin/nginx -s stop # stop Nginx server

Reference:
http://isitruby19.com/linecache19
https://github.com/carlhuda/bundler/issues/1356
https://github.com/mark-moseley/linecache/issues/8
https://github.com/gitlabhq/gitlabhq/issues/66
https://github.com/gitlabhq/gitlabhq/issues/34
https://github.com/gitlabhq/gitlabhq/issues/84
https://github.com/gitlabhq/gitlabhq/issues/141

2012/07/14

RHEL 6 安裝 LDAP



同事 Peter Lai 寫了篇非常清楚的 LDAP Wiki,一定要 Open Source 一下的!
LDAP 服務
LDAP 為輕量級名錄存取協定(Lightweight Directory Access Protocol)的簡稱。
若要簡單的說,LDAP是一種存取資料的方式。 LDAP 伺服器存放著特定格式的資料,提供給許多下游來查詢。 我們可將 LDAP 視為一種特別的資料庫,只是它存放資料的方法較為不同。
名錄資訊樹與項目
LDAP 中所儲存的資料被稱為名錄資訊樹(Directory Information Tree, DIT), 是由多個項目(entry)以階層方式所組成的樹狀資料結構。
物件類別與屬性
每一個項目可以被指派至少一個以上的的物件類別(objectClass), LDAP 已經內建許多物件類別,以供設計出不同類型的項目。
舉例來說,當我們需要設計一個項目用以存放組織或單位資訊,就可指派內建的 organizationalUnit 物件類別給該項目; 若是我們需要有關存放人事資料的資訊,例如員工基本資料,內建的 person 物件類別便是個不錯的選擇。 當然,LDAP 也支援自訂的物件類別。
不同的物件類別可以賦予擁有該類別的項目不同的屬性群(attributes) 在這些屬性群中,有些屬性是一定要存在的,稱為必要屬性(MUST attribute) 而其他不一定要存在的的則稱為選用屬性(MAY attribute) 屬性的值便是我們會在 LDAP 中儲存的資料。
如圖1-2,我們可以看到項目 D 被指派的物件類別為 person 而 person 物件類別被定義可擁有的屬性有: cn, sn, userPassword, telephoneNumber, seeAlso, description,其中 cn 與 sn 為必要的屬性。 值得一提的是,一個 DIT 的根項目(此例中的項目A),必須指派為 domain 物件類別,其必要屬性 dc 屬性。
相對識別名稱與識別名稱
每一個項目都都會有個自己的名字,稱作 相對識別名稱(relative distinguished name, RDN) 是取用項目數個(通常只用一個)屬性名稱與屬性值作為該項目的 RDN
例如項目 D 的 RDN 便可取作 “cn=Peter Lai”(cn 指的是 commonName) 此外,每一個項目在整個 DIT 中亦具有一個 唯一 的名字,稱為 識別名稱(distinguished name, DN) DN 是取用自根項目至該項目中所有項目節點之 RDN,將其以逗號(,)串接而成的字串。
如圖 1-3,我們假設: 項目 A 的 RDN 為 “dc=cwb,dc=gov” 項目 B 的 RDN 為 “ou=mfc”(ou 指的是 organizationUnit) 項目 D 的 RDN 為 “cn=Peter Lai” 則項目 D 的 DN 便為 “cn=Peter Lai,ou=mfc,dc=cwb,dc=gov”
在 DIT 中,項目間的 RND 可能也可以重複,但是 DN 必定是唯一的。 藉由 DN 我們可以找到 DIT 中特定的項目,再取出其中某個屬性值來取得資料。

yum install openldap openldap-clients openldap-servers
yum install httpd php php-ldap
yum insatll phpldapadmin

Reference:
http://tutarticle.com/linux/rhel-6-ldap-server
http://serverfault.com/questions/323497/how-do-i-configure-ldap-on-centos-6-for-user-authentication-in-the-most-secure-a

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

2011/10/24

套件管理員

Python:pip
easy_install 或 setuptools 或 ez_setup.py
使用 easy_install 安裝起來放在 site-packages 的 *.egg 類似 Java 的 *.jar

PHP:Pear

Ruby:RubyGems

Perl:CPAN(Comprehensive Perl Archive Network)

R:CRAN

Node.js:npm

Ubuntu:apt-get、dpkg

Redhat:yum

Mac:homebrew

Reference:
01. http://www.ibm.com/developerworks/cn/linux/l-cppeak3.html

2011/09/20

快速架設 NTP Server

yum install ntp tzdata
chkconfig ntpd on
編輯 /etc/ntp.conf:
# 拒絕 IPv4
restrict default kod nomodify notrap nopeer noquery

# 拒絕 IPv6
restrict -6 default kod nomodify notrap nopeer noquery

# 放行指定的主機,一般會填寫上層 NTP Server
restrict your.time.server

# 預設放行本機
restrict 127.0.0.1
restrict -6 ::1

# 放行指定的私有網路主機
restrict 192.168.100.0 mask 255.255.255.0 nomodify

# 設定上層 NTP Server 
# 原本的 [0|1|2].centos.pool.ntp.org 的可以註解掉
server your.time.server

# 預設時間差異分析檔案與暫不用到的 keys 等
driftfile /var/lib/ntp/drift
keys      /etc/ntp/keys
/etc/init.d/ntpd restart
Reference:
http://linux.vbird.org/linux_server/0440ntp.php#server

2011/09/07

在 RHEL 作業系統內使用 LUN

安裝作業系統或對主機進行磁碟管理時,最好先關機,然後把光纖線拔下來,再做其它動作。

multipathd
dev-mapper

/dev/sda
/dev/dm-1
/dev/mpath/mpath1
/dev/mapper/mpath1

2011/05/31

PyAOS

環境:RHEL 5.6 i386

Reference:
01. http://pyaos.johnny-lin.com/?p=76

2011/05/05

rpmbuild - 以 Python 2.7 為例

Red Hat Enterprise Linux 的很多東西都很舊,特別是 RHEL 5 系列。
有些新的軟體更新,它不見得會跟著推出新的 rpm 檔。
除了使用 tarball 安裝方法,也可以自己包一個 rpm 檔。

環境:RHEL 5.6

安裝必備套件
yum groupinstall "Development Tools"
yum install rpmdevtools

you should NEVER build an RPM with the root user.
絕對不要使用 root 來打包 rpm!


建立一個專門打包 rpm 的使用者帳號
useradd rpm_maker

切換成該使用者
su - rpm_maker

在 rpm_maker 的家目錄下執行
rpmdev-setuptree     # 會建立 ~/rpmbuild 目錄

下載 Python2.7 原始檔,解壓縮,放置 python-2.7.spec 與原始檔
cd ~
wget  http://www.python.org/ftp/python/2.7.1/Python-2.7.1.tar.bz2
tar  jxvf Python-2.7.1.tar.bz2
cp  ~/Python-2.7.1/Misc/RPM/python-2.7.spec  ~/rpmbuild/SPECS/
mv  Python-2.7.1.tar.bz2  ~/rpmbuild/SOURCES/

補足相關套件
yum install tk-devel tcl-devel expat-devel db4-devel gdbm-devel sqlite-devel

根據指定的 spec 建立 rpm 檔
cd ~/rpmbuild/SPECS/
rpmbuild -ba python-2.7.spec

http://blog.milford.io/2012/01/building-and-installing-python-2-7-rpms-on-centos-5-7/

Reference:
01. https://fedoraproject.org/wiki/How_to_create_an_RPM_package/zh-tw
02. http://www.grenadepod.com/2009/12/26/building-python-2-6-4-rpm-for-centos-5-4/
03. http://www.ibm.com/developerworks/library/l-rpm1/
04. http://villaroad.com/2010/10/rolling-python-2-6-2-on-centos-5-3/
05. http://willsani.com/2011/03/02/centos-5-5-x86_64-install-python-2-7/
06. http://www.joywang.info/?p=112
07. http://serverfault.com/questions/11209/python-3-0-rpms-for-centos-5-rhel-5
08. http://serverfault.com/questions/162217/upgrading-python-on-rhel5
09. http://stackoverflow.com/questions/4149361/on-linux-suse-or-redhat-how-do-i-load-python-2-7

2011/04/11

phpMyAdmin

【Red Hat Enterprise Linux】
yum install phpmyadmin
cp  /usr/share/phpmyadmin/config.sample.inc.php  /usr/share/phpmyadmin/config.inc.php
cat  /etc/httpd/conf.d/phpmyadmin.conf

【Ubuntu】
apt-get install phpmyadmin

【tarball】

新版的 phpMyAdmin 需要 PHP 5.2 以上的環境。

大致流程是:
1. 安裝 HTTP Server 與 PHP 環境
2. 下載最新版的 phpMyAdmin
3. 解壓縮到 HTTP Server 的 Document Root
4. 編輯 phpMyAdmin 的 config.inc.php 檔
5. 連線 http://localhost/phpmyadmin 測試

# using Ubuntu + Apache + MySQL
sudo apt-get install apache2 mysql-server php5-mysql
cd /var/www
wget URL_of_phpMyAdmin_Source_Package.zip (http://www.phpmyadmin.net/home_page/downloads.php)
unzip phpMyAdmin*.zip
mv phpMyAdmin* phpmyadmin
cd /var/www/phpmyadmin
cp config.sample.inc.php config.inc.php
vim config.inc.php

簡單的 config.inc.php 設定
$cfg['blowfish_secret'] = '123'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

/*
 * Servers configuration
 */
$i = 0; 

/*
 * First server
 */
$i++;
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'cookie';
/* Server parameters */
$cfg['Servers'][$i]['host'] = 'localhost';  // MySQL 主機的位址
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
/* Select mysqli if your server has it */
$cfg['Servers'][$i]['extension'] = 'mysql';
$cfg['Servers'][$i]['AllowNoPassword'] = false;

Reference:
01. http://wiki.phpmyadmin.net/pma/Quick_Install
02. http://wiki.phpmyadmin.net/pma/Config

2011/04/08

使用 Kickstart 自動安裝 RHEL

The Red Hat Kickstart installation method is used primarily (but not exclusively) by the Red Hat Enterprise Linux operating system to automatically perform unattended operating system installation and configuration.

【製作 Kickstart 光碟】

事前准備:
Red Hat Enterprise Linux 安裝光碟
一些編寫好的 kickstart 檔案(例如:rhel5.cfg)
一台可以燒錄 ISO 檔的 Linux 主機

首先,把 Red Hat Enterprise Linux 安裝光碟放到 Linux 主機。
到裏面找到 /images 這個資料夾,復制裏面的 boot.iso 到 Linux 主機上。

使用以下指令把 boot.iso 挂載到 /opt/boot_iso:
sudo su -
mkdir -p /opt/boot_iso
mount -o loop -t iso9660 boot.iso /opt/boot_iso

復制 /opt/boot_iso 裏面的 isolinux 資料夾:
cd /opt/boot_iso
cp -R isolinux /opt/

復制編寫好的 kickstart 檔案到 isolinux 資料夾:
cp rhel5.cfg /opt/isolinux

將 isolinux 資料夾制作成可開機的 boot.iso:
cd /opt/isolinux
mkisofs -r -T -J -V "kickstart" -b isolinux.bin -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -v -o /opt/kickstart.iso .

[注意!]
RHEL 5 跟 RHEL 6 的光碟檢查碼與架構都不一樣!
每個不同的版號都得使用不同版本的 boot.iso 來制作 kickstart 光碟!
簡單說:
RHEL 5.5 得使用它自己的 boot.iso 制作自己的 kickstart 光碟。
RHEL 5.6 得使用它自己的 boot.iso 制作自己的 kickstart 光碟。
雖然它們的 rhel5.cfg 檔案可以共用。
這跟光碟的檢查碼有關系。

將產生的 /opt/kickstart.iso 檔案燒錄成光碟。

使用該光碟開機後,在安裝的 shell prompt 中輸入指定的 kickstart 檔名:
> linux ks=cdrom://rhel5.cfg

當開機檔案與指定的 kickstart 讀取到記憶體之後,開始安裝時,可能會碰到以下訊息:
The Red Hat Enterprise Linux CD was not found in any of your CDROM drives.
Please insert the Red Hat Enterprise Linux CD and press OK to retry.

此時,把 kickstart 光碟拿出來,放入原始的 RHEL 安裝光碟,壓 Enter。
順利的話,RHEL 就會照指定的 kickstart 檔的設定安裝了。

Reference:
01. http://en.wikipedia.org/wiki/Kickstart_(Linux)
02. http://junktrap.naihl.net/doku.php?id=redhat:kickstartbootcd

2011/03/25

架設 Yum 伺服器

#!/bin/bash

# RPMForge

cd /yum/rpmforge5/i386/
wget --accept=rpm --level=1 --recursive --no-parent -N --no-directories --directory-prefix=./rpmforge http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/
wget --accept=rpm --level=1 --recursive --no-parent -N --no-directories --directory-prefix=./dag http://apt.sw.be/redhat/el5/en/i386/dag/RPMS/
wget --accept=rpm --level=1 --recursive --no-parent -N --no-directories --directory-prefix=./extras http://apt.sw.be/redhat/el5/en/i386/extras/RPMS/

cd /yum/rpmforge5/x86_64/
wget --accept=rpm --level=1 --recursive --no-parent -N --no-directories --directory-prefix=./rpmforge http://apt.sw.be/redhat/el5/en/x86_64/rpmforge/RPMS/
wget --accept=rpm --level=1 --recursive --no-parent -N --no-directories --directory-prefix=./dag http://apt.sw.be/redhat/el5/en/x86_64/dag/RPMS/
wget --accept=rpm --level=1 --recursive --no-parent -N --no-directories --directory-prefix=./extras http://apt.sw.be/redhat/el5/en/x86_64/extras/RPMS/

cd /yum/rpmforge6/i386/
wget --accept=rpm --level=1 --recursive --no-parent -N --no-directories --directory-prefix=./rpmforge http://apt.sw.be/redhat/el6/en/i386/rpmforge/RPMS/
wget --accept=rpm --level=1 --recursive --no-parent -N --no-directories --directory-prefix=./dag http://apt.sw.be/redhat/el6/en/i386/dag/RPMS/
wget --accept=rpm --level=1 --recursive --no-parent -N --no-directories --directory-prefix=./extras http://apt.sw.be/redhat/el6/en/i386/extras/RPMS/

cd /yum/rpmforge6/x86_64/
wget --accept=rpm --level=1 --recursive --no-parent -N --no-directories --directory-prefix=./rpmforge http://apt.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/
wget --accept=rpm --level=1 --recursive --no-parent -N --no-directories --directory-prefix=./dag http://apt.sw.be/redhat/el6/en/x86_64/dag/RPMS/
wget --accept=rpm --level=1 --recursive --no-parent -N --no-directories --directory-prefix=./extras http://apt.sw.be/redhat/el6/en/x86_64/extras/RPMS/

# EPEL

cd /yum/epel5/
wget --accept=rpm --level=1 --recursive --no-parent -N --no-directories --directory-prefix=./i386 http://download.fedora.redhat.com/pub/epel/5/i386/
wget --accept=rpm --level=1 --recursive --no-parent -N --no-directories --directory-prefix=./i386/debug http://download.fedora.redhat.com/pub/epel/5/i386/debug/
wget --accept=rpm --level=1 --recursive --no-parent -N --no-directories --directory-prefix=./x86_64 http://download.fedora.redhat.com/pub/epel/5/x86_64/
wget --accept=rpm --level=1 --recursive --no-parent -N --no-directories --directory-prefix=./x86_64/debug http://download.fedora.redhat.com/pub/epel/5/x86_64/debug/
wget --accept=rpm --level=1 --recursive --no-parent -N --no-directories --directory-prefix=./i386 http://download.fedora.redha t.com/pub/epel/testing/5/i386/
wget --accept=rpm --level=1 --recursive --no-parent -N --no-directories --directory-prefix=./x86_64 http://download.fedora.red hat.com/pub/epel/testing/5/x86_64/

cd /yum/epel6/
wget --accept=rpm --level=1 --recursive --no-parent -N --no-directories --directory-prefix=./i386 http://download.fedora.redhat.com/pub/epel/6/i386/
wget --accept=rpm --level=1 --recursive --no-parent -N --no-directories --directory-prefix=./i386/debug http://download.fedora.redhat.com/pub/epel/6/i386/debug/
wget --accept=rpm --level=1 --recursive --no-parent -N --no-directories --directory-prefix=./x86_64 http://download.fedora.redhat.com/pub/epel/6/x86_64/
wget --accept=rpm --level=1 --recursive --no-parent -N --no-directories --directory-prefix=./x86_64/debug http://download.fedora.redhat.com/pub/epel/6/x86_64/debug/
wget --accept=rpm --level=1 --recursive --no-parent -N --no-directories --directory-prefix=./i386 http://download.fedora.redhat.com/pub/epel/testing/6/i386/
wget --accept=rpm --level=1 --recursive --no-parent -N --no-directories --directory-prefix=./x86_64 http://download.fedora.redhat.com/pub/epel/testing/6/x86_64/

# Remi

cd /yum/remi5/
wget --accept=rpm --level=1 --recursive --no-parent -N --no-directories --directory-prefix=./i386 http://rpms.famillecollet.com/enterprise/5/remi/i386/
wget --accept=rpm --level=1 --recursive --no-parent -N --no-directories --directory-prefix=./i386 http://rpms.famillecollet.com/enterprise/5/olds/i386/
wget --accept=rpm --level=1 --recursive --no-parent -N --no-directories --directory-prefix=./x86_64 http://rpms.famillecollet.com/enterprise/5/remi/x86_64/ 
wget --accept=rpm --level=1 --recursive --no-parent -N --no-directories --directory-prefix=./x86_64 http://rpms.famillecollet.com/enterprise/5/olds/x86_64/

cd /yum/remi6/
wget --accept=rpm --level=1 --recursive --no-parent -N --no-directories --directory-prefix=./i386 http://rpms.famillecollet.com/enterprise/6/remi/i386/
wget --accept=rpm --level=1 --recursive --no-parent -N --no-directories --directory-prefix=./i386 http://rpms.famillecollet.com/enterprise/6/olds/i386/
wget --accept=rpm --level=1 --recursive --no-parent -N --no-directories --directory-prefix=./x86_64 http://rpms.famillecollet.com/enterprise/6/remi/x86_64/ 
wget --accept=rpm --level=1 --recursive --no-parent -N --no-directories --directory-prefix=./x86_64 http://rpms.famillecollet.com/enterprise/6/olds/x86_64/

# CentOS

cd /yum/centos5
wget --accept=rpm --level=1 --recursive --no-parent -N --no-directories --directory-prefix=./i386 http://mirror.centos.org/centos/5/os/i386/CentOS/
wget --accept=rpm --level=1 --recursive --no-parent -N --no-directories --directory-prefix=./x86_64 http://mirror.centos.org/centos/5/os/x86_64/CentOS/

#cd /yum/centos6/
#wget --accept=rpm --level=1 --recursive --no-parent -N --no-directories --directory-prefix=./i386 http://mirror.centos.org/centos/6/os/i386/
#wget --accept=rpm --level=1 --recursive --no-parent -N --no-directories --directory-prefix=./x86_64 http://mirror.centos.org/centos/6/os/x86_64/

2011/03/15

Gitorious

Setup Gitorious in Ubuntu
Setup Gitorious in RHEL 5.x

https://github.com/zx1986/Gitorious-Setup

舊筆記怎麽被刪掉了!?
該死!