Centos
搭建高性能WEB
服务器 Nginx+PHP+MYSQL+Discuz
论坛
2011-10-28 12:30:00
Nginx
是由
Igor Sysoev
为俄罗斯访问量第二的
Rambler.ru
站点开发的,它已经在该站点运行超过两年半了。
Igor
将源代码以类
BSD
许可证的形式发布。
Nginx
已经因为它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名了。是一个高性能
Web
和反向代理服务器,它超越
Apache
的高性能和稳定性
.
Nginx + PHP + MySQL 可以承受高并发连接数,相当于同等环境下 Apache 的 10 倍(呵呵 ~~ 这可是专家说的哦。。。)。
本章将介绍
Nginx + PHP + MYSQL+ PHPMyadmin+ Discuz_X2
搭建
:LNMP+BBS
系统
:Centos 5.6
准备工具
:
libiconv-1.13.1.1.tar.gz
libmcrypt-2.5.8.tar.gz
mhash-0.9.9.9.tar.gz
mcrypt-2.6.8.tar.gz
mysql-5.1.58.tar.gz
php-5.2.14.tar.bz2
nginx-1.0.0.tar.gz
phpMyAdmin-3.0.0-rc1-all-languages.tar
Discuz_X2_SC_UTF8
libiconv-1.13.1.1.tar.gz
libmcrypt-2.5.8.tar.gz
mhash-0.9.9.9.tar.gz
mcrypt-2.6.8.tar.gz
mysql-5.1.58.tar.gz
php-5.2.14.tar.bz2
nginx-1.0.0.tar.gz
phpMyAdmin-3.0.0-rc1-all-languages.tar
Discuz_X2_SC_UTF8
安装步骤
一、 编译安装PHP5.2.14 所需的支持库
一、 编译安装PHP5.2.14 所需的支持库
# tar zxvf libiconv-1.13.1.tar.gz
# cd libiconv-1.13.1/
# ./configure --prefix=/usr/local
# make;make install
# cd ../
# cd libiconv-1.13.1/
# ./configure --prefix=/usr/local
# make;make install
# cd ../
# tar zxvf libmcrypt-2.5.8.tar.gz
# cd libmcrypt-2.5.8/
# ./configure
# make;make install
# /sbin/ldconfig
# cd libltdl/
# ./configure --enable-ltdl-install
# make;make install
# cd ../../
# cd libmcrypt-2.5.8/
# ./configure
# make;make install
# /sbin/ldconfig
# cd libltdl/
# ./configure --enable-ltdl-install
# make;make install
# cd ../../
# tar zxvf mhash-0.9.9.9.tar.gz
# cd mhash-0.9.9.9/
# ./configure
# make;make install
# cd ../
# cd mhash-0.9.9.9/
# ./configure
# make;make install
# 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.1
# 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.1
PS:
我把上面的做成如下脚本:
ln.sh
#!/bin/bash
#########################################
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.1
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.1
###########################################
# chmod +x ln.sh
# tar zxvf mcrypt-2.6.8.tar.gz
# cd mcrypt-2.6.8/
# /sbin/ldconfig
#./configure
# make
# make install
# cd ../
# cd mcrypt-2.6.8/
# /sbin/ldconfig
#./configure
# make
# make install
# cd ../
二、编译安装MySQL 5.1.58
# /usr/sbin/groupadd mysql
# /usr/sbin/useradd -g mysql mysql
创建 mysql 用户和组 , 我这在装 MYSQL 时已经自动建了 ! 提示用户存在 !
# /usr/sbin/useradd -g mysql mysql
创建 mysql 用户和组 , 我这在装 MYSQL 时已经自动建了 ! 提示用户存在 !
解压
MYSQL,
配置
# tar zxvf mysql-5.1.58.tar.gz
# cd mysql-5.1.58
#./configure --prefix=/usr/local/mysql \
> --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client \
> --with-big-tables --with-readline \
> --with-ssl --with-embedded-server --enable-local-infile \
> --with-plugins=innobase
# make;make insatll
添加权限
# chmod +w /usr/local/mysql
# chown -R mysql:mysql /usr/local/mysql
# cd ../
# chmod +w /usr/local/mysql
# chown -R mysql:mysql /usr/local/mysql
# cd ../
三、编译安装PHP
# tar jxvf php-5.2.14.tar.bz2
# zip -cd php-5.2.14-fpm-0.5.14.diff.gz | patch -d php-5.2.14 -p1
进入
PHP
目录
.
指定编译选项安装
cd php-5.2.14/
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc--with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-freetype-dir --with-jpeg-dir --with-png-dir --with-iconv-dir=/usr/local --with-zlib --with-libxml-dir=/usr --enable-xml --with-curl --with-curlwrappers --enable-sqlite-utf8 --with-pdo-mysql=/usr/local/mysql --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --with-openssl --enable-pcntl --enable-fpm --with-fpm-user=www --with-fpm-group=ww --enable-mbstring --with-gd --enable-gd-native-ttf --enable-sockets --with-xmlrpc --enable-zip --enable-soap --disable-debug --enable-safe-mode --with-mcrypt --with-mhash
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc--with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-freetype-dir --with-jpeg-dir --with-png-dir --with-iconv-dir=/usr/local --with-zlib --with-libxml-dir=/usr --enable-xml --with-curl --with-curlwrappers --enable-sqlite-utf8 --with-pdo-mysql=/usr/local/mysql --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --with-openssl --enable-pcntl --enable-fpm --with-fpm-user=www --with-fpm-group=ww --enable-mbstring --with-gd --enable-gd-native-ttf --enable-sockets --with-xmlrpc --enable-zip --enable-soap --disable-debug --enable-safe-mode --with-mcrypt --with-mhash
编译安装
# make ZEND_EXTRA_LIBS='-liconv'
# make install
# make ZEND_EXTRA_LIBS='-liconv'
# make install
复制配置文件
php.ini-dist
到指定位置
# cp php.ini-dist/usr/local/php/etc/php.ini
# cp php.ini-dist/usr/local/php/etc/php.ini
四、修改php-fpm
配置文件
重新建个编辑
# vi /usr/local/php/etc/php-fpm.conf
输入以下内容:
保存退出!
五、创建www
用户和组
# useradd www
六、安装Nginx
# cd
# tar zxvf nginx-1.0.0.tar.gz
# cd nginx-1.0.0
#./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
# make;make install
七、修改fastcgi.conf
文件
重命名
fcgi.conf,
手动创建
# cd /usr/local/nginx/conf/
# mv fastcgi.conf fastcgi.conf.bak
# vi fsatcgi.conf
输入以下内容:
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
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 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 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;
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;
保存退出!!!
fastcgi_param REDIRECT_STATUS 200;
保存退出!!!
八、编辑Nginx
配置文件
# cd /usr/local/nginx/conf/
# mv nginx.conf nginx.conf.bak
# vi nginx.conf
输入以下内容
(
自己根据实际需要修改
)
user www www;
worker_processes 8;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;
events
worker_processes 8;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
}
http
{
include mime.types;
default_type application/octet-stream;
#charset gb2312;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
default_type application/octet-stream;
#charset gb2312;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
#limit_zone crawler $binary_remote_addr 10m;
server
{
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
#limit_zone crawler $binary_remote_addr 10m;
server
{
listen 80;
server_name sky.com;
index index.html index.htm index.php;
root /usr/local/web/;
#limit_conn crawler 20;
location ~ .*\.(php|php5)?$
location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.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 /usr/local/webserver/logs/access.log access;
}
}
九、创建日至目录,
并赋予权限
# chown -R www:www /usr/local/nginx/logs/
创建站点目录
# mkdir /usr/local/www
十、配置开机自动启动Nginx + PHP
# vi /etc/rc.local
在末尾增加以下内容:
/usr/local/php/sbin/php-fpm start
/usr/local/nginx/sbin/nginx
/usr/local/php/sbin/php-fpm start
/usr/local/nginx/sbin/nginx
十一、平滑启动nginx
# /usr/local/nginx/sbin/nginx
十二、安装phpmyadmin
# tar zxvf phpMyAdmin-3.0.0-rc1-all-languages.tar.gz
# mv phpMyAdmin-3.0.0-rc1-all-languages /usr/local/www/phpmyadmin
修改配置文件
# cd /usr/local/www/phpmyadmin
# vi libraries/config.default.php
/**
* MySQL hostname or IP address
*
* @global string $cfg['Servers'][$i]['host']
*/
$cfg['Servers'][$i]['host'] = '127.0.0.1';
大概在
95
行!!修改成上面样子!!
测试网页可以打开
PHPmyadmin
PS: phpmyadmin
这里只是简单介绍下
!!
十三、将Discuz
论坛程序传到站点上
# mv Discuz_X2_SC_UTF8 /usr/local/www/ds
给站点赋予权限
# chmod 777 -R /usr/local/www/ds
我们先创建一个数据库:
# mysql –uroot –p
mysql> create database bbs;
Query OK, 1 row affected (0.00 sec)
接下来再创建一个
远程登陆用户并授权
:
mysql> grant all privileges on ds.* to zjqiu@'172.28.12.49' identified by 'zjqiu';
下面就开始安装
Discuz
:
在地址栏输入:
http://IP/ds/upload
PS:
上图中当前状态一定要全部是可写状态!!在安装前一定要设置可写权限。
到了这步点下一步后就会开始安装
Discuz
了,安装完成后会直接跳转到
BBS
站点中!!
好了
,一个简单的Discuz
论坛就这样搭好了
, Nginux
配置较简单但功能是很强的!