Nginx架构WEB服务器
- Tue, 02 Jun 2009 20:17:53 +0800
现在说一下LNMP架构的服务器的安装过程,作为自己的一个笔记,也为一些需要帮助的朋友提供点参考。
L方面使用Debian(其实我用FreeBSD),基本是个什么都没的干净系统(连GCC都没)。1.首先我们安装GCC编译环境
因为后面的软件都需要编译,所以这个不装就太不像话了。
apt-get install build-essential如果出现如下提示:
E: Couldn't find package build-essential
则需要更新包列表:
apt-get update此开发环境包安装后,则已经安装上如下包了:
binutils bzip2 cpp cpp-4.3 dpkg-dev g++ g++-4.3 gcc gcc-4.3 libc6 libc6-dev libgmp3c2 libgomp1 libmpfr1ldbl libstdc++6-4.3-dev libtimedate-perl linux-libc-dev make patch perl perl-modulesSuggested packages:
binutils-doc bzip2-doc cpp-doc gcc-4.3-locales debian-keyring g++-multilib g++-4.3-multilib gcc-4.3-doc libstdc++6-4.3-dbg gcc-multilib
manpages-dev autoconf automake1.9 libtool flex bison gdb gcc-doc gcc-4.3-multilib libmudflap0-4.3-dev libgcc1-dbg libgomp1-dbg libmudflap0-dbg
glibc-doc libc6-i686 libstdc++6-4.3-doc make-doc diff-doc perl-doc libterm-readline-gnu-perl libterm-readline-perl-perl2.安装MYSQL
获取MysQL
wget http://mysql.west.mirrors.airband.net/Downloads/MySQL-5.1/mysql-5.1.34.tar.gztar -zxvf mysql-5.1.34.tar.gz
cd mysql-5.1.34
./configure --prefix=/usr/local/mysql --with-charset=utf8 \
--with-extra-charsets=complex \
--enable-thread-safe-client \
--enable-assembler \
--with-big-tables \
--with-readline \
--with-ssl \
--with-embedded-server \
--enable-local-infile \
--with-plugins=innobasemake && make install
如果有以下错误
checking for termcap functions library... configure: error: No curses/termcap library found
说明 curses/termcap 库没有安装
apt-cache search curses | grep lib安装 libncurses5-dev
wget http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.6.tar.gz
tar zxvf ncurses-5.6.tar.gz
cd ncurses-5.6
./configure --prefix=/usr --with-shared --without-debug
make
make install clean
或者这样更方便
apt-get install libncurses5-dev之后重新安装MYSQL部分
完成后加入运行mysql用户和组
groupadd mysql
useradd -g mysql mysql更改权限以及拷贝默认配置文件
chmod +w /usr/local/mysql
chown -R mysql:mysql /usr/local/mysqlcp support-files/my-medium.cnf /usr/local/mysql/my.cnf
*
建立MYSQL数据库
/usr/local/mysql/bin/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql设置为开机启动MYSQL
在/etc/rc.local中加入以下启动语句
/bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/my.cnf &如果有错误,查看mysql的错误日志即可。
3.安装PHP
因为要与Nginx配合,所以PHP以FastCGI的方式安装和运行。
同样,PHP也有相关的包要装。首先获取PHP:
wget http://us.php.net/distributions/php-5.2.9.tar.gz因为PHP需要一些库,我们先安装,具体如下:
libiconv libxml2 libxslt freetype libmcrypt jpeg6 libpng curl gd
OpenSSL-devwget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.tar.gz
tar zxvf libiconv-1.13.tar.gz
cd libiconv-1.13/
./configure --prefix=/usr/local
make && make install && make clean
cd ..wget http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make && make install
cd libltdl
./configure --enable-ltdl-install
make && make install
cd ..
make cleanwget http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure
make && make install && make clean
cd ..//注
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1wget http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
/sbin/ldconfig
./configure
make && make install && make clean
cd ..安装libxml2
apt-get install libxml2-dev安装libxslt
wget ftp://xmlsoft.org/libxslt/libxslt-1.1.24.tar.gz
tar -zxf libxslt-1.1.24.tar.gz
cd libxslt-1.1.24
./configure --prefix=/usr/local/libxslt --with-libxml-prefix=/usr/local/libxml2
make && make install && make clean
cd ..安装OpenSSL-dev
aptitude update
aptitude install openssl-dev安装libzlib1g-dev
apt-get install libzlib1g-dev安装freetype
wget http://superb-west.dl.sourceforge.net/sourceforge/freetype/freetype-2.3.9.tar.gz
tar zxvf freetype-2.3.9.tar.gz
cd freetype-2.3.9
./configure --prefix=/usr/local/freetype
make && make install && make clean
cd ..安装libpng
wget http://superb-west.dl.sourceforge.net/sourceforge/libpng/libpng-1.2.36.tar.gz
tar zxvf libpng-1.2.36.tar.gz
cd libpng-1.2.36
cp scripts/makefile.std makefile
make && make install安装jpeg6
mkdir /usr/local/jpeg6
mkdir /usr/local/jpeg6/bin
mkdir /usr/local/jpeg6/lib
mkdir /usr/local/jpeg6/include
mkdir /usr/local/jpeg6/man
mkdir /usr/local/jpeg6/man/man1
wget http://www.ijg.org/files/jpegsrc.v6b.tar.gz
tar zxvf jpegsrc.v6b.tar.gz
cd jpeg-6b
./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static
make && make install && make clean
cd ..安装GD库
wget http://www.boutell.com/gd/http/gd-2.0.33.tar.gz
tar -zxf gd-2.0.33.tar.gz
cd gd-2.0.33
./configure --prefix=/usr/local/gd2 \
--with-jpeg=/usr/local/jpeg6/ \
--with-png \
--with-zlib \
--with-freetype=/usr/local/freetype/
make && make install && make clean
cd ..安装CURL
wget http://curl.download.nextag.com/download/curl-7.19.5.tar.gz
tar -zxf curl-7.19.5.tar.gz
cd curl-7.19.5
./configure --prefix=/usr/local/curl配置并编译PHP(谢谢patch来源提供者):
wget http://blog.s135.com/soft/linux/nginx_php/phpfpm/php-5.2.9-fpm-0.5.10.diff.gz
gzip -cd php-5.2.9-fpm-0.5.10.diff.gz | patch -d php-5.2.9 -p1
./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/php5 \
--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-iconv-dir=/usr/local \
--with-freetype-dir=/usr/local/freetype \
--with-jpeg-dir=/usr/local/jpeg6 \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr/local/libxml2 \
--enable-xml \
--disable-rpath \
--enable-discard-path \
--enable-safe-mode \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl=/usr/local/curl \
--with-curlwrappers \
--enable-mbregex \
--enable-fastcgi \
--enable-fpm \
--enable-force-cgi-redirect \
--enable-mbstring \
--with-mcrypt \
--with-gd=/usr/local/gd2 \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-ldap \
--with-ldap-sasl \
--with-xmlrpc \
--with-xsl=/usr/local/libxslt \
--enable-xslt \
--enable-zip
make ZEND_EXTRA_LIBS='-liconv'
make installcp php.ini-dist /usr/local/php5/php.ini
4. 安装memcache以及eaccelerator
memcache
wget http://pecl.php.net/get/memcache-2.2.5.tgz
tar -zxf memcache-2.2.5.tgz
cd memcache-2.2.5
/usr/local/php5/bin/phpize
./configure --with-php-config=/usr/local/php5/bin/php-config
make && make install && make cleaneAccelerator
wget http://bart.eaccelerator.net/source/0.9.5.3/eaccelerator-0.9.5.3.tar.bz2
tar jxvf eaccelerator-0.9.5.3.tar.bz2
cd eaccelerator-0.9.5.3
/usr/local/php5/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php5/bin/php-config
make && make install
cd ..修改php.ini,以加memcache和eaccelerator
修改为extension_dir = "/usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/"
extension = "memcache.so"
修改output_buffering 为 On加入eAccelerator加速
mkdir /usr/local/ea_cache[eaccelerator]
zend_extension="/usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="32"
eaccelerator.cache_dir="/usr/local/ea_cache"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="300"
eaccelerator.shm_prune_period="120"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"修改php-fpm配置文件,启动php-cgi进程
vi /usr/local/php5/etc/php-fpm.conf
内容如下:
<?xml version="1.0" ?>
<configuration>
<section name="global_options">
<value name="pid_file">/usr/local/php5/logs/php-fpm.pid</value>
<value name="error_log">/usr/local/php5/logs/php-fpm.log</value>
<value name="log_level">notice</value>
<value name="emergency_restart_threshold">10</value>
<value name="emergency_restart_interval">1m</value>
<value name="process_control_timeout">5s</value>
<value name="daemonize">yes</value>
</section><workers>
<section name="pool">
<value name="name">default</value>
<value name="listen_address">127.0.0.1:9000</value>
<value name="listen_options">
<value name="backlog">-1</value>
<value name="owner"></value>
<value name="group"></value>
<value name="mode">0666</value>
</value>
<value name="php_defines">
<value name="sendmail_path">/usr/sbin/sendmail -t -i</value>
<value name="display_errors">1</value>
</value>
<value name="user">www</value>
<value name="group">www</value>
<value name="pm">
<value name="style">static</value>
<value name="max_children">25</value>
<value name="apache_like">
<value name="StartServers">20</value>
<value name="MinSpareServers">5</value>
<value name="MaxSpareServers">35</value>
</value>
</value>
<value name="request_terminate_timeout">0s</value>
<value name="request_slowlog_timeout">0s</value>
<value name="slowlog">logs/slow.log</value>
<value name="rlimit_files">10240</value>
<value name="rlimit_core">0</value>
<value name="chroot"></value>
<value name="chdir"></value>
<value name="catch_workers_output">yes</value>
<value name="max_requests">10240</value>
<value name="allowed_clients">127.0.0.1</value>
<value name="environment">
<value name="HOSTNAME">$HOSTNAME</value>
<value name="PATH">/usr/local/bin:/usr/bin:/bin</value>
<value name="TMP">/tmp</value>
<value name="TMPDIR">/tmp</value>
<value name="TEMP">/tmp</value>
<value name="OSTYPE">$OSTYPE</value>
<value name="MACHTYPE">$MACHTYPE</value>
<value name="MALLOC_CHECK_">2</value>
</value>
</section>
</workers></configuration>
5. 安装Nginx
Nginx依赖一些库,先安装它们,但都取决于是否需要
.gzip 模块需要 zlib 库
.rewrite 模块需要 pcre 库
.ssl 功能需要 openssl 库我需要rewrite,所以得装个pcre
wget http://superb-west.dl.sourceforge.net/sourceforge/pcre/pcre-7.9.tar.gz
tar zxf pcre-7.9.tar.gz
cd pcre-7.9
./configure
make && make install
cd ..创建www用户和组,用于Nginx
好了,装Nginxwget http://sysoev.ru/nginx/nginx-0.7.59.tar.gz
tar zxf nginx-0.7.59.tar.gz
cd nginx-0.7.59
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install配置Nginx
cd /usr/local/nginx/conf#vi nginx.conf
server段内
location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}location ~ .*\.(js|css)?$
{
expires 1h;
}log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log /data1/logs/access.log access;fcgi.conf的内容如下:
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;# PHP only, required if PHP was built with --enable-force-cgi-redirect
#fastcgi_param REDIRECT_STATUS 200;开机启动
在/etc/rc.local中加入
ulimit -SHn 10240
/usr/local/php5/sbin/php-fpm start
/usr/local/nginx/sbin/nginx
- Hots
- 评论
- capets 于 February 4, 2011 11:19 PM 说:
nice article thanks for the info very helpful
- Praca Bielsko Biała 于 February 10, 2011 12:42 AM 说:
I don’t even know how I ended up here, but I thought this post was great. I do not know who you are but definitely you are going to a famous blogger if you aren't already ;) Cheers!
- carpets 于 March 4, 2011 1:02 AM 说:
great article very informative will be back again to visit soon
- Keila Sinnott 于 April 12, 2011 8:23 PM 说:
I can see that you are an expert in your subject! I’m launching a new site quickly and hey these information will be very useful for me man. Thanks on your assist and I wish you success! ;)
- Estefana Offield 于 April 19, 2011 10:07 PM 说:
My brother and I were sent here simply because this particular article was tweeted by a girl I had been following and feel very I made it here.
- Shelby Carpenter 于 May 1, 2011 9:11 PM 说:
Strange this post is totaly unrelated to what I was searching google for, but it was listed on the first page. I guess your doing something right if Bing likes you enough to put you on the first page of a non related search. :)
- Brooklyn 于 May 17, 2011 7:42 PM 说:
I wish more people would write blogs like this that are really fun to read. With all the fluff floating around on the net, it is rare to read a blog like this instead.
- turbine powered living 于 May 18, 2011 1:56 AM 说:
What’s Happening i am new to this, I stumbled upon this I've found It positively useful and it has helped me out loads.I hope to contribute & aid other users like its helped me.Great job
- Donna Lucksom 于 May 26, 2011 3:38 AM 说:
Glorious data here. This interesting post made me smile. Possibly should you throw in a few pictures it would make the entire thing extra interesting. Anyway, in my language, there usually are not much good supply like this.
- Guillermo Soliman 于 May 26, 2011 9:51 AM 说:
Thanks for some good points there. I am kind of new to online , so I printed this off to put in my file, any better way to go about keeping track of it then printing?
- Stable Income Plan 于 May 28, 2011 11:59 PM 说:
Really good piece of writing. Many thanks. Please make sure to keep writing.
- Oretha Cripps 于 May 29, 2011 7:18 PM 说:
Your post has quite a few viewers. How did you get all of these viewers to look at your post I'm envious!
- Louboutin sale 于 May 30, 2011 2:02 PM 说:
Can someone explain what the writer meant in his continue paragraph? He makes an excellent start but lost me halfway throughout the article. I had a difficult time following what the author is wanting to say. The beginning was great but I feel he needs to focus on writing a better finish.
- Tory Burch flats sale 于 June 2, 2011 9:21 PM 说:
Just to let you know your site looks really strange in Firefox on my Linux .
- Ava Shartrand 于 June 4, 2011 4:16 PM 说:
you're sooo talented on paper. Lord is truly utilizing you in tremendous methods. You're doing a excellent work! It was an excellent blog!
- lewphee 于 June 4, 2011 6:02 PM 说:
thanks for remind
- Repair Pool Plaster 于 June 13, 2011 8:51 PM 说:
I’m having a small annoyance. I'm unable to subscribe to your rss feed for some reason. I’m using google reader by the way.
- Saul Barnt 于 June 15, 2011 10:18 AM 说:
I additionally obtained a website like this, nevertheless my articles are not too great as your own. keep up the truly amazing work and ideally we'll get to see much more content articles like this. Thanks.
- Treasure Hunters Roadshow Scam 于 June 16, 2011 4:38 AM 说:
My brother advised I would possibly like this blog site. He was completely perfect. This publish truly manufactured my day. You can not take into account simply how so a great deal time I had put in for this info! Thank you!
- sennheiser headphones 于 June 17, 2011 9:10 AM 说:
You should take part in a contest for one of the best blogs on the web. I will recommend this site!
- slot machines 于 June 17, 2011 10:17 AM 说:
Can't wait to read more of your articles in the future. Go for it!.
- here it is 于 June 18, 2011 1:34 AM 说:
I just added this feed to my bookmarks. I truly enjoy reading your posts. Thanks!
- best alarm clocks 于 June 19, 2011 1:58 PM 说:
I feel this is one of the most significant info for me. And i am happy studying your article. But want to commentary on few general things, The website taste is great, the articles is actually nice : D. Good activity, cheers
- Oolong 于 June 22, 2011 9:10 PM 说:
I'm adding your blog rss feed so that i can see your new posts. Continue the good work!
- 发表评论:
- Tags
- Apache C Emacs FreeBSD GODADDY MySQL Newage Nginx Perl Subversion UNIX WEB WINDOWS 单曲 数据库 服务器 网络 读书 随写 音乐
- Recent Post
- Recent Comments
-
- Oolong: I'm adding your blog rss feed so that i can see your new posts. Continue the good work!
- best alarm clocks: I feel this is one of the most significant info for me. And i am happy studying your article. But want to commentary on few general things, The website taste is great, the articles is actually nice : D. Good
- here it is: I just added this feed to my bookmarks. I truly enjoy reading your posts. Thanks!
- slot machines: Can't wait to read more of your articles in the future. Go for it!.
- sennheiser headphones: You should take part in a contest for one of the best blogs on the web. I will recommend this site!
- Treasure Hunters Roadshow Scam: My brother advised I would possibly like this blog site. He was completely perfect. This publish truly manufactured my day. You can not take into account simply how so a great deal time I had put in for this info!
- Saul Barnt: I additionally obtained a website like this, nevertheless my articles are not too great as your own. keep up the truly amazing work and ideally we'll get to see much more content articles like this. Thanks.
- Repair Pool Plaster: I’m having a small annoyance. I'm unable to subscribe to your rss feed for some reason. I’m using google reader by the way.
- lewphee: thanks for remind
- Ava Shartrand: you're sooo talented on paper. Lord is truly utilizing you in tremendous methods. You're doing a excellent work! It was an excellent blog!
- Links
- Copyright Notes
- You can reship all of these articles without permission but MUST mark the original link in your post. Please contact with me() if u have advice or other arrangements.





