Lnmp安裝配置(nginx)

1.準備php函式的rpm

yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

2.準備lnmp其他的原始碼包

wget http://blog.s135.com/soft/linux/nginx_php/nginx/nginx-0.8.46.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/php/php-5.2.14.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/phpfpm/php-5.2.14-fpm-0.5.14.diff.gz
wget http://blog.s135.com/soft/linux/nginx_php/mysql/mysql-5.5.3-m3.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/libiconv/libiconv-1.13.1.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/mcrypt/libmcrypt-2.5.8.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/mcrypt/mcrypt-2.6.8.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/memcache/memcache-2.2.5.tgz
wget http://blog.s135.com/soft/linux/nginx_php/mhash/mhash-0.9.9.9.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/pcre/pcre-8.10.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/eaccelerator/eaccelerator-0.9.6.1.tar.bz2
wget http://blog.s135.com/soft/linux/nginx_php/pdo/PDO_MYSQL-1.0.2.tgz
wget http://blog.s135.com/soft/linux/nginx_php/imagick/ImageMagick.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/imagick/imagick-2.3.0.tgz

3.安裝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
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/

./configure
make
make install
cd ../

4. 編譯安裝MySQL 5.5.3-m3

./configure –prefix=/usr/local/mysql –without-debug –enable-thread-safe-client –with-pthread –enable-assembler –enable-profiling –with-mysqld-ldflags=-all-static –with-client-ldflags=-all-static –with-extra-charsets=all –with-plugins=all –with-mysqld-user=mysql –without-embedded-server –with-server-suffix=-community –with-unix-socket-path=/tmp/mysql.sock

Make 

#編譯

Make install

#安裝

1.cp /usr/local/mysql/share/mysql/my-medium.cnf   /etc/my.cnf

修改mysql配置檔案

1.[client]

default-character-set=utf8

#客戶端字符集


#連線字符集

2.[ mysqld]

character-set-server = utf8

#伺服器字符集wwww

#資料庫字符集

collation-server = utf8_general_ci

#伺服器,庫,表的校驗字符集

#default-storage-engine=innodb

#把預設的表引擎改為innodb

生成MySQL配置檔案

 Useradd mysql

 Setfacl m u:mysql:rwx R /usr/local/mysql

 Setfacl m d:u:mysql:rwx R /usr/local/mysql

 acl來讓mysql使用者對/usr/local/mysql有所有許可權

/usr/local/mysql/bin/mysql_install_db –user=mysql

 建立資料庫授權表

啟動MySQL服務

1.用原本原始碼的方式去使用和啟動mysql

/usr/local/mysql/bin/mysqld_safe –user=mysql &

2.重啟以後還要生效:

Vi /etc/rc.local

/usr/local/mysql/bin/mysqld_safe –user=mysql &

4./usr/local/mysql/bin/mysqladmin -uroot password kkk  

#mysql使用者root加密碼.密碼為kkk

 /usr/local/mysql/bin/mysql -u root -pkkk test 

mysql>show databases;

mysql>use test

mysql>show tables;

#進入mysql以後用set來改密碼.

 mysql> exit

登入MySQL客戶端控制檯設定指定root密碼

 

 

5. 編譯安裝PHPFastCGI模式)

tar zxvf php-5.2.14.tar.gz
gzip -cd php-5.2.14-fpm-0.5.14.diff.gz | patch -d php-5.2.14 -p1
#解壓並打補丁,讓php支援fpm來方便管理php-cgi程式

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-iconv-dir=/usr/local –with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib –with-libxml-dir=/usr –enable-xml –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-fpm –enable-force-cgi-redirect –enable-mbstring –with-mcrypt –with-gd –enable-gd-native-ttf –with-openssl –with-mhash –enable-pcntl –enable-sockets –with-ldap –with-ldap-sasl –with-xmlrpc –enable-zip –enable-soap
make ZEND_EXTRA_LIBS=`-liconv`
make install
cp php.ini-dist /usr/local/php/etc/php.ini
cd ../

6.準備編譯安裝PHP5擴充套件模組

tar zxvf memcache-2.2.5.tgz
cd memcache-2.2.5/
/usr/local/php/bin/phpize
./configure –with-php-config=/usr/local/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/php/bin/phpize
./configure –enable-eaccelerator=shared –with-php-config=/usr/local/php/bin/php-config
make
make install
cd ../

