免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 6375 | 回复: 0
打印 上一主题 下一主题

在solaris上安装Nginx [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-01-20 09:54 |只看该作者 |倒序浏览
 本文根据 张宴 的
Nginx 0.5.33 + PHP 5.2.5(FastCGI)搭建胜过Apache 10倍的Web服务器(第2版)
,尝试在solaris 10 下配置 nginx 0.6.31。
  Nginx 的中文维基:
http://wiki.codemongers.com/NginxChs
  安装步骤:
      系统为Solaris 10,全新完全安装。
    一、获取相关开源程序:
  1、下载程序源码包到当前目录:
  本文中提到的所有开源软件为截止到2008年5月14日的最新稳定版。我将它们打了三个压缩包。

文件:
xaa.tar
大小:
5120KB
下载:
下载

文件:
xab.tar
大小:
5120KB
下载:
下载

文件:
xac.tar
大小:
4037KB
下载:
下载
     2、解压缩:
cat xa*.tar > ngi-solaris10.tar.bz2
bzip2 -d cat xa*.tar > ngi-solaris10.tar.bz2
tar xf cat xa*.tar > ngi-solaris10.tar
顺便记录下分卷的命令
tar cf target.tar source1 source2 source3
bzip2 -z --best target.tar
split -b 5m  ngi-solaris10.tar.bz2
  二、安装PHP 5.2-lastest(FastCGI模式)
  1、编译安装PHP 5.2-lastest 所需的支持库:
配置PATH,因为Solaris 10把一些东西放得比较乱。
PATH=/usr/local/bin:/usr/bin:/usr/sbin:/usr/dt/bin:/usr/openwin/bin:/usr/ccs/bin:/usr/sfw/bin:/usr/ucb
export PATH
配置类库位置,否则安装时可能会出现某某.so未被发现
crle -c /var/ld/ld.config -l /usr/local/lib:/usr/lib:/lib
tar xf libiconv-1.12.tar
cd libiconv-1.12/
./configure --prefix=/usr/local
make
make install
cd ../
tar xf freetype-2.3.5.tar
cd freetype-2.3.5/
./configure
make
make install
cd ../
tar xf libpng-1.2.29.tar
cd libpng-1.2.29/
./configure
make
make install
cd ../
tar xf jpegsrc.v6b.tar
cd jpeg-6b/
./configure --enable-static --enable-shared
make
make install
make install-lib
cd ../
#----If your system was install libxml2, you do not need to install it.----
#tar xf libxml2-2.6.32.tar
#cd libxml2-2.6.32/
#./configure
#make
#install
#cd ../
tar xf libmcrypt-2.5.8.tar
cd libmcrypt-2.5.8/
./configure
make
make install
cd libltdl/
./configure --enable-ltdl-install
make
make install
cd ../../
tar xf mhash-0.9.9.tar
cd mhash-0.9.9/
./configure
make
make install
cd ../
cp /usr/local/lib/libmcrypt.* /usr/lib
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
tar xf mcrypt-2.6.7.tar
cd mcrypt-2.6.7/
./configure
make
make install
cd ../
注:若出现You need at least libmhash 0.8.15 to compile this program可以这样configure
LD_LIBRARY_PATH=/usr/local/lib ./configure
tar xf curl-7.18.1.tar
cd curl-7.18.1
./configure
make && make install
cd ../
  2、编译安装MySQL 5.0.51b
tar zxvf mysql-5.0.51b.tar.gz
cd mysql-5.0.51b
./configure
--prefix=/usr/local/webserver/mysql/ --without-debug
--with-unix-socket-path=/tmp/mysql.sock
--with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static
--enable-assembler --with-extra-charsets=gbk,gb2312,utf8 --with-pthread
--enable-thread-safe-client
make && make install
cd ../
  附:以下为附加步骤,如果你想在这台服务器上运行MySQL数据库,则执行以下两步。如果你只是希望让PHP支持MySQL扩展库,能够连接其他服务器上的MySQL数据库,那么,以下两步无需执行。
  
     ①、拷贝文件,建立环境:
groupadd mysql
useradd -g mysql mysql
chmod +w /usr/local/webserver/mysql
chown -R mysql:mysql /usr/local/webserver/mysql
cp mysql-5.0.51b/support-files/my-medium.cnf /usr/local/webserver/mysql/my.cnf
  ②、以mysql用户帐号的身份建立数据表:
/usr/local/webserver/mysql/bin/mysql_install_db
--defaults-file=/usr/local/webserver/mysql/my.cnf
--basedir=/usr/local/webserver/mysql
--datadir=/usr/local/webserver/mysql/data --user=mysql
--pid-file=/usr/local/webserver/mysql/mysql.pid --skip-locking
--port=3306 --socket=/tmp/mysql.sock
  ③、启动MySQL(最后的&表示在后台运行)
/bin/sh /usr/local/webserver/mysql/bin/mysqld_safe --defaults-file=/usr/local/webserver/mysql/my.cnf &
  3、编译安装PHP(FastCGI模式)
wget http://snaps.php.net/php5.2-latest.tar.gz
tar zxvf php5.2-latest.tar.gz
cd php5.2-200805140830
./configure
--prefix=/usr/local/webserver/php
--with-config-file-path=/usr/local/webserver/php/etc
--with-mysql=/usr/local/webserver/mysql --with-iconv-dir=/usr/local
--with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib
--with-libxml-dir --enable-xml --disable-debug --disable-rpath
--enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop
--enable-sysvsem --enable-inline-optimization --with-curl
--with-curlwrappers --enable-mbregex --enable-fastcgi
--enable-force-cgi-redirect --enable-mbstring --with-mcrypt
configure我出现错误,more了下debug.log后发现未找到libmysqlclient.so.15,如下处理:
ln -s /usr/local/webserver/mysql/lib/mysql/libmysqlclient.so.15.0.0 /usr/local/lib/libmysqlclient.so.15
###以下这两句为原文作者为修复libiconv问题所写的Linux语句,我翻译为Solaris,但php5.2-lastest应该修正了这个问题,因此,并没有使用
###sed
's/ -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt/ -lz -lm -lxml2 -lz
-lm -lxml2 -lz -lm -lcrypt -liconv/' Makefile >mmm
###cp mmm Makefile
make
由于该主机在局域网内,未连接internet,需要在别的机器上先
wget http://pear.php.net/install-pear-nozlib.phar
后 cp install-pear-nozlib.phar pear
make install
cp php.ini-dist /usr/local/webserver/php/etc/php.ini
cd ../
注:
   
①在安裝 PHP 到系統中時要是發生「undefined reference to
`libiconv_open'」之類的錯誤訊息,那表示在「./configure 」沒抓好一些環境變數值。錯誤發生點在建立「-o
sapi/cli/php」時出錯,沒給到要 link 的 iconv 函式庫參數。
快速的解法是:
編輯 Makefile 大約 70 行左右的地方:
EXTRA_LIBS = ..... -lcrypt
在最後加上 -liconv,例如:
EXTRA_LIBS = ..... -lcrypt -liconv
然後重新再次 make 即可。
    ②编译过程中出现Undefined symbol mysql_set_character_set 则在编译参数后加--with-readline
  4、编译安装PHP5扩展模块
tar xf memcache-2.2.1.tar
cd memcache-2.2.1/
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ../
cd php5.2-200805140830/ext/gd/
/usr/local/webserver/php/bin/phpize
./configure
--with-jpeg-dir --with-png-dir --with-zlib-dir --with-ttf
--with-freetype-dir
--with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ../../../
注:
    ①phpize
时若出现未发现/usr/local/bin/autom4te或/usr/local/bin/autoheader,从sunfreeware重下了
m4后安装仍出错。后more了下/usr/local/bin/autom4te发现是perl未找到
ln -s /usr/perl5/5.8.4/bin/perl /usr/local/bin/perl
    ②2个phpize我都出现了大量的warning,但并不影响安装
  5、修改php.ini文件
  手工修改:查找/usr/local/webserver/php/etc/php.ini中的extension_dir = "./"
  修改为extension_dir = "/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/"
  并在此行后增加以下几行,然后保存:
  extension = "memcache.so"
  extension = "gd.so"
  自动修改:若嫌手工修改麻烦,可执行以下shell命令,自动完成对php.ini文件的修改:
sed
-i 's#extension_dir = "./"#extension_dir =
"/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/"\nextension
= "memcache.so"\nextension = "gd.so"\n#'
/usr/local/webserver/php/etc/php.ini
  6、创建www用户和组,以及其使用的目录:
/usr/sbin/groupadd www -g 48
/usr/sbin/useradd -u 48 -g www www
mkdir -p /webroot
chmod +w /webroot
chown -R www:www /webroot
  7、安装lighttpd中附带的spawn-fcgi,用来启动php-cgi
tar xf lighttpd-1.4.19.tar
cd lighttpd-1.4.19
./configure
make
cp ./src/spawn-fcgi /usr/local/webserver/php/bin
chmod +x /usr/local/webserver/php/bin/spawn-fcgi
  8、启动php-cgi进程,监听127.0.0.1的10080端口,进程数为64(如果服务器内存小于3GB,可以只开启25个进程),用户为www:
/usr/local/webserver/php/bin/spawn-fcgi -a 127.0.0.1 -p 10080 -C 64 -u www -f /usr/local/webserver/php/bin/php-cgi
  三、安装Nginx 0.6.31
  1、安装Nginx所需的pcre库:
tar xf pcre-7.7.tar
cd pcre-7.7/
./configure
make && make install
cd ../
  2、安装Nginx(支持ssl)
tar xf nginx-0.6.31.tar
cd nginx-0.6.31/
./configure
--user=www --group=www --prefix=/usr/local/webserver/nginx
--with-http_stub_status_module --with-http_ssl_module
--with-openssl=/src/openssl-0.9.8h
make && make install
cd ../
用openssl生成证书:
openssl req -new -x509 -nodes -out /usr/local/webserver/nginx/conf/slit.crt -keyout /usr/local/webserver/nginx/conf/slit.key
  3、创建Nginx日志目录
mkdir -p /data1/logs
chmod +w /data1/logs
chown -R www:www /data1/logs
  4、创建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 10;
error_log  /webroot/logs/nginx_error.log  crit;
pid /usr/local/webserver/nginx/conf/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;
events
{
      use eventport;
      worker_connections 51200;
}
http
{
      include       mime.types;
      default_type  application/octet-stream;
      charset  gb2312;
      
      server_names_hash_bucket_size 128;
      
      #sendfile on;
      #tcp_nopush     on;
      keepalive_timeout 60;
      tcp_nodelay on;
      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  localhost;
              index index.html index.htm index.php;
              root  /webroot;
              if (-d $request_filename)
              {
                     rewrite ^/(.*)([^/])$
http://$host/$1$2/
permanent;
              }
                             
              location ~ .*\.php?$
              {
                   include fcgi.conf;      
                   fastcgi_pass  127.0.0.1:10080;
                   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';
              access_log  /webroot/logs/access.log  access;
      }
      server
      {
              listen  83;
              location / {
                   stub_status on;
                   access_log   off;
              }
      }
      
      server
      {
              listen       443;
              ssl          on;
              ssl_certificate /usr/local/webserver/nginx/conf/slit.crt;
              ssl_certificate_key /usr/local/webserver/nginx/conf/slit.key;
              server_name  localhost;
              index index.html index.htm index.php;
              root  /webroot/new.slit.cn;
              rewrite ^/shop/([0-9]+)$ /shop.php?action=shopindex&shopid=$1;
              rewrite ^/shop/(.*)$ /$1;
              rewrite ^/bbs/archiver/((fid|tid)-[\w\-]+\.html)$   /bbs/archiver/index.php?$1 last;
                rewrite ^/bbs/forum-([0-9]+)-([0-9]+)\.html$   /bbs/forumdisplay.php?fid=$1&page=$2 last;
                rewrite ^/bbs/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$  /bbs/viewthread.php?tid=$1&extra=page
\%3D$3&page=$2 last;
                rewrite ^/bbs/tag-(.+)\.html$ /bbs/tag.php?name=$1 last;
                if (-d $request_filename)
              {
                     rewrite ^/(.*)([^/])$
http://$host/$1$2/
permanent;
              }
              location ~ .*\.php?$
              {
                   include fcgi.conf;
                   fastcgi_pass  127.0.0.1:10080;
                   fastcgi_index index.php;
                   fastcgi_connect_timeout 120;
                   fastcgi_send_timeout 180;
                   fastcgi_read_timeout 180;
              }
        }
}
  ②、在/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;
  5、启动Nginx
ulimit -SHn 51200
/usr/local/webserver/nginx/sbin/nginx -c /usr/local/webserver/nginx/conf/nginx.conf
  四、配置开机自动启动Nginx + PHP
vi /usr/bin/nginx
# pidfile: /usr/local/webserver/nginx/conf/nginx.pid
# config: /usr/local/webserver/nginx/conf/nginx.conf
NGINX_HOME=/usr/local/webserver/nginx/sbin
NGINX_CONF=/usr/local/webserver/nginx/conf
PHP_HOME=/usr/local/webserver/php/bin
if [ ! -f "$NGINX_HOME/nginx" ]
then
      echo "nginxserver startup: cannot start"
      exit
fi
case "$1" in
    'start')
        $PHP_HOME/spawn-fcgi -a 127.0.0.1 -p 10080 -C 25 -u www -f $PHP_HOME/php-cgi
        sleep 1
        $NGINX_HOME/nginx -c $NGINX_CONF/nginx.conf
        echo "nginx start successful"
        ;;
    'stop')
        pkill -TERM php-cgi
        pkill -TERM nginx
        ;;
    'stopcgi')
        pkill -TERM php-cgi
        ;;
    'startcgi')
        $PHP_HOME/spawn-fcgi -a 127.0.0.1 -p 10080 -C 25 -u www -f $PHP_HOME/php-cgi
        ;;
    'reload')
        kill -HUP `cat $NGINX_CONF/nginx.pid`
        ;;
    *)
        echo "Usage: $0 {start|stop|reload|startcgi|stopcgi}" >&2
        exit 3
        ;;
esac
exit 0
  增加文件链接
ln -s /usr/bin/nginx /etc/rc3.d/S90nginx
##尚未进行优化,以下为原作者所写
  五、优化Linux内核参数
vi /etc/sysctl.conf
  在末尾增加以下内容:
引用
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.ip_local_port_range = 5000    65000
  使配置立即生效:
/sbin/sysctl -p
相关资源:
利用Nginx替代apache实现高性能的Web环境

Nginx+Fastcgi+eAccelerator+Zend Optimizer


安装Nginx(负载均衡器)

Nginx安装和配置


[color="#000099"]原文地址
http://blog.s135.com/read.php/314.htm

[color="#000099"]TAG
nginx
php



[color="#295200"]发表于: 2008-05-14,修改于: 2008-07-17 08:23,已浏览673次,有评论3条
推荐
投诉







网友评论



网友:
本站网友
时间:2008-08-06 16:03:11    IP地址:210.76.108.★
你好,我在你的文章中看到一篇帖子,http://blog.chinaunix.net/u2/69195/showart_688359.html,
我遇到了同样的Undefined                       first referenced
symbol                             in file
mysql_set_character_set             ext/mysql/php_mysql.o
这个问题,我也加了with-readline,但是不起作用,你还记得你是怎样解决的吗?
myemail paradisna@gmail.com
                               
               
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/21041/showart_1805025.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP