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

2013年11月13日 星期三

在 Debian GNU/Linux 7 安裝 Node.js

在 Debian GNU/Linux 7 的套件庫裡並沒有 Node.js 的套件,若要安裝 Node.js 需要由 http://nodejs.org/ 下載源碼編譯安裝。

首先下載當前的版本 node-v0.10.22.tar.gz,此外亦可以參考以下文章編譯:

  1. 在Debian Squeeze 上编译 node.js

也使用 FPM 將編譯的結果製成 .deb 檔,步驟如下:

$ tar zxvf node-v0.10.22.tar.gz
$ cd node-v0.10.22
$ ./configure 
$ make
$ mkdir _install && make install DESTDIR=_install
$ fpm -s dir -t deb -n nodejs -v 0.10.22 -C _install usr

執行完成後會生成 nodejs_0.10.22_amd64.deb 這個檔案,接著安裝即可:

$ sudo dpkg -i nodejs_0.10.22_amd64.deb

2013年11月11日 星期一

在 Debian GNU/Linux 7 安裝 Ruby / FPM

關於 FPM 的介紹:

https://docs.google.com/presentation/d/11TOsLeg58w7GCt6i7y1VIQWnUYotsx0MzGMJ_dWUJNo/present#slide=id.i0

FPM 的功能可用於打包套件。

在 Debian GNU/Linux 7 安裝 FPM 很簡單,首先要安裝 ruby、rubygems、ruby-dev 幾個套件:

$ sudo apt-get install ruby rubygems ruby-dev

然後在執行以下指令安裝 FPM 即可:

$ sudo ruby install fpm

$ sudo gem install fpm

此外,以下也是關於 FPM 的幾篇參考文章:

  1. 用fpm便捷地打RPM包
  2. Linux--轻松定义自己的RPM/DEB软件包

2013年10月4日 星期五

在 CentOS 6.4 及 Debian GNU/Linux 7 之間使用 sshfs

在 Linux 裡如果要掛載遠端主機的磁碟或目錄,大多數可以使用 NFS 或 Samba。不過 SSHFS (SSH Filesystem) 提供了一個很簡單的方式,只要主機提供有 SSH 服務就可以使用了。我手邊正好各有一台 CentOS 6.4 與 Debian GNU/Linux 7,就拿來試試囉!

在 CentOS 6.4 安裝 SSHFS 套件

在 CentOS 6.4 的套件庫裡並沒有 SSHFS 的套件,爬文後參考了《CentOS 6.x / Debian / Ubuntu: NFS or SMB/CIFS alternative sshfs》這篇文章,得知在 EPEL (Extra Packages for Enterprise Linux) 的套件庫裡有這個套件。然後,又在《[完全用 GNU/Linux 工作] 05. 套件庫及鏡像站》這篇文章裡得知,「請先行安裝 RPMforge 再安裝 EPEL」。

於是,我又找了找 RPMforge 的套件庫,確定它也有 SSHFS 的套件,那麼就決定使用 RPMforge 裡的 SSHFS 套件了。

$ sudo yum -y install fuse fuse-sshfs

Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: ftp.cs.pu.edu.tw
 * extras: mirrors.163.com
 * rpmforge: ftp.riken.jp
 * updates: mirrors.163.com
Setting up Install Process
Package fuse-2.8.3-4.el6.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package fuse-sshfs.x86_64 0:2.2-1.el6.rf will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package            Arch           Version               Repository        Size
================================================================================
Installing:
 fuse-sshfs         x86_64         2.2-1.el6.rf          rpmforge          44 k

Transaction Summary
================================================================================
Install       1 Package(s)

Total download size: 44 k
Installed size: 103 k
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : fuse-sshfs-2.2-1.el6.rf.x86_64                               1/1
  Verifying  : fuse-sshfs-2.2-1.el6.rf.x86_64                               1/1

Installed:
  fuse-sshfs.x86_64 0:2.2-1.el6.rf

Complete! 

接著,將允許使用 SSHFS 的使用者加到 fuse 這個 group 裡,指令如下:

sudo gpasswd -a $USER fuse

然後,就可以使用 SSHFS 了。此時,要掛載遠端的目錄指令格式如下:

sshfs username@hostname:/directory /yetanotherlocaldirectory

例如,我要掛載遠端 (192.168.1.106) 使用者 online 家目錄裡的 share 目錄到本地端的 working 目錄時,指令如下:

sshfs online@192.168.1.106:/home/online/share ~/working

卸載的指令格式如下:

fusermount -u /directory

例如,我要卸載剛才掛載的那個目錄,指令如下:

fusermount -u working

最後,我在《好用的sshfs》這篇文章得知,SSHFS 是以遠端主機的權限來掛載,所以如果兩端的主機 uid/gid 不一致時,會出現權限錯誤的問題。解決辦法是在掛載時加上指定 uid/gid 的選項。因為我已經將 CentOS 6.4 與 Debian GNU/Linux 7 裡的使用者 uid/gid 改成一樣的,例如 online 這個帳號的 uid/gid 均為 1000,於是掛載指令變成如下:

sshfs -o "uid=1000,gid=1000" online@192.168.1.106:/home/online/share ~/working

在 Debian GNU/Linux 7 安裝 SSHFS 套件

Debian GNU/Linux 7 的套件庫已經收錄了 SSHFS 的套件,因此只要用 apt-get 指令安裝即可。

$ sudo apt-get -y install sshfs

