配置ng服务器

首先我们先更新下我们需要的环境,放心有的不会安装,没有的会从新安装:
[root@sulwan ~]# yum -y install ntp vim-enhanced gcc gcc-c++ gcc-g77 flex bison autoconf automake glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel libtool* zlib-devel libxml2-devel libjpeg-devel libpng-devel libtiff-devel fontconfig-devel freetype-devel libXpm-devel gettext-devel curl curl-devel pam-devel e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers neno  apr apr-util
[root@sulwan soft]# mkdir /opt/soft -p
[root@sulwan soft]# cd /opt/soft
把需要的软件列表list.txt上传到服务器/opt/soft,完后下载
[root@sulwan soft]# wget -i list.txt
上传完毕后,我们开始安装NG,安装NG需要有独立运行账户,除非你打算使用root运行我这里设置独立账户:
[root@sulwan soft]# groupadd www
[root@sulwan soft]# useradd -g www www
[root@sulwan soft]# mkdir -p /opt/www
[root@sulwan soft]#chmod +w /opt/www
[root@sulwan soft]# chown www:www /opt/www -R
安装NG需要pcre,这里我们要先安装下pcre
[root@sulwan soft]# tar zxvf pcre-7.8.tar.gz
[root@sulwan soft]# cd pcre-7.8
[root@sulwan pcre-7.8]# ./configure && make && make install
现在正式开始安装NG了,嘎嘎!我日,在装这个的时候北京停电了,我靠,北京也有停电的时候!
[root@sulwan pcre-7.8]# cd ../
[root@sulwan soft]# tar zxvf nginx-0.8.21.tar.gz
[root@sulwan soft]# cd nginx-0.8.21
[root@sulwan nginx-0.8.21]# ./configure --user=www --group=www --prefix=/opt/nginx/ --with-http_stub_status_module --with-http_ssl_module --with-md5=/usr/lib --with-sha1=/usr/lib
[root@sulwan nginx-0.8.21]# make && make install
接着我们安装mysql
[root@sulwan nginx-0.8.21]# cd ../
[root@sulwan soft]# tar zxvf mysql-5.1.50.tar.gz
[root@sulwan soft]# cd mysql-5.1.50
[root@sulwan mysql-5.1.50]# ./configure --prefix=/opt/mysql --enable-assembler --enable-thread-safe-client --with-extra-charsets=complex --with-ssl --with-embedded-server --with-plugins=innobase --with-named-curses-libs=/usr/lib/libncursesw.so.5
请不要问我这些参数是干啥的,您可以自己实验下,这些是我用到的,所以我设置,如果您不会,有两种解决途径,一个就是找别人帮助您解决,一个就是./configure --help 不过我不会了有奶哥,您不会了有谁呢?咋样,(此时sulwan本人一阵狂喜!!)
我们先做一件蛋疼的事情,其实有的机子不需要,有的机子需要,干脆直接蛋疼算了,省的麻烦ldconfig,管理搜寻动态库的破玩意,默认这个破玩意是 (/lib和/usr/lib)以及动态库配置文件/etc/ld.so.conf这两个位置,你可以编辑,也可以在你想加入的目录下直接运行命令,具体为啥,就是告诉程序那里找,不过您也可以做ln连接去,不过我不喜欢