tar zxvf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2/
/usr/local/php/bin/phpize
./configure –with-php-config=/usr/local/php/bin/php-config –with-pdo-mysql=/usr/local/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/php/bin/phpize
./configure –with-php-config=/usr/local/php/bin/php-config
make
make install
cd ../

 

7. 修改php.ini檔案,php模組生效

cp /lnmp/php-5.2.14/php.ini-dist /usr/local/php/etc/php.ini

vi php.ini

extension_dir = “/usr/local/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檔案型別錯誤解析漏洞

 

8. php.ini配置eAccelerator加速PHP

mkdir -p /usr/local/eaccelerator_cache

#準備eaccelerator快取目錄

 

Vi php.ini

[eaccelerator]
zend_extension=”/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so”
eaccelerator.shm_size=”64″
eaccelerator.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″

 

9.準備php-cginginx程式執行者使用者

Useradd nginx

 

10. 建立php-fpm配置檔案 php-fpm.conf

vi /usr/local/php/etc/php-fpm.conf

0

#0改成1,頁面上會輸出錯誤日誌

Unix user of processes
      nginx

      Unix group of processes
      nginx

 128
#最大子程式數128,如果記憶體小於2G,則64個最佳

65535
# Set open file desc rlimit,同時開啟的檔案數,linux系統允許同時開啟的檔案數為1024,修改linux系統中允許同時開啟的檔案,ulimit -SHn 65535,而且這個引數重啟後還能生效,加到 /etc/profile全域性配置檔案的最後,開機就會生效,

ulimit -a檢視open files 65535

1024
#最大請求數, How much requests each process should execute before respawn.一個子程式能夠回應1042個請求

 

11. 啟動php-cgi(fastcgi)程式,監聽127.0.0.19000埠,程式數為128(如果伺服器記憶體小於3GB,可以只開啟64個程式),使用者為nginx

/usr/local/php/sbin/php-fpm start

#啟動php-cgi

/usr/local/php/sbin/php-fpm reload

#重新載入配置檔案

/usr/local/php/sbin/php-fpm stop

#關閉php-fpm,此時nginx肯定不上php

 

12. 安裝Nginx所需的pcre

tar zxvf pcre-8.10.tar.gz
cd pcre-8.10/
./configure
make && make install
cd ../

 

13. 安裝Nginx

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

 

14. 修改Nginx配置檔案

vi /usr/local/nginx/conf/nginx.conf

user  nginx nginx;

worker_processes 8;

#相當於cpu個數

error_log  logs/nginx_error.log 

pid        /usr/local/nginx/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process. 
worker_rlimit_nofile 65535;

events 
{
  use epoll;
  worker_connections 65535;
}

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 65;

  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
  {
    listen       80;
    server_name  blog.s135.com;
    index index.html index.htm index.php;
    root  /data0/htdocs/blog;

    #limit_conn   crawler  20;    
                             
    location ~ .*.(php|php5)?$
    {      
      #fastcgi_pass  unix:/tmp/php-cgi.sock;
      fastcgi_pass  127.0.0.1:9000;
      fastcgi_index index.php;

   fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
      include fastcgi_params;
    }
    
    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  /data1/logs/access.log  access;
      }
}

 

15. /usr/local/nginx/conf/目錄中fastcgi_params檔案新增

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;

 

16.配置開機啟動nginx,php-fpm,ulimit

1)nginx

Vi /etc/rc.local

/usr/local/nginx/sbin/nginx

2)php-fpm

Vi /etc/rc.local

/usr/local/php/sbin/php-fpm start

3)ulimit

Vi /etc/profile

Ulimit -SHn 65535

 

17.檢查nginx配置檔案語句錯誤

/usr/local/nginx/sbin/nginx -t

 

18.平滑重啟nginx程式

1)Pkill -HUP nginx

2)kill -HUP `pgrep -uroot nginx`

3)/usr/local/nginx/sbin/nginx -s reload

 

(注意此處開啟cgi  /usr/local/php/sbin/php-fpm start)




20.配置nginx虛擬主機

Vi /usr/local/nginx/conf/nginx.conf

==èwww.baidu.com公司網站

