Tags

2011年10月27日 星期四

Linux 70% Lab – OpenWebMail Sending via IPv6

openwebmail 目前尚未支援使用IPv6 SMTP

經過guru老師的提點後,研究出用下面的方法便可以達成此需求。


建置環境:

Server:Suse Linux 11.1

Client:任一作業系統


Server:
下載 NET-INET6Glue-0.5.tar.gz
  • tar –zxvf NET-INET6Glue-0.5.tar.gz –C /usr/lib/perl5/5.10.0/i586-linux-thread-multi
  • cd /usr/lib/perl5/5.10.0/i586-linux-thread-multi/Net-INET6Glue-0.5
  • perl Makefile.PL
  • make
  • make test
  • make install
  • vi /srv/www/cgi-bin/openwebmail/openwebmail-send.pl
在23行下新增下列內容:
use IO::Socket::INET;
use Net::INET6Glue::INET_is_INET6;
my $sock = IO::Socket::INET->new('[server IPv6 address]:25' => 'ipv4address:smtp(25)');
  • service postfix restart
  • service cyrus restart
  • service saslauthd restart
  • /srv/www/cgi-bin/openwebmail/openwebmail-tools.pl
Client:
  • 開啟OpenWebMail 寄信測試

2011年10月16日 星期日

Linux 70% Lab – DHCP with IPv6

先設定一般DHCP功能(不固定發放某IP給特定CLIENT)

Server1:
  • yast -i dhcpv6
  • vi /etc/sysconfig/network/dhcp6s
做以下修改:
2:DHCP6SIF="eth0"
  • vi /etc/dhcp6s.conf
新增以下內容:
interface eth0 {
        server-preference 255;
        renew-time 60;
        rebind-time 90;
        prefer-life-time 130;
        valid-life-time 200;
        allow rapid-commit;
        option dns_servers 2002:a78:d01:0:800:27ff:fe03:b3e9 31100173.com;
        link 31100173.com {
                range 2002:a78:d01::1000 to 2002:a78:d01::2000/64;
                prefix 2002:a78:d01::/64;
        };
};
  • service dhcp6s start
  • chkconfig dhcp6s on
Client1:(建議使用一台新VM)
  • yast –i dhcpv6
  • yast –> Networking Devices –> Networking Settings –> Edit 要使用的網卡
--> 標定Dynamic Address  選單選DHCP 和 DHCP Version 6 Only
--> Next –>OK
  • ifconfig 確認是否取得指定IP

設定發放固定IP給特定Client:

Client1
  • vi /var/lib/dhcpv6/client6.leasesxxxxxxxxxxx
開著等下設定會需要參考這裡的內容
Server1:
  • vi /etc/dhcp6s.conf
將內容改成:
interface eth0 {
        server-preference 255;
        renew-time 60;
        rebind-time 90;
        prefer-life-time 130;
        valid-life-time 200;
        allow rapid-commit;
        option dns_servers 2002:a78:d01:0:800:27ff:fe03:b3e9 31100173.com;
        link 31100173.com {
                range 2002:a78:d01::1000 to 2002:a78:d01::2000/64;
                prefix 2002:a78:d01::/64;
        };
        host client1 {
                 duid [client1文件中的duid];
                 iaidinfo {
                      iaid [client1文件名的iaid];
                      renew-time 1000;
                      rebind-time 2000;
                 };
                 address {
                      2002:a78:d01::1688/64;
                      prefer-life-time 2000;
                      valid-life-time 3000;
                 };
            };
};



  • service dhcp6s restart
Client1:
  • ifconfig 應該已經自動更新為指定的IP

2011年10月15日 星期六

Linux 70% Lab - Postfix + Cyrus + OpenWebMail with IPv6

Apache2:

Server1:
  • vi /etc/apache2/vhost.d/mail.31100173.com.conf
新增以下內容:
<VirtualHost 2002:a78:d01:0:800:27ff:fe03:b3e9:80>
    ServerAdmin root@31100173.com
    ServerName mail.31100173.com
    DocumentRoot /srv/apache2/mail
    ErrorLog /var/log/apache2/mail.31100173.com-error_log
    CustomLog /var/log/apache2/mail.31100173.com-access_log combined
    HostnameLookups Off
    ScriptAlias /cgi-bin/ "/srv/www/cgi-bin/"
    <Directory "/srv/www/cgi-bin">
        AllowOverride None
        Options +ExecCGI -Includes
        Order allow,deny
        Allow from all
    </Directory>
    <IfModule mod_userdir.c>
        UserDir public_html
        Include /etc/apache2/mod_userdir.conf
    </IfModule>
    <Directory "/srv/apache2/mail">
        Options Indexes FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>















  • Service apache2 restart
HostOS:
  • 開啟browser連入mail.31100173.com測試apache2是否正常運作

 

Postfix:

Server1:
  • chkconfig postfix on
  • vi /etc/postfix/main.cf
做下列修改:
91:mydomain = 31100173.com
107:myorigin = $mydomain
268:mynetworks = [2002:a78:d01::]/64, [::1]/128
671:myhostname = mail.31100173.com
675:inet_interfaces = localhost, $myhostname
676:masquerade_domains = $mydomain
677:mydestination = $myhostname, localhost.$mydomain, $mydomain
679:mynetworks_style = subnet
681:relayhost = 10.120.101.101 <---驗收時再補上
687:smtpd_client_restrictions = hash:/etc/postfix/access
  • service postfix restart
HostOS:
  • telnet mail.31100173.com 25 測試smtp是否有通 (出現220才算成功)
Server2:
  • zypper ar http://download.opensuse.org/distribution/11.1/repo/oss opensuse11.1
  • zypper install kmail
  • kmail設定:Setting –> Configure Kmail..
Identities:Add
    General:Your name:amy
               Email address:amy@mail.31100173.com
OK.
Accounts:
    Receiving:Add—> POP3 :
         Account Name: amy
                                 Host: mail.31100173.com
                                 Login: amy
                                 Password: XXXXXXXX
                Sending:Add:
   Name:amy
                                Host:mail.31100173.com
  • 寄信到外部信箱做測試
  • vi /etc/postfix/sender-canonical
         新增兩筆資料:
amy info@mail.31100173.com
boby info@mail.31100173.com
  • postmap hash:/etc/postfix/sender_canonical

Cyrus:

Server1:
  • yast –i cyrus (預設應該裝好了)
  • service cyrus start
HostOS:
  • telnet mail.31100173.com 110
  • telnet mail.31100173.com 143
  • vi /etc/postfix/transport
於文件最末端新增一行:
31100173.com    cyrus:
  • postmap hash:/etc/postfix/transport
  • vi /etc/imapd.conf
於文件末端新增一行:
allowplaintext: yes
  • service postfix restart
  • service cyrus restart
  • service saslauthd restart
  • chkconfig saslauthd on
  • chkconfig cyrus on
Server2:
  • 用Kmail測試收發信

OpenWebMail:
Server1:
  • yast –i perl-MIME-tools (ver. 5.427-2.8)
  • yast –i perl-Text-Iconv (ver. 1.4.3.85)
  • tar –zxvf openwebmail-2.53.tar.gz –C /srv/apache2
  • tar –zxvf openwebmail-2.53.tar.gz –C /srv/www
(事先於 http://www.openwebmail.org/openwebmail/download/release/2.53/ 下載)
  • cp –a /srv/apache2/data/openwebmail /srv/apache2/mail
  • cd /srv/www/cgi-bin/openwebmail
  • vi etc/openwebmail.conf
做下列修改:
13:31100173.com
16:/srv/www/cgi-bin/openwebmail
18:/srv/apache2/mail/openwebmail
31:預設簽名檔  隨便改
  • vi etc/defaults/openwebmail.conf
做以下修改:
30:mail.31100173.com
  • cp etc/default/dbm.conf etc/
  • vi etc/dbm.conf
做以下修改:
30:.db 改成 .pag
  • cp etc/default/auth_unix.conf etc/
  • vi etc/auth_unix.conf
做下列修改:
73: /etc/shadow
74: none
  • chmod 4555 /srv/www/cgi-bin/openwebmail/openwebmail*.pl
  • chown root.mail /srv/www/cgi-bin/openwebmail/openwebmail*.pl
  • chmod 4555 /usr/bin/suidperl
  • vi /etc/openwebmail_path.conf
新增以下內容:
/srv/www/cgi-bin/openwebmail
  • rcapparmor stop
  • chkconfig boot.apparmor off
  • vi /srv/apache2/mail/index.html
修改為:
<html>
<head>
<meta http-equiv="refresh" content="0;
url=http://mail.31100173.com/cgi-bin/openwebmail/openwebmail.pl/">
</head>
</html>
  • /srv/www/cgi-bin/openwebmail/openwebmail-tool.pl –init
(最後的send report可以不用送.若送了有錯誤訊息是正常的)
HostOS:
  • 開啟browser連入mail.31100173.com 登入openwebmail 測試收信

Linux 70% Lab – Samba Server with IPv6

Server2:
  • mv /etc/samba/smb.conf /etc/samba/smb.conf.origin
  • mkdir /srv/samba
  • vi /etc/samba/smb.conf
新增下列內容:
 [global]
        workgroup = LXLAB
        netbios name = server01
        server string = samba server on server01
        interfaces = lo eth0
        log file = /var/samba/log.%m
        max log size = 100
        security = user
        passdb backend = tdbsam
        hosts allow = fd53:1a82:4e39:0::/64 ::1
        printing = cups
        printcap name = cups
        cups options = raw

[labdir]
        comment = user level, for amy and boby (rw)
        path = /srv/samba/labdir
        read only = No
        printable = No
        public = No
        browseable = Yes
        inherit acls = Yes
        valid user = amy boby

  • chkconfig smb on
  • chkconfig nmb on
  • useradd –m amy
  • useradd –m boby
  • smbpasswd –a amy
  • smbpasswd –a boby
  • pdbedit –L –v | grep amy
  • pdbedit –L –v | grep boby
  • service smb start
  • service nmb start
  • testparm

HostOS:
  • smbclient –L server2
  • smbclient –U amy //server2/labdir

磁碟配額部份:

Server2:
  • 先關機多加一顆虛擬硬碟
  • fdisk /dev/sdb
          n --> p --> 1 --> default --> default --> p --> w
  • mkfs.ext3 /dev/sdb1
  • vi /etc/fstab
做下列修改:
/dev/sdb1 /           /srv/samba         ext3       defaults,usrquota        0 0
  • mount -a
  • mount   確定剛才的設定是否套用
  • cd /srv/samba
  • quotacheck –uvcm /dev/sdb1
  • ll   應有aquota.user
  • chkconfig boot.quota on
  • quotaon -uv /dev/sdb1
  • edquota –u amy
  • edquota –u boby
amy和boby都做以下設定
Filesystem                   blocks       soft       hard         inodes     soft     hard                     /dev/sdb1                          0       8000      10000         14           0        0
  • quota –u amy
  • quota –u boby  查看是否設定正確
  • mkdir labdir
  • chmod 1777 labdir
HostOS:
  • smbclient -U amy //server2/labdir
  • put files 測試

2011年10月14日 星期五

Linux 70% Lab – Apache2 with IPv6

Server1:
  • yast –i apache2 apache2-doc apache2-example pages
                       apache2-mod_perl apache2-mod_php5 apache2-prefork apache2-utils
  • service apache2 start
  • chkconfig apache2 on
HostOS:
  • 使用browser連線到www.31100173.com測試apache2是否正常運作
Server1:
  • vi /etc/apache2/default-server.conf
於文件末端新增兩行:
ServerName server1
ServerAdmin root@server1
  • vi /etc/apache2/listen.conf
46行改為: VirtualNameHost [server IPv6 address]:80

  • mkdir –p /srv/apache2/www
  • mkdir  /srv/apache2/mail
  • mkdir /srv/apache2/public
  • mkdir /srv/apache2/private

  • cp /srv/www/htdocs/index.html /srv/apache2/www/index.html
  • cp /srv/www/htdocs/index.html /srv/apache2/mail/index.html
  • cp /srv/www/htdocs/index.html /srv/apache2/public/index.html
  • cp /srv/www/htdocs/index.html /srv/apache2/private/index.html
  • 將每個目錄下的index.html稍作修改以便識別

  • cd /etc/apache2/vhost.d
  • cp vhost.template www.31100173.com.conf
  • vi www.31100173.com
做以下修改:
<VirtualHost 2002:a78:d01:0:800:27ff:fe03:b3e9:80>
    ServerAdmin root@31100173.com
    ServerName www.31100173.com

    DocumentRoot /srv/apache2/www

    ErrorLog /var/log/apache2/www.31100173.com-error_log
    CustomLog /var/log/apache2/www.31100173.com-access_log combined

    HostnameLookups Off

    ScriptAlias /cgi-bin/ "/srv/www/cgi-bin/"
    Alias /public "/srv/apache2/public"
    Alias /private "/srv/apache2/private"

    <Directory "/srv/www/cgi-bin">

        AllowOverride None
        Options +ExecCGI -Includes
        Order allow,deny
        Allow from all

    </Directory>


    <IfModule mod_userdir.c>

        UserDir public_html
        Include /etc/apache2/mod_userdir.conf

    </IfModule>


    <Directory "/srv/apache2/www">

        Options Indexes FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all</Directory>

    <Directory "/srv/apache2/public">

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

    </Directory>

    <Directory "/srv/apache2/private">

        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all

    </Directory>

</VirtualHost>     
  • cp www.31100173.com.conf mail.31100173.com.conf (之後做openmail才會用到)
  • vi /srv/apache2/private/.htaccess
新增下列內容:
           AuthName "Password Required ..."
           AuthType Basic
           AuthUserFile /etc/htusers
           require valid-user

  • htpasswd2 –cm /etc/htusers amy
  • htpasswd2 –m /etc/htusers boby
HostOS:
  • 使用browser分別連入 www.31100173.com 測試是否能正常運作.限制使用者
                                    www.31100173.com/public
                                    www.31100173.com/private
                                    mail.31100173.com

2011年10月13日 星期四

Linux 70% Lab – FTP (pure-ftpd) with IPv6

Server1:
  • yast –i pure-ftpd
  • vi /etc/pure-ftpd/pure-ftpd.conf
修改下列內容:
40行:20
52行:2
74行:no
80行:yes
107行:5
146行:yes
230行:32
347行:1280:5
449行:10066:10088
  • service pure-ftpd restart
  • chkconfig pure-ftpd on

HostOS:
測試上述設定是否有效執行

Linux 70% Lab - CUPS with IPv6

Server2:
  • vi /etc/cups/cupsd.conf
於18行下方新增一筆: Listen [server2 IPv6 address]:631
    25行下方新增兩筆: BrowseAddress @LOCAL
                                       BrowseAddress [IPv6 prefix]/64
    31行註解掉,下方新增一筆
      DefaultAuthType BasicDigest
    37及44行下方新增一筆: allow @LOCAL
  • lppasswd –a admin –g sys
  • vi /etc/cups/printers.conf
  • service cups restart

HostOS:
  • 使用browser開啟http://server2.31100173.com:631
  • 新增印表機lp0

Server2:
  • watch ls –l /var/spool/cups 觀看佇列
  • lpq –P lp0

HostOS:
  • 繼續使用browser讓lp0列印測試頁,再回頭看server2佇列是否有增加檔案
  • 使用browser開啟http://127.0.0.1:631
  • 新增網路印表機lp0
  • 列印測試頁

Linux 70% Lab – DNS(BIND) with IPv6

Server1:
  • yast –i bind bind-doc bind-chrootenv
  • vi /etc/named.conf
修改71行: notify yes;
於文件末端新增:
zone "31100173.com" in {
        allow-transfer { any; };
        file "master/31100173.com";
        type master;
};
  • vi /var/lib/named/master/31100173.com
新增以下內容:
$TTL 2d
@               IN SOA          server70-1.lxlab.com.   root.server70-1.lxlab.com. (
                                2011101300      ; serial
                                3h              ; refresh
                                1h              ; retry
                                1w              ; expiry
                                1d )            ; minimum
31100173.com.   IN MX           1 mail.31100173.com.
31100173.com.   IN NS           server1.31100173.com.
31100173.com.   IN NS           server2.31100173.com.
server1         IN AAAA         fd53:1a82:4e39:0:800:27ff:fea7:bfd0
server2         IN AAAA         fd53:1a82:4e39:0:800:27ff:fe3b:5470
www             IN CNAME        server1
mail            IN CNAME        server1
ftp             IN CNAME        server1
### 上面兩步的內容也可以用yast做,會輕鬆許多 ###
  • service named restart
  • chkconfig named on

Server2:
  • yast –i bind bind-doc bind-chrootenv
  • scp root@server1:/etc/named.conf /etc/named.conf
  • vi /etc/named.conf
做以下修改:
zone "31100173.com" in {
        allow-transfer { any; };
        masters { fd53:1a82:4e39:0:800:27ff:fea7:bfd0; };        file "slave/31100173.com";
        type slave;
  • service named restart
  • chkconfig named on

Server1:
  • service named restart

Server2:
  • vi /var/lib/named/slave/31100173.com 查看內容是否正確無誤

2011年10月1日 星期六

作業三 :自動化異地備份所有使用者家目錄

目標:
於server1(自己的主機), 建立一指令稿(使用bash) backup.sh 存放於/root/bin/內,
工作內容是對/home目錄進行差異式備份(differential backup), 且必須滿足以下需求:
a) 指令稿內必須使用tar 指令進行備份.
b) 於每週五時, 指令稿必須進行完整備份(full backup).
c) 於每週一至週四, 指令稿必須進行差異式備份(differential backup), 只備份full backup後有異動的部份資料.
d) 指令稿必須能找出備份當日的星期名稱(如Mon,Tue,Wed,...), 以便能判斷出必須採用的備份方法.
e) 使用一參考檔案(/var/backup/last-backup), 以便進行 full backup 後的郵戮時間點, 作為 differential backup 啟始點的依據.
f) 對產生的備份檔須符合以下格式:
* Full backup: /var/backup/backup-full-YYY-MM-DD.tar.bz2
* Differential backup: /var/backup/backup-diff-YYYY-MM-DD.tar.bz2. 其中YYYY-MM-DD 是備份當日的格式 (如. 2011-09-29).
g) 若進行備份失敗, 該指令稿必須能發出 email 給 root@server1. 主旨為"Backup failed !", email內容可不需要指定.
h) 於指令稿內使用rsync進行同歩server1的/var/backup目錄, push 到 server2的 /home/bkman/backup目錄,
    以實現異地備份任務.(bkman 為該帳戶的home folder. 且server2為測試主機)
