tag:blogger.com,1999:blog-186890562024-02-19T16:25:42.171+08:00張旭about.me/zx1986Anonymoushttp://www.blogger.com/profile/12837594111497927241noreply@blogger.comBlogger101125tag:blogger.com,1999:blog-18689056.post-25465462904151263742014-10-29T07:59:00.002+08:002014-10-29T08:00:32.072+08:00使用 Docker<br />
Docker 是基於 LXC(Linux Container)的一個工具,<br />
Docker 妥善運用了 LXC,並提供了一個友善的操作介面(Command Line)以及額外的功能。<br />
<br />
---<br />
<br />
# LXC<br />
<br />
先了解一下 LXC:<br />
LXC is a userspace interface for the Linux kernel containment features. <br />
Through a powerful API and simple tools, it lets Linux users easily create and manage system or application containers. <br />
LXC is often considered as something in the middle between a chroot on steroids and a full fledged virtual machine. <br />
The goal of LXC is to create an environment as close as possible as a standard Linux installation but without the need for a separate kernel.<br />
<br />
LXC 是一個讓你可以輕鬆操作 userspace 的工具,只要你的 Linux kernel 支援 LXC,就可以透過 LXC 封裝 kernel 層以外的任何東西。<br />
<br />
我舉一個比較糟糕的例子來說明:<br />
<br />
想像 Linux 作業系統就是一個煮東西的大鍋子,你想要用鍋子煮出什麼東西,就要往鍋子裡加什麼料。<br />
你加了 Apache,加了 MySQL,加了 PHP;接著又加了 Ruby,加了各式 Ruby gems;加了 Python,加了各種 Python eggs …<br />
於是大鍋子漸漸開始變成了大雜燴,各種食材的味道開始互相影響。 <br />
<br />
LXC 就像是在大鍋子上面加了一個大蒸架(LXC API),讓你可以放置各種容器(Container)盛煮各種料理(Packages,Programs)。<br />
Docker 就是讓你可以非常簡單地使用這個蒸架,放置這些各別的料理容器,以及其他一些額外的好用功能(例如 docker pull)。<br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipQlpDVqJwVU-K2ssKF463w_rmYJ-Tk-1EciL047Y6YUavQY035jd6dYRQcmY9zhWTkxq2z6Y58lwBxt15hXJquaoXXqaozLXQJYOR2DEf2q5r85icHVNzJhWwJaGw3p3azFlLHA/s1600/container.png" imageanchor="1"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipQlpDVqJwVU-K2ssKF463w_rmYJ-Tk-1EciL047Y6YUavQY035jd6dYRQcmY9zhWTkxq2z6Y58lwBxt15hXJquaoXXqaozLXQJYOR2DEf2q5r85icHVNzJhWwJaGw3p3azFlLHA/s1600/container.png" /></a><br />
<br />
Reference:<br />
https://linuxcontainers.org/<br />
http://zh.wikipedia.org/wiki/LXC<br />
http://en.wikipedia.org/wiki/UnionFS<br />
<br />
---<br />
<br />
# Docker 基礎<br />
<br />
Docker 有 Server 端跟 Client 端。<br />
<br />
Docker Server 端的主機也叫做 Docker Host;<br />
Docker Server 預設透過 2375 跟 2376 port 提供 Docker REST API。<br />
Docker Client 可以透過 Docker REST API 操作 Docker Server 上的 Docker images 或 containers。<br />
<br />
image 跟 container 可以想像成這樣:<br />
<br />
image 就是事先準備好的料理容器,這些容器是五花八門的。<br />
它可以是乾乾淨淨的料理容器(精簡安裝的 Ubuntu、CentOS、FreeBSD 等),<br />
它也可以事先放了幾杯水、加了幾勺鹽巴(安裝了 Apache、MySQL 等)。<br />
這些料理容器(image)都可以直接拿來放到架上蒸煮(執行),<br />
image 每次被執行時,會將它自己當成藍本,複製產生一個 container,<br />
執行中的 container 可以持續改變(被料理),而 image 則一直以本來的樣子存在著。<br />
<br />
container 是 Docker 執行(docker run 指令)時,以指定的 image 為藍本,產生出來的。<br />
image 可以看成是虛擬機的硬碟檔(例如 VirtualBox 的 vdi 檔,或 Vagrant 的 box 檔),<br />
container 就是根據某個指定的硬碟檔複製產生的虛擬機,產生這個虛擬機的成本是很低的。<br />
執行中的 container 可以看成是開機運行中的虛擬機,可以使用 docker ps 指令查看;<br />
執行完畢的 container 就是已經關機的虛擬機,可以使用 docker ps -a 指令查看。<br />
<br />
container 可以透過 docker commit 指令轉換成 image,<br />
相當於將運行到某個階段虛擬機 snapshot 起來,並匯出變成一個虛擬機硬碟檔。<br />
<br />
剛開始使用時,Docker Client 跟 Docker Server 通常會在同一臺主機上。<br />
在 Ubuntu 中安裝 Docker Client(docker.io)跟 Docker Server(lxc-docker)是非常簡單的:<br />
<br />
1. sudo apt-get update<br />
2. sudo apt-get install docker.io<br />
3. sudo ln -sf /usr/bin/docker.io /usr/local/bin/docker<br />
4. sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9<br />
5. sudo sh -c "echo deb https://get.docker.com/ubuntu docker main > /etc/apt/sources.list.d/docker.list”<br />
6. sudo apt-get update<br />
7. sudo apt-get install lxc-docker<br />
<br />
正常來說,安裝完 lxc-docker,就會自動啟動 Docker Server,可以執行 sudo docker info 指令來確認。<br />
<br />
因為 docker daemon(Docker Server)預設使用 root 權限啟動的,<br />
所以透過 Docker Client 對它進行操作時,通常都要加上 sudo 命令。<br />
http://askubuntu.com/questions/477551/how-can-i-use-docker-without-sudo<br />
<br />
先檢查本機有哪些可用的 image:<br />
sudo docker image<br />
<br />
搜尋遠端是否有自己感興趣的 image:<br />
sudo docker search ubuntu<br />
<br />
將遠端的 image 複製到本地端:<br />
sudo docker pull ubuntu<br />
<br />
以 ubuntu image 為基礎,創建一個 container,並進入這個 container 的 shell;<br />
相當於使用 ubuntu image 創建一台虛擬機,並登入這台虛擬機的 console:<br />
sudo docker run -i -t ubuntu<br />
<br />
接著在 container 的 shell 中,就可以跟平常操作 Ubuntu 一樣進行使用了。<br />
使用告一段落後,如果使用 exit 指令離開,這個 container 就會結束執行(相當於虛擬機關機),<br />
想要離開 container 的 shell,但是讓它保持執行,可以先按 Ctrl + P,再按 Ctrl + Q 離開。<br />
<br />
顯示執行中的 container(container 對於 Docker 而言就像是 process):<br />
sudo docker ps<br />
<br />
顯示全部的 container:<br />
sudo docker ps -a<br />
<br />
啟動沒有執行的 container:<br />
sudo docker start {container id}<br />
<br />
接續回到執行中的 container 的畫面:<br />
sudo docker attach {container id}<br />
<br />
將進行到某個階段的 container 轉成 image:<br />
sudo docker commit {container id} {image name}<br />
<br />
移除 container:<br />
sudo docker rm {container id}<br />
<br />
移除 image:<br />
sudo docker rmi {image name}<br />
<br />
執行一個 container,將它的 80 port 對應到 Docker Host 主機的 8080 port,並將 Docker Host 的 /www 共享到 container 的 /var/www/ 目錄:<br />
sudo docker run -i -t -p 8080:80 -v /www:/var/www ubuntu<br />
<br />
Reference:<br />
https://docs.docker.com/articles/basics/<br />
https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-getting-started<br />
http://slopjong.de/2014/09/17/install-and-run-a-web-server-in-a-docker-container/<br />
<br />
---<br />
<br />
# Docker Best PracticeAnonymoushttp://www.blogger.com/profile/12837594111497927241noreply@blogger.com0tag:blogger.com,1999:blog-18689056.post-22705290690756657162013-06-03T00:05:00.000+08:002013-06-03T00:08:48.689+08:00RHEL 5 安裝 Indeferohttp://www.indefero.net<br />
<br />
Indefero 是一個 Web 介面 Git 的前端工具,類似 Gitorious。<br />
簡單說,它就是類似 Google Code 那樣的原始碼管理系統。<br />
其實它可以接管 Git、Subversion、Mercurial、Monotone 等 SCM 軟體。<br />
Indefero 是使用 PHP 撰寫的,搭配 Pluf 框架。<br />
<br />
*<br />
<br />
【Setup Indefero with Git in RHEL 5.x】<br />
<br />
[修改 /etc/hosts]<br />
<br />
<pre class="prettyprint">127.0.0.1 indefero
</pre><br />
[MySQL 資料庫]<br />
資料庫版本:MySQL 5.x<br />
資料庫帳號:indefero<br />
資料庫密碼:indefero<br />
資料庫名稱:indefero<br />
<br />
<pre class="prettyprint">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';
</pre><br />
[相關使用者]<br />
<br />
手動新增的使用者:git<br />
httpd 預設的使用者:apache<br />
<br />
[相關路徑]<br />
/home/git/repositories<br />
/home/git/.ssh<br />
/var/www/html/indefero<br />
/var/www/html/pluf<br />
<br />
[1]安裝 Pluf 框架<br />
<br />
Pluf:http://www.pluf.org<br />
<br />
Pluf 需要至少 5.2.4 版本以上的 PHP,RHEL 5.x 附帶的通常都很舊。<br />
RHEL 5.x 需要的 rpm 套件可以去這找:http://rpms.famillecollet.com<br />
<br />
先使用 yum 安裝必須的 PHP 套件:<br />
<br />
<pre class="prettyprint">yum install php-pear
yum install php-pear-Mail php-pear-Mail-Mime php-pear-mail_mime
</pre><br />
下載 Pluf 原始檔到 /var/www/html 并解壓縮,完成。<br />
<br />
[2]安裝 Indefero<br />
<br />
前往:http://projects.ceondo.com/p/indefero/<br />
<br />
下載 Indefero 原始檔到 /var/www/html,解壓縮,然後執行:<br />
<br />
<pre class="prettyprint">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
</pre><br />
確認 MySQL 資料庫與資料庫使用者。<br />
<br />
修改 src/IDF/conf/idf.php:<br />
<br />
<pre class="prettyprint">$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';
</pre><br />
修改 src/IDF/conf/path.php:<br />
<br />
<pre class="prettyprint"># 如果沒有特殊修改,使用預設的相對路徑即可。
</pre><br />
開始安裝:<br />
<br />
<pre class="prettyprint">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
</pre><br />
建立 /var/www/html/indefero/www/bootstrap.php:<br />
<br />
<pre class="prettyprint">
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";
</pre><br />
建立管理者:<br />
<br />
<pre class="prettyprint">php /var/www/html/indefero/www/bootstrap.php
</pre><br />
順利執行完成後,可以刪除或改名 bootstrap.php 檔。<br />
<br />
建立 /etc/httpd/conf.d/indefero:<br />
<br />
<pre class="prettyprint"># 請自行把 [ ] 換成 < >
[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]
</pre><br />
在 /var/www/html/indefero/www 內補一個 .htaccess:<br />
<br />
<pre class="prettyprint">Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /index.php/$1
</pre><br />
重新啟動 Apache:<br />
<br />
<pre class="prettyprint">service httpd restart
</pre><br />
連到 http://indefero 登入看看。<br />
<br />
[3]設定 Git Repositories<br />
<br />
Indefero 原始檔的 doc 資料夾下,有完整的設定說明檔(doc/syncgit.mdtext)。<br />
<br />
建立使用者用以控制 Indefero 的 Git Repositories:<br />
<br />
<pre class="prettyprint">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
</pre><br />
把 httpd 的控制者加到 Git Repositories 控制者的群組:<br />
<br />
<pre class="prettyprint">usermod -a -G git apache
</pre><br />
確認系統可以執行 python 程式,因為後面需要執行 scripts/gitserver.py。<br />
<br />
<pre class="prettyprint">python -v
</pre><br />
重新修改 src/IDF/conf/idf.php 內的設定:<br />
<br />
<pre class="prettyprint">$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';
</pre><br />
使用 git 的身份加入一下 Cron job:<br />
<br />
<pre class="prettyprint">* * * * * php /var/www/html/indefero/scripts/gitcron.php
</pre><br />
<del><br />
安裝 git-daemon:<br />
yum install git-daemon<br />
<br />
制作一個 Git Daemon 寫在 /etc/event.d/local-git-daemon:<br />
start on startup<br />
stop on shutdown<br />
exec /usr/bin/git-daemon \<br />
--user=git --group=git \<br />
--verbose \<br />
--reuseaddr \<br />
--base-path=/home/git/repositories/ \<br />
/home/git/repositories/<br />
respawn<br />
<br />
啟動:<br />
start local-git-daemon<br />
</del><br />
<br />
使用網友寫的 git-daemon,編寫到 /etc/init.d/git-daemon:<br />
(http://projects.ceondo.com/p/indefero/page/git-daemon-sysV-InitScript/)<br />
<br />
<pre class="prettyprint">#!/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"
</pre><br />
啟動:<br />
<br />
<pre class="prettyprint">chmo a+x /etc/init.d/git-daemon
/etc/init.d/git-daemon start
service httpd restart
</pre><br />
*<br />
<br />
【關于 /home/git/repositories】<br />
<br />
Git 其實可以 init 一個 bare repository(裸倉儲庫),bare repository 預設允許任何人 push。<br />
實際的 Git 命令是:<br />
cd some_directory && git init --bare<br />
<br />
Indefero(大部分相似的系統)正是利用這個 Git 命令幫助使用者建立專案的 Repository。<br />
Indefero 會根據使用者 create project 時給的 project name,<br />
到 /home/git/repositories 內,建立 project_name.git 這種類型的資料夾,<br />
再切換到該資料夾內,使用 git init --bare 初始化這個 Repository。<br />
<br />
*<br />
<br />
【版本升級】<br />
<br />
備份舊的 Pluf 與 Indefero 資料夾:<br />
<br />
<pre class="prettyprint">cp -r pluf pluf_backup
cp -r indefero indefero_backup
</pre><br />
備份舊的 Indefero 資料庫:<br />
<br />
<pre class="prettyprint">mysqldump -u indefero -p --databases indefero > indefero_backup.sql
</pre><br />
下載最新的 Pluf 與 Indefero 原始檔,並解壓縮取代掉原本的資料夾。<br />
然後執行資料庫升級:<br />
<br />
<pre class="prettyprint">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
</pre><br />
重啟 Apache 檢查:<br />
<pre class="prettyprint">service httpd restart
</pre><br />
*<br />
<br />
【錯誤修正】<br />
<br />
[idf_plugin_syncgit_base_repositories]<br />
http://projects.ceondo.com/p/indefero/issues/198/<br />
<br />
[Getting Write Access to Git Repositories]<br />
http://www.openflow.org/wk/index.php/Git<br />
<br />
Reference:<br />
01. http://projects.ceondo.com/p/indefero/page/Installation/<br />
02. http://code.google.com/hosting/<br />
03. https://git.wiki.kernel.org/index.php/InterfacesFrontendsAndTools<br />
04. http://www.pluf.org/doc/install.html<br />
05. http://zx-1986.blogspot.com/2010/08/git-manual.htmlAnonymoushttp://www.blogger.com/profile/12837594111497927241noreply@blogger.com0No. 110, Lane 21, Wénhú St, Neihu District, Taipei City, Taiwan 11425.091075 121.559834524.976033 121.401906 25.206117 121.71776299999999tag:blogger.com,1999:blog-18689056.post-38422814593018909682013-06-02T23:53:00.000+08:002013-06-02T23:56:59.966+08:00RHEL 6 安裝 Gitlab [Old]Gitlab(a.k.a. Gitlabhq)<br />
<br />
Gitlab 是一套以 gitolite 爲基礎的 Git Hosting Website,<br />
Gitlab 是用 Ruby on Rails 框架開發的,需要合適的 Ruby 環境。<br />
<br />
作業系統:RHEL 6.0 i386<br />
<br />
[前置安裝]<br />
<br />
<pre class="prettyprint">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
</pre><br />
[安裝 Ruby]<br />
<br />
<pre class="prettyprint"># 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
</pre><br />
[設定 Gitolite]<br />
<br />
<pre class="prettyprint">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
</pre><br />
http://sitaramc.github.com/gitolite/<br />
http://sitaramc.github.com/gitolite/rpmdeb.html<br />
http://sitaramc.github.com/gitolite/add.html<br />
<br />
[設定 Gitlab]<br />
<br />
<pre class="prettyprint">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
</pre><br />
測試網址<br />
http://localhost:3000<br />
<br />
預設的帳號密碼<br />
admin@local.host / 5iveL!fe<br />
<br />
https://github.com/gitlabhq/gitlabhq/blob/stable/doc/installation.md<br />
http://dl.dropbox.com/u/936096/debian_ubuntu.sh<br />
<br />
[設定 Nginx]<br />
<br />
<pre class="prettyprint">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
</pre><br />
編輯 /etc/nginx/nginx.conf,在 http { 後加入以下內容:<br />
<br />
<pre class="prettyprint"># 注意修改 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;
}
}
</pre><br />
編輯 /etc/init.d/gitlab<br />
<br />
<pre class="prettyprint">#! /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
</pre><br />
避免 SSH 主機信任問題<br />
<br />
<pre class="prettyprint">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 表示信任該主機
</pre><br />
注意!目前 Gitlab 有一個 README 顯示 utf8 的 bug<br />
https://github.com/gitlabhq/gitlabhq/issues/725#issuecomment-5669823<br />
<br />
測試啓動<br />
<br />
<pre class="prettyprint">chmod +x /etc/init.d/gitlab
/etc/init.d/nginx restart
/etc/init.d/gitlab restart
</pre><br />
設定開機啓動<br />
<br />
<pre class="prettyprint">yum install postfix
chkconfig postfix on
chkconfig nginx on
echo "/etc/init.d/gitlab start" >> /etc/rc.local
</pre><br />
Reference:<br />
http://zx-1986.blogspot.com/2011/11/gitlabhq.html<br />
http://zx-1986.blogspot.com/2011/11/gitlabhq-in-redhat.htmlAnonymoushttp://www.blogger.com/profile/12837594111497927241noreply@blogger.com0tag:blogger.com,1999:blog-18689056.post-1045122551541933482013-06-02T12:23:00.000+08:002013-06-02T23:55:41.785+08:00Redhat 安裝 Gitlabhq [Old]<span style="color: red;">這是舊的筆記,請前往:</span><br />
<span style="color: red;">http://zx-1986.blogspot.com/2012/03/setup-gitlab-in-rhel-6.html</span><br />
<br />
<span style="color: red;">this note was out of date! please check the update version:</span><br />
<span style="color: red;">http://zx-1986.blogspot.com/2012/03/setup-gitlab-in-rhel-6.html</span><br />
<br />
作業系統:RHEL 6.0 i386<br />
<br />
<pre class="prettyprint">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
</pre><br />
<pre class="prettyprint">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 # 啟動測試服務器
</pre><br />
測試網址<br />
http://localhost:3000<br />
<br />
預設的帳號密碼<br />
admin@local.host / 5iveL!fe<br />
<br />
# 設定 Nginx<br />
<br />
<pre class="prettyprint">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
</pre><br />
Reference:<br />
http://isitruby19.com/linecache19<br />
https://github.com/carlhuda/bundler/issues/1356<br />
https://github.com/mark-moseley/linecache/issues/8<br />
https://github.com/gitlabhq/gitlabhq/issues/66<br />
https://github.com/gitlabhq/gitlabhq/issues/34<br />
https://github.com/gitlabhq/gitlabhq/issues/84<br />
https://github.com/gitlabhq/gitlabhq/issues/141Anonymoushttp://www.blogger.com/profile/12837594111497927241noreply@blogger.com19Taipei City, Taiwan25.091075 121.559834524.976033 121.401906 25.206117 121.71776299999999tag:blogger.com,1999:blog-18689056.post-62743306109539296962013-06-02T11:45:00.000+08:002013-06-02T12:21:20.186+08:00Ubuntu 安裝 Gitlabhq [Failed]<span style="color: red;">這是無效的筆記,請前往:</span><br />
<span style="color: red;">http://zx-1986.blogspot.com/2012/03/setup-gitlab-in-rhel-6.html</span><br />
<br />
<span style="color: red;">it does NOT WORK! please check the update version:</span><br />
<span style="color: red;">http://zx-1986.blogspot.com/2012/03/setup-gitlab-in-rhel-6.html</span><br />
<br />
在 Ubuntu 11.04 Server 安裝 Gitlabhq<br />
<br />
THIS IS NOT WORK!<br />
<br />
<pre class="prettyprint">su -
export http_proxy="your_proxy"
export https_proxy="your_proxy"
apt-get update && apt-get upgrade
</pre><br />
# 設定 Ruby 環境<br />
<br />
<pre class="prettyprint">apt-get install git-core curl gcc checkinstall make build-essential
apt-get install libxml2-dev libxslt-dev sqlite3 libsqlite3-dev libcurl4-openssl-dev libreadline5-dev libc6-dev libssl-dev libmysql++-dev zlib1g-dev
bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
source /etc/bash.bashrc
rvm install 1.9.2
rvm install 1.9.3
rvm --default use 1.9.2
gem update --system
echo "gem: --no-rdoc --no-ri" > ~/.gemrc
</pre><br />
注意:使用的是 rvm 管控下的 Ruby 1.9.2 與其搭配的 rubygems<br />
<br />
# 安裝 Gitosis<br />
<br />
<pre class="prettyprint">apt-get install git gitosis
adduser --system --shell /bin/sh --gecos 'git version control' --group --disabled-password --home /home/git git
ssh-keygen -t rsa
sudo -H -u git gitosis-init < ~/.ssh/id_rsa.pub
chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update
</pre>
# 安裝 Gitlabhq
<pre class="prettyprint">cd /opt
pip install pygments
apt-get install python-setuptools
easy_install pygments
apt-get install libsqlite3-dev
gem install bundler
git clone https://github.com/gitlabhq/gitlabhq.git
cd gitlabhq
vim Gemfile # :%s/git:/https:/g
vim Gemfile.lock # :%s/git:/https:/g
echo $rvm_path/src/$(rvm tools strings)
rvm @global gem install ruby-debug19 -- --with-ruby-include=$rvm_path/src/$(rvm tools strings)
bundle install
bundle exec rake db:setup RAILS_ENV=production
bundle exec rake db:seed_fu RAILS_ENV=production
vim /opt/gitlabhq/config/gitosis.yml # 檢查內容與路徑
rails s -e production # 啟動測試服務器
</pre>
測試網址
http://localhost:3000
預設的帳號密碼
admin@local.host / 5iveL!fe
# 安裝 Nginx
<pre class="prettyprint">apt-get autoremove apache2*
dpkg --purge apache2*
apt-get install nginx
gem install passenger
passenger-install-nginx-module
# 選擇 1. Yes: download, compile and install Nginx for me. (recommended)
# passenger-install-nginx-module 會自動下載并編譯安裝 Nginx,預設裝到 /opt/nginx
</pre>設定 Nginx 當作 Gitlabhq 的 Server
<pre class="prettyprint">vim /opt/nginx/conf/nginx.conf
===
user root;
server {
listen 80;
server_name gitlabhq;
root /opt/gitlabhq/public;
passenger_enabled on;
}
===
</pre><br />
Reference:<br />
http://isitruby19.com/linecache19<br />
https://github.com/carlhuda/bundler/issues/1356<br />
https://github.com/mark-moseley/linecache/issues/8<br />
https://github.com/gitlabhq/gitlabhq/issues/66<br />
https://github.com/gitlabhq/gitlabhq/issues/34<br />
https://github.com/gitlabhq/gitlabhq/issues/84<br />
https://github.com/gitlabhq/gitlabhq/issues/141Anonymoushttp://www.blogger.com/profile/12837594111497927241noreply@blogger.com5Taipei City, Taiwan25.091075 121.559834524.975944 121.401906 25.206206 121.71776299999999tag:blogger.com,1999:blog-18689056.post-50051630152718728132013-05-22T17:13:00.000+08:002013-05-22T22:21:14.468+08:00Git 使用手冊本篇文章以 Markdown 編寫,較佳的閱讀體驗請前往:<br />
<a href="http://zx1986.github.io/blog/using-git.html">http://zx1986.github.io/blog/using-git.html</a><br />
<br />
[Git][1] 是一套版本控制系統(Version Control System),<br />
常用在對程式碼或文件進行版本管理及協作。<br />
從前比較常用的版本控制系統是 SVN(Subversion), <br />
但 SVN 是中央式的,而 Git 是分散式的,<br />
且 Git 比 SVN 強大、先進許多。<br />
<br />
我簡單解釋版本控制的概念,請想像一下:<br />
<br />
你電腦內的資料夾類似一個書櫃,書櫃裡有許多書(檔案),<br />
偶而有新書進來(新增檔案),有舊書捐出去(刪除檔案),<br />
有時候會在某些書上作筆記、寫心得、畫畫(檔案內容變動)。<br />
<br />
你在書櫃的側邊貼上一張「大大的白紙」,對書櫃裡的所有變動作紀錄。<br />
<br />
紀錄新書擺入的時間,擺放的位置,甚至後面加個註記:『購於網路拍賣』;<br />
紀錄舊書清除的時間,原本的位置,加個註記:『捐給讀書會』;<br />
紀錄某書寫入筆記的時間,筆記的內容,心得或隨手塗鴉;<br />
紀錄 ......<br />
<br />
你可以把這張書櫃側邊貼著的「大大白紙」想像成版本控制系統(Git),<br />
而且版本控制系統(Git)做的記錄會更鉅細靡遺。<br />
<br />
當你對一個資料夾啟用 Git 進行追蹤管理與控制時(Git 初始化時),<br />
Git 程式會在該資料夾底下新增一個名為「.git」的隱藏資料夾,<br />
「.git」類似於前面提到那張「大大的白紙」,裡面紀錄了檔案的變化史。<br />
Git 會對該資料夾內所有的檔案與其底層的所有資料夾進行紀錄追蹤,<br />
而追蹤、記錄的結果都會儲存到「.git」這個資料夾內。<br />
<br />
不過,Git 並不會主動記錄,必須是由使用者操作它去執行記錄的動作。<br />
使用者類似史官的角色,而 Git 則是書寫史冊的工具。<br />
<br />
Git 背後的運作方式是非常聰明而複雜的,<br />
它的功能也不僅僅在於記錄(還有恢復、合併、差異處理等等)。<br />
<br />
團隊合作時,同樣一個文件,在你手上跟在他人手上,可能有不一樣的變化史。<br />
當你的檔案要與他人的合併時,內容有出入的地方,Git 會協助進行處理。<br />
(例如開發同一個程式,你寫的 code 可能被他人改動,或反之。)<br />
<br />
### 安裝與設定 Git<br />
<br />
Ubuntu 底下安裝 Git 非常簡單,只要在終端機執行:<br />
<pre class="prettyprint">sudo apt-get install git-core git-doc
</pre>接着,建議執行以下指令,將系統預設編輯器設定為 Vim:<br />
<pre class="prettyprint">sudo update-alternatives --config editor
</pre>每個使用者帳號都會有自己的 Git 設定檔,通常是:<br />
<pre class="prettyprint">~/.gitconfig
</pre>例如我的設定檔內容是:<br />
<pre class="prettyprint">[user]
name = 張旭
email = zx1986@gmail.com
[color]
diff = auto
</pre>初始化 Git<br />
(資料夾內會多出一個名為 .git 的隱藏資料夾):<br />
<pre class="prettyprint">git init
</pre>之後只要每次修改或新增檔案後,<br />
執行以下兩個指令,Git 就會做一次紀錄:<br />
<pre class="prettyprint">git add 修改或新增的檔案名
git commit -m '關於此次修改的描述訊息'
</pre>可以開一個新的資料夾進行練習:<br />
<pre class="prettyprint">mkdir test
cd test
touch hello
git init
git add hello
git commit -m 'hello, Git!'
</pre>好了,您已經開始在使用 Git 啦!<br />
<br />
### Git 輔助說明<br />
<br />
需要注意,Git 不會把空的資料夾加入控管,<br />
例如 log、cache 這類資料夾,我們通常不會想要追蹤裏面的檔案,<br />
但還是需要這個資料夾存在,可以在底下建立一個隱藏檔,例如 .gitkeep:<br />
<pre class="prettyprint">cd log
tocuh .gitkeep
</pre>在跟「.git」同一層的目錄中,可以建立一個 .gitignore 檔案。<br />
.gitignore 用來設定「不希望被 Git 控管的檔案與資料夾」。<br />
一個簡單的 .gitignore 內容可以是這樣:<br />
<pre class="prettyprint">cache/
log/*.log
tmp/
*.tmp
*.swp
*.o
*.so
*.a
*.exe
*~
</pre>執行 `git help` 會顯示常用的 Git 指令與簡單說明:<br />
<pre class="prettyprint">add Add file contents to the index
bisect Find by binary search the change that introduced a bug
branch List, create, or delete branches
checkout Checkout a branch or paths to the working tree
clone Clone a repository into a new directory
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
fetch Download objects and refs from another repository
grep Print lines matching a pattern
init Create an empty git repository or reinitialize an existing one
log Show commit logs
merge Join two or more development histories together
mv Move or rename a file, a directory, or a symlink
pull Fetch from and merge with another repository or a local branch
push Update remote refs along with associated objects
rebase Forward-port local commits to the updated upstream head
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index
show Show various types of objects
status Show the working tree status
tag Create, list, delete or verify a tag object signed with GPG
</pre>在 Git 指令後加上 -h 參數,能夠查詢該指令詳細的用法,例如:<br />
<pre class="prettyprint">git add -h
git commit -h
git pull -h
git push -h
</pre>要查詢更完整的指令手冊,則執行:`git help 指令名稱`<br />
<br />
### 練習 Git<br />
<br />
我推薦一個非常棒的線上練習:[Try Git](http://try.github.io)<br />
<br />
這是由線上學習網站 [Code School](http://codeschool.com) 開發的,<br />
他們還有一個 Git Real 的系列課程,我也非常推薦,<br />
但 Git Real 系列課程是需要收費的。<br />
<br />
Try Git 會帶着你練習基礎的 Git 指令,<br />
畫面上半部是簡單明瞭的指令與情境說明,<br />
畫面中間是一個模擬的 Console 端介面,<br />
畫面下半部是當前情境下資料夾內的狀況。<br />
雖然內容都是英文,但用字遣詞並不難,<br />
就當成是玩電動闖關,邊玩邊學。<br />
<br />
當進行到 Remote Repositories 這個關卡時,<br />
如果對 Repository、Local、Remote 不大瞭解,<br />
可以再回來這,繼續閱讀後面的內容。<br />
<br />
### 關於 Git Repository 與 Branch<br />
<br />
被 Git 所管理的專案,就是 Git Repository(倉儲)。<br />
簡單點說,一個含有「.git」的資料夾,就是一個 Git Repository。<br />
而一個 Git Repository 內,可以建立很多 Branch(分支),<br />
不同的分支代表不同的變化史。<br />
<br />
分支是可以任意建立、刪除、合併的。<br />
<br />
Git Repository 裡預設的 Trunk Branch(主幹)稱為「master」,<br />
其他的 Branch(分支)則由使用者自行命名,<br />
master 這個 branch 也是可以被改成其他名字的。<br />
(其實 Git 的世界並沒有 Trunk 這種講法,那是 SVN 的習慣,<br />
在 Git 的世界,應該說那是“一個被叫做 master 的 branch”。)<br />
<br />
Git 是一個分散式的版本控制系統,不同於 SVN 的 Server/Client 架構,<br />
Git 不需要像 SVN 必須有一個 Repository Server 作為主要的倉儲伺服器。<br />
Git 預設就可以使用 ssh 互相進行 Repository 傳輸了。<br />
<br />
當使用 git clone 指令從遠端複製一個 Git Repository 到本地端電腦上時,<br />
遠端的 Git Repository 通常稱為「origin」,「origin」可能有若干的 branch。<br />
本地端 Git Repository 沒有特別的名稱,本地端也有自己的 branch。<br />
<br />
`git remote -v` 指令可以查詢當前 Git Repository 的遠端來源。<br />
<br />
假設一個簡單的應用情境:<br />
<br />
假設遠端的電腦叫做 Remote;本地端的電腦叫做 Local。<br />
Remote 上面有一個 Git Repository 資料夾叫做 remote_repository。<br />
<br />
要將 remote_repository 複製到 Local 並命名為 local_repository,<br />
在 Local 執行:<br />
<pre class="prettyprint">Local$ git clone 「Remote 使用者帳號@Remote 位址」:「remote_repository 在 Remote 上的路徑」 local_repository
</pre>如果您執行過 scp 指令,相信對這個 git clone 格式會覺得很熟悉。<br />
<br />
複製完成(git clone)後,Local 與 Remote 已經可以分開獨立工作了。<br />
Git 不必拘泥於一定要把修改過的檔案存回當初取得檔案的地方。<br />
Remote 可以在 remote_repository 裡發展它的檔案;<br />
Local 可以在 local_repository 裡發展它的檔案。<br />
<br />
等到哪天 Remote 突然想取得並合併 Local 發展的檔案,<br />
可以在 Remote 上執行:<br />
<pre class="prettyprint">Remote$ git pull 「Local 使用者帳號@Local 位址」:「local_repository 在 Local 上的路徑」
</pre>當然,如果 Local 想取得與合併其他人發展的檔案,<br />
可以在 Local 上執行:<br />
<pre class="prettyprint">Local$ git pull 「使用者帳號@位址」:「路徑」
</pre><br />
* 補充說明<br />
<br />
git fetch - Download objects and refs from another repository. <br />
git merge - Join two or more development histories together. <br />
git pull - Fetch from and merge with another repository or a local branch. <br />
<br />
`git pull` 等於先執行了 `git fetch`,然後再自動執行 `git merge` 。<br />
[有前輩建議][4]少用 `git pull`,改用 `git fetch` 搭配 `git merge` 。<br />
[也有前輩建議][5]應當多使用 `git rebase` 或 `git pull --rebase` 。<br />
<br />
### SVN 式的往日時光<br />
<br />
之前,我在不同的電腦上修改程式:研究室的電腦、宿舍的電腦、筆記型電腦。<br />
因此我在研究室的一台主機上架了 SVN 伺服器,程式主要版本儲存在 SVN 伺服器上。<br />
每當在不同的電腦進行程式編輯時,會先從 SVN 伺服器上抓最新版本的程式下來。<br />
編輯告一段落後,再把修改過的程式上傳回 SVN 伺服器。<br />
程式集中在一台 SVN 伺服器上,要編輯時從上面更新下來,編輯完再更新回去。<br />
<br />
從 SVN 轉換到 Git 時,會很習慣於從前 SVN 那種模式:<br />
<br />
1. 使用 svn checkout 從 SVN 伺服器將整個 Repository 複製到本機端。<br />
2. 本機端對 Repository 的內容進行編輯、修改、新增、刪除等等。<br />
3. 使用 svn update 檢查 SVN 伺服器有沒有其他更新與自己修改的內容有衝突。<br />
4. 解決內容衝突的情況。<br />
5. 使用 svn commit 將自己本機端的所有修改上傳到 SVN 伺服器。<br />
<br />
怎麼用 Git 做到類似 SVN 那樣的情形?<br />
有個簡單的方法。<br />
<br />
首先,選定一台要當 Repository Server 的機器,假設叫 Server。<br />
在 Server 開一個空的資料夾,假設叫 origin,並切換到該資料夾下。<br />
<pre class="prettyprint">Server$ mkdir origin
Server$ cd origin
</pre>在空資料夾底下執行:<br />
<pre class="prettyprint">Server$ git init --bare
</pre>這個動作會產生一個 [Bare Git Repository][2],<br />
該資料夾下會產生:<br />
<pre class="prettyprint">branches/
config
description
HEAD
hooks/
info/
objects/
refs/
</pre>本地端的電腦,假設叫 Local。<br />
Local 上一個叫 local_project 的資料夾要上傳到 Server 進行統一管理。<br />
<br />
切換到該資料夾底下,執行:<br />
<pre class="prettyprint">Local$ git add .
Local$ git commit -a -m 'initialization'
Local$ git remote add origin 「Server 使用者帳號@Server 位址」:「Server 上 origin 資料夾的路徑」
Local$ git push origin master
</pre>完成以後,其他的電腦就可以使用以下指令,<br />
從 Server 上的 origin 複製 local_project 的內容:<br />
<pre class="prettyprint">Other$ git clone 「Server 使用者帳號@Server 位址」:「Server 上 origin 資料夾的路徑」 「自訂的資料夾名稱」
</pre>其他電腦要將其修改的內容傳回 Server,可以執行:<br />
<pre class="prettyprint">Other$ git push origin master
</pre><br />
### Git Repository Hosting<br />
<br />
Git Repository 除了使用 git 協定或 ssh 協定,<br />
還可以使用 http、https 等方式傳輸、瀏覽、管理。<br />
如果不想要用簡單的 Bare Git Repository 架設 Repository Server,<br />
有些 Open Source 的工具可以選擇:<br />
<br />
- [Gitosis](https://github.com/res0nat0r/gitosis)<br />
- [Gitorious](http://gitorious.org/)<br />
- [Gitlab](http://gitlab.org/)<br />
<br />
全世界最知名的 Git Repository Hosting 網站:<br />
<br />
- [Github](https://github.com/)<br />
<br />
中國大陸版的 Github:<br />
<br />
- [GitCafe](https://gitcafe.com/)<br />
<br />
Github 與 GitCafe 都非常棒,<br />
它們的使用教學也有很多 Git 技巧可以參考:<br />
<br />
https://help.github.com/ <br />
https://gitcafe.com/GitCafe/Help <br />
<br />
GitCafe 的 Git [作弊表][3]。<br />
<br />
_Git Cheating Sheet_<br />
<br />
<pre class="prettyprint">git init # 將當前資料夾進行 Git 初始化
git add . # 將當前資料夾內所有檔案加入 Git 追蹤(tracking 或 staging)
git add 檔案名稱 # 把當前資料夾內某個檔案加入 Git 追蹤(tracking 或 staging)
git status # 查詢從上一次 commit 到現在,資料夾裡有哪些變化,各個檔案處於什麼狀況
git commit -a # 將目前的變動送繳 Git 進行紀錄,會進入編寫修改訊息的畫面
git commit -a -m "*" # commit 時直接寫入修改訊息,不進入編寫修改訊息的畫面
git tag v1.0 # 將當前 commit 過後的檔案版本命名為 v1.0
git diff # 比較所有檔案的內容與上一次 commit 時有何差異
git diff v1.0 v2.0 # 比較 v1.0 與 v2.0 兩個版本間所有檔案的內容
git diff v1.0:檔案名稱 v2.0:檔案名稱 # 比較 v1.0 與 v2.0 兩個版本間某個檔案的內容
git log # 查詢所有版本的修改狀況,顯示各版本的 hash 編號
git log -p # 查詢哪幾行被修改
git log --stat --summary # 查詢每個版本間變動的檔案跟行數
git show v1.0 # 查詢 v1.0 版裡的修改內容
git show v1.0:檔案名稱 # 查詢某個檔案在 v1.0 時的內容
git show HEAD # 看此版本修改的資料
git show HEAD^ # 看此版本前一版的修改的資料
git show HEAD^^ # 看此版本前前一版的修改的資料
git grep "*" v1.0 # 查詢 0.01 版裡頭有沒有某些內容
git grep "*" # 查詢現在的版本裡有沒有某些內容
git branch # 查看現有的分支
git branch 分支名稱 # 建立新的分支
git branch 分支名稱 v1.0 # 依照 v1.0 版本裡的內容來建立一個分支
git branch -d 分支名稱 # 刪除某個分支
git merge 某個分支名稱 # 將當前所在的分支與某個分支合併,如果出現衝突,會紀錄在有衝突的檔案中
git checkout master # 切換到主幹上
git checkout 分支名稱 # 切換到某個分支上
git checkout HEAD # 將所有檔案恢復到上次 commit 的狀態
git checkout -- 檔案名稱 # 將某個檔案恢復到上次 commit 的狀態
git reset --hard 某個版本的 hash 編號 # 整個 Repository 恢復到某個版本的狀態
git count-objects # 分析 Git 資料庫狀況,計算鬆散的物件
git gc # 維護 Git 資料庫,重組物件
git fsck --full # 應該是類似 Git 磁碟重組之類的東西
</pre><br />
Reference: <br />
http://github.com/schacon/whygitisbetter <br />
http://git-scm.com/documentation <br />
http://gitcafe.com/riku/GitTips <br />
http://gitimmersion.com/ <br />
http://gitref.org <br />
http://rypress.com/tutorials/git/ <br />
<br />
[1]: http://git-scm.com/<br />
[2]: http://www.saintsjd.com/2011/01/what-is-a-bare-git-repository/<br />
[3]: https://gitcafe.com/GitCafe/Help/blob/master/Git/Git_Cheat_Sheet.md<br />
[4]: http://longair.net/blog/2009/04/16/git-fetch-and-merge <br />
[5]: http://ihower.tw/blog/archives/3843 Anonymoushttp://www.blogger.com/profile/12837594111497927241noreply@blogger.com2tag:blogger.com,1999:blog-18689056.post-30604768505571874502013-05-19T22:12:00.000+08:002013-05-22T17:25:54.316+08:00安裝 Percona XtraDB Cluster本篇文章以 Markdown 編寫,較佳的閱讀體驗請前往:<br />
<a href="http://zx1986.github.io/blog/setup-percona-xtradb-cluster.html">http://zx1986.github.io/blog/setup-percona-xtradb-cluster.html</a><br />
<br />
## 背景知識<br />
<br />
#### Codership<br />
<br />
[Codership][1] 是一家成立於 2007 年的公司,公司的 Founder 都是 Database 專家。<br />
Codership 致力於研究及實做高擴展性且快速的資料庫同步機制(Replication),<br />
並帶頭制定了名爲 WSREP 的 API 標準,<br />
且根據這套 API 實做了 Galera 同步器(Replicator)。<br />
<br />
#### WSREP(Write Set REPlication)<br />
<br />
[WSREP][2] 是一個爲 DBMS(DataBase Management System)設計的 API 標準,<br />
它爲 DBMS 類型的應用程式建立了一個 Replication 介面(Interface),<br />
這個介面位於 DBMS 軟體與 Replication Servcie Provider(即 Replicator)之間。<br />
[WSREP Group][3] 是討論與建立這個標準的開放性羣組。<br />
<br />
> WSREP API defines a set of application callbacks and replication library calls necessary to implement synchronous writeset replication of transactional databases and similar applications. It aims to abstract and isolate replication implementation from application details.<br />
<br />
#### Galera Replicator<br />
<br />
[Galera][4] 是一套根據 WSREP 標準實做出來的 Replication 函式庫。<br />
Galera 的運作架構可以參考[它們的說明][5]。大致的原則是:<br />
當對 Cluster 中其中一個節點做寫入(Write)時,<br />
Galera 會自動將寫入動作 Replicate 到 Cluster 其他的節點上。<br />
<br />
> Galera implements WSREP pluggable interface, and can provide several replication modes and topologies, including the ultimate Synchronous Multi-Master replication.<br />
<br />
#### MySQL Galera Cluster<br />
<br />
傳統的 [MySQL Server][6] 只要打上 WSREP 的 Patch,支援了 WSREP 介面,<br />
再搭配使用 Galera 函式庫,調整好設定檔,就可以組出一個 Cluster。<br />
<br />
> MySQL/Galera cluster uses Galera library for the replication implementation. To interface with Galera replication, we have enhanced MySQL server to support replication API definition in the wsrep API project.<br />
<br />
#### MariaDB Galera Cluster<br />
<br />
相較於 MySQL 要額外打 Patch,<br />
MariaDB 直接推出包好的 [MariaDB Galera Cluster][7],<br />
MariaDB 還針對不同的 Linux 發佈版提供了[套件庫][8]。<br />
它是 Percona XtraDB Cluster 之外的另一個選擇。<br />
<br />
#### Percona XtraDB Cluster(PXC)<br />
<br />
Percona 是一家專業的 MySQL 顧問與技術公司,<br />
他們有一個很知名的 MySQL Blog:[MySQL Performance][9];<br />
Percona 也開發了許多知名的[資料庫工具與軟體][10]。<br />
<br />
XtraDB 是 Percona 基於 InnoDB 改良出來的一個資料庫引擎。<br />
在 XtraDB 引擎的基礎上,Percona 發佈了一個修改過的 MySQL:Percona Server,<br />
而 Percona XtraDB Cluster 則是 Percona Server + Galera Library 的整合產品。<br />
Percona XtraDB Cluster 的資料庫同步機制是靠 Galera 完成。 <br />
<br />
## 安裝 Percona XtraDB Cluster<br />
<br />
最新的 XtraDB 安裝檔: <br />
[Percona XtraDB Cluster][11] <br />
[XtraBackup][12]<br />
<br />
以 Red Hat 環境(RHEL,Cent OS)爲例。<br />
<br />
<pre class="prettyprint">rpm -Uhv http://www.percona.com/downloads/percona-release/percona-release-0.0-1.x86_64.rpm
yum install Percona-XtraDB-Cluster-server Percona-XtraDB-Cluster-client percona-xtrabackup
vim /etc/my.cnf
[mysqld]
wsrep_provider=/usr/lib64/libgalera_smm.so
wsrep_cluster_name=叢集的名稱
wsrep_cluster_address=gcomm://節點一的位址,節點二的位址,節點三的位址
wsrep_slave_threads=4
wsrep_sst_method=rsync
binlog_format=ROW
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
innodb_locks_unsafe_for_binlog=1
service mysql start --wsrep-cluster-address="gcomm://"
mysql -e "CREATE FUNCTION fnv1a_64 RETURNS INTEGER SONAME 'libfnv1a_udf.so'"
mysql -e "CREATE FUNCTION fnv_64 RETURNS INTEGER SONAME 'libfnv_udf.so'"
mysql -e "CREATE FUNCTION murmur_hash RETURNS INTEGER SONAME 'libmurmur_udf.so'"
mysqladmin -u root password '12345678'
service mysql stop
service mysql start
mysql -u root -p
mysql> show status like 'wsrep_%';
</pre><br />
以上是第一個節點的設定,其他節點只要重複到啓動 MySQL 那個步驟,<br />
並將啓動的指令改爲:`service mysql start`<br />
<br />
* `--wsrep-cluster-address="gcomm://"` 參數代表初始化一個全新的叢集!<br />
<br />
#### SST<br />
<br />
> State Snapshot Transfer is the full copy of data from one node to another.<br />
<br />
SST 是 State Snapshot Transfer 的縮寫,指的是 PXC 各節點間同步資料的方式。<br />
可以在 /etc/my.cnf 中透過 wsrep_sst_method 參數來設定。<br />
PXC 有三種同步方式,分別是:<br />
<br />
* wsrep_sst_method=mysqldump<br />
<br />
> If you use mysqldump SST it should be the same as this mysql client connection address plus you need to set wsrep_sst_auth variable to hold user:password pair. The user should be privileged enough to read system tables from donor and create system tables on this node. For simplicity that could be just the root user. Note that it also means that you need to properly set up the privileges on the new node before attempting to join the cluster.<br />
<br />
* wsrep_sst_method=rsync<br />
<br />
> If you use rsync SST, wsrep_sst_auth is not necessary unless your SST script makes use of it.<br />
<br />
* wsrep_sst_method=xtrabackup<br />
<br />
> If you use xtrabackup as SST method, it will use /usr/bin/wsrep_sst_xtrabackup provided in Percona-XtraDB-Cluster-server package. And this script also needs user password if you have a password for root@localhost.<br />
<br />
要使用 [xtrabackup 當作 SST method][13] 時,<br />
需要設定 Database 的 root password 到 /etc/my.cnf 內,<br />
例如:`wsrep_sst_auth=root:12345678`<br />
<br />
PXC 官方手冊: <br />
http://www.percona.com/doc/percona-xtradb-cluster/installation.html <br />
http://www.percona.com/doc/percona-xtradb-cluster/manual/bootstrap.html <br />
<br />
PXC 專有名詞: <br />
http://www.percona.com/doc/percona-xtradb-cluster/glossary.html<br />
<br />
Reference: <br />
http://www.mysqlperformanceblog.com/2013/01/29/how-to-start-a-percona-xtradb-cluster/ <br />
http://www.percona.com/files/presentations/WEBINAR-percona-xtradb-cluster-installation-and-setup.pdf <br />
<br />
[1]: http://www.codership.com/company/<br />
[2]: https://launchpad.net/wsrep/<br />
[3]: https://launchpad.net/wsrep-group/<br />
[4]: https://launchpad.net/galera/<br />
[5]: http://www.codership.com/products/galera_replication/<br />
[6]: http://www.codership.com/products/mysql_galera/<br />
[7]: https://downloads.mariadb.org/mariadb-galera/<br />
[8]: https://downloads.mariadb.org/mariadb/repositories/<br />
[9]: http://www.mysqlperformanceblog.com<br />
[10]: http://www.percona.com/software<br />
[11]: http://www.percona.com/downloads/Percona-XtraDB-Cluster/LATEST/<br />
[12]: http://www.percona.com/downloads/XtraBackup/LATEST/<br />
[13]: http://serverfault.com/questions/389190/xtrabackup-for-sst-with-xtradb-cluster<br />
Anonymoushttp://www.blogger.com/profile/12837594111497927241noreply@blogger.com0tag:blogger.com,1999:blog-18689056.post-5987906820133998672013-01-14T14:56:00.000+08:002013-01-14T14:57:01.536+08:00Apache 的 Proxy 設定http://httpd.apache.org/docs/2.4/mod/mod_proxy.html<br />
<br />
Forward Proxy:ProxyRequests<br />
Reverse Proxy:ProxyPassAnonymoushttp://www.blogger.com/profile/12837594111497927241noreply@blogger.com0tag:blogger.com,1999:blog-18689056.post-55176811183096850782012-08-19T23:41:00.000+08:002012-08-21T22:50:13.381+08:00Bootstraphttps://speakerdeck.com/u/evenwu/p/twitter-bootstrap-hao-yong-de-wang-ye-she-ji-kuang-jia-1<br />
<br />
(http://bootswatch.com/)<br />
(https://wrapbootstrap.com/)<br />
(http://ckrack.github.com/fbootstrapp/)<br />
(http://addyosmani.github.com/jquery-ui-bootstrap/)Anonymoushttp://www.blogger.com/profile/12837594111497927241noreply@blogger.com0tag:blogger.com,1999:blog-18689056.post-58755621541268552882012-08-19T23:36:00.004+08:002013-05-22T17:14:33.363+08:00Javascript MVChttp://javascriptmvc.com<br />
<br />
(http://javascriptmvc.com/docs.html#!jQuery.fixture)Anonymoushttp://www.blogger.com/profile/12837594111497927241noreply@blogger.com0tag:blogger.com,1999:blog-18689056.post-50409060888042792542012-07-15T11:50:00.002+08:002012-07-15T11:52:04.267+08:00Haskellapt-get install haskell-platform<br />
<br />
http://hackage.haskell.org/platform/linux.html<br />
http://www.vex.net/~trebla/haskell/haskell-platform.xhtml<br />
http://www.haskell.org/ghc/<br />
<br />
http://yannesposito.com/Scratch/en/blog/Yesod-tutorial-for-newbies/Anonymoushttp://www.blogger.com/profile/12837594111497927241noreply@blogger.com0tag:blogger.com,1999:blog-18689056.post-13809462481189818222012-07-14T18:06:00.001+08:002012-07-14T18:06:43.155+08:00RHEL 6 安裝 LDAP<br />
<br />
同事 Peter Lai 寫了篇非常清楚的 LDAP Wiki,一定要 Open Source 一下的!<br />
LDAP 服務<br />
LDAP 為輕量級名錄存取協定(Lightweight Directory Access Protocol)的簡稱。<br />
若要簡單的說,LDAP是一種存取資料的方式。 LDAP 伺服器存放著特定格式的資料,提供給許多下游來查詢。 我們可將 LDAP 視為一種特別的資料庫,只是它存放資料的方法較為不同。<br />
名錄資訊樹與項目<br />
LDAP 中所儲存的資料被稱為名錄資訊樹(Directory Information Tree, DIT), 是由多個項目(entry)以階層方式所組成的樹狀資料結構。<br />
物件類別與屬性<br />
每一個項目可以被指派至少一個以上的的物件類別(objectClass), LDAP 已經內建許多物件類別,以供設計出不同類型的項目。<br />
舉例來說,當我們需要設計一個項目用以存放組織或單位資訊,就可指派內建的 organizationalUnit 物件類別給該項目; 若是我們需要有關存放人事資料的資訊,例如員工基本資料,內建的 person 物件類別便是個不錯的選擇。 當然,LDAP 也支援自訂的物件類別。<br />
不同的物件類別可以賦予擁有該類別的項目不同的屬性群(attributes) 在這些屬性群中,有些屬性是一定要存在的,稱為必要屬性(MUST attribute) 而其他不一定要存在的的則稱為選用屬性(MAY attribute) 屬性的值便是我們會在 LDAP 中儲存的資料。<br />
如圖1-2,我們可以看到項目 D 被指派的物件類別為 person 而 person 物件類別被定義可擁有的屬性有: cn, sn, userPassword, telephoneNumber, seeAlso, description,其中 cn 與 sn 為必要的屬性。 值得一提的是,一個 DIT 的根項目(此例中的項目A),必須指派為 domain 物件類別,其必要屬性 dc 屬性。<br />
相對識別名稱與識別名稱<br />
每一個項目都都會有個自己的名字,稱作 相對識別名稱(relative distinguished name, RDN) 是取用項目數個(通常只用一個)屬性名稱與屬性值作為該項目的 RDN<br />
例如項目 D 的 RDN 便可取作 “cn=Peter Lai”(cn 指的是 commonName) 此外,每一個項目在整個 DIT 中亦具有一個 唯一 的名字,稱為 識別名稱(distinguished name, DN) DN 是取用自根項目至該項目中所有項目節點之 RDN,將其以逗號(,)串接而成的字串。<br />
如圖 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”<br />
在 DIT 中,項目間的 RND 可能也可以重複,但是 DN 必定是唯一的。 藉由 DN 我們可以找到 DIT 中特定的項目,再取出其中某個屬性值來取得資料。<br />
<br />
yum install openldap openldap-clients openldap-servers<br />
yum install httpd php php-ldap<br />
yum insatll phpldapadmin<br />
<br />
Reference: <br />
http://tutarticle.com/linux/rhel-6-ldap-server <br />
http://serverfault.com/questions/323497/how-do-i-configure-ldap-on-centos-6-for-user-authentication-in-the-most-secure-aAnonymoushttp://www.blogger.com/profile/12837594111497927241noreply@blogger.com0tag:blogger.com,1999:blog-18689056.post-31531243634916204492012-07-06T22:36:00.000+08:002012-07-09T10:56:24.204+08:00gitflowgit-flow 下載:<br />
<code><br />
git clone https://github.com/nvie/gitflow.git<br />
</code><br />
<br />
git-flow 有綁一個 submodule 叫 shFlags(https://github.com/nvie/shFlags)<br />
必須執行以下指令來設定:<br />
<code><br />
git submodule init && git submodule update<br />
</code><br />
<br />
如果無法執行 git submodule update<br />
可以直接切換到剛 clone 下來的 gitflow 內,手動下載 shFlags:<br />
<code><br />
cd gitflow<br />
rm -rf shFlags<br />
git clone https://github.com/nvie/shFlags.git<br />
</code><br />
<br />
git-flow 安裝:<br />
<code><br />
cd gitflow<br />
sudo make install<br />
</code><br />
<br />
使用說明:<br />
http://jeffkreeftmeijer.com/2010/why-arent-you-using-git-flow/<br />
http://codesherpas.com/screencasts/on_the_path_gitflow.mov<br />
http://vimeo.com/16018419<br />
<br />
Reference:<br />
01. https://github.com/nvie/gitflow<br />
02. http://ihower.tw/blog/archives/5140<br />
03. https://github.com/nvie/gitflow/raw/develop/contrib/gitflow-installer.shAnonymoushttp://www.blogger.com/profile/12837594111497927241noreply@blogger.com0tag:blogger.com,1999:blog-18689056.post-36042125600121525442012-07-06T14:04:00.000+08:002012-07-06T14:04:57.401+08:00Guard Livereloadapt-get install mpdcron<br />
apt-get install libreadline-dev<br />
apt-get install google-chrome-stable<br />
<br />
Chrome Extension<br />
http://download.livereload.com/2.0.8/LiveReload.crx<br />
<br />
rvm install 1.9.3<br />
rvm use 1.9.3 --default<br />
<br />
gem install rails<br />
gem install bundler<br />
gem install em-websocket<br />
gem install guard<br />
gem install guard-livereload<br />
<br />
rails new TEST<br />
cd TEST<br />
vim Gemfile 加入 gem 'guard' 和 gem 'rb-readline'<br />
bundle exec guard init livereload<br />
guard start<br />
<br />
https://github.com/mockko/livereload/issues/91<br />
http://feedback.livereload.com/knowledgebase/articles/86242-how-do-i-install-and-use-the-browser-extensions-<br />
http://stackoverflow.com/questions/9340497/cannot-load-such-file-readline-loaderror-when-running-heroku-create-stack<br />Anonymoushttp://www.blogger.com/profile/12837594111497927241noreply@blogger.com0tag:blogger.com,1999:blog-18689056.post-6290500662773141522012-06-25T10:34:00.000+08:002012-06-25T10:35:09.073+08:00Redis 與 ResqueMessage Queue<br />
<br />
Redis:key-value 資料庫<br />
http://redis.io<br />
<br />
Resque:Github.com 開發的,用 Ruby 寫的 Redis 後端工具<br />
https://github.com/defunkt/resque<br />
https://github.com/blog/542-introducing-resque<br />
<br />
PHP-Resque:使用 PHP 實作的 Resque<br />
https://github.com/chrisboulton/php-resque<br />
http://blog.hsatac.net/2012/01/php-resque-introduction<br />
<br />
Sidekiq:類似 Resque,但聽說更猛<br />
https://github.com/mperham/sidekiq<br />Anonymoushttp://www.blogger.com/profile/12837594111497927241noreply@blogger.com0台灣台北市25.091075 121.559834524.975944 121.401906 25.206206 121.71776299999999tag:blogger.com,1999:blog-18689056.post-69572262879076996832012-06-15T17:22:00.000+08:002012-06-25T10:30:55.164+08:00導致 PHP 語法錯誤的 xml 標籤處理到一個很奇怪的問題。<br />
<br />
有個負責 echo 出 xml 內容的 php 程式,一直出現語法錯誤:<br />
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING your_file.php on line 123<br />
<br />
your_file.php 是在 Windows 環境來的,在 Linux 內使用 Vim 開啓時,行尾會出現 Windows 的蠢符號 ^M<br />
<br />
我如同往常一樣使用以下指令將 ^M 清除:<br />
:%s/^M//g<br />
(^M 是壓 Ctrl + V 再壓 Ctrl + M 的效果)<br />
<br />
但是 123 行一直報錯,123 行的 php code 類似這樣:<br />
<p id="$_GET['id']"><br />
<br />
如果把 123 行註解掉,在 Vim 內的重新輸入一模一樣的內容,就 ok 了!<br />
看起來是有些神祕的行尾符號,人類的肉眼無法察覺,待查 .....<br />
<br />
Vim 有沒有好的外掛顯示 space、tab、break 啊!?<br />
<br />
熱心的朋友們給了許多解法:<br />
<blockquote>曼珠:":set invlist"可達到要求嗎?我自己試用是看的到行尾的 $,但我沒有其他的不可見符號所以沒辧法進一步測試。原來 :set invlist 是 invert list 的簡寫(等同 :set list!),而查詢 'list' 後發現他能顯示 ^I 和行尾,但對於其他不可見字元就沒多寫了,所以可能要再查。 <br />
<br />
雲端CrBoy+:把那行複製出來塞進新的檔案 用 hexdump 去看!<br />
<br />
__CA__.py:vim -b abc.php ?<br />
<br />
Chester Chang:try hex editor<br />
</blockquote><br />
Reference:<br />
http://www.perturb.org/display/679_Make_Vim_show_hidden_characters.html<br />
http://grx.no/kb/2008/11/17/remove-windows-line-endings-in-vim/<br />
http://www.grok2.com/blog/2010/04/21/getting-rid-of-m-ctrl-m-characters-in-windows-text-using-vim/<br />
http://stackoverflow.com/questions/799417/gvim-showing-carriage-return-m-even-when-file-mode-is-explicitly-dos<br />
<br />
====================================================<br />
<br />
後來發現根本不是行尾的問題!<br />
<br />
該 php 檔中混合了 php tag 與 xml tag,例如:<br />
<pre class="brush:php"><?php
// code
?>
<?xml version="1.0" encoding="UTF-8" ?>
<?php
// code
echo $XML
?>
</pre><br />
如果修改成以下格式,將 xml tag 使用 heredoc 輸出就正確了:<br />
<pre class="brush:php"><?php
// code
echo <<<HERE
<?xml version="1.0" encoding="UTF-8" ?>
HERE
// code
echo $XML
?>
</pre><br />
看起來是 php 與 xml 的 tag 讓 Web Server 混亂了,不是行尾有問題 ....Anonymoushttp://www.blogger.com/profile/12837594111497927241noreply@blogger.com0tag:blogger.com,1999:blog-18689056.post-54055920233083858452012-06-07T09:50:00.001+08:002012-06-07T09:50:32.144+08:00python fabrichttp://fabfile.org<br />
http://docs.fabfile.org/en/1.4.2/tutorial.htmlAnonymoushttp://www.blogger.com/profile/12837594111497927241noreply@blogger.com0tag:blogger.com,1999:blog-18689056.post-49615854266228476232012-05-30T14:45:00.003+08:002012-05-30T15:18:21.691+08:00設定 Apache 與網頁的字元編碼http://httpd.apache.org/docs/2.0/mod/core.html#adddefaultcharset<br />
http://stackoverflow.com/questions/913869/how-to-change-the-default-encoding-to-utf-8-for-server<br />
http://www.askapache.com/htaccess/setting-charset-in-htaccess.html<br />
http://rackerhacker.com/2007/11/15/change-the-default-apache-character-set/<br />
<br />
http://www.w3.org/TR/html4/charset.html#h-5.2<br />
http://en.wikipedia.org/wiki/Character_encodings_in_HTML<br />
http://www.w3schools.com/html5/att_meta_charset.asp<br />
<br />
http://tlt.its.psu.edu/suggestions/international/web/tips/declare.html<br />
http://www.i18nguy.com/markup/serving.html#tip01<br />
http://www.personal.psu.edu/ejp10/blogs/gotunicode/2009/02/when-apache-and-utf-8-fight.htmlAnonymoushttp://www.blogger.com/profile/12837594111497927241noreply@blogger.com0台灣台北市25.091075 121.559834524.976033 121.401906 25.206117 121.71776299999999tag:blogger.com,1999:blog-18689056.post-90272621366702204292012-05-28T16:39:00.004+08:002012-05-28T17:45:34.694+08:00使用字型符號替代 icon 圖示http://css-tricks.com/flat-icons-icon-fonts/<br />
http://css-tricks.com/html-for-icon-font-usage/<br />
http://css-tricks.com/examples/IconFont/<br />
<br />
http://owltastic.com/2011/08/simple-interface-design-icons/<br />
<br />
http://pictos.cc/server/<br />
http://fontello.com/<br />
http://www.patentbolt.com/<br />
http://www.entypo.com/<br />
http://keyamoon.com/icomoon/<br />
http://fortawesome.github.com/Font-Awesome/Anonymoushttp://www.blogger.com/profile/12837594111497927241noreply@blogger.com0tag:blogger.com,1999:blog-18689056.post-60079944332767203042012-04-19T00:39:00.000+08:002012-04-19T00:43:28.483+08:00使用 ruhoh 寫 Bloghttp://ruhoh.com/Anonymoushttp://www.blogger.com/profile/12837594111497927241noreply@blogger.com0tag:blogger.com,1999:blog-18689056.post-28372711219138986962012-04-18T21:12:00.000+08:002012-07-14T18:08:28.814+08:00使用 Octopress 寫 Bloghttp://jekyllbootstrap.com/<br />
http://ruhoh.com/<br />
http://orgmode.org/worg/org-tutorials/org-jekyll.html<br />
https://github.com/imathis/octopress/wiki<br />
<br />
Jekyll<br />
<br />
Jekyll is a simple, blog aware, static site generator. It takes a template directory (representing the raw form of a website), runs it through Textile or Markdown and Liquid converters, and spits out a complete, static website suitable for serving with Apache or your favorite web server. This is also the engine behind GitHub Pages, which you can use to host your project’s page or blog right here from GitHub.<br />
<br />
https://github.com/mojombo/jekyll/wiki <br />
http://orgmode.org/worg/org-tutorials/org-jekyll.html<br />
<br />
Jekyll-Bootstrap<br />
<br />
Octopress<br />
Octopress 可以看成是一個 blog 書寫工具,它將你書寫的 blog 內容加工成靜態網頁。<br />
<br />
[安裝 Ruby]<br />
http://zx-1986.blogspot.com/2011/10/rvm.html<br />
<br />
http://octopress.org/docs/deploying/github/<br />
http://octopress.org/docs/deploying/heroku/<br />
<br />
Enter the read/write url for your repository: git@github.com:zx1986/zx1986.github.com.git<br />
<br />
http://markdown.tw/<br />
http://octopress.org/docs/<br />
http://zespia.tw/blog/2012/01/14/hello-octopress/<br />
http://blog.lyhdev.com/2011/10/octopress-github-markdown.html<br />
http://killtw.k2ds.net/blog/2011/10/29/how-to-install-rails/Anonymoushttp://www.blogger.com/profile/12837594111497927241noreply@blogger.com0tag:blogger.com,1999:blog-18689056.post-44483724405428891422012-04-17T08:52:00.000+08:002012-04-17T08:52:38.550+08:00Sass[Sass]<br />
<br />
sudo apt-get ruby<br />
sudo apt-get rubygems<br />
sudo gem --update system<br />
sudo gem install sass<br />
<br />
[Scss]<br />
<br />
語法改良後的 Sass,同樣使用 sass 命令來編譯,副檔名通常是 *.scss<br />
<br />
[Compass]<br />
<br />
sudo gem install compass<br />
<br />
http://designshack.net/articles/css/sass-vs-stylus-who-wins-the-minimal-syntax-battle/<br />
<br />
Reference:<br />
http://sass-lang.com<br />
http://compass-style.org<br />
http://blueprintcss.org<br />
http://960.gs<br />
http://upgrade2rails31.com/sass-scss<br />
http://upgrade2rails31.com/compass<br />
https://github.com/imathis/fancy-buttonsAnonymoushttp://www.blogger.com/profile/12837594111497927241noreply@blogger.com0Taipei City, Taiwan25.091075 121.559834524.976033 121.401906 25.206117 121.71776299999999tag:blogger.com,1999:blog-18689056.post-25569076534505265952012-04-06T23:43:00.000+08:002012-04-17T17:00:58.696+08:00RVM - Ruby Version Manager[安裝 rvm]<br />
<pre class="brush:bash"># 注意:使用 root 身份安裝的 rvm 是 system wide 的!
sudo su -
apt-get remove --purge ruby
apt-get remove --purge gem
apt-get install git autoconf patch curl bash wget
curl -L get.rvm.io | bash -s stable
usermod -a -G rvm YOUR_ACCOUNT
exit
logout
login
rvm notes
# ZSH 4.3.15 is buggy with RVM (2012/03)
</pre><br />
[安裝 Ruby]<br />
<pre class="brush:bash">rvm install 1.8.6
rvm install 1.9.3
# rvm alias create default ruby-1.9.3
rvm --default use 1.9.3
ruby --version
which ruby
which gem
rvm help
rvm list
rvm list known
</pre>[使用 gemset]<br />
<pre class="brush:bash">rvm gemdir # 顯示 gems 資料夾
rvm gemset name # 查詢當前所用 gemset 的名稱
rvm gemset list # 查詢所有的 gemset
rvm gemset use NAME # 切換到指定的 gemset
rvm gemset create foo # 建立一個叫 foo 的 gemset 集合
rvm use 1.9.3@foo # 切換到 Ruby 1.9.3 搭配 foo 這個 gemset 的環境
rvm list # 查看 Ruby 1.9.3 的 foo 內有哪些 gems
rvm install rails # 在 Ruby 1.9.3 的 foo 內安裝 rails
rvm use 1.9.3@global # 切換回 Ruby 1.9.3 default 的 gemset 環境
rvm list # 查看 default 的 gemset 內有哪些 gems
rvm gemset export backup.gems # 將當前的 gems 備份
rvm gemset import backup.gems # 將 backup.gems 倒回來
# global gemset(~/.rvm/gemsets/global.gems)
# default gemset(~/.rvm/gemsets/default.gems)
# 這兩個 gemset 有點特殊,而且兩個其實不盡相同。
# global 會被 "added" 到每個用 rvm 安裝的 ruby
# default 會被 "included" 到每個新建的 gemset
</pre><br />
[rvmrc]<br />
<br />
rvmrc 是 rvm 的 runtime configuration,可以依據作用範圍的不同做區分。<br />
<br />
系統範圍的:/etc/rvmrc<br />
使用者範圍的:~/.rvmrc<br />
專案範圍的:.rvmrc<br />
<br />
組合技:<br />
rvm --create --rvmrc 1.9.3@project<br />
# 搭配 Ruby 1.9.3 建立一個叫 project 的 gemset,並 use 它,並幫它建立一個 .rvmrc<br />
<br />
MRI:Matz's Ruby Interpreter(Matz 的 Ruby 直譯器)<br />
p.s. Matz 是發明 Ruby 語言的日本程式設計師 Yukihiro Matsumoto 的昵稱。<br />
<br />
Reference:<br />
http://sirupsen.com/get-started-right-with-rvm/<br />
http://beginrescueend.com<br />
http://beginrescueend.com/rvm/install<br />
http://beginrescueend.com/rvm/basicsAnonymoushttp://www.blogger.com/profile/12837594111497927241noreply@blogger.com2Taipei City, Taiwan25.091075 121.559834524.976033 121.401906 25.206117 121.71776299999999tag:blogger.com,1999:blog-18689056.post-18249852418211731212012-04-05T20:26:00.000+08:002013-03-16T11:30:29.374+08:00Ubuntu 的 ATi 驅動https://wiki.ubuntu.com/X/Troubleshooting/FglrxInteferesWithRadeonDriver<br />
https://help.ubuntu.com/community/RadeonDriver<br />
<br />
我的 laptop 有一張非常古怪的顯示卡:ATI Mobility Radeon X2300<br />
ATi 對 Linux 本來就很不友善了,再加上這張怪卡,更有得煩了。<br />
<pre class="brush:bash">lspci -nn | grep VGA
01:00.0 VGA compatible controller [0300]: ATI Technologies Inc Mobility Radeon X2300 [1002:718a]
</pre>我的環境是 Ubuntu 11.10 i386,先來認識一些名詞。<br />
<br />
[Mesa]<br />
Mesa is a software library for 3D computer graphics that provides a generic OpenGL implementation for rendering three-dimensional graphics on multiple platforms.<br />
<br />
[Radeon Driver]<br />
Open Source driver for many ATI graphics cards called "radeon" or "ati". It will provide 2D and 3D acceleration in your video hardware. This driver is not as fast as the closed-source, proprietary "fglrx" driver from AMD/ATI Inc. for some cards, but has better dual-head support, and supports some older chipsets that fglrx does not.<br />
<br />
[Catalyst | fglrx]<br />
fglrx is a proprietary, Linux binary-only driver for ATI graphic chips with support for 3D acceleration. fglrx is the name of the Linux display driver used for ATI Radeon and ATI FireGL family of video adapters and stands for "FireGL and Radeon for X". It contains both free and open-source and proprietary parts.<br />
<br />
=== fglrx ===<br />
<br />
fglrx 就是 Catalyst for Linux<br />
ATi 很小氣,不願意開放它的驅動原始碼,只提供編譯好的二進位驅動檔給 Linux OS<br />
每個不同的 Linux 發行版再自行打包它們的 ATi Driver,就是 fglrx(FireGL and Radeon for X)<br />
你看 ATi 取的這爛名字 ....<br />
<br />
fglrx 雖然還有其他問題:<br />
http://www.thinkwiki.org/wiki/Problems_with_fglrx<br />
http://askubuntu.com/questions/78906/ati-amd-proprietary-fglrx-graphics-install-fails-how-can-i-resolve-the-problem<br />
<br />
但是大家最推薦、最簡便的解法還是使用 fglrx<br />
<br />
不管是透過 PPA 使用 apt-get 安裝:<br />
https://launchpad.net/~ubuntu-x-swat/+archive/x-updates<br />
https://launchpad.net/~xorg-edgers/+archive/ppa<br />
<br />
或下載官方原始檔來編譯安裝(ATi Radeon 系列):<br />
http://support.amd.com/us/gpudownload/linux/previous/Pages/radeon_linux.aspx<br />
<br />
只是根據硬體支援清單,我的 Radeon X2300 看起來已經不被新版的 fglrx 支援了:<br />
http://wiki.cchtml.com/index.php/Hardware#Not_Yet_Supported_or_Unoffically_Supported<br />
<br />
我測試了 apt-get 安裝的 fglrx:<br />
<pre class="brush:bash">sudo apt-add-repository ppa:ubuntu-x-swat/x-updates
sudo apt-add-repository ppa:xorg-edgers/ppa
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install fglrx fglrx-amdcccle
sudo apt-get install fglrx-updates fglrx-amdcccle-updates
sudo apt-get update
sudo apt-get upgrade
</pre>也測試了官方不同版本的的原始檔安裝:<br />
ati-driver-installer-9-3-x86.x86_64.run<br />
ati-driver-installer-10-12-x86.x86_64.run<br />
ati-driver-installer-11-10-x86.x86_64.run<br />
ati-driver-installer-11-12-x86.x86_64.run<br />
<br />
=== Radeon Driver ===<br />
<br />
使用 apt-cache search radeon,找到下列套件:<br />
<pre class="brush:bash">xserver-xorg-video-ati - X.Org X server -- AMD/ATI display driver wrapper
xserver-xorg-video-ati-dbg - X.Org X server -- AMD/ATI display driver wrapper (debugging symbols)
xserver-xorg-video-radeon - X.Org X server -- AMD/ATI Radeon display driver
xserver-xorg-video-radeon-dbg - X.Org X server -- AMD/ATI Radeon display driver (debugging symbols)
radeontool - utility to control ATI Radeon backlight functions on laptops
fglrx-amdcccle-updates - Catalyst Control Center for the AMD graphics accelerators
fglrx-amdcccle - Catalyst Control Center for the AMD graphics accelerators
fglrx-updates - Video driver for the AMD graphics accelerators
fglrx-updates-dev - Video driver for the AMD graphics accelerators (devel files)
fglrx - Video driver for the AMD graphics accelerators
fglrx-dev - Video driver for the AMD graphics accelerators (devel files)
libdrm-radeon1 - Userspace interface to radeon-specific kernel DRM services -- runtime
libdrm-radeon1-dbg - Userspace interface to radeon-specific kernel DRM services -- debugging symbols
</pre><br />
根據 https://help.ubuntu.com/community/RadeonDriver<br />
看起來 Radeon Driver 另外一個可以嘗試的選擇。<br />
<br />
If you've previously installed the ATI binary/proprietary driver (a.k.a Catalyst/fglrx), you need to make sure it's fully purged before trying to use the open-source ati/radeon driver.<br />
<pre class="brush:bash">sudo apt-get purge fglrx*
sudo apt-add-repository ppa:xorg-edgers/ppa
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install xserver-xorg-video-ati* xserver-xorg-video-radeon* radeontool
</pre><br />
但是,在使用 Chrome 或 Firefox 搭配 Flash 時,gnome 經常會當掉,很糟糕。<br />
將 Flash 套件移除之後,目前還沒有出現當幾狀況!COOL!<br />
<br />
Reference:<br />
http://www.hardwareheaven.com/modtool.php<br />
http://ubuntuforums.org/showthread.php?t=1556555<br />
http://ubuntuforums.org/showthread.php?t=1250530<br />
http://wiki.cchtml.com/index.php/Ubuntu_Oneiric_Installation_Guide<br />
http://en.wikipedia.org/wiki/AMD_Catalyst<br />
http://maketecheasier.com/install-custom-gnome-shell-themes/2011/09/27<br />
http://mrrichard.hubpages.com/hub/How-to-Install-FGLRX-in-Ubuntu-1010<br />
https://wiki.ubuntu.com/X/Troubleshooting/FglrxInteferesWithRadeonDriver<br />
https://help.ubuntu.com/community/BinaryDriverHowto/ATI<br />
https://help.ubuntu.com/community/RadeonDriver<br />
https://help.ubuntu.com/community/RadeonHD<br />
http://mrrichard.hubpages.com/hub/How-to-Install-FGLRX-in-Ubuntu-1010<br />
http://support.amd.com/us/gpudownload/linux/previous/Pages/radeon_linux.aspx<br />
http://askubuntu.com/questions/124292/what-is-the-correct-way-to-install-ati-catalyst-video-drivers-fglrx/129200#129200<br />
http://askubuntu.com/questions/71457/how-can-i-set-up-dual-monitor-display-with-ati-driverAnonymoushttp://www.blogger.com/profile/12837594111497927241noreply@blogger.com0台灣台北市25.091075 121.559834524.975944 121.401906 25.206206 121.71776299999999tag:blogger.com,1999:blog-18689056.post-284014334783166942012-04-05T09:49:00.000+08:002012-04-05T09:56:09.309+08:00Node.js[什麽是 Node.js]<br />
<pre class="brush:bash"># 如果你熟悉 Linux 與程式開發,我想我應該可以這樣子解釋 Node.js
shell$ python hello.py
shell$ perl hello.py
shell$ ruby hello.rb
shell$ php hello.php
shell$ alias javascript='node'
shell$ javascript hello.js
</pre>Node.js 把 javascript 從瀏覽器中釋放出來了!<br />
<br />
[使用 nvm 安裝 Node.js]<br />
<pre class="brush:bash">git clone http://github.com/creationix/nvm.git ~/nvm
source ~/nvm/nvm.sh
nvm install v0.6.10
nvm use v0.6.10
nvm alias default 0.6
node --help
which node
which npm
</pre><br />
使用 nvm 安裝 nodejs 後,它會自動安裝相應版本的 npm(Nodejs Package Manager)。<br />
使用 npm 可以安裝各種 nodejs 模組。<br />
<br />
但是每次要使用好像都要 source nvm.sh 一次,而且 nodejs 也沒有加到系統路徑中。<br />
<br />
<del>[使用 apt-get 安裝 Node.js]</del><br />
<pre class="brush:bash">sudo apt-get install python
sudo apt-get install openssh-server libssl-dev
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
</pre><br />
<del>[自行編譯安裝 Node.js]</del><br />
<pre class="brush:bash">sudo apt-get install python
sudo apt-get install openssh-server libssl-dev
git clone --depth 1 git://github.com/joyent/node.git
cd node
git checkout v0.4.12
./configure
make -j2 # -j sets the number of jobs to run
sudo make install
</pre><br />
<del>[安裝 Node.js 的套件管理程式 NPM]</del><br />
<pre class="brush:bash"># Node Packages Manager
sudo su -
curl http://npmjs.org/install.sh | sh
</pre><br />
強力推薦的電子書:<br />
http://contpub.org/read/nodejs-wiki-book<br />
<br />
Framework:<br />
https://github.com/dreamerslab/coke<br />
<br />
http://nodejs.tw<br />
http://wiki.nodejs.tw<br />
https://github.com/dreamerslab/nodejs.basics<br />
<br />
Reference:<br />
http://nodejs.org<br />
http://npmjs.org<br />
https://github.com/joyent/node/wiki/Installation<br />
https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager<br />
https://github.com/nodejs-tw/nodejs-community-book<br />
https://www.facebook.com/NodeJS.tw<br />
http://jsdc.twAnonymoushttp://www.blogger.com/profile/12837594111497927241noreply@blogger.com1台灣台北市25.091075 121.559834524.975944 121.401906 25.206206 121.71776299999999