LNMP構建高可用WEB服務器安裝篇

聲明:此文章有部分內容參考網上的一些文章,文章中所有代碼在Centos 6.2 X84 64位系統上經過測試。

一、下載軟件包

wget http://mozbuildtools.googlecode.com/files/libiconv-1.13.1.tar.gz
wget http://acelnmp.googlecode.com/files/mhash-0.9.9.9.tar.gz
wget http://mysql.ntu.edu.tw/Downloads/MySQL-5.5/mysql-5.5.25a.tar.gz
wget http://sysoev.ru/nginx/nginx-0.8.46.tar.gz
wget http://www.php.net/get/php-5.2.14.tar.gz/from/this/mirror
wget http://php-fpm.org/downloads/php-5.2.14-fpm-0.5.14.diff.gz
wget http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?modtime=1171868460&big_mirror=0
wget http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?modtime=1194463373&big_mirror=0
wget http://pecl.php.net/get/memcache-2.2.5.tgz
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.10.tar.gz
wget http://bart.eaccelerator.net/source/0.9.6.1/eaccelerator-0.9.6.1.tar.bz2
wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
wget http://blog.s135.com/soft/linux/nginx_php/imagick/ImageMagick.tar.gz
wget http://pecl.php.net/get/imagick-2.3.0.tgz
wget http://www.cmake.org/files/v2.8/cmake-2.8.4.tar.gz

二、安裝依賴軟件包

yum -y install dialog ntp vim-enhanced vixie-cron 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 net-snmp net-snmp-devel nss_ldap openldap-clients openldap-servers libtidy libtidy-devel wget libc-client libc-client-devel pcre pcre-devel

三、安裝MySQL

1、安裝cmake

tar zxvf cmake-2.8.4.tar.gz
cd $src_dir/cmake-2.8.4
./configure && make && make install

2、安裝mysql 5.5

tar zxvf mysql-5.5.25a.tar.gz
cd mysql-5.5.25a
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_SSL=yes  -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_READLINE=on
gmake && make install

3、創建MySQL數據庫存放目錄

mkdir -p /usr/local/mysql/data
mkdir -p /usr/local/mysql /binlog/
mkdir -p /usr/local/mysql /relaylog/
chown -R mysql:mysql /usr/local/mysql

5、創建mysql配置文件和啓動腳本

/bin/cp support-files/my-small.cnf /etc/my.cnf
                                                
/bin/cp support-files/mysql.server /etc/rc.d/init.d/mysqld

6mysql用戶帳號的身份建立數據表:

/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql --defaults-file=/etc/my.cnf

四、安裝PHP 5.3.16(php-fpm模式)

1、安裝編譯安裝PHP 5.2.14所需的支持庫:

tar zxvf libiconv-1.13.1.tar.gz
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 ../../
                                       
tar zxvf mhash-0.9.9.9.tar.gz
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/bin/libmcrypt-config /usr/bin/libmcrypt-config
                                       
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make
make install
cd ../

2、編譯安裝PHP5

tar zxvf php-5.3.13.tar.gz
cd php-5.3.13
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/lib --with-mysql=/usr/local/mysql/bin/mysql_config --with-enable-sysvsem --enable-fpm --with-openssl --with-zlib --with-bz2 --with-curl --with-libxml-dir=/usr --with-gd --with-jpeg-dir --with-png-dir --with-zlib-dir --enable-gd-native-ttf --enable-gd-jis-conv --with-iconv=/use/local/libiconv --with-ldap --with-mcrypt=/usr/local/libmcypt --with-zlib-dir --with-snmp --enable-zip --with-curlwrappers --with-imap --with-kerberos --with-imap-ssl --with-freetype-dir --with-mysql=/usr/local/mysql
make && make install
cp php.ini-development /usr/local/php/lib/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

3、編譯安裝PHP5擴展模塊

tar zxvf memcache-2.2.5.tgz
cd memcache-2.2.5/
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ../
                           
tar jxvf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1/
/usr/local/webserver/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ../
                           
tar zxvf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2/
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config --with-pdo-mysql=/usr/local/webserver/mysql
make
make install
cd ../
                           
tar zxvf ImageMagick.tar.gz
cd ImageMagick-6.5.1-2/
./configure
make
make install
cd ../
                           
tar zxvf imagick-2.3.0.tgz
cd imagick-2.3.0/
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ../

4、修改php.ini文件
手工修改:查找/usr/local /php/etc/php.ini中的extension_dir = "./"
  修改爲extension_dir = "/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/"
  並在此行後增加以下幾行,然後保存:
extension = "memcache.so"
extension = "pdo_mysql.so"
extension = "imagick.so"

  再查找output_buffering = Off
  修改爲output_buffering = On

  再查找; cgi.fix_pathinfo=0
  修改爲cgi.fix_pathinfo=0,防止Nginx文件類型錯誤解析漏洞。

5、配置eAccelerator加速PHP

mkdir -p /usr/local/webserver/eaccelerator_cache

vi /usr/local/webserver/php/etc/php.ini

  按shift+g鍵跳到配置文件的最末尾,加上以下配置信息:

引用

[eaccelerator]
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="64"
accelerator.cache_dir="/usr/local/eaccelerator_cache"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="3600"
eaccelerator.shm_prune_period="3600"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"

五、安裝Nginx 0.8.46


1、安裝Nginx所需的pcre庫:  yum -y install pcre pcre-devel


2、安裝Nginx

tar zxvf nginx-0.8.46.tar.gz
cd nginx-0.8.46/
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
cd ../

4nginx配置文件模板

user  nobody;  
worker_processes  1;
           
pid        logs/nginx.pid;
worker_rlimit_nofile 65535;
           
events {
    worker_connections  65535;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
           
    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  logs/access.log  main;
           
    sendfile        on;
    tcp_nopush     on;
           
    #keepalive_timeout  0;
    keepalive_timeout  300;
    proxy_connect_timeout 300;
    proxy_read_timeout 600;
    proxy_send_timeout 600;
    proxy_buffer_size 64k;
    proxy_buffers 4 32k;
    proxy_busy_buffers_size 64k;
           
    gzip  on;
    gzip_min_length 1000;
    gzip_buffers        4 8k;
    gzip_comp_level     3;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
             
      server
      {
        listen  80;
            server_name  status.chlinux.net;
           
         location / {
         stub_status on;
            access_log   off;
        }
      }
    server {
        listen       80;
        server_name  www.chlinux.net chlinux.net;
    root   html/;
            index  index.php index.html index.htm;
        location / {
            root   html/;
            index  index.php index.html index.htm;
        if (-f $request_filename/index.html){
                rewrite (.*) $1/index.html break;
                }
            if (-f $request_filename/index.php){
                rewrite (.*) $1/index.php;
                }
            if (!-f $request_filename){
                rewrite (.*) /index.php;
                }
            location /nginx_status {
                 stub_status on;
                 access_log off;
              }
            }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        location ~ \.php$ {
           root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;
            include        fastcgi.conf;
        }
    }

更多博文請訪問 平凡的日子 http://www.chlinux.net/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章