Reading package lists...
Building dependency tree...
Reading state information...
The following NEW packages will be installed:
  sshfs
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/54.8 kB of archives.
After this operation, 147 kB of additional disk space will be used.
Selecting previously unselected package sshfs.
(Reading database ... 119936 files and directories currently installed.)
Unpacking sshfs (from .../archives/sshfs_2.4-1_amd64.deb) ...
Processing triggers for man-db ...
Setting up sshfs (2.4-1) ...

接著,如同 CentOS 6.4 一般,將使用者加入 fuse 這個 group,然後該使用者重新登入後就可以使用 SSHFS 了。

延伸閱讀:

  1. CentOS 的第三方套件庫
  2. 在 CentOS 裡修改使用者帳號的 UID / GID

2013年9月10日 星期二

安裝 Debian GNU/Linux 7 (Wheezy)

過去我在部落格上貼過一些 Linux 的安裝記錄,不過對於 Debian GNU/Linux 安裝的部份,似乎就沒有自己整理一些比較連貫的文章。這幾天我將手邊跑 Debian 那台 ThinkPad X61 重新安裝,順便整理了一下安裝的過程。至於本文的擷圖部份,為了方便操作,所以我利用 KVM / libvirt 也裝了一個同樣的 Debian 環境,然後在 Windows 下配合 Xshell 和 Xming 秀出視窗,再用 PicPick 擷圖。

Step 1.

對於安裝 Debian GNU/Linux,我經常會參考這兩篇文章:

在第一篇文章裡介紹了圖形化的安裝方式 (Graphical install),不過我比較偏好採用文字介面的方式 (Install) 來安裝 Debian GNU/Linux。

在安裝過程中,我會先安裝 SSH 伺服器和基本的工具 (Standard system utilities):

這是因為這陣子以來,我習慣將 Debian 作為遠端登入操作的選擇,所以並不特別需要安裝桌面套件。在安裝完基本的系統後,就可以在文字介面登入 Debian 了。

Step 2.

當第一次登入 Debian 後,我會執行 su - 指令變成 root 身份,然後執行下面的指令安裝 ufw 及 sudo。

$ sudo apt-get install ufw sudo

接著,參考《在 Debian 上使用 ufw 設定防火牆》這篇文章啟用 ufw 並設定防火牆。

然後,再執行 visudo 指令修改 /etc/sudoers,讓安裝基本系統時建立的使用者帳號能使用 sudo 指令。

Step 3.

修改 /etc/apt/sources.list 的內容如下,目前我偏向採用 Stable 的版本,雖然它的軟體不一定是當前的最新版本,但穩定度很高。而我的習慣是將 Debian 當作伺服器來用,所以就選擇這個版本了。

# stable
deb http://http.us.debian.org/debian/ stable main contrib non-free
deb-src http://http.us.debian.org/debian/ stable main contrib non-free

# stable-updates, previously known as 'volatile'
deb http://http.us.debian.org/debian/ stable-updates main contrib non-free
deb-src http://http.us.debian.org/debian/ stable-updates main contrib non-free

# security / stable
deb http://security.debian.org/ stable/updates main contrib non-free
deb-src http://security.debian.org/ stable/updates main contrib non-free

Step 4.

一直以來,我將安裝 Debian GNU/Linux 時需要安裝的套件寫成了腳本,接著只要執行這個腳本就可以將大部份需要的套件全部安裝好。

#!/bin/bash

# Get information from Debian GNU/Linux
VERSION=`cat /etc/debian_version`
ARCH=`uname -a | awk '{print $8}'`

# Get Account's ID
THIS_ID=`echo $HOME | cut -d '/' -f 3`

echo Hello $THIS_ID, your system is Debian GNU/Linux $VERSION, $ARCH.

PKG_BASIC="xserver-xorg-core xinit"
PKG_I18N="ttf-arphic-ukai ttf-arphic-uming ttf-kochi-gothic ttf-kochi-mincho ttf-sazanami-gothic ttf-sazanami-mincho ttf-sawarabi-gothic ttf-sawarabi-mincho ttf-wqy-microhei ttf-wqy-zenhei msttcorefonts"

# Development
PKG_EDITOR="vim ctags cscope global"
PKG_COMPILER="make gdb gcc build-essential gcc-multilib g++-multilib gdb-multiarch"
PKG_LIBS="libncurses5-dev libnetpbm10-dev libsdl-dev libesd0-dev zlib1g-dev liblzo2-dev libusb-dev libreadline6-dev binutils-dev libc6-dev linux-libc-dev libx11-dev xorg-dev libpam-dev libxrender-dev libgl1-mesa-dev libgl1-mesa-glx libxml2-dev x11proto-core-dev"
PKG_UTILITIES="gnupg minicom lrzsz netpbm libtool bison flex doxygen indent fakeroot valgrind gperf zip curl uboot-mkimage tmux binutils ccache intltool mtools alien gawk pngcrush schedtool mingw32 tofrodos python-setuptools python-markdown xsltproc libxml2-utils python-libxml2 genext2fs genisoimage syslinux squashfs-tools"
PKG_DOCS="pinfo info2man manpages manpages-dev manpages-posix manpages-posix-dev glibc-doc glibc-doc-reference"
PKG_KERNEL="linux-headers-$(uname -r) kernel-package firmware-linux firmware-linux-free firmware-linux-nonfree"
PKG_VCTRL="git-core git-cola git-cvs git-svn gitk cvs subversion mercurial mercurial-git"
PKG_JAVA="openjdk-7-jdk"
PKG_EXTRA=""

# Service 
PKG_SERVICE="samba samba-tools libpam-smbpass ssh"

# Packages depond on 32-bit or 64-bit
case $ARCH in
 "x86_64")
  PKG_ARCH="libc6-dev-i386 lib32ncurses5-dev lib32readline6-dev lib32z-dev binutils-multiarch"
  ;;
 "i686")
  PKG_ARCH=""
  ;;
