`
lu2002lulu
  • 浏览: 95037 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

RHEL 5.X WWW全功能服务器搭建教程V1.0(一)

阅读更多
操作系统更换为rhel 5.2,WWW服务器更改为nginx,php更改为php-fastcgi等。
下次更新将修改为nginx 0.7.x mysql 5.1.x php 5.3.x,并且将采用mysqlnd,SSL连接

更换操作系统的原因,还是觉得RHEL更适合自己,更适合用作公网上运行的操作系统。

本文章将在http://www.cnprint.org/bbs/blogs/1/blog312.html
长期维护。欢迎转帖,转帖请注意出处。谢谢。

先声明,以下的这些文字个人的安装笔记,是参考了网上许多高手的成功经验组合而成的,说实话我自己的东西不多 :)我想把这些经验写下来,既可以对其他跟我一样摸索的兄弟一个经验,也可以防止以后自己都忘记了,嘿嘿。

所以如果某个大虾看到我借用了您的资源,请不要生气。同时欢迎大家指出错误。

by wangyu1314


一、基本系统安装
1、下载RHEL 5
我是下载的DVD版本,大家也可以下载服务器CD安装版本,其实都差不多。大家可以到这儿下载,速度很快的。
http://rhel.ieesee.net/uingei/RHEL5....r-i386-dvd.iso
建议在windows下用BT或迅雷下载,速度会快很多。
下载后刻录成光盘。我建议您刻录DVD啦,如果是菜鸟,把图形界面也装上,可以在图形界面进行学习,当然强烈不建议在服务器上装桌面。
RHEL 5系列任何一个版本就行了,安装后可以通过yum upgrade直接更新为最新版本。

2、安装RHEL 5
作为服务器,不安装不需要的组件,所以在选择组件的时候,除了选择FTP SERVER外取消所有组件的选择。也不要选web服务器。因为我们后面要手动编译安装。
系统约定RPM包和源码包存放位置
RPM包和源码包存放位置 /usr/local/src
源码包编译安装位置(prefix) /usr/local/webserver/
脚本以及维护程序存放位置 /usr/local/sbin
MySQL 数据库位置 /var/lib/mysql
nginx 网站根目录 /website/htdocs/
nginx 虚拟主机日志根目录 /website/logs/www
yum RPM包信息文件 /etc/yum.list

3、系统环境部署及调整
(1)检查系统是否正常
# more /var/log/messages //检查有无系统内核级错误信息
# dmesg //检查硬件设备是否有错误信息
# ifconfig //检查网卡设置是否正确
# ping www.163.com // 检查网络是否正常
(2)关闭不需要的服务
# export LANG='en_US' //设置语言
# setup //选择启动的服务
进入system service 选项。
以space 键选定所需服务。
以下仅列出需要启动的服务,未列出的服务一律关闭:
crond
irqbalance 仅当服务器CPU为S.M.P架构或支持双核心、HT技术时,才需开启,否则关闭。
microcode_ctl
network
iptables
vsftpd
sshd
syslog
yum-updatesd
(3)修改/etc/yum.repos.d/RHEL-Base.repo,将镜象站点地址改为在中国的镜象站点地址。不然我们通过yum安装软件速度会极慢。修改如下:
[Cluster]
name=Red Hat Enterprise Linux $releasever - $basearch - Cluster
baseurl=http://rhel.ieesee.net/rhel5x86/Cluster
enabled=1
gpgcheck=1
gpgkey=http://rhel.ieesee.net/rhel5x86/RPM-GPG-KEY-redhat-release
[ClusterStorage]
name=Red Hat Enterprise Linux $releasever - $basearch - ClusterStorage
baseurl=http://rhel.ieesee.net/rhel5x86/ClusterStorage
enabled=1
gpgcheck=1
gpgkey=http://rhel.ieesee.net/rhel5x86/RPM-GPG-KEY-redhat-release
[Server]
name=Red Hat Enterprise Linux $releasever - $basearch - Server
baseurl=http://rhel.ieesee.net/rhel5x86/Server
enabled=1
gpgcheck=1
gpgkey=http://rhel.ieesee.net/rhel5x86/RPM-GPG-KEY-redhat-release
[VT]
name=Red Hat Enterprise Linux $releasever - $basearch - VT
baseurl=http://rhel.ieesee.net/rhel5x86/VT
enabled=1
gpgcheck=1
gpgkey=http://rhel.ieesee.net/rhel5x86/RPM-GPG-KEY-redhat-release

保存文件。
注意,这不是一个纯粹的在线升级服务器,而只是rhel 5.2的在线安装器。也不能保证长期能用。有需要的可以将自己的光盘作为yum的对象,将光盘设置为yum对象请看http://www.cnprint.org/bbs/blogs/1/blog103.html

(4)更新系统,我们使用yum,
运行:
# yum upgrade
建议更新所有列出的程序,包括内核,rhel 5.X的稳定性还要继续努力呢。

(5)定时校正服务器时间
# yum install –y ntp
# crontab -e
0 23 * * * /usr/sbin/ntpdate 210.167.182.10
以上命令设置好后存盘。
# /sbin/service crond reload
重载计划任务配置
您的机器将在每天的23:00根据日本的某个NTP服务器时间自动校准时间。

(6)FTP服务器的配置
vi /etc/vsftpd/vsftpd.conf
把anonymous_enable=YES
修改为anonymous_enable=No不允许匿名登录。
添加两句
chroot_local_user=yes
listen_port=2121
将用户锁定在主目录,并将FTP监听端口修改为2121
把ftpd_banner=*前的注释去掉。后面改成您的欢迎信息(这样设置可以避免显示ftp服务器的版本信息)
然后保存,service vsftpd start就可以了。
这时应当添加用户,因为root默认不能通过FTP方式登录,也不安全。
groupadd upload
useradd upload -g upload -d /website/htdocs/ -M

如果FTP登录时出现
ftp服务器连接失败,错误提示:
500 OOPS: cannot change directory:/home/*******
500 OOPS: child died
解决方法:
# setsebool ftpd_disable_trans 1
# service vsftpd restart
这样对于我们上传一些文件到系统中很方便。
大家有兴趣的可以看下这篇文章对vsftpd进行一个比较详细的了解
http://blog.chinaunix.net/u/10047/showart_198837.html

4、重新启动系统
# init 6
此时系统启动成功,可以删除老的内核

二、安装mysql, nginx, php, Zend Optimizer等基本环境
5. 使用 yum 程序安装所需开发包(以下为标准的rpm包名称)
# yum install gcc gcc-c++ flex bison autoconf automake bzip2-devel zlib-devel ncurses-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel pam-devel openssl-devel libxml2-devel gettext-devel pcre-devel
#这里我们将编译GD所必须的一些小软件比如libpng,libtiff,freetype,libjpeg,gettext-devel等先用RPM 的方式一并安装好,避免手动编译浪费时间,同时也能避免很多错误,这几个小软件的编译很麻烦。这几个小软件编译错误了,GD当然安装不了,php5的编译当然也没戏了。所以我们抓大放小,对这些小牛鬼蛇神采取快速简洁的方式进行安装。并且对服务器的性能也不能产生什么影响。
另外libxml2系统已经默认安装了,所以我们不需要手工编译了,直接安装它的开发包就行了。

6. 源码编译安装所需包 (Source)
(1) GD2
# cd /usr/local/src
# wget http://www.libgd.org/releases/gd-2.0.35.tar.gz
# tar xzvf gd-2.0.35.tar.gz
# cd gd-2.0.35
# yum install libtool libtool-ltdl
# aclocal
# CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer -fstack-protector -ftracer -fvisibility=hidden -fweb -frename-registers" CXXFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -felide-constructors -fno-exceptions -fno-rtti -fomit-frame-pointer -fvisibility-inlines-hidden -fno-enforce-eh-specs -fstack-protector -ftracer -fvisibility=hidden -fweb -frename-registers" LDFLAGS="-Wl,-O3 -Wl,-z -Wl,--enable-new-dtags -Wl,--sort-common -s" ./configure --prefix=/usr/local/webserver/gd2 --mandir=/usr/share/man
// 注意,CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer -fstack-protector -ftracer -fvisibility=hidden -fweb -frename-registers" CXXFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -felide-constructors -fno-exceptions -fno-rtti -fomit-frame-pointer -fvisibility-inlines-hidden -fno-enforce-eh-specs -fstack-protector -ftracer -fvisibility=hidden -fweb -frename-registers" LDFLAGS="-Wl,-O3 -Wl,-z -Wl,--enable-new-dtags -Wl,--sort-common -s" 这个环境参数只针对intel P4 芯片,如果您的CPU是AMD的,注意不能使用。请查看相应的编译优化参数。否则程序会无法编译,即使编译成功也无法运行,嘿嘿。
关于其他CPU的优化参见我的BLOG的一篇转贴:
http://www.cnprint.org/bbs/blogs/1/blog43.html
//./configure 配置。
# make //make 是用来编译的,它从 Makefile 中读取指令,然后编译。
# make install //make install 是用来安装的,它也从 Makefile 中读取指令,安装到指定的位置。

7、编译mysql 5.0.70
mysql 5.0.70是企业版本,貌似双数版本都是企业版本了。个人觉得代码质量要比社区版本要好一些。大家可以下载,免费使用。并不需要向mysql公司交钱。
其他版本可以在这个地址下载:http://www.linuxnew.cn/thread/3/86/
#cd /usr/local/src
# wget http://mirror.provenscaling.com/mysq...-5.0.70.tar.gz
# tar xzvf mysql-5.0.70.tar.gz
# cd mysql-5.0.70
修改mysql 客户端最大连接数, 默认的只有100,远远达不到我们的要求。
# vi sql/mysqld.cc
搜索找到下面一行:
{"max_connections", OPT_MAX_CONNECTIONS,
"The number of simultaneous clients allowed.", (gptr*) &max_connections,
(gptr*) &max_connections, 0, GET_ULONG, REQUIRED_ARG, 100, 1, 16384, 0, 1,
0},
将其中的100改为1500, 当然小点也可以,根据您的需要来,不建议改的太大。
{"max_connections", OPT_MAX_CONNECTIONS,
"The number of simultaneous clients allowed.", (gptr*) &max_connections,
(gptr*) &max_connections, 0, GET_ULONG, REQUIRED_ARG, 1500, 1, 16384, 0, 1,
0},
保存。
# CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer -fstack-protector -ftracer -fvisibility=hidden -fweb -frename-registers" CXXFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -felide-constructors -fno-exceptions -fno-rtti -fomit-frame-pointer -fvisibility-inlines-hidden -fno-enforce-eh-specs -fstack-protector -ftracer -fvisibility=hidden -fweb -frename-registers" LDFLAGS="-Wl,-O3 -Wl,-z -Wl,--enable-new-dtags -Wl,--sort-common -s" ./configure --prefix=/usr/local/webserver/mysql --localstatedir=/var/lib/mysql --with-comment=Source --with-server-suffix=-enterprise-gpl --with-mysqld-user=mysql --without-debug --with-big-tables --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=gbk,latin1 --with-pthread --enable-static --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --enable-assembler --without-innodb --without-ndb-debug --without-isam --enable-local-infile --with-readline --with-raid
配置成功会提示:
MySQL has a Web site at http://www.mysql.com/ which carries details on the
latest release, upcoming features, and other information to make your
work or play with MySQL more productive. There you can also find
information about mailing lists for MySQL discussion.
Remember to check the platform specific part of the reference manual for
hints about installing MySQL on your platform. Also have a look at the
files in the Docs directory.
Thank you for choosing MySQL!
# make
编译的时间可能会比较长,毕竟优化的比较厉害。
# make install
编译安装完成后执行后续操作:
# useradd mysql //添加 mysql 用户
# cd /usr/local/webserver/mysql
# bin/mysql_install_db --user=mysql
# chown -R root:mysql . //设置权限,注意后面有一个 "."
# chown -R mysql /var/lib/mysql //设置 mysql 目录权限
# chgrp -R mysql . //注意后面有一个 "."
# cp share/mysql/my-medium.cnf /etc/my.cnf
# cp share/mysql/mysql.server /etc/rc.d/init.d/mysqld //开机自动启动 mysql。
# chmod 755 /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
#添加LIB PATH
echo "/usr/local/webserver/mysql/lib" >> /etc/ld.so.conf && ldconfig
vi /etc/my.cnf
修改 MySQL 配置,增加部分优化参数,如下:
[mysqld]
ft_min_word_len=2
运行以下命令即可启动 MySQL 服务器:
# /etc/rc.d/init.d/mysqld start //启动 MySQL
# bin/mysqladmin -u root password "password_for_root"
# service mysqld stop //关闭 MySQL


8、创建www用户和组,以及供虚拟主机使用的目录:
/usr/sbin/groupadd www -g 48
/usr/sbin/useradd -u 48 -g www www
mkdir -p /website/htdocs/blog
chmod +w /website/htdocs/blog
chown -R www:www /website/htdocs/blog
mkdir -p /website/htdocs/www
chmod +w /website/htdocs/www
chown -R www:www /website/htdocs/www


9、编译php 5.2.6
Suhosin是php增强型安全补丁,可以编译到静态内核中,也可以编译成php动态扩展。我个人强烈您建议安装成静态内核。Suhosin已经进入 Gentoo Linux、FreeBSD、OpenSuSE Linux、Mandriva Linux、Debian Linux官方包。下面的以下先说静态安装步骤。当然您也可以在安装php后将它编译成php的动态扩展。
在使用FastCGI方式运行php的时候,如果我们改变了php.ini的设置,就得重新启动php的fastcgi守护程序。如果你的系统负载比较大的话,这个重启过程或许会让你的系统中断服务一段时间。php-fpm就是为了解决这个问题而诞生的,它可以在php的fastcgi进程不中断的情况下重新加载你改动过的php.ini。
而且php-fpm可以不用再依赖其它的fastcgi启动器,比如lighttpd的spawn-fcgi,对于我来说终于可以摆脱lighttpd的影子了。

# cd /usr/local/src
# wget http://cn.php.net/get/php-5.2.6.tar.gz/from/this/mirror
# wget http://download.suhosin.org/suhosin-...9.6.2.patch.gz
wget http://php-fpm.anight.org/downloads/...-0.5.9.diff.gz
# tar zxvf php-5.2.6.tar.gz
# gunzip suhosin-patch-5.2.6-0.9.6.2.patch.gz
# gzip -cd php-5.2.6-fpm-0.5.9.diff.gz | patch -d php-5.2.6 -p1
# cd php-5.2.6
# patch -p 1 -i ../suhosin-patch-5.2.6-0.9.6.2.patch
# ./buildconf --force
# CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer -fstack-protector -ftracer -fvisibility=hidden -fweb -frename-registers" CXXFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -felide-constructors -fno-exceptions -fno-rtti -fomit-frame-pointer -fvisibility-inlines-hidden -fno-enforce-eh-specs -fstack-protector -ftracer -fvisibility=hidden -fweb -frename-registers" LDFLAGS="-Wl,-O3 -Wl,-z -Wl,--enable-new-dtags -Wl,--sort-common -s" ./configure --prefix=/usr/local/webserver/php --with-pear=/usr/share/php --with-zlib-dir --with-bz2 --with-libxml-dir=/usr --with-gd=/usr/local/webserver/gd2 --enable-gd-native-ttf --enable-gd-jis-conv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-ttf=shared,/usr --enable-mbstring --with-mysql=/usr/local/webserver/mysql --with-mysqli=/usr/local/webserver/mysql/bin/mysql_config --with-config-file-path=/etc --with-iconv --disable-ipv6 --enable-static --enable-zend-multibyte --enable-inline-optimization --enable-zend-multibyte --enable-sockets --enable-soap --with-openssl --with-gettext --enable-sysvsem --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --with-mcryp --with-curl --with-curlwrappers --enable-mbregex --enable-bcmath --enable-shmop --enable-suhosin

配置成功会提示:
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
Thank you for using PHP.
# sed -i 's#-lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt#& -liconv#' Makefile
# make
# make test
# make install
# cp php.ini-recommended /etc/php.ini
# echo "/usr/local/webserver/php/lib" >> /etc/ld.so.conf && ldconfig


在这里也顺便说一下将suhosin安装成为php的动态扩展的方法。毕竟网上根本不见它的中文安装教程。
虽然我个人不推荐这种方式。
wget http://download.suhosin.org/suhosin-0.9.20.tgz
tar zxvf suhosin-0.9.20.tgz
cd suhosin-0.9.20
./configure --with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
会提示编译的模块存在的目录,记住它。
Installing shared extensions: /usr/local/webserver/php/lib/php/extensions/no-debug-zts-20060613/
然后在php.ini中增加一行下列语句。
extension="/usr/local/webserver/php/lib/php/extensions/no-debug-zts-20060613/suhosin.so"

10、创建php-fpm配置文件(php-fpm是为PHP打的一个FastCGI管理补丁,可以平滑变更php.ini配置而无需重启php-cgi):
在/usr/local/webserver/php/etc/目录中创建php-fpm.conf文件:
rm -f /usr/local/webserver/php/etc/php-fpm.conf
vi /usr/local/webserver/php/etc/php-fpm.conf

输入以下内容(如果您安装 Nginx + PHP 用于程序调试,请将以下的<value name="display_errors">0</value>改为<value name="display_errors">1</value>,以便显示PHP错误信息,否则,Nginx 会报状态为500的空白错误页):

<?xml version="1.0" ?>
<configuration>

All relative paths in this config are relative to php's install prefix

<section name="global_options">

Pid file
<value name="pid_file">/usr/local/webserver/php/logs/php-fpm.pid</value>

Error log file
<value name="error_log">/usr/local/webserver/php/logs/php-fpm.log</value>

Log level
<value name="log_level">notice</value>

When this amount of php processes exited with SIGSEGV or SIGBUS ...
<value name="emergency_restart_threshold">10</value>

... in a less than this interval of time, a graceful restart will be initiated.
Useful to work around accidental curruptions in accelerator's shared memory.
<value name="emergency_restart_interval">1m</value>

Time limit on waiting child's reaction on signals from master
<value name="process_control_timeout">5s</value>

Set to 'no' to debug fpm
<value name="daemonize">yes</value>

</section>

<workers>

<section name="pool">

Name of pool. Used in logs and stats.
<value name="name">default</value>

Address to accept fastcgi requests on.
Valid syntax is 'ip.ad.re.ss:port' or just 'port' or '/path/to/unix/socket'
<value name="listen_address">127.0.0.1:9000</value>

<value name="listen_options">

Set listen(2) backlog
<value name="backlog">-1</value>

Set permissions for unix socket, if one used.
In Linux read/write permissions must be set in order to allow connections from web server.
Many BSD-derrived systems allow connections regardless of permissions.
<value name="owner"></value>
<value name="group"></value>
<value name="mode">0666</value>
</value>

Additional php.ini defines, specific to this pool of workers.
<value name="php_defines">
<value name="sendmail_path">/usr/sbin/sendmail -t -i</value>
<value name="display_errors">1</value>
</value>

Unix user of processes
<value name="user">www</value>

Unix group of processes
<value name="group">www</value>

Process manager settings
<value name="pm">

Sets style of controling worker process count.
Valid values are 'static' and 'apache-like'
<value name="style">static</value>

Sets the limit on the number of simultaneous requests that will be served.
Equivalent to Apache MaxClients directive.
Equivalent to PHP_FCGI_CHILDREN environment in original php.fcgi
Used with any pm_style.
<value name="max_children">128</value>

Settings group for 'apache-like' pm style
<value name="apache_like">

Sets the number of server processes created on startup.
Used only when 'apache-like' pm_style is selected
<value name="StartServers">20</value>

Sets the desired minimum number of idle server processes.
Used only when 'apache-like' pm_style is selected
<value name="MinSpareServers">5</value>

Sets the desired maximum number of idle server processes.
Used only when 'apache-like' pm_style is selected
<value name="MaxSpareServers">35</value>

</value>

</value>

The timeout (in seconds) for serving a single request after which the worker process will be terminated
Should be used when 'max_execution_time' ini option does not stop script execution for some reason
'0s' means 'off'
<value name="request_terminate_timeout">0s</value>

The timeout (in seconds) for serving of single request after which a php backtrace will be dumped to slow.log file
'0s' means 'off'
<value name="request_slowlog_timeout">0s</value>

The log file for slow requests
<value name="slowlog">logs/slow.log</value>

Set open file desc rlimit
<value name="rlimit_files">51200</value>

Set max core size rlimit
<value name="rlimit_core">0</value>

Chroot to this directory at the start, absolute path
<value name="chroot"></value>

Chdir to this directory at the start, absolute path
<value name="chdir"></value>

Redirect workers' stdout and stderr into main error log.
If not set, they will be redirected to /dev/null, according to FastCGI specs
<value name="catch_workers_output">yes</value>

How much requests each process should execute before respawn.
Useful to work around memory leaks in 3rd party libraries.
For endless request processing please specify 0
Equivalent to PHP_FCGI_MAX_REQUESTS
<value name="max_requests">10240</value>

Comma separated list of ipv4 addresses of FastCGI clients that allowed to connect.
Equivalent to FCGI_WEB_SERVER_ADDRS environment in original php.fcgi (5.2.2+)
Makes sense only with AF_INET listening socket.
<value name="allowed_clients">127.0.0.1</value>

Pass environment variables like LD_LIBRARY_PATH
All $VARIABLEs are taken from current environment
<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>


11、启动php-cgi进程,监听127.0.0.1的9000端口,进程数为200(如果服务器内存小于3GB,可以只开启64个进程),用户为www:
ulimit -SHn 51200
/usr/local/webserver/php/sbin/php-fpm start

注:/usr/local/webserver/php/sbin/php-fpm还有其他参数,包括:start|stop|quit|restart|reload|logrotate,修改php.ini后不重启php-cgi,重新加载配置文件使用reload。

PHP5.1.x开始需要设置时区,默认时区与中国时区差8个小时,这种情况需要在php.ini中这么设置,找到date.timezone,去掉前面的分号,修改为以下值,大陆地区可用的值是:Asia/Chongqing ,Asia/Shanghai ,Asia/Urumqi (依次为重庆,上海,乌鲁木齐)
不然一些php程序的时间老是和中国标准时间相差8个小时。我的我的VBB论坛在windows上就是这样。这儿有亚洲地区的对应时区。
http://www.php.net/manual/en/timezones.asia.php


12. 编译安装 nginx

Nginx ("engine x") 是一个高性能的 HTTP 和反向代理服务器,也是一个 IMAP/POP3/SMTP 代理服务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,它已经在该站点运行超过两年半了。Igor 将源代码以类BSD许可证的形式发布。

Nginx 超越 Apache 的高性能和稳定性,使得国内使用 Nginx 作为 Web 服务器的网站也越来越多,其中包括新浪博客、新浪播客、网易新闻等门户网站频道,六间房、56.com等视频分享网站,Discuz!官方论坛、水木社区等知名论坛,豆瓣、YUPOO相册、海内SNS、迅雷在线,中文印刷社区等新兴Web 2.0网站。

# cd /usr/local/src
# wget http://sysoev.ru/nginx/nginx-0.6.32.tar.gz
# tar zxvf nginx-0.6.32.tar.gz
# cd nginx-0.6.32
# CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer -fstack-protector -ftracer -fvisibility=hidden -fweb -frename-registers" CXXFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -felide-constructors -fno-exceptions -fno-rtti -fomit-frame-pointer -fvisibility-inlines-hidden -fno-enforce-eh-specs -fstack-protector -ftracer -fvisibility=hidden -fweb -frename-registers" LDFLAGS="-Wl,-O3 -Wl,-z -Wl,--enable-new-dtags -Wl,--sort-common -s" ./configure --user=www --group=www --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module
# make
# make install

将nginx设置成开机自启动:
在/etc/rc.d/rc.local文件中加入一行
/usr/local/webserver/nginx/sbin/nginx
这样每次重新启动系统以后,nginx也会随系统一起启动.

13、创建Nginx日志目录
mkdir -p /website/logs
chmod +w /website/logs
chown -R www:www /website/logs


14、创建Nginx配置文件
①、在/usr/local/webserver/nginx/conf/目录中创建nginx.conf文件:
rm -f /usr/local/webserver/nginx/conf/nginx.conf
vi /usr/local/webserver/nginx/conf/nginx.conf

输入以下内容:

user www www;

worker_processes 8;

error_log /website/logs/nginx_error.log crit;

pid /usr/local/webserver/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 utf-8;

server_names_hash_bucket_size 128;

sendfile on;
tcp_nopush on;

keepalive_timeout 180;

tcp_nodelay on;

fastcgi_connect_timeout 180;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 128k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
fastcgi_temp_path /dev/shm;

gzip on;
gzip_min_length 1k;
gzip_buffers 4 8k;
gzip_http_version 1.1;
gzip_types text/plain application/x-javascript text/css text/html application/xml;

server
{
listen 80;
server_name www.cnprint.org;
index index.html index.htm index.php;
root /website/htdocs/cnprint;

location /bbs/ {
rewrite ^/bbs/((urllist|sitemap_).*\.(xml|txt)(\.gz)?)$ /bbs/vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 last;

if ($request_filename ~ "\.php$") {
rewrite ^(.*)$ /bbs/vbseo.php?vbseourl=$1 last;
}

if (!-e $request_filename) {
rewrite ^/bbs/(.*)$ /bbs/vbseo.php?vbseourl=$1 last;
}
}

location ~ .*\.php?$
{
include fcgi.conf;
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;

}

log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
sendfile on;
keepalive_timeout 180;

tcp_nodelay on;

fastcgi_connect_timeout 180;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
tcp_nopush on;
client_max_body_size 50m;
}

server
{
listen 80;
server_name www.cpcprint.cn;
index index.html index.htm index.php;
root /website/htdocs/www/syssite;

location ~ .*\.php?$
{
include fcgi.conf;
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
}

log_format wwwlogs '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log /website/logs/wwwlogs.log wwwlogs;
}

server
{
listen 80;
server_name www.cpcjob.com;
index index.php index.html index.htm;
root /website/htdocs/job;

location ~ .*\.php?$
{
include fcgi.conf;
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
}

sendfile on;
tcp_nopush on;
client_max_body_size 5m;
}
server
{
listen 80;
server_name www.linuxnew.cn;
index index.php index.html index.htm;
root /website/htdocs/rhel;
location / {
rewrite ^/((urllist|sitemap_).*\.(xml|txt)(\.gz)?)$ /vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 last;

if ($request_filename ~ "\.php$") {
rewrite ^(.*)$ /vbseo.php?vbseourl=$1 last;
}

if (!-e $request_filename) {
rewrite ^/(.*)$ /vbseo.php?vbseourl=$1 last;
}
}


location ~ .*\.php?$
{
include fcgi.conf;
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
}

sendfile on;
tcp_nopush on;
client_max_body_size 25m;
}
server
{
listen 80;
server_name www.788900.cn;
index index.php index.html index.htm;
root /website/htdocs/cnprint;
location /bbs/ {
rewrite ^/bbs/((urllist|sitemap_).*\.(xml|txt)(\.gz)?)$ /bbs/vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 last;

if ($request_filename ~ "\.php$") {
rewrite ^(.*)$ /bbs/vbseo.php?vbseourl=$1 last;
}

if (!-e $request_filename) {
rewrite ^/bbs/(.*)$ /bbs/vbseo.php?vbseourl=$1 last;
}
}


location ~ .*\.php?$
{
include fcgi.conf;
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
}

sendfile on;
tcp_nopush on;
client_max_body_size 50m;
}
}



②、在/usr/local/webserver/nginx/conf/目录中创建fcgi.conf文件:
vi /usr/local/webserver/nginx/conf/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;


15、启动Nginx
ulimit -SHn 51200
/usr/local/webserver/nginx/sbin/nginx

16、配置开机自动启动Nginx + PHP
vi /etc/rc.local

在末尾增加以下内容:
引用
ulimit -SHn 51200
/usr/local/webserver/php/sbin/php-fpm start
/usr/local/webserver/nginx/sbin/nginx


# pkill nginx
# /usr/local/webserver/nginx/sbin/nginx //重启 nginx


17、在不停止Nginx服务的情况下平滑变更Nginx配置
1、修改/usr/local/webserver/nginx/conf/nginx.conf配置文件后,请执行以下命令检查配置文件是否正确:
/usr/local/webserver/nginx/sbin/nginx -t

如果屏幕显示以下两行信息,说明配置文件正确:
the configuration file /usr/local/webserver/nginx/conf/nginx.conf syntax is ok
the configuration file /usr/local/webserver/nginx/conf/nginx.conf was tested successfully

这时,输入以下命令查看Nginx主进程号:
ps -ef | grep "nginx: master process" | grep -v "grep" | awk -F ' ' '{print $2}'

屏幕显示的即为Nginx主进程号,例如:
6302
这时,执行以下命令即可使修改过的Nginx配置文件生效:
kill -HUP 6302

或者无需这么麻烦,找到Nginx的Pid文件:
kill -HUP `cat /usr/local/webserver/nginx/nginx.pid`

其实更简单的方法就是不管啥子进程
直接用
pkill nginx
结束程序所有进程
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics