Nabeko Notebook: Server 筆記

来源:百度文库 编辑:神马文学网 时间:2024/05/03 00:49:00

lighttpd with ssl support(Embedded Linux)

Suppose we use the toolchain for arm(arm-linux).

1) Openssl
Download openssl(0.9.8k)
extract and configure it.

Shell$ ./Configure linux-generic32 no-asm shared --prefix=$PWD/install
modify the Makefile

CC= arm-linux-gcc
......
AR=arm-linux-ar $(ARFLAGS) r
ARD=arm-linux-ar $(ARFLAGS) d
RANLIB= arm-linux-ranlib
......
MAKEDEPPROG= arm-linux-gcc
......
make & make install

2) lighttpd
Download lighttpd(1.4.23)
extract it and configure with openssl

Shell$ ./configure --host=arm-linux --disable-ipv6 --with-openssl=(openssl_installed_dir) --prefix=/lighttpd --without-zlib --without-bzip2 --without-pcre
Shell$ make
Shell$ make install
*web compress module(zlib,bzip2), perl cgi program(pcre)

The prefix is suggested to be a sub dir of root("/"). The reason is: when lighttpd be executed, it loads needed modules from the prefix path. You won't wanna create dirs like "/home/XXX/XXX/XXX/XXX" on your target rootfs. Orz