esac

# All packages
PACKAGES="$PKG_BASIC $PKG_I18N $PKG_EDITOR $PKG_COMPILER $PKG_LIBS $PKG_UTILITIES $PKG_DOCS $PKG_KERNEL $PKG_VCTRL $PKG_JAVA $PKG_EXTRA $PKG_SERVICE $PKG_ARCH"

# If running Gnome, you can use DEBIAN_FRONTEND='gnome' to show Gnome's dialog.
sudo apt-get update
sudo apt-get -y --force-yes dist-upgrade
sudo apt-get install -y --force-yes $PACKAGES

echo 'done.'

Step 5.

Debian GNU/Linux 7 並沒有收錄 Oracle 的 Java JDK / JRE,因此在安裝時我會先安裝上 OpenJDK 7。但,接著我仍然會再將 Oracle JDK 6 安裝起來。

首先自 Oracle 的網站找到 JDK 6 的 Linux 版本,由於這裡我安裝的是 64 位元的 Debian,因此下載了 jdk-6u45-linux-x64.bin 這個檔案。

執行 jdk-6u45-linux-x64.bin 這個檔案,會解壓縮並得到 jdk1.6.0_45 這個目錄,將這個目錄搬移到 /usr/lib/jvm/ 目錄內。

接著建立 /usr/lib/jvm/.jdk1.6.0_45.jinfo 這個檔案,內容如下:

name=jdk1.6.0_45
alias=java-6-oracle
priority=63
section=non-free

jre ControlPanel /usr/lib/jvm/jdk1.6.0_45/jre/bin/ControlPanel
jre java /usr/lib/jvm/jdk1.6.0_45/jre/bin/java
jre java_vm /usr/lib/jvm/jdk1.6.0_45/jre/bin/java_vm
jre javaws /usr/lib/jvm/jdk1.6.0_45/jre/bin/javaws
jre jcontrol /usr/lib/jvm/jdk1.6.0_45/jre/bin/jcontrol
jre keytool /usr/lib/jvm/jdk1.6.0_45/jre/bin/keytool
jre policytool /usr/lib/jvm/jdk1.6.0_45/jre/bin/policytool
jre pack200 /usr/lib/jvm/jdk1.6.0_45/jre/bin/pack200
jre rmid /usr/lib/jvm/jdk1.6.0_45/jre/bin/rmid
jre rmiregistry /usr/lib/jvm/jdk1.6.0_45/jre/bin/rmiregistry
jre unpack200 /usr/lib/jvm/jdk1.6.0_45/jre/bin/unpack200
jre orbd /usr/lib/jvm/jdk1.6.0_45/jre/bin/orbd
jre servertool /usr/lib/jvm/jdk1.6.0_45/jre/bin/servertool
jre tnameserv /usr/lib/jvm/jdk1.6.0_45/jre/bin/tnameserv
jre jexec /usr/lib/jvm/jdk1.6.0_45/jre/lib/jexec
jdk appletviewer /usr/lib/jvm/jdk1.6.0_45/bin/appletviewer
jdk apt /usr/lib/jvm/jdk1.6.0_45/bin/apt
jdk extcheck /usr/lib/jvm/jdk1.6.0_45/bin/extcheck
jdk idlj /usr/lib/jvm/jdk1.6.0_45/bin/idlj
jdk jar /usr/lib/jvm/jdk1.6.0_45/bin/jar
jdk jarsigner /usr/lib/jvm/jdk1.6.0_45/bin/jarsigner
jdk javac /usr/lib/jvm/jdk1.6.0_45/bin/javac
jdk javadoc /usr/lib/jvm/jdk1.6.0_45/bin/javadoc
jdk javah /usr/lib/jvm/jdk1.6.0_45/bin/javah
jdk javap /usr/lib/jvm/jdk1.6.0_45/bin/javap
jdk jconsole /usr/lib/jvm/jdk1.6.0_45/bin/jconsole
jdk jdb /usr/lib/jvm/jdk1.6.0_45/bin/jdb
jdk jhat /usr/lib/jvm/jdk1.6.0_45/bin/jhat
jdk jinfo /usr/lib/jvm/jdk1.6.0_45/bin/jinfo
jdk jmap /usr/lib/jvm/jdk1.6.0_45/bin/jmap
jdk jps /usr/lib/jvm/jdk1.6.0_45/bin/jps
jdk jrunscript /usr/lib/jvm/jdk1.6.0_45/bin/jrunscript
jdk jsadebugd /usr/lib/jvm/jdk1.6.0_45/bin/jsadebugd
jdk jstack /usr/lib/jvm/jdk1.6.0_45/bin/jstack
jdk jstat /usr/lib/jvm/jdk1.6.0_45/bin/jstat
jdk jstatd /usr/lib/jvm/jdk1.6.0_45/bin/jstatd
jdk native2ascii /usr/lib/jvm/jdk1.6.0_45/bin/native2ascii
jdk rmic /usr/lib/jvm/jdk1.6.0_45/bin/rmic
jdk schemagen /usr/lib/jvm/jdk1.6.0_45/bin/schemagen
jdk serialver /usr/lib/jvm/jdk1.6.0_45/bin/serialver
jdk wsgen /usr/lib/jvm/jdk1.6.0_45/bin/wsgen
jdk wsimport /usr/lib/jvm/jdk1.6.0_45/bin/wsimport
jdk xjc /usr/lib/jvm/jdk1.6.0_45/bin/xjc
plugin xulrunner-1.9-javaplugin.so /usr/lib/jvm/jdk1.6.0_45/jre/lib/amd64/libnpjp2.so
plugin firefox-javaplugin.so /usr/lib/jvm/jdk1.6.0_45/jre/lib/amd64/libnpjp2.so
plugin iceape-javaplugin.so /usr/lib/jvm/jdk1.6.0_45/jre/lib/amd64/libnpjp2.so
plugin iceweasel-javaplugin.so /usr/lib/jvm/jdk1.6.0_45/jre/lib/amd64/libnpjp2.so
plugin mozilla-javaplugin.so /usr/lib/jvm/jdk1.6.0_45/jre/lib/amd64/libnpjp2.so
plugin midbrowser-javaplugin.so /usr/lib/jvm/jdk1.6.0_45/jre/lib/amd64/libnpjp2.so
plugin xulrunner-javaplugin.so /usr/lib/jvm/jdk1.6.0_45/jre/lib/amd64/libnpjp2.so