server
  {
    listen       80;
    server_name  www.baidu.com;
    index index.html index.php index.htm;
    root  /web/baidu;

    location ~ .*.(php|php5)?$
    {
      fastcgi_pass  127.0.0.1:9000;
      fastcgi_index index.php;

   fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
      include fastcgi_params;
    }
    
    location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
    {
      expires      30d;
    }
#設定圖片在客戶端快取時間為30days
    location ~ .*.(js|css)?$
    {
      expires      1h;
    }
#設定jscss檔案在客戶端的快取時間為1hour
    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  logs/access.log  access;

#自定義日誌區域
   }

==èwww.sina.com公司網站

 

server
  {
    listen       80;
    server_name  www.sina.com;
    index index.html index.php index.htm;
    root  /web/baidu;

    location ~ .*.(php|php5)?$
    {
      fastcgi_pass  127.0.0.1:9000;
      fastcgi_index index.php;

   fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
      include fastcgi_params;
    }
    
    location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
    {
      expires      30d;
    }
#設定圖片在客戶端快取時間為30days
    location ~ .*.(js|css)?$
    {
      expires      1h;
    }
#設定jscss檔案在客戶端的快取時間為1hour
    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  logs/access.log  access;

#自定義日誌區域
   }

最後在客戶端測試虛擬主機www.baidu.comwww.sina.com兩家公司網站




其他模組安裝部分(環境不同 僅供參考)

 

TTsevser 

(參考網址 http://www.cnblogs.com/kudosharry/articles/2261924.html

entos 5.5 下安裝Tokyo 資料庫tokyocabinet-1.4.47 和 網路介面tokyotyrant-1.1.41

需求:

  實現一個高效能類似memcached 記憶體快取,並可以持續化資料。

下載:

wget http://fallabs.com/tokyocabinet/tokyocabinet-1.4.47.tar.gz

wget http://fallabs.com/tokyotyrant/tokyotyrant-1.1.41.tar.gz

 

更新庫:

yum install bzip2-devel

安裝:

tar -zxvf tokyocabinet-1.4.47.tar.gz   && cd tokyocabinet-1.4.47 && ./configure –prefix=/home/tc  && make && make install

tar -zxvf tokyotyrant-1.1.41.tar.gz   && cd tokyotyrant-1.1.41 && ./configure –prefix=/home/tt –with-tc=/home/tc  && make && make install 

軟連結下庫:

ln -s /home/tc/lib/libtokyocabinet.so.9 /lib/libtokyocabinet.so.9

啟動:(mkdir /ttserver)

   cd /home/tt/bin/

  ./ttserver

  或:

   /home/tt/bin/ttserver -host 127.0.0.1 -port 1978 -thnum 8 -dmn -pid /ttserver/ttserver.pid -log /ttserver/ttserver.log -le -ulog /ttserver/ -ulim 128m -sid 1 -rts /ttserver/ttserver.rts /ttserver/database.tch

 

 

測試命令:

 儲存:

  curl -X PUT http://127.0.0.1:11211/my_key -d “this is value” 

 讀取:

  curl http://127.0.0.1:11211/my_key 

 刪除:

  curl -X DELETE http://127.0.0.1:11211/my_key

 

安裝php擴充套件 tokyo_tyrant

Webserver 相應目錄

–with-tokyo-tyrant   安裝目錄 相應改動

wget http://pecl.php.net/get/tokyo_tyrant-0.6.0.tgz
tar zxvf tokyo_tyrant-0.6.0.tgz
cd tokyo_tyrant-0.6.0
/usr/local/webserver/php/bin/phpize
./configure –with-php-config=/usr/local/webserver/php/bin/php-config –with-tokyo-tyrant=/usr/local/webserver/tt/ –with-tokyo-cabinet-dir=/usr/local/webserver/tc/
make
cd modules
cp tokyo_tyrant.so /usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/


vi /usr/local/webserver/php/etc/php.ini
extension = tokyo_tyrant.so記得重啟

 

 

Memcached 

http://www.cnblogs.com/czh-liyu/archive/2010/04/27/1722084.html

http://blog.johntechinfo.com/technology/264

本文轉自 linuxzkq 51CTO部落格,原文連結:http://blog.51cto.com/linuxzkq/1583401