After installation is finished, copy the essential file to target rootfs
host rootfs ==> target rootfs
(installed dir)/sbin/* ==> /sbin/
(installed dir)/lib/*.so ==> /(installed dir)/lib/
(source dir)/doc/lighttpd.conf ==> /etc/

3) Settings
modify lighttpd.conf

# Modules
server.modules = (
"mod_alias",
"mod_access",
"mod_auth",
"mod_accesslog" )
......
# replace it by your default web dir
server.document-root = "/var/www/"
......
# mark the followings for embedded system
#url.access-deny = ( "~", ".inc" )
#$HTTP["url"] =~ "\.pdf$" {
# server.range-requests = "disable"
#}
......
# set CGI
cgi.assign = ( ".cgi" => "" )
alias.url = ("/cgi-bin" => "/var/www/cgi-bin" )

# set SSL
$SERVER["socket"]==":443" {
ssl.engine = "enable"
ssl.pemfile = "/etc/ssl/private/lighttpd.pem"
}
$SERVER["socket"]==":443" { ... } means when clients connect server by https(port 443), the ssl engine is enable. The others who use default port(80) can surf the server also.

Create /etc/ssl/private/lighttpd.pem by openssl

Shell$ openssl req -new -x509 -keyout lighttpd.pem -out lighttpd.pem -days 365 -nodes

Create dir /var/log/lighttpd on target rootfs(define in lighttpd.conf)

4) Run on target system!!!

Shell$ lighttpd -f /etc/lighttpd.conf


References:
Lighttpd Configuration
Lighttpd Secure HTTP張貼者: Cloud 位於 10/22/2009 08:12:00 下午 0 意見 標籤: Embedded_System, Linux, Server

2009年5月7日星期四

Dovecot-IMAP,POP3(Debian,Ubuntu)

Dovecot is a IMAP and POP3 Server

System : GNU/Linux Debian 5.0 lenny
Package: dovecot-imapd dovecot-pop3d dovecot-common

修改/etc/dovecot/dovecot.conf

......
protocols = pop3 imap
......
listen = *
......
disable_plaintext_auth = no
......
mechanisms = plain login
......

Add imap port 143 and pop3 port 110 to firewall exception rules and restart the dovecot.

$Shell /etc/init.d/dovecot restart


Related Knowledge:
Mail Server Setup:Postfix Mail Server (Debian,Ubuntu)
Postfix SMTP Authentication:Postfix + SASL(Debian,Ubuntu)張貼者: Cloud 位於 5/07/2009 03:00:00 下午 0 意見 標籤: Linux, Server

2009年3月19日星期四

Postfix Mail Server (Debian,Ubuntu)

依照DNS Server(Debian,Ubuntu)架設的DNS Server,使用mail.nabeko.net來做為Mail Server的hostname。

System : GNU/Linux Debian 5.0 lenny
Package: postfix

安裝完postfix後,會出現設定畫面

General type --> Internet Site
System mail name --> mail.nabeko.net

也可以執行以下命令修改設定檔

Shell$ dpkg-reconfigure postfix
修改的設定檔為/etc/postfix/main.cf

修改/etc/postfix/main.cf

...略...
myhostname = mail.nabeko.net
mydomain = bike.net
myorigin = $mydomain
#www.nabeko.net為主機hostname,需要讓它也可以收到信
mydestination = $myhostname, $mydomain, www.nabeko.net
relay_domains = $mydestination
relayhost =
mynetworks = 127.0.0.0/8
...略...
若一直有信寄不出去的問題,可以設定relayhost = [msa.hinet.net],由hinet的mail server來幫你做relay的動作

重新啟動postfix,防火牆記得開啟smtp port 25

$Shell /etc/init.d/postfix restart

Mail Server的log在/var/log/mail.log,有任何問題可以查看log檔

延伸閱讀:
Postfix SMTP驗證:Postfix + SASL(Debian,Ubuntu)
Dovecot架設:Dovecot-IMAP,POP3(Debian,Ubuntu)
DNS Server:DNS Server(Debian,Ubuntu)

Reference:
鳥哥的Linux私房菜-Mail伺服器張貼者: Cloud 位於 3/19/2009 12:39:00 下午 0 意見 標籤: Linux, Server

2009年3月18日星期三

DNS Server(Debian,Ubuntu)

假設我申請了一個domain name叫做nabeko.net,對應的IP為192.168.1.68,並需要兩個hostname,www.nabeko.net與mail.nabeko.net對應到同一個IP。

System : GNU/Linux Debian 5.0 lenny
Package: bind9

修改/etc/bind/named.conf.options

options {
directory "/var/cache/bind";
//Hinet DNS
forwarders { 168.95.1.1; };
allow-query { any; };
allow-transfer { none; };};

修改/etc/bind/named.conf並加入

...略...
zone "nabeko.net" {
type master;
file "/etc/bind/db.nabeko.net";};

zone "1.168.192.in-addr.arpa" {
type master;
file "/etc/bind/db.192.168.1";};

include "/etc/bind/named.conf.local";

接著設定正解檔案/etc/bind/db.nabeko.net
複製一份/etc/bind/db.local來修改

$TTL 604800
@ IN SOA nabeko.net. root.www (...略...)
@ IN NS www.nabeko.net.
@ IN NS mail.nabeko.net.
@ IN MX 10 mail.nabeko.net.
@ IN A 192.168.1.68
www IN A 192.168.1.68
mail IN A 192.168.1.68
相關資訊可參考鳥哥:正解資料庫檔案設定

接著設定反解檔案/etc/bind/db.192.168.1
一樣複製一份/etc/bind/db.local來修改

$TTL 604800
@ IN SOA nabeko.net. root.www (...略...)
@ IN NS www.bikeid.net.
68 IN PTR www.bikeid.net.
68 IN PTR mail.bikeid.net.
相關資訊可參考鳥哥:反解資料庫檔案設定

修改/etc/hostname

www.nabeko.net

修改/etc/hosts

127.0.0.1 localhost
192.168.1.68 www.nabeko.net
192.168.1.68 nabeko.net
...略...

修改/etc/resolv.conf

nameserver 192.168.1.68
...略...

重新啟動,並記得防火牆設定開啟DNS port:53

Shell$ shutdown -r now


利用nslookup進行正反解測試

Shell$ nslookup nabeko.net
Shell$ nslookup www.nabeko.net
Shell$ nslookup mail.nabeko.net
Shell$ nslookup 192.168.1.68

DNS Server確定正常後,在申請Domain name的網站,填入DNS Server主機www.nabeko.net

延伸閱讀:
Mail Server架設:Postfix Mail Server (Debian,Ubuntu)

Reference:
鳥哥的Linux私房菜-DNS伺服器張貼者: Cloud 位於 3/18/2009 02:12:00 下午 0 意見 標籤: Linux, Server

2009年3月17日星期二

Apache設定限制瀏覽網站目錄(Debian,Ubuntu)

如果沒有設定限制瀏覽網站目錄,那就表示瀏覽者可以任意觀看並下載你網站目錄內的所有資料,這樣的網站幾乎沒有安全性可言。

Apache利用網站目錄Options的Indexes參數來決定要開放/限制瀏覽網站目錄

有Indexes --> 開放
無Indexes --> 限制
去掉Indexes,Apache就不會產生目錄的索引,瀏覽時會出現403 forbidden的頁面

假設我們有一個網站www.nabeko.webhop.net,網站的目錄為/var/www/web,而網站可讓使用者瀏覽的目錄為/var/www/web/downloads

修改/etc/apache2/sites-available/default

NameVirtualHost *:80

ServerName www.nabeko.webhop.net
DocumentRoot /var/www/web

Options FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all



Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all


延伸閱讀:
Apache使用VirtualHost將不同網址對應到不同資料夾(Debian,Ubuntu)張貼者: Cloud 位於 3/17/2009 01:14:00 上午 0 意見 標籤: Linux, Server

2009年3月16日星期一

Apache使用VirtualHost將不同網址對應到不同資料夾(Debian,Ubuntu)

假設從DynDns.com申請一個domain name名叫nabeko.webhop.net,伺服器內有兩個網站,網址與資料夾位置對應如下

www.nabeko.webhop.net --> /var/www/web
blog.nabeko.webhop.net --> /var/www/blog


因為要在domain name前加www或blog,所以要先開啟Wildcard

開啟Wildcard的功能在於,你在domain name前面加任何的hostname,都可以對應到原本的domain name

www.nabeko.webhop.net --> nabeko.webhop.net
blog.nabeko.webhop.net --> nabeko.webhop.net


接著修改/etc/apache2/sites-available/default

NameVirtualHost *:80

ServerName www.nabeko.webhop.net
DocumentRoot /var/www/web

Options FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all



ServerName blog.nabeko.webhop.net
DocumentRoot /var/www/blog

Options FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all



重新啟動apache

Shell$ /etc/init.d/apache2 restart

延伸閱讀:
Apache設定限制瀏覽網站目錄(Debian,Ubuntu)張貼者: Cloud 位於 3/16/2009 12:52:00 下午 0 意見 標籤: Linux, Server

2009年3月13日星期五

Pure-FTPD (Embedded Linux)

下載Pure-FTPD(我用的是1.0.21)
(以arm平台為例 cross-compiler為arm-none-linux-gnueabi-gcc,安裝到目前目錄的install資料夾內)

Shell$ ./configure --prefix=$PWD/install CC=arm-none-linux-gnueabi-gcc --host=arm-none-linux-gnueabi

結果出現以下error訊息

...略...
configure: error: cannot run test program while cross compiling
...略...


編輯configure並搜尋"error: cannot run test program while cross compiling"

if test "$cross_compiling" = yes; then
{ { $as_echo "$as_me:$LINENO: error: cannot run test program while cross compiling
將yes 改成 no(大概改7個左右)

修改完後再重新configure
執行

Shell$ make
Shell$ make install
將安裝目錄內bin/與sbin/內的執行檔複製到rootfs內,並記得將原始碼資料夾configuration-file內的pure-ftpd.conf複製到rootfs內的/etc

pure-ftpd.conf內的設定都有註解,
詳細設定可以參考:柏青哥的SuSE Linux -- 架設Pure-ftpd Server
我的設定如下

ChrootEveryone no
BrokenClientsCompatibility no
MaxClientsNumber 10
Daemonize yes
MaxClientsPerIP 5
VerboseLog no
DisplayDotFiles yes
AnonymousOnly yes
NoAnonymous no
SyslogFacility ftp
DontResolve yes
MaxIdleTime 15
UnixAuthentication yes
LimitRecursion 2000 8
AnonymousCanCreateDirs yes
MaxLoad 4
PassivePortRange 40000 90000
AntiWarez yes
Bind ,21
Umask 133:022
MinUID 100
AllowUserFXP no
AllowAnonymousFXP no
ProhibitDotFilesWrite no
ProhibitDotFilesRead no
AutoRename no
AnonymousCantUpload yes
MaxDiskUsage 99
CustomerProof yes
PerUserLimits 1


版子開機執行

Shell$ pure-ftpd &


登入時必須有user密碼,可用passwd修改,且家目錄必須存在
(EX: user為root 家目錄為/root)張貼者: Cloud 位於 3/13/2009 12:37:00 上午 0 意見 標籤: Embedded_System, Server

2009年3月3日星期二

Remote Linux Kernel & rootfs for Embedded System(NFS,Tftpd,VMWare)

在Embedded Linux的開發階段,Kernel與rootfs都需要常常修改,每修改一次,就要download到target board一次,是很麻煩的動作,所以通常都會將kernel與rootfs放在Server,讓target board開機時自動載入。

硬體:
網卡x2(一張對外,另一張連接target board)
系統:
Host OS: Windows XP SP3
Client OS: VMWare ACE 6.0 + GNU/Linux Debian 4.0 Etch

假設Server IP為 192.168.0.10, target board IP為192.168.0.2

1.首先配置網卡的部份
在Edit-->Virtual Network Settings
選擇Host Virtual Network Mapping
將VMnet?(選沒用到的,我用VMnet2)mapping到連接target board的網卡

在VM-->Settings
點選Add加入Ethernet Adapter
在Network Type點選Custom,並選擇VMnet?(選剛剛定的,我用VMnet2)

然後開啟GNU/Linux Debian

修改/etc/network/interfaces

auto eth0
iface eth0 inet dhcp

auto eth1
iface eth1 inet static
address 192.168.0.10
netmask 255.255.255.0

重新啟動網路

Shell$ /etc/init.d/networking restart


2.接著安裝所需的package

Linux Kernel會透過tftp的方式載入
需要安裝Tftp Server的package

Shell$ apt-get install tftpd


修改/etc/inetd.conf
找到

tftp dgram udp wait nobody /usr/sbin/tcpd /usr/sbin/in.tftpd /tftpboot
假設/tftpboot為Linux Kernel所在路徑

rootfs會透過nfs的方式掛載
需要安裝NFS Server的package

Shell$ apt-get install nfs-kernel-server

假設rootfs路徑為/root/rootfs/install
修改/etc/exports,並加入

/root/rootfs/install 192.168.0.2/32(rw,no_root_squash)
表示只有192.168.0.2這個IP對rootfs的路徑有讀寫的權限,使用no_root_squash為以root的權限來讀寫該目錄,32是netmask,為255.255.255.255,表示要完全符合192.168.0.2才能適用於這項規則。

重新啟動inetd與nfs

Shell$ /etc/init.d/openbsd-inetd restart
Shell$ /etc/init.d/nfs-kernel-server restart


3.設定U-boot

設定網路相關變數

U-boot=> set ipaddr 192.168.0.2
U-boot=> set serverip 192.168.0.10
U-boot=> set netmask 255.255.255.0
U-boot=> set gateway 192.168.0.254

設定開機自動載入Linux Kernel

# 0x20000000 為我的版子上RAM的位址
U-boot=> set kerneladdr 0x20000000
U-boot=> set bootcmd tftp ${kerneladdr} uImage\; bootm ${kerneladdr}

設定bootargs使Kernel啟動後掛載nfs為rootfs

U-boot=> set bootargs console=ttyS0,115200 root=/dev/nfs rw init=/sbin/init nfsroot=${serverip}:/root/rootfs/install ip=${ipaddr}:${serverip}:${gateway}:${netmask}::eth0:off
除了紅字的部份,其他請依照自己的rootfs設定

參數設定好,存入flash

U-boot=> saveenv

接下來可重新開機或執行以下命令測試

U-boot=> run bootcmd
張貼者: Cloud 位於 3/03/2009 02:57:00 下午 0 意見 標籤: Embedded_System, Linux, Server

2009年3月2日星期一

Postfix + SASL(Debian,Ubuntu)

Postfix是一種mail server,相關知識請參考鳥哥,架設Mail Server可以參考Postfix Mail Server (Debian,Ubuntu) ,在Mail Server中,為了防止不速之客利用我們架設的Mail Server 來亂發郵件,所有的mail server預設都會把Open Relay的功能關閉,而為了分辨誰有資格使用這個mail server寄信,會透過SMTP Auth來驗證身份。

這邊我們使用SASL(Simple Authentication and Security Layer)來作為SMTP Auth。

System : GNU/Linux Debian 5.0 lenny
Package: postfix-tls sasl2-bin libsasl2-2 libsasl2-modules

先修改/etc/default/saslauthd

START=yes
MECHANISMS="pam"


接著建立/etc/postfix/sasl/smtpd.conf
並加入內容,將驗證密碼的方式指定為saslauthd這個Daemon

pwcheck_method: saslauthd


然後在/etc/postfix/main.cf內加入以下內容
來enable SASL

# 設定 Postfix 使用 SASL 認証。
smtpd_sasl_auth_enable = yes
# 不使用 ANONYMOUS 這個認証。
smtpd_sasl_security_options = noanonymous
# 設定 SASL 支援非標準 E-mail Client 的認証動作。
broken_sasl_auth_clients = yes
# 設定 SASL 的認証方法
smtpd_recipient_restrictions = permit_sasl_authenticated,
permit_mynetworks,
reject_unauth_destination


因為Postfix預設以chroot來啟動,導致saslauthd無法與Postfix溝通
所以做了以下設定,將原本saslauthd的執行資料夾link到以chroot啟動Postfix後的資料夾內,使saslauthd還是可以用自己預設的路徑來與Postfix溝通

Shell$ rm -r /var/run/saslauthd
Shell$ mkdir -p /var/spool/postfix/var/run/saslauthd
Shell$ ln -s \
/var/spool/postfix/var/run/saslauthd /var/run/saslauthd


考慮到權限問題,必須把/var/spool/postfix/var/run/saslauthd設定為sasl的群組,並將postfix加入sasl的群組內

Shell$ chgrp sasl /var/spool/postfix/var/run/saslauthd
Shell$ adduser postfix sasl


最後重新啟動

Shell$ /etc/init.d/postfix restart
Shell$ /etc/init.d/saslauthd start


可以用以下命令測試sasl是否正常運作

Shell$ testsaslauthd -u username -p password

延伸閱讀:
Mail Server架設:Postfix Mail Server (Debian,Ubuntu)
Dovecot架設:Dovecot-IMAP,POP3(Debian,Ubuntu)

Reference:
Debian Wiki-Postfix-SASL張貼者: Cloud 位於 3/02/2009 09:32:00 下午 0 意見 標籤: Linux, Server

2007年8月10日星期五

DHCP Server (Ubuntu, Debian)

DHCP(Dynamic Host Configuration Protocol)最主要的目的就是分配某一個網段的IP給內網的主機,大部分都用在當只有一個IP可連上網路,而想讓多數主機可以同時上網的時候,所以除了DHCP外,還需要有NAT(Network Address Translation)的功能,來將內網IP轉換出去來連接到網路

假設有一個固定IP要分配給多台主機同時上網,想要分配的IP range為192.168.1.100~200

1. 安裝dhcp

Shell$ sudo apt-get install dhcp3-server


修改/etc/network/interface

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address 140.118.x.x
netmask 255.255.255.0
gateway 140.118.x.254

auto eth1
iface eth1 inet static
address 192.168.1.254
netmask 255.255.255.0


設定好後要重新啟動網路設定

Shell$ sudo /etc/init.d/networking restart
也可以使用系統-->管理-->網路來設定
eth0為對外的網卡,eth1對內,而eth1的ip設定成192.168.1.254是因為我的dhcp要分配192.168.1.0這個網段的ip,記得內網IP與要分配的位址要在同一網段

3.修改/etc/default/dhcp3-server

INTERFACES="eth1"


4.修改/etc/dhcp3/dhcpd.conf
找到

# option definitions common to all supported networks...
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;

default-lease-time 600;
max-lease-time 7200;

加#號註解掉

找到

# A slightly different configuration for an internal subnet.
#subnet 10.5.5.0 netmask 255.255.255.224 {
# range 10.5.5.26 10.5.5.30;
# option domain-name-servers ns1.internal.example.org;
# option domain-name "internal.example.org";
# option routers 10.5.5.1;
# option broadcast-address 10.5.5.31;
# default-lease-time 600;
# max-lease-time 7200;
#}

改成

# A slightly different configuration for an internal subnet.
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.100 192.168.1.200 ;
option domain-name-servers 168.95.1.1;
option domain-name "ubuntu.org";
option routers 192.168.1.254 ;
option broadcast-address 192.168.1.255;
default-lease-time 600;
max-lease-time 7200;
}


存檔後執行

Shell$ sudo /etc/init.d/dhcp3-server restart
到這邊為止,DHCP已經正常運作,內網主機也都可以分配到IP位址,但是還是沒辦法上網,所以還要設定NAT,在這邊我使用Firestarter來設定,對iptables設定有興趣的請參考鳥哥的網站

5. NAT
Firestarter-->Preferences-->NetWork Settings,勾選Enable Internet connection sharing(NAT)和Enable DHCP for the local network,而下面的DHCP server details選擇第一個就會使用我們剛剛的設定,若選擇第二個並設定好IP range,Firestarter會自動幫我們更改/etc/dhcp3/dhcpd.conf的內容

P.S. 修改檔案記得備份

延伸閱讀:
Firestarter:好用的圖形介面防火牆(Ubuntu, Debian)

Reference:
鳥哥-DHCP伺服器張貼者: Cloud 位於 8/10/2007 04:52:00 下午 0 意見  from site :  http://nabeko-notebook.blogspot.com/search/label/Server