再建立 /usr/lib/jvm/debian-orcale-jdk6-alternatives.sh 這個檔案,內容如下:

#!/bin/bash
# "Register JDK7 for update-alternatives Script in Debian Way"
# Based on 1. codeslinger's "install_java7_alternatives" from https://gist.github.com/445930
#          2. oracle-java6-plugin.deb postint script (for plugin)
# Modified by Cheng-Wei Chien<e.cwchien@gmail.com>, 2011-07-30
# ------------------------------------------------------------------------------
# Note:  This script works on x86 Debian GNU/Linux.
#        If you use other arch or distro, you may have to modify some parameters.
#
# Usage: 1. Extract jdk7 tar.gz to, for example, /usr/lib/jvm/java-7-oracle-1.7.0,
#           create a symbolic link /usr/lib/jvm/java-7-oracle to it.
#        2. Download java-7-oracle.jinfo from https://gist.github.com/1114515,
#           move it to /usr/lib/jvm/.java-7-oracle.jinfo, do some modification if necessary.
#        3. Run this script with sudo
#        4. sudo update-java-alternatives -s java-7-oracle
#        5. Have fun with jdk7!
#
# Trouble Shooting: If something goes wrong,
#        1. Uncomment "remove" commands and comment "install" commands.
#        2. Run this script again to rollback.
#        3. Fix what causes the problem, maybe typo or something else.
#        4. Comment "remove" commands and uncomment "install" commands
#        5. Run this script to update

# Force the shell to exit immediately if something goes wrong
set -e

# Follow the Debian's priority rule for java5 = 53, java6 = 63 .. I guess
priority=63

# Your jdk7 home, in this case, it's /usr/lib/jvm/java-7-oracle-1.7.0
# But I create a symbolic link /usr/lib/jvm/java-7-oracle to meet Debian's way
basedir=/usr/lib/jvm/jdk1.6.0_45

# Your man1 dir, you don't need to change this
mandir=$basedir/man/man1

# Variables from /usr/lib/jvm/.java-6-oracle.jinfo except HtmlConverter (not in jdk7)
jdk_var='appletviewer apt extcheck idlj jar jarsigner javac javadoc javah javap jconsole jdb jhat jinfo jmap jps jrunscript jsadebugd jstack jstat jstatd native2ascii rmic schemagen serialver wsgen wsimport xjc'
jre_var='ControlPanel java java_vm javaws jcontrol keytool pack200 rmid rmiregistry unpack200 orbd servertool tnameserv jexec policytool'
# browser_var="xulrunner-addons firefox iceape iceweasel mozilla midbrowser xulrunner"
browser_var="firefox iceweasel mozilla midbrowser"

# Java plugin path, you don't need to change this
plugin=$basedir/jre/lib/amd64/libnpjp2.so

# First, gzip man1 files to meet the 1.gz form
if [ -e $mandir ]; then
  for i in $mandir/*.1; do
    gzip $i
  done
fi

# Register jdk variables
for i in $jdk_var; do
  unset slave || true
  if [ -e $mandir/$i.1.gz ]; then
    slave="--slave /usr/share/man/man1/$i.1.gz $i.1.gz $mandir/$i.1.gz"
  fi
  #update-alternatives --remove $i $basedir/bin/$i
  update-alternatives --install /usr/bin/$i $i $basedir/bin/$i $priority $slave
done

# Register jre variables
for i in $jre_var; do
  unset slave || true
  if [ -e $mandir/$i.1.gz ]; then
    slave="--slave /usr/share/man/man1/$i.1.gz $i.1.gz $mandir/$i.1.gz"
  fi
  if [ $i = jexec ]; then
    # update-alternatives --remove jexec $basedir/jre/lib/jexec
    update-alternatives --install /usr/bin/jexec jexec $basedir/jre/lib/jexec $priority
  elif [ $i = java ]; then
    # update-alternatives --install /usr/bin/java java $basedir/jre/bin/java $priority $slave --slave /usr/bin/policytool policytool $basedir/jre/bin/policytool
    update-alternatives --install /usr/bin/java java $basedir/jre/bin/java $priority $slave
  else
    # update-alternatives --remove $i $basedir/jre/bin/$i
    update-alternatives --install /usr/bin/$i $i $basedir/jre/bin/$i $priority $slave
  fi
done

# Register plugins
for i in $browser_var; do
  if [ $i = xulrunner-addons ]; then
    browser=xulrunner-1.9
  else
    browser=$i
  fi
  mkdir -p /usr/lib/$i/plugins
  #update-alternatives --remove $browser-javaplugin.so $plugin
  update-alternatives --install /usr/lib/$i/plugins/libjavaplugin.so $browser-javaplugin.so $plugin $priority
done

然後執行 /usr/lib/jvm/debian-orcale-jdk6-alternatives.sh 將 Oracle JDK 6 安裝到系統裡。

接著執行這個指令列出系統有那些 JDK:

$ sudo update-java-alternatives -l

此時應該能看到稍早安裝的 OpenJDK 7,和剛才安裝的 Oracle JDK 6 了。

java-1.7.0-openjdk-amd64 1051 /usr/lib/jvm/java-1.7.0-openjdk-amd64
jdk1.6.0_45 63 /usr/lib/jvm/jdk1.6.0_45

接著,再執行這個指令將預設的 JDK 改成 Oracle JDK 6 就可以了。

$ sudo update-java-alternatives -s jdk1.6.0_45

Step 6.

接著參考《使用 GitHub 管理 VIM》這篇文章及 https://github.com/yuanfarn/vimrc/blob/master/README.md 的說明,建立 ~/.vimrc 及 ~/.vim 的內容。摘錄指令如下:

$ git clone https://github.com/yuanfarn/vimrc.git ~/.vim
$ cd ~/.vim
$ git submodule init
$ git submodule update
$ cd ~ && ln -s ~/.vim/vimrc ~/.vimrc
$ vim +BundleInstall

Step 7.

接著,我會執行以下指令設定 git 的幾項參數:

$ git config --global user.name "Shau-Hung Hsieh"
$ git config --global user.email "shauhung -AT- gmail.com"
$ git config --global color.diff auto
$ git config --global color.status auto
$ git config --global color.branch auto
$ git config --global color.log auto

Step 8.

Debian 預設的 Samba 設定裡,每個使用者透過 Samba 對自己的家目錄是「唯讀」的,因此我通常會修改 Samba 的 /etc/samba/smb.conf,讓使用者可以透過 Samba 寫入自己的家目錄。修改前後差異如下:

--- /etc/samba/smb.conf 2013-09-10 05:59:58.410688535 +0000
+++ /etc/samba/smb.conf 2013-09-10 06:02:28.674702041 +0000
@@ -99,7 +99,7 @@
 # in this server for every user accessing the server. See
 # /usr/share/doc/samba-doc/htmldocs/Samba3-HOWTO/ServerType.html
 # in the samba-doc package for details.
-#   security = user
+   security = user

 # You may wish to use password encryption.  See the section on
 # 'encrypt passwords' in the smb.conf(5) manpage before enabling.
@@ -247,11 +247,11 @@

 # By default, the home directories are exported read-only. Change the
 # next parameter to 'no' if you want to be able to write to them.
-   read only = yes
+   read only = no

 # File creation mask is set to 0700 for security reasons. If you want to
 # create files with group=rw permissions, set next parameter to 0775.
-   create mask = 0700
+   create mask = 0600

 # Directory creation mask is set to 0700 for security reasons. If you want to
 # create dirs. with group=rw permissions, set next parameter to 0775.

基本上,改動的內容以家目錄 (HOME) 的分享為主:

# "security = user" is always a good idea. This will require a Unix account
# in this server for every user accessing the server. See
# /usr/share/doc/samba-doc/htmldocs/Samba3-HOWTO/ServerType.html
# in the samba-doc package for details.
   security = user

[homes]
   comment = Home Directories
   browseable = no

# By default, the home directories are exported read-only. Change the
# next parameter to 'no' if you want to be able to write to them.
   read only = no

# File creation mask is set to 0700 for security reasons. If you want to
# create files with group=rw permissions, set next parameter to 0775.
   create mask = 0600

# Directory creation mask is set to 0700 for security reasons. If you want to
# create dirs. with group=rw permissions, set next parameter to 0775.
   directory mask = 0700

# By default, \\server\username shares can be connected to by anyone
# with access to the samba server.
# The following parameter makes sure that only "username" can connect
# to \\server\username
# This might need tweaking when using external authentication schemes
   valid users = %S

Step 9.

安裝到這裡,我已經擁有一個很好用的 Debian GNU/Linux 環境了。如同本文一開始所說的,我習慣以遠端登入的方式來操作,所以並沒有安裝 X 視窗 (X Window System)。不過,在我的腳本裡確實安裝了 X 視窗的基本套件 (xserver-xorg-core 與 xinit) 和幾個字型的套件。

如果需要在本機前面操作,且需要視窗介面時,目前 Debian GNU/Linux 已收錄了 Gnome 3,只要執行這個指令安裝基本的 Gnome 套件:

sudo apt-get install gnome-core

或是執行這個指令安裝更完整的 Gnome 桌面套件:

sudo apt-get install gnome

下圖就是安裝了 Gnome 的樣子:

如果只是偶爾需要在主機前使用少數圖形化的軟體,又不想安裝一整個的 Gnome 桌面,那麼還有一個更簡單的方式。在之前的腳本裡已經安裝了基本的 X 視窗套件 (xserver-xorg-core 與 xinit),因此只要再安裝像 FVWM 這類比較簡捷的視窗管理程式:

$ sudo apt-get install fvwm

然後,參考 https://wiki.debian.org/ 上的 Xorg 與 Xinitrc 兩個詞目的說明,執行 Xorg -configure 指令建立 Xorg 的設定檔 /etc/X11/xorg.conf,接著在使用者的家目錄裡建立 ~/.xinitrc 這個檔案,內容如下:

# ~/.xinitrc
# This file is sourced when running startx and 
#    other programs which call xinit
# As in all Bash/sh scripts lines starting with 
#    '#' are comments

# Set background to your favorite pic
xsetbg -fullscreen /morphix/background.png &

# Start a XTerm
/usr/bin/X11/xterm &

# Start the systems window manager.
# See WindowManagers for other choices.
exec /etc/alternatives/x-window-manager

# To run Gnome instead of system default, place a 
# '#' before the previous line and uncomment the 
# next line.
# exec gnome-session

這麼一來,使用者可以在文字介面登入後,執行 startx 指令進入 X 視窗。就像下面這張圖一樣。

註:我實際在 KVM 及 VMware 下安裝 Debian GNU/Linux 與 FVWM,似乎可以不用理會 /etc/X11/xorg.conf 這個設定檔。

延伸閱讀:

  1. 在 Debian 上使用 ufw 設定防火牆
  2. 製作 Debian 的 USB 開機碟
  3. 升級至 Linux Mint 15 (Olivia)
  4. 在 Debian 使用 KVM / libvirt 的虛擬化系統
  5. 在 Linux Mint 14 安裝 Oracle JDK 6
  6. 在 OpenSUSE 12.2 安裝 Oracle JDK 6
  7. 如何安裝 Linux Mint 14
  8. 在 Debian GNU/Linux 安裝 Gnome
  9. 安裝 Debian GNU/Linux
  10. 在 Ubuntu 12.04 安裝 JDK 6 (最終版)
  11. 在 Ubuntu 12.04 安裝 JDK 6
  12. 讓 Ubuntu 12.04 的 ibus 倉頡五代輸入法預設使用繁體語系
  13. 在 OpenSUSE 12.1 安裝 Sun JDK 6
  14. Debian GNU/Linux 安裝記錄
  15. Ubuntu 10.10 安裝記錄
  16. Ubuntu 10.04 LTS 安裝記錄
  17. 在 Ubuntu 10.04 裡安裝 Sun JDK
  18. Ubuntu 9.10 安裝記錄
  19. Samba on Ubuntu 9.04
  20. Debian (testing) on VMware Workstation 6.0.5
  21. Debian 4.0 安裝記錄
  22. Ubuntu Linux 安裝筆記

2013年8月26日 星期一

在 Debian 上使用 ufw 設定防火牆

以前設定防火牆時是直接使用 iptables 指令,但畢竟使用 iptables 頗有難度,所以基本上我都參考鳥哥的 "第九章、防火牆與 NAT 伺服器" 這篇文章,然後使用鳥哥提供的範例來設定。幸好,我手上的機器只需要 SSH 和 Samba 兩個服務,通常只要允許這兩個服務使用的埠 (port) 可以進入就行了。

後來,發現 ufw 這個工具後,我一直覺得 ufw 是個好東西,因為它不像 iptables 那麼複雜,對於一般防火牆的設定其實已經很足夠了。不過,若要對防火牆更進一步控管,建議還是學學 iptables 吧!

在 Debian 上安裝 ufw 很簡單,只要一行指令即可:

$ sudo apt-get install ufw

安裝完畢後,接著要先啟用 ufw:

$ sudo ufw enable

然後,將 ufw 的 defualt 設定改成 Deny:

sudo ufw default deny

這樣一來,INPUT 及 FORWARD 兩個 Chain 都會被設定成 DROP。

接著,就可以開始設定要允許的連線,由於我的機器只提供了 SSH 和 Samba 的服務,因此首先將 SSH 監聽的埠打開,此時可以執行這個指令直接允許 22 這個埠的 TCP 及 UDP 連線:

$ sudo ufw allow ssh

然後,再允許 Samba (SMB/CIFS 通訊協定) 監聽的幾個埠:

$ sudo ufw allow proto tcp to any port 135 from 192.168.1.0/24
$ sudo ufw allow proto udp to any port 137 from 192.168.1.0/24
$ sudo ufw allow proto udp to any port 138 from 192.168.1.0/24
$ sudo ufw allow proto tcp to any port 139 from 192.168.1.0/24
$ sudo ufw allow proto tcp to any port 445 from 192.168.1.0/24

其中,135 (Remote Procedure Call)、139 (NetBIOS Session Service) 和 445 (Microsoft-DS) 是 TCP 埠,而 137 (NetBIOS Name Service) 和 138 (NetBIOS Name Service) 是 UDP 埠。

參考閱讀:

  1. 鳥哥的 Linux 私房菜:第九章、防火牆與 NAT 伺服器
  2. 鳥哥的 Linux 私房菜:第十六章、檔案伺服器之二: SAMBA 伺服器
  3. Ubuntu: ufw
  4. UFW防火牆簡單設置
  5. [SOLVED] samba and ufw
  6. Allow Samba through your Linux firewall with ufw
  7. 開啟 CIFS / SMB / UNC 連線應開放哪些 Ports 與注意事項
  8. 設立 UFW防火牆與 Samba

2013年8月21日 星期三

在 Debian 及 Linux Mint 上安裝 Apache + PHP + MariaDB

之前在 Debian 裡試裝了 Apache 及 PostgreSQL,也安裝了 WordPress 試用了一陣子,同時也簡單記錄了 "在 Debian 上安裝 Apache + PHP + PostgreSQL" 及 "如何安裝 WordPress?" 這兩篇文章。

這陣子因為還計畫試用一些其它的架站套件,因此也就繼續在 Debian 及 Linux Mint 裡安裝了 MariaDB,這篇是簡易的記錄。

目前 MariaDB 尚未收到 Debian 7 及 Linux Mint 15 的套件庫裡,所以必須從 MariaDB 的網站取得安裝程式。

在 MariaDB 的網站的下載頁面,選擇使用 repository configuration tool,依據說明選擇 Linux Distribution、版本及套件庫來源。

在 Debian 7 安裝 MariaDB 5.5:

$ sudo apt-get install python-software-properties
$ sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db
$ sudo add-apt-repository 'deb http://download.nus.edu.sg/mirror/mariadb/repo/5.5/debian wheezy main'
$ sudo apt-get update
$ sudo apt-get install mariadb-server

在 Linux Mint 15 安裝 MariaDB 5.5:

首先,建立 /etc/apt/sources.list.d/mariadb.list 這個檔案,並加入以下內容:

# MariaDB 5.5 repository list - created 2013-08-16 01:23 UTC
# http://mariadb.org/mariadb/repositories/
deb http://ftp.yz.yamagata-u.ac.jp/pub/dbms/mariadb/repo/5.5/ubuntu raring main
deb-src http://ftp.yz.yamagata-u.ac.jp/pub/dbms/mariadb/repo/5.5/ubuntu raring main

接著,執行以下的指令:

$ sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db
$ sudo apt-get update
$ sudo apt-get install software-properties-common
$ sudo apt-get install mariadb-server

安裝 Apache 與 PHP

$ sudo apt-get install apache2 php5 php5-mysql libapache2-mod-php5filter

基本上,安裝完這些套件就可以用了。

此外,建議再安裝幾個與 PHP 相關的套件:

$ sudo apt-get install php5-curl php5-gd php5-gmp php5-imagick php5-json php5-mcrypt php5-xdebug php5-xmlrpc

然後在 /var/www 路徑下編寫一個 info.php 檔,內容如下:

<?php phpinfo(); ?>

用瀏覽器開啟 http://localhost/info.php 查看 PHP 是否順利安裝。

安裝 phpMyAdmin

到 http://www.phpmyadmin.net/ 下載最新版的 phpMyAdmin,將它解壓縮到 /var/www 目錄後,並修改屬性權限裡的使用者為 www-data,然後將 config.sample.inc.php 複製成 config.inc.php。

接著,編輯 config.inc.php,找到這一行:

$cfg['Servers'][$i]['auth_type'] = 'cookie';

將它修改如下:

$cfg['Servers'][$i]['auth_type'] = 'http';

這是最基本的設定,其它設定請自行參閱 phpMyAdmin 的說明文件。

2013年8月20日 星期二

製作 Debian 的 USB 開機碟

之前製作 Debian 的 USB 開機光碟要用 syslinux 之類的方式,之前爬過一些文,總覺得步驟挺繁瑣的。這幾天爬到 "製作 Debian Linux USB 開機安裝磁碟" 這篇文章,然後又翻閱了 Debian 的文件後,在 "使用混合 CD 或 DVD 映像制作 U 盘" 這節裡發現原來製作 USB 開機光碟變得很簡單。

首先,確定 USB 碟的裝置 /dev/sdX,然後下載 Debian 的 ISO 檔 (debian-7.1.0-amd64-netinst.iso),然後執行以下指令即可:

$ sudo cp debian-7.1.0-amd64-netinst.iso /dev/sdX
$ sudo sync

接著,就可以用這個 USB 碟開機,並安裝 Debian。

2013年6月12日 星期三

在 Debian 上安裝 Apache + PHP + PostgreSQL

好久沒自己在 Linux 下設定 Apache、SQL 等等,這幾天在 Google 上爬了爬文,參考以下數篇文章:

本來想繼續使用 MySQL,不過爬了爬文,似乎 MariaDB 又比 MySQL 受歡迎些,我猜這或許和 Oracle 公司收購了 MySQL 有關吧!不過,目前我並沒有特別偏好那一套 SQL 產品,於是爬了爬文後選擇了 PostgreSQL 這個。

在 Debian 裡安裝東西其實很便利的,基本上使用 apt-get 就可以搞定了。所以,我執行了以下的指令安裝了需要的套件:

apt-get update
apt-get install apache2 postgresql postgresql-9.1 postgresql-contrib php5 php5-pgsql libapache2-mod-php5filter
apt-get install libpg-perl libdbd-pg-perl imagemagick

然後,在 /var/www 路徑下編寫一個 info.php 檔,內容如下:

<?php phpinfo(); ?>

然後,用瀏覽器開啟 http://localhost/info.php 查看 PHP 是否順利安裝。

接著,進入 PostgreSQL 的管理介面 (Console),先變更 postgres 這個帳號的密碼。

sudo -u postgres psql
psql (9.1.9)
Type "help" for help.

postgres=# \password
Enter new password:
Enter it again:
postgres=# \q

然後,使用這個指令建立一個存取資料庫的帳號:

CREATE USER name WITH PASSWORD 'string';

再建立一個資料庫,OWNER 則設定成剛才建立的帳號:

CREATE DATABASE dbname OWNER name ENCODING 'UTF8';

接著,下載 phpPgAdmin,並解壓縮到 /var/www 路徑下,然後修改 conf/config.inc.php,將 servers 的部份指定成 localhost。

// Hostname or IP address for server.  Use '' for UNIX domain socket.
// use 'localhost' for TCP/IP connection on this computer
// 底下欄位加入 localhost 內容,指定此程式連接到放在本機 host 上
$conf['servers'][0]['host'] = 'localhost';

有些文章提到,如果將 extra_login_security 改成 false,就可以讓 postgres 這個管理帳號從遠端登入了,不過目前我不打算這麼做,就沒去改動它了。

基本上,到這裡大致就可以使用了。

2013年5月30日 星期四

在 Debian 使用 KVM / libvirt 的虛擬化系統

Step 1.

sudo aptitude install libvirt-bin virt-manager kvm

Step 2.

將使用者帳號 [username] 加入 libvirt 群組以方便遠端控制。

sudo gpasswd -a [username] libvirt

Step 3.

修改 /etc/network/interfaces 修改 /etc/networking/interfaces,將原本 eth0 的部份取消,加入以下這段:

auto br0
iface br0 inet dhcp
bridge_ports eth0
bridge_stp on
bridge_maxwait 0
bridge_fd 0

Step 4.

修改 /etc/sysctl.conf,加入這段:

net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0

Step 5.

修改 /etc/rc.local,在 exit 0 之前加入一行:

/sbin/sysctl -p /etc/sysctl.conf

在重新載入設定並重啟 KVM 後,就可以執行 virt-manager 來使用及管理 Virtual Machine 了。

以下是簡易的示範。

執行 virt-manager 時會出現如下的 Virtual Machine Manager 視窗,由於 KVM 和 virt-manager 均在 localhost 端,預設會看到連線上的是 localhost (QEMU):

查看 localhost (QEMU) 的細節,在 Network interfaces 頁面可以看到 br0 藉由 eth0 提供了橋接 (Bridge) 的架構:

在 Virtual Networks 裡則預設提供了 default 這個選項,它提供 Virtual Machines 使用的 NAT 網路,如下圖所示使用的 192.168.122.0/24 這個網域:

在 Storage 裡預設也提供了 default 的選項,它的路徑在 /var/lib/libvirt/images。這裡我另外添加一個位於 /home/kvm/images 的空間。

以下示範如何建立一個 Virtual machine。

在執行 virt-manager 開啟的 Virtual Machine Manager 視窗裡按下 NEW 按鈕開始建立 Virtual machine,首先要給它一個名字:

接著選擇安裝媒體的來源,一般容易使用的是採 ISO image 來安裝:

接著指定記憶體大小,及 CPU 數量:

接著指定 Hard disk 的大小:

接著在最後一步驟時,點開 "Advanced options",確認它使用了 Host device eth0 (Bridge 'br0') 作為網路介面:

設定完成後,就可以啟動 Virtual machine,並安裝系統:

以本文的示範為例,我在 Virtual machine 上安裝了 FreeNAS,安裝完成後這個 Virtual machine 會呈現如下圖的畫面:

由於我在 Virtual machine 裡指定使用 Host device eth0 (Bridge 'br0) 作為網路介面,如上圖所示在啟後取得的 IP 位址是 192.168.1.111。而執行 KVM 的 Debian 也位於同一個 192.168.1.0/24 的網路裡。

而在這個網路裡有另一台執行 Windows 的電腦,下圖就是它以 Google Chrome 瀏覽器開啟 http://192.168.1.111 的畫面:

延伸閱讀:

2013年3月6日 星期三

apt 與 zypper 的比較

Debian GNU/Linux 與其它以 Debian GNU/Linux 為基礎的發行版本都採用 apt-get 指令來管理 package 的安裝移除,而 OpenSUSE 則採用 zypper 這個指令來管理。

以往嘗試使用 OpenSUSE 時,我都直接使用圖型化介面的工具來管理 package 的安裝移除,畢竟 OpenSUSE 在桌面環境的整合上確實很有一套,不過這兩天重新安裝了 OpenSUSE 12.2 後,我一直很好奇有沒有指令工具可以使用。在摸索及爬文後,發現原來 OpenSUSE 可以使用 zypper 這支工具程式來管理 package 及 repository。稍微嘗試了一下,這個指令確實好用,不過和以往使用 apt-get 指令的習慣不同,所以我也整理了一下比較表。在比較表裡,我同時列上了 aptitude 這個指令,目前在 Debian GNU/Linux 裡,因為我習慣以 aptitude 這個指令工具來取代 apt-get。

延伸閱讀:

2010年8月15日 星期日

在 Debian / Ubuntu 使用 gitosis 架設 GIT server

首先自套件庫安裝 python-setuptools。

sudo aptitude install python-setuptools

然後自 eagain.net 下載 gitosis 的程式碼。

git clone git://eagain.net/gitosis.git

接著將下載回來的 gitosis 搬移到 /opt 目錄,再到該目錄執行安裝動作。

sudo mv gitosis/ /opt/
cd /opt/gitosis/
sudo python setup.py install

安裝完畢後。接著建立一個使用者 git 以存取 repository。

sudo adduser --system --shell /bin/sh \
--gecos 'git version control' --group \
--disabled-password --home /home/git git

接著以平時使用的帳號產生一組 SSH 的 key。

ssh-keygen -t rsa

再使用這個 SSH key 初始化 Git Server。

sudo -H -u git gitosis-init < /tmp/id_rsa.pub
sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update

接著透過 git 下載 gitosis-admin.git。

git clone git@YOUR_SERVER_HOSTNAME:gitosis-admin.git

進入下載回來的 gitosis-admin 目錄後,會有一個 gitosis.conf 檔案和一個 keydir 目錄,其中要新增存取 git server 的使用者時,將 SSH key 添加到 keydir 目錄;而 gitosis.conf 則可以用來建立專案。

例如修改 gitosis.conf,添加一個叫 hello 的專案。

--- old/gitosis.conf   2010-08-12 23:08:13.684510792 +0800
+++ new/gitosis.conf 2010-08-12 23:10:55.504778775 +0800
@@ -4,3 +4,7 @@
writable = gitosis-admin
members = online@local

+[group]
+writable = hello
+members = online@local

接著將它送回 git repository,

git commit -a -m "Added a new project \"hello\""
git push

然後就可以開始建立 hello 這個專案了。

mkdir hello
cd hello/
git init
touch README
git add .
git commit -a -m 'Initial import'
git remote add origin git@YOUR_SERVER_HOSTNAME:hello.git
git push origin master