1 / 53

Apache @ Ubuntu

Apache @ Ubuntu. Apache2 安裝. $ sudo apt-get install apache2 $ sudo aptitude install apache2. 關閉或重新啟動 apache. $ sudo /etc/init.d/apache2 start $ sudo /etc/init.d/apache2 stop $ sudo /etc/init.d/apache2 restart $ sudo service apache2 restart. PHP 安裝.

silvio
Télécharger la présentation

Apache @ Ubuntu

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Apache @ Ubuntu

  2. Apache2 安裝 • $ sudo apt-get install apache2 • $ sudo aptitude install apache2

  3. 關閉或重新啟動 apache • $ sudo /etc/init.d/apache2 start • $ sudo /etc/init.d/apache2 stop • $ sudo /etc/init.d/apache2 restart • $ sudo service apache2 restart

  4. PHP 安裝 • $ sudo apt-get install php5 libapache2-mod-php5 php5-gd php5-mysqli • $ sudo apt-get install php4 libapache2-mod-php4 php4-gd php4-mysqli • $ sudo /etc/init.d/apache2 restart • $ sudo service apache2 restart

  5. MySQL 安裝 • $ sudo apt-get install mysql-server mysql-client

  6. 修改 MySQL 密碼 • $ sudo mysqladmin -u root -p password<輸入您要的新密碼>

  7. 重新啟動 MySQL • $ sudo /etc/init.d/mysql restart • sudo service mysql restart

  8. Apache2 設定 Debian 裡面的 Apache2 和其他發行版的管理方式有點不同 在 Debian 的設定檔不再是傳統的 httpd.conf,而是放在 apache2.conf,並且把很多模組設定或者虛擬主機設定拆開來放到各自的目錄。 這些獨立出來的設定檔又可以透過 Debian 專屬的工具程式啟用或關閉 Ubuntu 也繼承到 Debian 的這個特性

  9. Apache2 設定 apache2.conf 以下投影片內容主要參考 … 1.鳥哥的 Linux 私房菜:http://linux.vbird.org/linux_server/0360apache.php 2. http://xuxueliang.blog.51cto.com/5576502/971093

  10. apache2.conf 重要設定 ServerRoot "/etc/apache2" Apache Server 設定檔放置處

  11. apache2.conf 重要設定 KeepAlive On / Off 是否允許持續性的連線,亦即一個 TCP 連線可以具有多個檔案資料傳送的要求。 原則上 … 如果你的網頁內含很多圖檔,那麼這一次連線就會將所有的資料送完,而不必每個圖檔都需要進行一次 TCP 連線  改為 On 較佳 如果你的網站多為動態網頁 (e.g., 內容為資料庫存取)  改為 Off 較佳

  12. Refresh 一次,GET 了無數東東 …

  13. Skype, Line 2014/9/15 13

  14. In DOS command 視窗輸入:netstat -n 2014/9/15 14

  15. TCP connection establishmentestablishing connection-oriented connection(three-way handshake) 2014/9/15 15

  16. apache2.conf 重要設定 Timeout 300 不論接收或傳送,當持續連線等待超過 300 秒則該次連線就中斷 一般來說,此數值在 300 秒左右即可,不需要修改這個原始值  by 鳥哥 But, 300 is still far more than necessary in most situations. It is not set any lower by default because there may still be odd places in the code where the timer is not reset when a packet is sent.(http://users.cis.fiu.edu/~downeyt/cgs4854/timeout)

  17. apache2.conf 重要設定 打開 KeepAlive 後,意味著每次使用者完成全部訪問後,都要保持一定時間後才會關閉TCP連接,那麼在關閉連接之前,必然會有一個 Apache 程序 (process) 對應於該使用者而不能處理其他用戶 假設 KeepAlive 的時間為 100 秒,伺服器每秒處理 50 個獨立使用者訪問,那麼系統 中 Apache的總程序數就是100* 50=5000 個,如果一個程序佔用 4M 記憶體,那麼總共會消耗 20G 記憶體,所以可以看出,在這種配置中,相當消耗記憶體,但好處是系統只處理了 50 次 TCP 的握手和關閉操作。

  18. apache2.conf 重要設定 如果關閉 KeepAlive,如果還是每秒 50 個用戶訪問,如果用戶每次連續的請求數為3個,那麼 Apache 的總程序數就是50 * 3= 150 個,如果還是每個程序佔用 4M 記憶體,那麼總的記憶體消耗為 600 M,這種配置能節省大量記憶體 但是,系統處理了150 次 TCP 的握手和關閉的操作,因此又會多消耗一些CPU資源。

  19. apache2.conf 重要設定 MaxKeepAliveRequests 100 MaxKeepAliveRequests 是每次 Client 端建立連線後,可以要求最大的檔案數,設成 0 為不限制,或者可以把它設高一點,尤其是在網頁很複雜的時候, 效能會有明顯改善 為了增進效能則可以改大一點,e.g. 500

  20. apache2.conf 重要設定 <IfModule prefork.c> StartServers 5 MinSpareServers 5 MaxSpareServers 10 MaxClients 150 MaxRequestsPerChild 0 </IfModule>

  21. What is “prefork”? mpm-worker 數個 child processes,每個 processes 都會再有數個 threads 很多第三方的套件沒有 thread safe,也就是沒有考慮到 multi-thread 的問題  不穩定! mpm-prefork 最傳統的模式,運作時會有數個 child processes,每個 processes 都只跑一個 thread 效能較差且耗費比較多記憶體,穩定性比較好! etc

  22. apache2.conf 重要設定 StartServers 5 # StartServers 為 Apache2 啟動時,會啟用幾個程序 (processes),可以透過 ps -aux 來驗證。若您的網站流量很大,可以改大一點,但是若用量沒有那麼大,會浪費系統資源。   

  23. apache2.conf 重要設定 MinSpareServers 5 MaxSpareServers 10 最小 & 最大的預備使用的程序 (processes) 數量。   

  24. apache2.conf 重要設定 MaxClients 150 最大的同時連線數量,也就是程序 (processes) 不會超過此一數量,可以視您網站的規模修改

  25. apache2.conf 重要設定 MaxRequestsPerChild 0 無限制 每個程序能夠提供的最大傳輸次數要求。 舉例來說,如果有個使用者連上伺服器後(一個 process),卻要求數百個網頁,當他的要求數量超過此一數值, 則該程序會被丟棄,另外切換一個新程序。 這個設定可以有效的控管每個 process 在系統上的『存活時間』。 因為根據觀察所得,新程序的效能較佳

  26. 用白話文說 … <IfModule prefork.c> StartServers 5 MinSpareServers 5 MaxSpareServers 10 MaxClients 150 MaxRequestsPerChild 0 </IfModule> 假設有 10 個人連上來,左邊 這個設定代表 … 1. apache 此時的程序數應有 15-20 個 2. 而這個最終程序數不可超過 150 個

  27. $ top

  28. apache2.conf 重要設定(sites-enable) DocumentRoot /www/htdocs 網頁放置的根目錄 ServerNamewww.im.ncue.edu.tw 主機所傾聽 (listen) 的網域

  29. apache2.conf 重要設定(mods-enable) DirectoryIndex index.html index.cgi index.pl index.php index.xhtml 若沒有明確指定網頁檔名,Apache2 會依序以下順序來嘗試送給 client 端瀏覽器 In mods-enabled dir.conf

  30. apache2.conf 重要設定(/etc/apache2/envvars) User www-data (${APACHE_RUN_USER}) Group www-data (${APACHE_RUN_GROUP}) Apache2 Server 執行時所用的帳號和群組,若沒有特別的理由可以不用更動 Now in /etc/apache2/envvars

  31. apache2.conf 重要設定(in conf.d/charset) #AddDefaultCharset Big5 AddCharset utf-8 .utf8 AddCharset big5 .big5 .b5 AddDefaultCharset 千萬不要加上去,這個方式會在表頭就送出說這個網頁是用什麼語言編碼,但是若您的網頁有 big5 和 utf-8 混用的話,就會造成錯誤! 正確的作法是在網頁 html 內都指定編碼,如 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 後面那些 AddCharset 是指可以支援的編碼,預設都設好了,不要改動。

  32. apache2.conf 重要設定 AccessFileName .htaccess The name of the file to look for in each directoryfor additional configuration directives Ref:http://sparc.nfu.edu.tw/teacher/htaccess/index.htm

  33. apache2.conf 重要設定 Include …

  34. Include … Include conf.d/ Include sites-enabled/

  35. httpd.conf empty

  36. ports.conf

  37. Directory conf.d

  38. mods-enabled

  39. mods-available

  40. Add / Remove module $ a2enmod userdir $ a2dismod userdir (Anytime you change some configuration, do remember to restart apache…)

  41. 新增模組 - 1(以啟用 “個人網頁” 為例) What is“個人網頁”? Recall … you create a sub-directory “www” under your home directory, put your web files there. there you go …http://120.107.152.251/~tkwu/

  42. 新增模組 - 2(以啟用 “個人網頁” 為例) 在非Debian and Ubuntu 系統,it’s … UserDir www^^^^^預設為public_html But,在 Ubuntu 裡,使用者個人網頁獨立到一個額外的模組和設定檔

  43. 新增模組 - 3(以啟用 “個人網頁” 為例) 啟用個人網頁$ a2enmod userdir $ /etc/init.d/apache2 restart $ service apache2 restart 關閉個人網頁: $ a2dismod userdir $ /etc/init.d/apache2 restart $ service apache2 restart

  44. 新增模組 - 4(以啟用 “個人網頁” 為例) 個人網頁設定檔 /etc/apache2/mods-available/userdir.conf

  45. 虛擬主機 一主機多網站 IP-based Name-based 需搭配DNS Port-based

  46. IP-based

  47. Name-based

  48. Port-based

  49. Name-based 虛擬主機設定 - 1(以新增 “tkwu.im.ncue.edu.tw” 為例) Copy 範本 $ cd /etc/apache2/sites-available $ cp default tkwu

  50. Name-based 虛擬主機設定(以新增 “tkwu.im.ncue.edu.tw” 為例) 編輯新的設定檔 (tkwu)

More Related