2012年9月26日 星期三
qemu 下載與安裝
1. 下載:
Qemu 下載網頁 - http://wiki.qemu.org/Download
2. 解壓縮:
tar xfva qemu-2.5.0.tar.bz2
解開後會出現 qemu-2.5.0 目錄
3. 設定前安裝套件:
libtool
zlib1g-dev
pkg-config
libsdl1.2-dev
libcurl4-openssl-dev
libsasl2-dev
libaio-dev
libvde-dev
libvdeplug2-dev
uuid-dev
libcap-ng-dev
4. 設定:
在 qemu-2.5.0 目錄下執行:
./configure
請注意底下兩個參數一定要設定成功:
SDL support yes
KVM support yes
如果有類似底下訊息時:
lzo support no
bzip2 support no
我們可以編輯 configure 這個檔案,搜尋 bzip2 與 lzo 這兩個關鍵字,此時會發現有底下片段,分別是:
if test "$bzip2" = "yes"; then
feature_not_found "libbzip2" "Install libbzip2 devel"
fi
以及
if test "$lzo" = "yes"; then
feature_not_found "liblzo2" "Install liblzo2 devel"
fi
這表示我們的系統中沒有安裝 bzip2 devel 以及 lzo devel 套件,在 Debian 底下,此兩個套件的名稱為:
libbz2-dev
liblzo2-dev
將上述兩個套件安裝,再執行 ./configure 後會發現 lzo 及 bzip2 都已支援,其訊息如下:
lzo support yes
bzip2 support yes
其它找不到套件的訊息依此類推來解決,理論上可以作到的訊息如下:
./configure
Disabling libtool due to broken toolchain support
Install prefix /usr/local
BIOS directory /usr/local/share/qemu
binary directory /usr/local/bin
library directory /usr/local/lib
module directory /usr/local/lib/qemu
libexec directory /usr/local/libexec
include directory /usr/local/include
config directory /usr/local/etc
local state directory /usr/local/var
Manual directory /usr/local/share/man
ELF interp prefix /usr/gnemul/qemu-%M
Source path /home/herman/tmp/qemu/qemu-2.5.0
C compiler cc
Host C compiler cc
C++ compiler c++
Objective-C compiler cc
ARFLAGS rv
CFLAGS -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -pthread -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -g
QEMU_CFLAGS -I/usr/include/pixman-1 -fPIE -DPIE -m64 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -Wendif-labels -Wmissing-include-dirs -Wempty-body -Wnested-externs -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wold-style-declaration -Wold-style-definition -Wtype-limits -fstack-protector-strong -I/usr/include/libpng12 -I/usr/local/include/spice-server -I/usr/local/include/cacard -I/usr/local/include -I/usr/local/include/spice-1 -I/usr/include/nss -I/usr/include/nspr -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/local/include/cacard -I/usr/include/nss -I/usr/include/nspr -I/usr/local/include/libusb-1.0 -I/usr/local/include
LDFLAGS -Wl,--warn-common -Wl,-z,relro -Wl,-z,now -pie -m64 -g
make make
install install
python python -B
smbd /usr/sbin/smbd
module support no
host CPU x86_64
host big endian no
target list aarch64-softmmu alpha-softmmu arm-softmmu cris-softmmu i386-softmmu lm32-softmmu m68k-softmmu microblaze-softmmu microblazeel-softmmu mips-softmmu mips64-softmmu mips64el-softmmu mipsel-softmmu moxie-softmmu or32-softmmu ppc-softmmu ppc64-softmmu ppcemb-softmmu s390x-softmmu sh4-softmmu sh4eb-softmmu sparc-softmmu sparc64-softmmu tricore-softmmu unicore32-softmmu x86_64-softmmu xtensa-softmmu xtensaeb-softmmu aarch64-linux-user alpha-linux-user arm-linux-user armeb-linux-user cris-linux-user i386-linux-user m68k-linux-user microblaze-linux-user microblazeel-linux-user mips-linux-user mips64-linux-user mips64el-linux-user mipsel-linux-user mipsn32-linux-user mipsn32el-linux-user or32-linux-user ppc-linux-user ppc64-linux-user ppc64abi32-linux-user ppc64le-linux-user s390x-linux-user sh4-linux-user sh4eb-linux-user sparc-linux-user sparc32plus-linux-user sparc64-linux-user tilegx-linux-user unicore32-linux-user x86_64-linux-user
tcg debug enabled no
gprof enabled no
sparse enabled no
strip binaries yes
profiler no
static build no
pixman system
SDL support yes
GTK support yes
GTK GL support no
GNUTLS support no
GNUTLS hash no
libgcrypt yes
nettle no ()
libtasn1 yes
VTE support yes
curses support yes
virgl support no
curl support yes
mingw32 support no
Audio drivers oss
Block whitelist (rw)
Block whitelist (ro)
VirtFS support no
VNC support yes
VNC SASL support yes
VNC JPEG support yes
VNC PNG support yes
xen support no
brlapi support yes
bluez support yes
Documentation yes
PIE yes
vde support yes
netmap support no
Linux AIO support yes
ATTR/XATTR support yes
Install blobs yes
KVM support yes
RDMA support no
TCG interpreter no
fdt support yes
preadv support yes
fdatasync yes
madvise yes
posix_madvise yes
sigev_thread_id yes
uuid support yes
libcap-ng support yes
vhost-net support yes
vhost-scsi support yes
Trace backends nop
spice support yes (0.12.7/0.12.5)
rbd support yes
xfsctl support yes
smartcard support yes
libusb yes
usb net redir yes
OpenGL support no
libiscsi support yes
libnfs support no
build guest agent yes
QGA VSS support no
QGA w32 disk info no
QGA MSI support no
seccomp support yes
coroutine backend ucontext
coroutine pool yes
GlusterFS support no
Archipelago support no
gcov gcov
gcov enabled no
TPM support yes
libssh2 support yes
TPM passthrough yes
QOM debugging yes
vhdx yes
lzo support yes
snappy support no
bzip2 support yes
NUMA host support no
tcmalloc support no
jemalloc support no
5. 編譯 qemu
請在設定完成後執行:
make -j 8 (8 核)
6. 安裝
請以 root 權限執行底下指令:
make install
將 qemu 安裝在 /usr/local/bin 目錄下
7. 測試
X86 版本:
請執行底下指令:
$ qemu-system-x86_64 -version
qemu-system-x86_64: error while loading shared libraries: libiscsi.so.1: cannot open shared object file: No such file or directory
我們會看到 qemu-system-x86_64 抱怨找不到 libiscsi.so.1,這最主要的原因目前的 libiscsi 這個動態連結函式庫的檔名已經是 libiscsi.so.2 了,所以 qemu 找不到 libiscsi.so.1,要解決此問題,我們要手動新增這個檔案,請以 root 權限切換至 /usr/lib/x86_64-linux-gnu 目錄,執行:
/usr/lib/x86_64-linux-gnu# ls -l libiscsi.so*
lrwxrwxrwx 1 root root 18 Jul 31 2014 libiscsi.so -> libiscsi.so.2.1.12
lrwxrwxrwx 1 root root 18 Jul 31 2014 libiscsi.so.2 -> libiscsi.so.2.1.12
-rw-r--r-- 1 root root 143344 Jul 31 2014 libiscsi.so.2.1.12
可以看到目前只有 libiscsi.so.2 這個檔案,在此目錄中要再新增 libiscsi.so.1 連結檔,指令如下:
/usr/lib/x86_64-linux-gnu# ln -s libiscsi.so.2.1.12 libiscsi.so.1
之後可以再執行 ls 確認一下連結檔是否已建立成功:
/usr/lib/x86_64-linux-gnu# ls -l libiscsi*
-rw-r--r-- 1 root root 223084 Jul 31 2014 libiscsi.a
lrwxrwxrwx 1 root root 18 Jul 31 2014 libiscsi.so -> libiscsi.so.2.1.12
lrwxrwxrwx 1 root root 18 Mar 25 10:43 libiscsi.so.1 -> libiscsi.so.2.1.12
lrwxrwxrwx 1 root root 18 Jul 31 2014 libiscsi.so.2 -> libiscsi.so.2.1.12
-rw-r--r-- 1 root root 143344 Jul 31 2014 libiscsi.so.2.1.12
此時再執行 qemu 即沒有問題:
$ qemu-system-x86_64 -version
QEMU emulator version 2.5.0, Copyright (c) 2003-2008 Fabrice Bellard
qemu-system-arm -M ?
可以看到 qemu arm 模擬器的資訊
qemu-system-arm -version
可以看到 qemu 模擬器版本資訊
QEMU emulator version 1.2.0, Copyright (c) 2003-2008 Fabrice Bellard
2012年6月12日 星期二
暑假作業
暑假作業
1. 課本看到第 15 章,並作每一個作業,自己寫不要看解答。
以下作業自行 Google
-------------------------------------
0. 建立 Linux 底下程式開發環境 -> 使用我講義中的流程
1. 將暑假作業全部以 Linux 環境來開發
2. 弄清楚 C 的結構該如定義
3. 寫基本貪食蛇程式 -> 以 X 視窗的繪圖函式庫來撰寫
4. 迷官貪食蛇
迷宮大小為 400x400 個點
貪食蛇的點為 5x5,初始長度為 5(五個點排在一起)
有三顆食物,以亂數方式出現,當其中一個被吃掉時,會在另一個地方出現,
但是不得在:牆壁、另二顆食物、貪食蛇身體出現。
按 P 暫停、按 Q 結束、按 S 重來。上、下、左、右 鍵控制貪食蛇移動。
-------------------------------------
俄羅斯方塊 (Optional)
-------------------------------------
讀以下網頁
http://caterpillar.onlyfun.net/Gossip/AlgorithmGossip/AlgorithmGossip.htm
google 資料結構 樹
1. 什麼是樹
2. 樹的應用
3. 如何搜尋
2012年5月30日 星期三
安裝執行 Blender
1. 請至 blender 網頁下載 Blender 檔案:
http://www.blender.org/download/get-blender/
下載 blender-2.63a-linux-glibc27-i686.tar.bz2
2. 將此檔案解壓縮至 /usr/local
/usr/local# tar jxfv 目錄/blender-2.63a-linux-glibc27-i686.tar.bz2
此時會解開一個 blender-2.63a-linux-glibc27-i686 目錄,其完整路徑為
/usr/local/blender-2.63a-linux-glibc27-i686
3. 在 /usr/local/bin 建一個 blender 之連結
/usr/local/bin# ln -s /usr/local/blender-2.63a-linux-glibc27-i686/blender .
4. 呼叫 Blender
在選單中啟動 Blender 或是直接輸入 blender,看是不是最新的 2.63a 版
5. 畫薑餅人
http://wiki.blender.org/index.php/Doc:2.4/Manual/Your_First_Animation/1.A_static_Gingerbread_Man
5. 畫薑餅人
http://wiki.blender.org/index.php/Doc:2.4/Manual/Your_First_Animation/1.A_static_Gingerbread_Man
2012年5月23日 星期三
自編 Linux 核心
自編 Linux 核心
為什麼要自己編 Linux 核心 ?
缺點:程度還沒到那邊的人,編出來的核心有時候開機會當機。
優點:
1. 修正舊核心的 bug
2. 支援新的硬體
3. 針對自己主機的硬體進行最佳化
4. 關閉不必要的核心模組,精簡編譯完之核心大小
如何挑核心
Linux 有一個存放核心的官方網站 (https://www.kernel.org/),在此網站中會有各個版本的最新核心,我們為了要調整自己使用機器之效能,因此必須要自行編譯核心,在核心官方網站中有三個種類的核心可下載,分別是:
- mainline - 目前開發版本,主要目的是加入新功能及測試,不建議在伺服器/嵌入式系統中使用,以免有未修正之 bug 導致機器不穩。
- stable - 穩定版核心,可提供日常使用
- longterm - 此版核心又稱為 LTS (Long Term Support - 長期支援) 核心,主要目的在於修正已知 bug,非常適合伺服器/嵌入式系統中使用。
如何編核心
1. 安裝程式編譯環境
2. 安裝核心編譯環境
3. 下載核心
4. 編譯核心
5. 安裝核心
6. 重新開機 -> 正常開機(OK)
-> 當機(以舊版核心重開,設法解決問題)
1. 安裝程式編譯環境
編譯 Linux 核心主要會使用到 GCC,在安裝 GCC 之前,我們可以看一下目前系統的 Linux 核心是由那一版的 GCC 所編譯完成,請執行:
$ dmesg | more
可以看到底下片段:
[ 0.000000] Linux version 3.16.0-4-amd64 (debian-kernel@lists.debian.org) (gcc version 4.8.4 (Debian 4.8.4-1) ) #1 SMP Debian 3.16.7-ckt20-1+deb8u3 (2016-01
-17)
此訊息告訴我們 Linux 核心是由 gcc 4.8.4 所編譯完成,因此如果我們安裝 GCC 的話,以 4.8.4 (以上) 為主。
編譯 Linux 核心主要會使用到 GCC,在安裝 GCC 之前,我們可以看一下目前系統的 Linux 核心是由那一版的 GCC 所編譯完成,請執行:
$ dmesg | more
可以看到底下片段:
[ 0.000000] Linux version 3.16.0-4-amd64 (debian-kernel@lists.debian.org) (gcc version 4.8.4 (Debian 4.8.4-1) ) #1 SMP Debian 3.16.7-ckt20-1+deb8u3 (2016-01
-17)
此訊息告訴我們 Linux 核心是由 gcc 4.8.4 所編譯完成,因此如果我們安裝 GCC 的話,以 4.8.4 (以上) 為主。
請安裝
gcc-4.8
cpp-4.8
g++-4.8
這三個套件,其中每個套件各有兩個版本:
gcc
gcc-4.8
gcc-4.9
cpp
cpp-4.8
cpp-4.9
g++
g++-4.8
g++-4.9
我們可以在 /usr/bin 目錄中看到目前的版本為何,或是執行以下指令:
gcc -v
cpp -v
g++ -v
如果我們至 /usr/bin 目錄下執行
ls -l gcc* cpp* g++*
會看到以下輸出:
lrwxrwxrwx 1 root root 7 3月 4 10:05 cpp -> cpp-4.8
-rwxr-xr-x 1 root root 772600 12月 20 2014 cpp-4.8
-rwxr-xr-x 1 root root 833080 12月 26 2014 cpp-4.9
lrwxrwxrwx 1 root root 7 3月 4 10:05 g++ -> g++-4.8
-rwxr-xr-x 1 root root 776696 12月 20 2014 g++-4.8
lrwxrwxrwx 1 root root 7 3月 4 10:05 gcc -> gcc-4.8
-rwxr-xr-x 1 root root 772600 12月 20 2014 gcc-4.8
-rwxr-xr-x 1 root root 24736 12月 20 2014 gcc-ar-4.8
-rwxr-xr-x 1 root root 24704 12月 20 2014 gcc-nm-4.8
-rwxr-xr-x 1 root root 24704 12月 20 2014 gcc-ranlib-4.8
lrwxrwxrwx 1 root root 7 3月 4 10:05 cpp -> cpp-4.8
-rwxr-xr-x 1 root root 772600 12月 20 2014 cpp-4.8
-rwxr-xr-x 1 root root 833080 12月 26 2014 cpp-4.9
lrwxrwxrwx 1 root root 7 3月 4 10:05 g++ -> g++-4.8
-rwxr-xr-x 1 root root 776696 12月 20 2014 g++-4.8
lrwxrwxrwx 1 root root 7 3月 4 10:05 gcc -> gcc-4.8
-rwxr-xr-x 1 root root 772600 12月 20 2014 gcc-4.8
-rwxr-xr-x 1 root root 24736 12月 20 2014 gcc-ar-4.8
-rwxr-xr-x 1 root root 24704 12月 20 2014 gcc-nm-4.8
-rwxr-xr-x 1 root root 24704 12月 20 2014 gcc-ranlib-4.8
這表示上述三個命令都聯結到 4.8 版,全部的聯結版本都要一致才行。檢查方式是執行:
$ gcc -v
$ g++ -v
$ cpp -v
$ gcc -v
$ g++ -v
$ cpp -v
來觀看版本編號,安裝完畢後請編譯 hello.c,指令如下:
gcc hello.c -o hello
再執行
./hello
如果出現 Hello world!! 即代表我們的程式編譯環境安裝 OK!!
2. 安裝核心編譯環境
請安裝以下套件才可編譯核心
kernel-package
libncurses5-dev
bzip2
xz-utils
3. 下載核心
國內 Linux 核心映站在:
linux.cdpa.nsysu.edu.tw (與底下那台合併了)
ftp://ftp.twaren.net/pub/Unix/Kernel/linux/kernel/v4.x/
ftp.isu.edu.tw
請將 Linux 核心下載至 /usr/src 目錄,我們以 4.4.23 為例,請下載
linux-4.4.23.tar.xz
附帶一提:xz 格式是目前壓縮率最高之非失真壓縮演算法
(失真壓縮演算法->jpg)
3.5 解壓縮
請在 /usr/src 目錄執行:
/usr/src/ # tar xfva linux-4.4.23.tar.xz
此時會出現一個 linux-4.4.23 的目錄,我們要建一個 link
/usr/src/ # ln -s linux-4.4.23 linux
4. 編譯核心
a. /usr/src # cd linux
a.5 複製已存在核心編譯參數,注意那個點!!
/usr/src/linux # cp /boot/config-3.16.0-4-amd64 .config
b. 設定編譯核心參數
/usr/src/linux # make menuconfig
General setup --->
Kernel compression mode (XZ) --->
Processor type and features --->
Processor family (Core 2/newer Xeon) --->
[*] Networking support --->
Networking options --->
[*] Network packet filtering framework (Netfilter) ---
IP: Netfilter Configuration ---> M
IPv6: Netfilter Configuration ---> M
修改完畢後退出 Linux 核心編譯的設定畫面。
/usr/src/linux # make menuconfig
General setup --->
Kernel compression mode (XZ) --->
Processor type and features --->
Processor family (Core 2/newer Xeon) --->
[*] Networking support --->
Networking options --->
[*] Network packet filtering framework (Netfilter) ---
IP: Netfilter Configuration ---> M
IPv6: Netfilter Configuration ---> M
c. time make-kpkg --initrd --revision=1.0.lpm kernel_image -j8
編譯完成後,你會有一個檔案叫:
/usr/src/linux-image-4.4.23_1.0.lpm_amd64.deb
我們再來安裝此檔即可,安裝指令如下:
/usr/src # dpkg -i linux-image-4.4.23_1.0.lpm_amd64.deb
/usr/src # dpkg -i linux-image-4.4.23_1.0.lpm_amd64.deb
d. 我們編譯到一半如果出現錯誤的話,該如何解決 ? 例如:
H16TOFW firmware/matrox/g200_warp.fw
H16TOFW firmware/matrox/g400_warp.fw
make[1]: Leaving directory `/usr/src/linux-3.3.7'
/usr/bin/make -j2 ARCH=i386 \
-C Documentation/lguest
make: *** Documentation/lguest: 沒有此一檔案或目錄. Stop.
make: *** [debian/stamp/build/kernel] Error 2
real 38m37.627s
user 65m58.119s
sys 5m21.180s
上述的問題是 LGUEST 不存在,因此我們看 .config 這檔案,將裡面的 LGUEST 設定
完全註記,再重新執行一次 make menuconfig (回到步驟 b)。
5. 安裝核心
/usr/src# dpkg -i linux-image-4.1.18_1.0.lpm_amd64.deb
其畫面如下:
選取了原先未選的套件 linux-image-4.1.18。
(讀取資料庫 ... 目前共安裝了 79198 個檔案和目錄。)
Preparing to unpack linux-image-4.1.18_1.0.lpm_amd64.deb ...
Done.
Unpacking linux-image-4.1.18 (1.0.lpm) ...
設定 linux-image-4.1.18 (1.0.lpm) ...
Running depmod.
Examining /etc/kernel/postinst.d.
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.1.18 /boot/vmlinuz-4.1.18
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.1.18 /boot/vmlinuz-4.1.18
update-initramfs: Generating /boot/initrd.img-4.1.18
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 4.1.18 /boot/vmlinuz-4.1.18
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.1.18
Found initrd image: /boot/initrd.img-4.1.18
Found linux image: /boot/vmlinuz-3.16.0-4-amd64
Found initrd image: /boot/initrd.img-3.16.0-4-amd64
done
/usr/src# dpkg -i linux-image-4.1.18_1.0.lpm_amd64.deb
其畫面如下:
選取了原先未選的套件 linux-image-4.1.18。
(讀取資料庫 ... 目前共安裝了 79198 個檔案和目錄。)
Preparing to unpack linux-image-4.1.18_1.0.lpm_amd64.deb ...
Done.
Unpacking linux-image-4.1.18 (1.0.lpm) ...
設定 linux-image-4.1.18 (1.0.lpm) ...
Running depmod.
Examining /etc/kernel/postinst.d.
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.1.18 /boot/vmlinuz-4.1.18
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.1.18 /boot/vmlinuz-4.1.18
update-initramfs: Generating /boot/initrd.img-4.1.18
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 4.1.18 /boot/vmlinuz-4.1.18
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.1.18
Found initrd image: /boot/initrd.img-4.1.18
Found linux image: /boot/vmlinuz-3.16.0-4-amd64
Found initrd image: /boot/initrd.img-3.16.0-4-amd64
done
如果安裝過程中有一些 missing firmware 的訊息,這是表示某些 firmware 沒有裝的意思,請直接安裝此套件,再重裝一次核心即可修正。
6. 重新開機 -> 正常開機(OK)
-> 當機(以舊版核心重開,設法解決問題)
2012年5月16日 星期三
如何架設 www 伺服器 ?
1. 有那些 web server 程式 ?
在 aptitude 底下找 httpd,我們會發現這是一個 v 的套件,按 Enter 看其內容。我們可以看到目前有許多 www 伺服器套件,如下所示:
p nginx 0.7.67-3+squeeze2
p monkey 0.9.3-1
p boa 0.94.14rc21-3.1
p cherokee 1.0.8-5+squeeze1
p nginx-naxsi 1.1.19-1~bpo60+1
p nginx-light 1.1.19-1~bpo60+1
p nginx-full 1.1.19-1~bpo60+1
p nginx-extras 1.1.19-1~bpo60+1
p dhttpd 1.02a-18
p ocsigen 1.3.3-1squeeze1
p lighttpd 1.4.28-2+squeeze1
p mathopd 1.5p6-1.1
p tntnet 1.6.3-4
p mini-httpd 1.19-9.2
p webfs 1.21+ds1-8
p yaws 1.88-2
i A apache2-mpm-worker 2.2.16-6+squeeze7
p apache2-mpm-prefork 2.2.16-6+squeeze7
p apache2-mpm-itk 2.2.16-6+squeeze7
p apache2-mpm-event 2.2.16-6+squeeze7
p thttpd 2.25b-11
p aolserver4-daemon 4.5.1-12
p aolserver4-core 4.5.1-12
p micro-httpd 20051212-12
p bozohttpd 20100621-1
p ebhttpd 1:1.0.dfsg.1-4.1
以上套件只要安裝一個就可以啟動 www 伺服器功能,以 RHCE 來說,所採用之 web server 為 apache。
2. 安裝 apache
# apt-get install apache2
即可安裝,安裝完後請以 firefox 開啟 http://127.0.0.1
3. 設定 Virtual Host
假設我們所架的 www 伺服器要能夠支援三個網域的服務,分別如下所示:
www.debian.example.com.tw
wyvern.example.com
localhost
那麼我們該如何設定 ?
3.1 設定 /etc/hosts 如以下所示:
192.168.1.21 wyvern.example.com wyvern
192.168.1.21 www.debian.example.com.tw
(上面的 IP 請改為自己的 IP),改完 /etc/hosts 後可以 ping 看看能不能 ping 到主機。
3.2 設定 /etc/apache2/httpd.conf 如下所示:
NameVirtualHost 192.168.1.21
<VirtualHost www.debian.example.com.tw>
DocumentRoot /home/debian
ServerName www.debian.example.com.tw
</VirtualHost>
<VirtualHost wyvern.example.com>
DocumentRoot /home/wyvern
ServerName wyvern.example.com
</VirtualHost>
3.3 設定 index.html -> 開啟網頁預定之檔案。
/home/debian/index.html 之內容如下:
This is debian.
/home/wyvern/index.html 之內容如下:
This is wyvern.
4. 重新載入 web 設定:
/etc/init.d/apache2 reload
5. 測試:
5.1 以 localhost 開啟網頁看結果如何 ?
5.2 以 www.debian.example.com.tw 開啟網頁看結果如何 ?
5.3 以 wyvern.example.com 開啟網頁看結果如何 ?
6. 收工
在 aptitude 底下找 httpd,我們會發現這是一個 v 的套件,按 Enter 看其內容。我們可以看到目前有許多 www 伺服器套件,如下所示:
p nginx 0.7.67-3+squeeze2
p monkey 0.9.3-1
p boa 0.94.14rc21-3.1
p cherokee 1.0.8-5+squeeze1
p nginx-naxsi 1.1.19-1~bpo60+1
p nginx-light 1.1.19-1~bpo60+1
p nginx-full 1.1.19-1~bpo60+1
p nginx-extras 1.1.19-1~bpo60+1
p dhttpd 1.02a-18
p ocsigen 1.3.3-1squeeze1
p lighttpd 1.4.28-2+squeeze1
p mathopd 1.5p6-1.1
p tntnet 1.6.3-4
p mini-httpd 1.19-9.2
p webfs 1.21+ds1-8
p yaws 1.88-2
i A apache2-mpm-worker 2.2.16-6+squeeze7
p apache2-mpm-prefork 2.2.16-6+squeeze7
p apache2-mpm-itk 2.2.16-6+squeeze7
p apache2-mpm-event 2.2.16-6+squeeze7
p thttpd 2.25b-11
p aolserver4-daemon 4.5.1-12
p aolserver4-core 4.5.1-12
p micro-httpd 20051212-12
p bozohttpd 20100621-1
p ebhttpd 1:1.0.dfsg.1-4.1
以上套件只要安裝一個就可以啟動 www 伺服器功能,以 RHCE 來說,所採用之 web server 為 apache。
2. 安裝 apache
# apt-get install apache2
即可安裝,安裝完後請以 firefox 開啟 http://127.0.0.1
3. 設定 Virtual Host
假設我們所架的 www 伺服器要能夠支援三個網域的服務,分別如下所示:
www.debian.example.com.tw
wyvern.example.com
localhost
那麼我們該如何設定 ?
3.1 設定 /etc/hosts 如以下所示:
192.168.1.21 wyvern.example.com wyvern
192.168.1.21 www.debian.example.com.tw
(上面的 IP 請改為自己的 IP),改完 /etc/hosts 後可以 ping 看看能不能 ping 到主機。
3.2 設定 /etc/apache2/httpd.conf 如下所示:
NameVirtualHost 192.168.1.21
<VirtualHost www.debian.example.com.tw>
DocumentRoot /home/debian
ServerName www.debian.example.com.tw
</VirtualHost>
<VirtualHost wyvern.example.com>
DocumentRoot /home/wyvern
ServerName wyvern.example.com
</VirtualHost>
3.3 設定 index.html -> 開啟網頁預定之檔案。
/home/debian/index.html 之內容如下:
This is debian.
/home/wyvern/index.html 之內容如下:
This is wyvern.
4. 重新載入 web 設定:
/etc/init.d/apache2 reload
5. 測試:
5.1 以 localhost 開啟網頁看結果如何 ?
5.2 以 www.debian.example.com.tw 開啟網頁看結果如何 ?
5.3 以 wyvern.example.com 開啟網頁看結果如何 ?
6. 收工
2012年5月2日 星期三
在 Debian 底下建置 Android 開發環境
1. 請至 Eclipse 網站下載最新版之 Eclipse 軟體,其下載位置如下:
http://www.eclipse.org/downloads/
下載 eclipse-jee-indigo-SR2-linux-gtk.tar.gz
tar xfvz eclipse-jee-indigo-SR2-linux-gtk.tar.gz
將此檔案解開至 eclipse 目錄,並執行
mv eclipse ~/
將 eclipse 移至家目錄
2. 啟動 eclipse
~/eclipse $ ./eclipse
3. 下載 android SDK
http://developer.android.com/sdk/index.html
下載最新版,目前最新版為 android-sdk_r18-linux.tgz
在 ~/ 下建立 android 目錄,並將 android-sdk_r18-linux.tgz 放至此目錄。
~/android $ tar xfvz android-sdk_r18-linux.tgz
此時會解開一個 android-sdk-linux 目錄
4. 安裝 android 開發環境
在 eclipse 的選單中,選擇 Help -> Install New Software...
然後按 Add 按鍵,在 Add 視窗出現時,請在
Name 欄位填 ADT Plugin
Location 欄位填 https://dl-ssl.google.com/android/eclipse/
然後按 OK
5. http://developer.android.com/sdk/eclipse-adt.html
6. Android SDK -> 請在 Window -> Android SDK Manager 中設定,並下載 Android SDK。等一段時間後,SDK 會安裝完畢。
7. AVD Manager -> 請在 Window -> AVD Manager 去新增一個 Android Device,並按 Start 啟動 Android 虛擬機器。
以上流程為 Android 開發環境建置說明。
8 網路上 Android 程式開發資源:
Android 教學| 孫傳雄研究室| Android 教學
蓋索林的Android 空間
http://www.eclipse.org/downloads/
下載 eclipse-jee-indigo-SR2-linux-gtk.tar.gz
tar xfvz eclipse-jee-indigo-SR2-linux-gtk.tar.gz
將此檔案解開至 eclipse 目錄,並執行
mv eclipse ~/
將 eclipse 移至家目錄
2. 啟動 eclipse
~/eclipse $ ./eclipse
3. 下載 android SDK
http://developer.android.com/sdk/index.html
下載最新版,目前最新版為 android-sdk_r18-linux.tgz
在 ~/ 下建立 android 目錄,並將 android-sdk_r18-linux.tgz 放至此目錄。
~/android $ tar xfvz android-sdk_r18-linux.tgz
此時會解開一個 android-sdk-linux 目錄
4. 安裝 android 開發環境
在 eclipse 的選單中,選擇 Help -> Install New Software...
然後按 Add 按鍵,在 Add 視窗出現時,請在
Name 欄位填 ADT Plugin
Location 欄位填 https://dl-ssl.google.com/android/eclipse/
然後按 OK
5. http://developer.android.com/sdk/eclipse-adt.html
6. Android SDK -> 請在 Window -> Android SDK Manager 中設定,並下載 Android SDK。等一段時間後,SDK 會安裝完畢。
7. AVD Manager -> 請在 Window -> AVD Manager 去新增一個 Android Device,並按 Start 啟動 Android 虛擬機器。
以上流程為 Android 開發環境建置說明。
8 網路上 Android 程式開發資源:
Android 教學| 孫傳雄研究室| Android 教學
蓋索林的Android 空間
安裝 FTP (File Transfer Protocal) 套件
安裝 FTP (File Transfer Protocal) 套件:
1. 請以 root 權限安裝
proftpd-basic 套件
安裝完畢後,其設定檔在 /etc/proftpd 目錄中
2. 啟動/停止/重啟 ftp
/etc/init.d/proftpd start/stop/restart
3. 開啟暱名權限
開啟公共檔案在 FTP 伺服器上以供暱名帳號連線,不需特別的帳號/密碼。要開啟暱名權限,請編輯 /etc/proftpd/proftpd.conf 這個設定檔,找到以下段落:
# <Anonymous ~ftp>
# User ftp
# Group nogroup
..
..
# </Anonymous>
將前面的 # 移除掉,並執行
# /etc/init.d/proftpd restart
重新啟動 proftpd 伺服器,並在 firefox 中開啟:ftp://127.0.0.1 或是 ftp://localhost 看能否開啟 ftp 目錄而且無需帳號/密碼。
/home/ftp -> ftp 開放目錄
如何連線至 FTP 主機 ?
要連線至 FTP 必須使用 FTP Client,常見的 Windows 版 FTP Client 有 Cuteftp 以及 Filezilla,其中 Filezilla 是自由軟體,因此推薦各位使用。至於在 Linux 底下的 FTP Client 有 gftp 以及命令列的 ncftp。以下說明以命令列的 ncftp 為主:
1. 一般帳號如何連線
ncftp -u 使用者 主機 -> ncftp -u herman localhost
此時會出現以下畫面:
NcFTP 3.2.4 (Apr 07, 2010) by Mike Gleason (http://www.NcFTP.com/contact/).
Connecting to 127.0.0.1...
ProFTPD 1.3.3a Server (Debian) [::ffff:127.0.0.1]
Logging in...
Password requested by 127.0.0.1 for user "herman".
Password required for herman
Password:
我們要輸入密碼以便連線,連線成功後,我們可以使用命令模式來進行操作。以下介紹幾個指令:
cd 目錄 -> 切換目錄
bi -> 切換至 2 進位模式 (傳 rar、zip、avi、mp3 .. 等檔案用)
as -> 切換至 ascii 模式 (傳純文字檔使用)
get -> 自遠端主機下載資料
put -> 將本機的資料上傳至遠端主機(先確定我們有上傳權限)
lls、lcd、lpwd -> 自機端之 ls、cd、pwd (local ls、local cd、lpwd)
by -> 離開 ftp
練習:
1. a. 新增帳號 hunter、密碼 hunter123、家目錄在 /home/hunter
hunter 目錄下有三個檔案,其檔名為 a、b、c,內容為:
This is file a/b/c
b. 架設 proftp 伺服器軟體,開放 hunter 登入
c. 二二一組,以 hunter 帳號登入對方主機,並練習抓檔案、上傳檔案
1. 請以 root 權限安裝
proftpd-basic 套件
安裝完畢後,其設定檔在 /etc/proftpd 目錄中
2. 啟動/停止/重啟 ftp
/etc/init.d/proftpd start/stop/restart
3. 開啟暱名權限
開啟公共檔案在 FTP 伺服器上以供暱名帳號連線,不需特別的帳號/密碼。要開啟暱名權限,請編輯 /etc/proftpd/proftpd.conf 這個設定檔,找到以下段落:
# <Anonymous ~ftp>
# User ftp
# Group nogroup
..
..
# </Anonymous>
將前面的 # 移除掉,並執行
# /etc/init.d/proftpd restart
重新啟動 proftpd 伺服器,並在 firefox 中開啟:ftp://127.0.0.1 或是 ftp://localhost 看能否開啟 ftp 目錄而且無需帳號/密碼。
/home/ftp -> ftp 開放目錄
如何連線至 FTP 主機 ?
要連線至 FTP 必須使用 FTP Client,常見的 Windows 版 FTP Client 有 Cuteftp 以及 Filezilla,其中 Filezilla 是自由軟體,因此推薦各位使用。至於在 Linux 底下的 FTP Client 有 gftp 以及命令列的 ncftp。以下說明以命令列的 ncftp 為主:
1. 一般帳號如何連線
ncftp -u 使用者 主機 -> ncftp -u herman localhost
此時會出現以下畫面:
NcFTP 3.2.4 (Apr 07, 2010) by Mike Gleason (http://www.NcFTP.com/contact/).
Connecting to 127.0.0.1...
ProFTPD 1.3.3a Server (Debian) [::ffff:127.0.0.1]
Logging in...
Password requested by 127.0.0.1 for user "herman".
Password required for herman
Password:
我們要輸入密碼以便連線,連線成功後,我們可以使用命令模式來進行操作。以下介紹幾個指令:
cd 目錄 -> 切換目錄
bi -> 切換至 2 進位模式 (傳 rar、zip、avi、mp3 .. 等檔案用)
as -> 切換至 ascii 模式 (傳純文字檔使用)
get -> 自遠端主機下載資料
put -> 將本機的資料上傳至遠端主機(先確定我們有上傳權限)
lls、lcd、lpwd -> 自機端之 ls、cd、pwd (local ls、local cd、lpwd)
by -> 離開 ftp
練習:
1. a. 新增帳號 hunter、密碼 hunter123、家目錄在 /home/hunter
hunter 目錄下有三個檔案,其檔名為 a、b、c,內容為:
This is file a/b/c
b. 架設 proftp 伺服器軟體,開放 hunter 登入
c. 二二一組,以 hunter 帳號登入對方主機,並練習抓檔案、上傳檔案
訂閱:
文章 (Atom)