[root@sulwan mysql-5.1.50]# ldconfig
这样程序就可以在这里找东西了,否则有的机子是没法装mysql我见过四个机子都这个,汗,最近天天装系统,真麻烦,不过学到了很多东西,每次都有感受,最近在装gentoo感觉那个叫麻烦啊,正在努力学习乔大妈的孩子
[root@sulwan mysql-5.1.50]# make && make install
root@sulwan mysql-5.1.50]# cp support-files/my-large.cnf /etc/my.cnf
[root@sulwan mysql-5.1.50]# /opt/mysql/bin/mysql_install_db
[root@sulwan mysql-5.1.50]# groupadd mysql
[root@sulwan mysql-5.1.50]# useradd -g mysql mysql
[root@sulwan mysql-5.1.50]# chown -R mysql.mysql /opt/mysql/var
[root@sulwan mysql-5.1.50]# mkdir /opt/mysql/init.d/
[root@sulwan mysql-5.1.50]# cp support-files/mysql.server /opt/mysql/init.d/mysqld
[root@sulwan mysql-5.1.50]# chmod 755 /opt/mysql/init.d/mysqld
[root@sulwan mysql-5.1.50]# ln -s /opt/mysql/init.d/mysqld /etc/rc.d/init.d/mysqld
[root@sulwan mysql-5.1.50]# chkconfig --add mysqld
[root@sulwan mysql-5.1.50]# service mysqld start
[root@sulwan mysql-5.1.50]# PATH=$PATH:/opt/mysql/bin
[root@sulwan mysql-5.1.50]# /opt/mysql/bin/mysql_secure_installation
完后回车,Y,输入密码,在输入一边你想设置的密码,Y,Y,Y
[root@sulwan mysql-5.1.50]# mysql -uroot -p
输入你的密码,看看是否安装成功了呢,嘎嘎,高兴不不?高兴就感谢上天把,因为你已经是一个帅哥了!
输入exit;从该死的mysql中退出来
下边我们开始安装php了,这里和apache不一样了
[root@sulwan mysql-5.1.50]# cd ../
[root@sulwan soft]# tar zxvf libiconv-1.13.1.tar.gz
[root@sulwan soft]# cd libiconv-1.13.1
[root@sulwan libiconv-1.13.1]# ./configure --prefix=/usr
[root@sulwan libiconv-1.13.1]# make && make install
[root@sulwan libiconv-1.13.1]# cd ../
[root@sulwan soft]# tar zxvf libmcrypt-2.5.8.tar.gz
[root@sulwan soft]# cd libmcrypt-2.5.8
[root@sulwan libmcrypt-2.5.8]# ./configure --prefix=/usr
[root@sulwan libmcrypt-2.5.8]# make && make install
[root@sulwan libmcrypt-2.5.8]# echo "/usr/lib" >> /etc/ld.so.conf
[root@sulwan libmcrypt-2.5.8]# ldconfig
[root@sulwan libmcrypt-2.5.8]# cd libltdl
[root@sulwan libltdl]# ./configure --enable-ltdl-install
[root@sulwan libltdl]# make && make install
[root@sulwan libltdl]# cd ../../
[root@sulwan soft]# tar zxvf mhash-0.9.9.9.tar.gz
[root@sulwan soft]# cd mhash-0.9.9.9
[root@sulwan mhash-0.9.9.9]# ./configure --prefix=/usr
[root@sulwan mhash-0.9.9.9]# make && make install
[root@sulwan mhash-0.9.9.9]# cd ../
[root@sulwan soft]# tar zxvf mcrypt-2.6.8.tar.gz
[root@sulwan sof]# cd mcrypt-2.6.8
[root@sulwan mcrypt-2.6.8]#/sbin/ldconfig
[root@sulwan mcrypt-2.6.8]# ./configure --prefix=/usr
[root@sulwan mcrypt-2.6.8]# make && make install
[root@sulwan mcrypt-2.6.8]# cd ../
[root@sulwan soft]# tar zvxf spawn-fcgi-1.6.3.tar.gz
[root@sulwan soft]# cd spawn-fcgi-1.6.3
[root@sulwan spawn-fcgi-1.6.3]# ./configure
[root@sulwan spawn-fcgi-1.6.3]# make && make install
[root@sulwan spawn-fcgi-1.6.3]# cd ../
[root@sulwan soft]# tar jvxf php-5.2.9.tar.bz2
[root@sulwan soft]# cd php-5.2.9
[root@sulwan php-5.2.9]# ./configure --prefix=/opt/php --enable-fastcgi --enable-fpm --enable-discard-path --enable-force-cgi-redirect --with-config-file-path=/opt/php/etc --with-mysql=/opt/mysql --with-mysqli=/opt/mysql/bin/mysql_config --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-gd --with-zlib --with-libxml-dir --with-curl --with-curlwrappers --with-openssl --with-mhash --with-xmlrpc --with-mcrypt --with-ldap --with-ldap-sasl --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-gd-native-ttf --enable-ftp --enable-pcntl --enable-sockets --enable-zip --disable-debug --disable-ipv6
上边的选项自己用到就写,用不到就不写,看个人配置了,全写上也没事,不过safe必须要
[root@sulwan php-5.2.9]# make ZEND_EXTRA_LIBS='-liconv'
后边那句是因为库,有的机子上出错,不加不可以,有的机子大家可以直接make
[root@sulwan php-5.2.9]#./configure --with-php-config=/usr/local/php/bin/php-config
[root@sulwan php-5.2.9]# make install
[root@sulwan php-5.2.9]# cp php.ini-dist /opt/php/etc/php.ini
[root@sulwan php-5.2.9]# cd ../
接着我们安装memcache
[root@sulwan soft]# tar zvxf memcache-2.2.5.tgz
[root@sulwan soft]# cd memcache-2.2.5
[root@sulwan memcache-2.2.5]# /opt/php/bin/phpize
[root@sulwan memcache-2.2.5]# ./configure --with-php-config=/opt/php/bin/php-config
[root@sulwan memcache-2.2.5]# make && make install
[root@sulwan memcache-2.2.5]# cd ../
这次我们多讲解一个:eaccelerator,我在APACHE中没有说这个,理由很简单,当时觉得这个没有用,不过最近我也装上了
[root@sulwan soft]# tar jvxf eaccelerator-0.9.5.3.tar.bz2
[root@sulwan soft]# cd eaccelerator-0.9.5.3
[root@sulwan eaccelerator-0.9.5.3]# /opt/php/bin/phpize
[root@sulwan eaccelerator-0.9.5.3]# ./configure --enable-eaccelerator=shared --with-php-config=/opt/php/bin/php-config
[root@sulwan eaccelerator-0.9.5.3]# make && make install
[root@sulwan eaccelerator-0.9.5.3]# cd ../
安装PDO_MYSQL
[root@sulwan soft]# tar zxvf PDO_MYSQL-1.0.2.tgz
[root@sulwan soft]# cd PDO_MYSQL-1.0.2
[root@sulwan PDO_MYSQL-1.0.2]# /opt/php/bin/phpize
[root@sulwan PDO_MYSQL-1.0.2]# ./configure --with-php-config=/opt/php/bin/php-config --with-pdo-mysql=/opt/mysql
[root@sulwan PDO_MYSQL-1.0.2]# make && make install
[root@sulwan PDO_MYSQL-1.0.2]# cd ../
安装ImageMagick
[root@sulwan soft]# tar zxvf ImageMagick-6.6.4-8.tar.gz
[root@sulwan soft]# cd ImageMagick-6.6.4-8
[root@sulwan ImageMagick-6.6.4-8]# ./configure --enable-shared --with-modules --without-x --with-gs-font-dir=default --with-perl=yes --with-xml=yes --with-zlib=yes --with-jpeg=yes
[root@sulwan ImageMagick-6.6.4-8]# make && make install
[root@sulwan ImageMagick-6.6.4-8]# mkdir -p /opt/cache/ea
[root@sulwan ImageMagick-6.6.4-8]# cp /opt/php/etc/php.ini /opt/php/etc/php.ini.bak
[root@sulwan ImageMagick-6.6.4-8]# vi /opt/php/etc/php.ini
现在开始统一修改PHPINI
[eAccelerator]
zend_extension="/opt/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="32"
eaccelerator.cache_dir="/opt/cache/ea"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"

 extension_dir = "/opt/php/lib/php/extensions/no-debug-non-zts-20060613/"
