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

2013年12月16日 星期一

[SA] Hw4 FAMP(FreeBSD+Apache+MySQL+PHP)










  • # 先從 devel/git 的 ports 中安裝 git
  • # 同時間選取 gitweb 以提供網頁界面
  • # 之後遇到的設定頁照原來的 OK OK 就可以
  • cd /usr/ports/devel/git
  • make install clean
  •  
  • # 增加 git 的使用者,並指定 git 的家用目錄為 /home/git
  • # 同時間使用 git-shell 作為 shell 指令, uid, gid 為 9418
  • pw groupadd -n git -g 9418
  • pw useradd -n git -u 9418 -g git -c git -d /home/git -s /usr/local/libexec/git-core/git-shell -h -
  •  
  • # 新增 repo (倉庫 work),並更改屬性
  • chown git:git /home/git
  • chmod 755 /home/git
  •  
  • mkdir /home/git/work/
  • chmod 775 /home/git/work/
  • chown git:git /home/git/work/
  •  
  • # 設定除了 commit 外還可以使用額外指令的用戶
  • # 如果使用者只需要 commit,就可以不加進來
  • vi /etc/group
  • git:*:9418:zeuxis,neo
  •  
  • # 設定 SSH 認證金鑰,因為 git 要用到這東西
  • # 每個使用者的 SSH Key 也要加進 authorized_keys.
  • # 每個 key 為一行
  • mkdir /home/git/.ssh/
  • chmod 700 /home/git/.ssh/
  •  
  • touch /home/git/.ssh/authorized_keys
  • chmod 600 /home/git/.ssh/authorized_keys
  • chown -R git:git /home/git/.ssh/
  •  
  • # 生成指定用戶的 SSH Key
  • # 在安裝情況下是使用 ssh-keygen -d 生成 dsa
  • # 另還可用 ssh-keygen -t rsa 生成 rsa
  • # 生成時 Enter passphrase 無視按下 enter 即可
  • su username
  • ssh-keygen -d
  • su root
  • cat /home/username/.ssh/id_dsa.pub > /home/git/.ssh/anthorized_keys
  •  
  • # 接著設定 git 的 repo
  • mkdir /home/git/work/test.git
  • cd /home/git/work/test.git && git init --bare --shared
  •  
  • # 接著進行一個簡單的測試
  • mkdir /tmp/test && cd /tmp/test && git init
  • echo "This is a test" > index.html
  • git add
  • git commit -m 'added index.html'
  •  
  • # 之後 commit 到遠端的 repo
  • git remote add origin username@example.com:work/test.git
  • git push origin master
  •  
  • # 之後再設定 gitweb
  • mkdir /home/git/public_html
  • chmod 755 /home/git/public_html
  • chown git:git /home/git/public_html
  • cp /usr/local/share/examples/git/gitweb/git* /home/git/public_html
  •  
  • # 再設定 apache
  • <VirtualHost *:80>
  •   ServerAdmin no-reply@example.com
  •   DocumentRoot "/home/git/public_html"
  •   ServerName git.example.com
  •  
  •   <Directory "/home/git/public_html">
  •     Options ExecCGI
  •     Order allow,deny
  •     Allow from all
  •  
  •     DirectoryIndex gitweb.cgi
  •     AddHandler cgi-script .cgi
  •   </Directory>
  • </VirtualHost>
  •  
  • # 之後再編輯 gitweb.cgi
  • our $projectroot = "/home/git/work";
  • our $home_link_str = "work";
  • our $site_name = "git.example.com"
  • our $projects_list_description_width = 40; # 調整 description 空間
  •  
  • # 修改 test.git 的描述
  • echo "test.git" > /home/git/work/test.git/description
  •  
  • # 修改 test.git 的 owner
  • vim /home/git/work/test.git/config
  •  
  • # 在其後面加入
  • [gitweb]
  • owner = zeuxis
  • url = git://git.example.com/work/test.git
  • url = username@git.example.com:work/test.git
  •  
  • # 最後就是設定 Git protocol
  • # 在 /etc/rc.conf 最後加入這段
  • git_daemon_enable="YES"
  • git_daemon_directory="/home/git"
  • git_daemon_flags="--syslog --base-path=/git --export-all"
  •  
  • # 之後啟動 Git Daemon
  • /usr/local/etc/rc.d/git_daemon start
  •  
  • # 如果以上面這句子會出現停在 starting 的字眼可以改為以下句式
  • # 送出後接兩下 Enter 結束即可
  • /usr/local/etc/rc.d/git_daemon start &
  •  
  • # 檢查是否在執行
  • ps -eaf | grep -v grep | grep git
  •  
  • # 如有東西就可以再測試可否使用了
  • cd /tmp/test
  • rm -Rf *
  • git clone git://git.example.com/work/test.git
  • - See more at: http://www.chair.im/?p=597#sthash.2F0agDtP.qSAdRJ2D.dpuf

    Requirement

    • To do this homework , you need 2 domain name.
      • http://twbbs.org/
      • http://www.nctucs.net/
    • You need two hostnames use same IP address.
    • When access http://yourdomain1, it will show the php information.
    • When access http://yourdomain1/sademo.html, it will show the text “This page is for sa demo.”. 
      • Notice that user can use both http and https portocal to access this page.
    • When access http://yourdomain1/private/, user need enter id "nctucs" and password "sahw4" which is implemented by .htaccess. And it will show the text “It’s my secret.”
    • System user sysadm can put file at ~/WWW/ and others can access it by visiting http://yourdomain1/~sysadm/. sysadm's password is your student id.
    • Your git website url is http://yourdomain2/gitweb
    • For demo, you need to put a git repository named “sademo.git”. And it’s decription is “This repository is for sa demo.”.
    • On your website, enter the sademo.git will show URL information, it’s URL is http://yourdomain2/gitweb/sademo.git.
    • You can clone and push your repository by http://yourdomain2/gitweb/sademo.git and password is your student id.
    • Users use cookie authentication when access your phpMyAdmin site http://yourdomain1/phpMyAdmin/
      • (You need to add a MySQL user for authentication).
      • Create another user with limited privilege
      • And notice that if others access http://yourdomain2/phpMyAdmin/, they can not access it.
      • Only 140.113.*.* can access it
      • But 140.113.235.* can’t access it
    • Redirect http://yourdomain1/ILoveSA to http://help.cs.nctu.edu.tw/ 
      • But http://yourdomain2/ILoveSA will not redirect .

    2013年12月2日 星期一

    [SA] Hw3 shell programming



    因為這次都是寫 code ,所以我這次就把 code 丟上 GitHub 囉

    ================================================

    2013年11月2日 星期六

    [SA] Hw2 ftp

    SA HW2 DEMO 流程說明

    ===================
    注意: 先在下列位置事先放置檔案供 demo 測試
    -----------------------------------------
    /home/ftp/public/
    /home/ftp/hidden/
    /home/ftp/hidden/treasure

    使用的 ftp 是 proftpd,FreeBSD 9.2-RELEASE

    ZFS

    ZFS on /home/ftp
    Create a zfs file system with mirror
    Do zfs snapshot
    Do zfs rollback
    Set compression
    Reboot and everything is fine (zfs still mount)



    2013年10月26日 星期六

    [SA] ProFTPd



    因為有人推薦 ProFTPd,所以這次就捨棄 PureFTPd 來用用看 ProFTPd 吧。

    先來簡介一下 ProFTPd 。

    ProFTPD (short for Pro FTP daemon) is a FTP server. ProFTPD is Free and open-source software, compatible to Unix-like systems and Microsoft Windows (via Cygwin). Along with vsftpd and Pure-FTPd, ProFTPD is among the most popular FTP servers in UNIX-like environments today. Compared to those, which focus e.g. on simplicity, speed or security, ProFTPD's primary design goal is to be a highly feature rich FTP server, exposing a large amount of configuration options to the user.

    ProFTPd 在 FreeBSD 裏面的位置是 /usr/ports/ftp/proftpd
    cd 到那裡然後 make install clean 之後就能順利安裝了:D


    [SA] ZFS

    ZFS 概觀

    ZFS 是 Sun Microsystems 為 Solaris 作業系統 (Unix 的一支) 開發的檔案系統。
    ZFS 具備 logical volume management 的能力 (稱為 Zpool)、也提供快照(snapshots)、copy-on-write 副本與自動修復的功能。

    不同於傳統的檔案系統是建立在單一的磁碟分割之上,ZFS 是建立在虛擬的儲存池(pool)之上,稱為 Zpool。Zpool 可以是由多個 volume 所組成,之後檔案系統再透過 zpool 取得使用空間。ZFS的另一項特點就是 128 位元的設計,理論上可以 2 的 48 次方個檔案,每個檔案最大可以有 16EB,最大單一 volume 可達 16EB。

    在資料安全與穩定性方面,ZFS 採用 copy- on-write 與 snapshots 計術來進一步維護檔案系統的正確性。所謂 copy-on-write 簡單的說就是每當檔案有變更時,不是直接覆蓋舊 有的資料,而是將使用中的區塊複製出來,而這些變更是在這複製的區塊上。Copy-on-Write 最大的好處就是當資料變更時,舊有的資料依然能夠維持,方便作為復原之用。Snapshot 就是保存著這些就有資料的映像副本的技術。ZFS 有著另一項先進的計術,就是透過刪除重複的資料 (Deduplication) 來節省儲存的空間。


    2013年9月29日 星期日

    [SA] Hw1-1


    Requirements

    • Basic:
      • Install up-to-date –RELEASE of FreeBSD (9.1-R)
      • Add a user and a group
        • Group name should be identical to your username
        • User should also be in the ‘wheel’ group
      •  Set your machine to current time zone and adjust current time
      •  Enable sshd