新安装的系统,软件包更新,首先找一个速度不错的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 /ubuntu maverick-security
main restricted deb-src
http: //security .ubuntu.com /ubuntu maverick-security
main restricted deb
http: //security .ubuntu.com /ubuntu maverick-security
universe deb-src
http: //security .ubuntu.com /ubuntu maverick-security
universe deb
http: //security .ubuntu.com /ubuntu maverick-security
multiverse deb-src
http: //security .ubuntu.com /ubuntu maverick-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
|
sudo apt-get
update sudo apt-get
upgrade |
安装Nginx
1
|
apt-get install nginx |
安装Mysql-server
1
|
apt-get install mysql-server |
安装php,php-fpm,php常用模块
1
|
apt-get install php5-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 /plain text /css image /jpeg application /json application /x-javascript text /xml application /x-shockwave-flash application /xml application /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