i) 使用例行式排程於週一至週五晚上22:30執行backup.sh.
j) 假設你backup資料的安全存量為四周, 此script能自動刪除超過一個月的backup 資料.
 
Server1:
  • vi /root/bin/backup.sh
#!/bin/sh
#WrittenBy YuningLau
#Full Backup Funtion
full()
{
touch /var/backup/last-backup
rm -rf /var/backup/backup_full_"$date28".tar.bz2
tar -cjvf /var/backup/backup_full_`date +%F`.tar.bz2 /home
}
#Differential Backup Funtion
diff()
{
rm -rf /var/backup/backup_diff_"$date28".tar.bz2
find /home -type f -newer /var/backup/last-backup -print0 | tar --null -cjvf /var/backup/backup_diff_`date +%F`.tar.bz2 -T -
}
#Name parameters to see which day today is :
today=`date +%u`
date28=`date --date='28days ago' +%F`

#Remove backup files over 4 weeks
rm -rf /var/backup/backup_*_"$date28".tar.bz2

#Exam which type to backup
case "$today" in
        [5])
                full
                ;;
        [1234])
                diff
                ;;
esac

#Exam the backup is complete or not
#If fail, send notification to root
#If sucess, push to backup server(server2)
if [ $# -ne 0 ]
then
        mail -s "Backup Failed!!!" root@es11-s1
else
        rsync -ave ssh -6 --delete /var/backup root@es11-s2:/home/bkman
fi

exit 0
 
 
  • mkdir /var/backup

  • ssh-keygen –t rsa

  • scp id_rsa.pub root@[server2 IPv6 Addr.]:/root/server1.pub

  • vi /etc/crontab
於文件末端新增一筆:
30 22 * * 1-5  root  bash /root/bin/backup.sh

Server2:
  • useradd –m bkman
  • passwd bkman
  • cat server1.pub >> /root/.ssh/authorized_keys