extension = "memcache.so"
extension = "pdo_mysql.so"
extension = "imagick.so"

output_buffering = On


设置NG
[root@sulwan ImageMagick-6.6.4-8]# cd /opt/nginx/conf
[root@sulwan ImageMagick-6.6.4-8]# cp nginx.conf nginx.conf.bak
[root@sulwan ImageMagick-6.6.4-8]# cd /opt/nginx/conf
[root@sulwan conf]# vi nginx.conf
nginx.conf 内容如下:

user  nobody;
#启动账户
worker_processes  10;
#工作进程

error_log  logs/error.log;
#开启错误记录位置
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

pid /tmp/nginx.pid;
#启动状态
worker_rlimit_nofile 50000;
#数目不能超过linux内核文件打开数,至于写多少随便个人
events {
        use epoll;
        #maxclient = worker_processes * worker_connections / cpu_number
        worker_connections 50000;
}


http {
    include       /opt/nginx/conf/mime.types;
    #位置格式的,比如你要下载支持啥的
    default_type  application/octet-stream;
    charset utf8;
    #字符

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    #日志记录格式
    access_log  /opt/nginx/logs/access.log  main;
    #日志记录
     #General Options
    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    ignore_invalid_headers   on;
    recursive_error_pages    on;
    server_name_in_redirect off;
  
    sendfile                 on;

    #timeouts
    keepalive_timeout 60;
  
    #TCP Options
    tcp_nopush  on;
    tcp_nodelay on;
    #fastcgi options
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    
    fastcgi_buffer_size 128k;
    fastcgi_buffers 4 128k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;
    fastcgi_intercept_errors on;
    ssi on;
    ssi_silent_errors on;
    ssi_types text/shtml;
    #size limits
    client_max_body_size       50m;
    client_body_buffer_size    256k;
    #gzip  compression
    gzip on;
    gzip_min_length  0;
    gzip_buffers     16 8k;
    gzip_http_version 1.0;
    gzip_comp_level 9;
    gzip_types       text/plain text/css image/x-icon image/png;
    gzip_vary on;

    #temp files
    proxy_temp_path            /dev/shm/proxy_temp;
    fastcgi_temp_path          /dev/shm/fastcgi_temp;
    client_body_temp_path      /dev/shm/client_body_temp;
    #client_body_temp_path  /opt/nginx/client_body_temp 1 2;
    #proxy_temp_path        /opt/nginx/proxy_temp 1 2;
    #fastcgi_temp_path      /opt/nginx/fastcgi_temp 1 2;
    
    #upstream
    upstream  spawn {
    # ip_hash;
     server   127.0.0.1:9000 max_fails=0 fail_timeout=30s;
     server   127.0.0.1:9001 max_fails=0 fail_timeout=30s;
    }

    # The following includes are specified for virtual hosts
     #www.linuxtone.org
     include          /opt/nginx/conf/vhost/main.conf;


}
main.conf如下:
server
        {
                listen       80;
                server_name  www.ng.com .ng.com;
                index index.html index.htm index.php;
                root  /opt/www/;
                error_page 404 http://www.ng.com;
                location ~ .*\.php?$
                {
                        fastcgi_pass spawn;
                        include /opt/nginx/conf/spawn_php5.conf;
                        fastcgi_index  index.php;
                }
                location ~* \.(js|css|jpg|jpeg|gif|png)$ {
                if (-f $request_filename) {
                   access_log   off;
                   expires      1d;
                   break;
                   }
                 }
        }
spawn_php5.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;
[root@sulwan ImageMagick-6.6.4-8]# mkdir /opt/php/sbin
[root@sulwan ImageMagick-6.6.4-8]# chmod 755 /opt/php/sbin/spawn-fcgi
[root@sulwan ImageMagick-6.6.4-8]# /opt/php/sbin/spawn-fcgi start
[root@sulwan ImageMagick-6.6.4-8]#/opt/nginx/sbin/nginx
到这里我们也就装完毕了NG了,现在设置他开机启动把
[root@sulwan ImageMagick-6.6.4-8]##vi /etc/rc.local
在最后加入:
ulimit -SHn 51200
/opt/nginx/sbin/nginx
/opt/php/sbin/spawn-fcgi start
在给防火墙关闭或者开开80端口9000,9001,否则是无法浏览的:
至于为什么,看张宴的图书,他上边有写

 转载自:http://blog.pv3.com.cn/post/47/1/2/ 

石家庄程序员[刘军颖
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值