Ubuntu Server 10.10安裝配置Nginx+php-fpm+mysql

新安裝的系統,軟件包更新,首先找一個速度不錯的Ubuntu源,這裏網上搜了一個。

http://www.cnblogs.com/lei1016cn/archive/2010/10/21/1857761.html

更改源

?
1
vi/etc/apt/source.list

全部刪除,加入下面的源。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
### Security Sourcelist
 
deb http://security.ubuntu.com/ubuntumaverick-security main restricted
deb-src http://security.ubuntu.com/ubuntumaverick-security main restricted
deb http://security.ubuntu.com/ubuntumaverick-security universe
deb-src http://security.ubuntu.com/ubuntumaverick-security universe
deb http://security.ubuntu.com/ubuntumaverick-security multiverse
deb-src http://security.ubuntu.com/ubuntumaverick-security multiverse
 
### 163.com Sourcelist
deb http://mirrors.163.com/ubuntu/maverick main universe restricted multiverse
deb-src http://mirrors.163.com/ubuntu/maverick main universe restricted multiverse
deb http://mirrors.163.com/ubuntu/maverick-security universe main multiverse restricted
deb-src http://mirrors.163.com/ubuntu/maverick-security universe main multiverse restricted
deb http://mirrors.163.com/ubuntu/maverick-updates universe main multiverse restricted
deb http://mirrors.163.com/ubuntu/maverick-proposed universe main multiverse restricted
deb-src http://mirrors.163.com/ubuntu/maverick-proposed universe main multiverse restricted
deb http://mirrors.163.com/ubuntu/maverick-backports universe main multiverse restricted
deb-src http://mirrors.163.com/ubuntu/maverick-backports universe main multiverse restricted
deb-src http://mirrors.163.com/ubuntu/maverick-updates universe main multiverse restricted

上面部分是保留Ubuntu官方緊急安全補丁源。保存後,執行

?
1
2
sudoapt-get update
sudoapt-get upgrade

安裝Nginx

?
1
apt-getinstallnginx

安裝Mysql-server

?
1
apt-getinstallmysql-server

安裝php,php-fpm,php常用模塊

?
1
apt-getinstallphp5-cgi php5-mysql php5-fpm php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl php5-ming php5-pspell php5-recode

就這樣,把Nginx,mysql,php都安裝好了,安裝好後都是啓動了的,手動啓動或者停止服務用下面的命令。

?
1
2
3
4
5
6
7
8
9
10
11
12
service nginx start     #啓動nginx
service nginx restart   #重啓nginx
service nginx stop      #停止nginx
 
service php5-fpm start    #啓動php5-fpm
service php5-fpm restart  #重啓php5-fpm
service php5-fpm reload   #重加載php5-fpm
service php5-fpm stop     #停止php5-fpm
 
service mysql start       #啓動mysql
service mysql restart     #重啓mysql
service mysql stop        #停止mysql

安裝好了,還需要做一些優化配置。
nginx優化配置,/etc/nginx/nginx.conf

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
user www-data;
worker_processes  8;
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;
 
error_log /var/log/nginx/error.log;
pid       /var/run/nginx.pid;
 
events {
    use epoll;
    worker_connections  51200;
    multi_accept on;
}
 
http {
    include      /etc/nginx/mime.types;
 
    access_log /var/log/nginx/access.log;
 
    sendfile       on;
    keepalive_timeout  65;
    tcp_nodelay    on;
    tcp_nopush     on;
 
    server_names_hash_bucket_size 128;
    client_header_buffer_size 2k;
    large_client_header_buffers 4 4k;
    client_max_body_size 20m;
 
    ## gzip
    gzip on;
    gzip_disable"MSIE [1-6]\.(?!.*SV1)";
    gzip_min_length 1k;
    gzip_buffers     4 16k;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_types  text/plaintext/cssimage/jpegapplication/jsonapplication/x-javascripttext/xmlapplication/x-shockwave-flashapplication/xmlapplication/xml+rss text/javascript;
    gzip_vary on;
 
    include/etc/nginx/conf.d/*.conf;
    include/etc/nginx/sites-enabled/*;
}

上面的是按照服務器8個cpu來配置的,也就是每個cpu開一個worker總共8個,並且指定每個worker的序號

php-fpm優化配置,主要是進出數的配置,找到以下幾個關鍵配置選項,在/etc/php5/fpm/poll.d/www.conf

?
1
2
3
4
5
6
pm = dynamic                        #這裏可以設置爲dynamic/static,前者爲動態管理php-fpm進程,後者爲靜態
 
pm.max_children  200                #最大的子進程數量,這個參數只在pm=static模式下有效,dynamic模式得下面參控制
pm.start_servers = 200              #啓動的時候開啓的進程數
pm.min_spare_servers = 100          #空閒時候最少保留的進程數
pm.max_spare_servers = 300          #最大進程數

上面假如選擇pm的方式爲static,那麼只有pm.max_children參數設置起作用,因爲使用靜態的模式管理進程,php-fpm管理器只會靜態的設置最大的進程數量爲max_children,而反過來,使用pm=dynamic,則pm.max_children不起作用了,會根據下面的三個參數聯合控制。這裏,pm.start_servers是要根據pm.min_spare_servers和pm.max_spare_servers兩個參數的設置計算來的,公式爲:pm.start_servers = pm.min_spare_servers + (pm.max_spare_servers – pm.min_spare_servers)/2。
另外,到底開啓多少進程數合適呢?以及選擇怎樣的模式更好呢?
假如服務器配置不錯,那就是用static模式,畢竟動態的管理php-fpm進程會有消耗服務器資源,以及數量上的話,一般一個php-fpm據說是消耗20-30MB的內存(我自己也沒考究過-_-!)。按照這樣算,1G內存的機器,大概開30個差不多了,8G的話,我多的時候是配置到了300個最大進程數量。
原文地址:Ubuntu Server 10.10安裝配置Nginx+php-fpm+mysql


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章