Varnish nginx php(FastCGI) MYSQL5 MenCache MenCachedb(2)

2019-06-22 02:19 来源:未知

二.) 安装MYSQL
安装mysql-5.0.45.tar.gz, 下面是总体的编译文件

安装步骤:
  (系统要求:Linux 2.6 内核,本文中的Linux操作系统为CentOS 4.4)

  1. -static  13%
       --with-client-ldflags=-all-static
       --with-mysqld-ldflags=-all-static
    静态链接提高13%性能

  2. -pgcc  1%
       CFLAGS="-O3 -mpentiumpro -mstack-align-double" CXX=gcc
         CXXFLAGS="-O3 -mpentiumpro -mstack-align-double
         -felide-constructors -fno-exceptions -fno-rtti"
    如果是Inter处理器,使用pgcc提高1%性能

  3. Unix Socket  7.5%
       --with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock
    使用unix套接字链接提高7.5%性能,所以在Windows下mysql性能肯定不如unix下面

  4. --enable-assembler
    允许使用汇编模式(优化性能)

  一、获取相关开源程序:
  1、下载程序源码包到当前目录:
  本文中提到的所有开源软件为截止到2007年11月25日的最新稳定版。我将它们打了两个压缩包。

[root@localhost]#tar zxvf mysql-5.0.45.tar.gz
[root@localhost]#./configure --prefix=/usr/local/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
[root@localhost]#make -j 50 && make install
[root@localhost]#groupadd mysql           
[root@localhost]#useradd -g mysql mysql       
[root@localhost]#bin/mysql_install_db --user=mysql     
[root@localhost]#chown -R root  .         
[root@localhost]#chown -R mysql data       
[root@localhost]#chgrp -R mysql .       
[root@localhost]#bin/mysqld_safe --user=mysql &      
[root@localhost]#cd bin         
[root@localhost]#/usr/local/mysql/share/mysql/mysql.server stop    
[root@localhost]#cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysql
[root@localhost]#chmod 755 /etc/init.d/mysql
[root@localhost]#chkconfig --level 345 mysql on

  第一个压缩包:nginx-php-1.zip
  下载地址:http://ishare.iask.sina.com.cn/cgi-bin/fileid.cgi?fileid=2746375


  第二个压缩包:nginx-php-2.zip
  下载地址:http://ishare.iask.sina.com.cn/cgi-bin/fileid.cgi?fileid=2746370

三、)安装PHP 5.2.5(FastCGI模式)
1、编译安装PHP 5.2.5所需的支持库:

  附:各开源软件单独下载地址(如果下载了以上两个压缩包,则无需下载以下软件):
  http://down.s135.com/linux/nginx-php/ (登录用户名、密码均为blog.s135.com)

[root@localhost]#tar zxvf libiconv-1.11.tar.gz
[root@localhost]#cd libiconv-1.11/
[root@localhost]#./configure --prefix=/usr/local/webserver/lib/libiconv
[root@localhost]#make && make install
[root@localhost]#cd ../

  2、解压缩:

[root@localhost]#tar zxvf freetype-2.3.5.tar.gz
[root@localhost]#cd freetype-2.3.5/
[root@localhost]#./configure --prefix=/usr/local/webserver/lib/freetype
[root@localhost]#make && make install
[root@localhost]#cd ../

mkdir -p /data0/software
cd /data0/software
unzip nginx-php-1.zip
unzip nginx-php-2.zip
cd /data0/software/nginx-php

[root@localhost]#tar zxvf libpng-1.2.20.tar.gz
[root@localhost]#cd libpng-1.2.20/
[root@localhost]#./configure
[root@localhost]#make && make install
[root@localhost]#cd ../


[root@localhost]#tar zxvf jpegsrc.v6b.tar.gz
[root@localhost]#cd jpeg-6b/
[root@localhost]#./configure --enable-static --enable-shared
[root@localhost]#make && make install
[root@localhost]#cd ../

  二、安装PHP 5.2.5(FastCGI模式)
  1、编译安装PHP 5.2.5所需的支持库:

t[root@localhost]#ar zxvf gd-2.0.35.tar.gz
[root@localhost]#cd gd-2.0.35/
[root@localhost]#./configure --prefix=/usr/local/webserver/lib/gd --with-freetype=/usr/local/webserver/lib/freetype --with-jpeg --with-png
[root@localhost]#make
[root@localhost]#make install
[root@localhost]#cd ../

tar zxvf libiconv-1.11.tar.gz
cd libiconv-1.11/
./configure --prefix=/usr/local
make
make install
cd ../

[root@localhost]#tar zxvf libxml2-sources-2.6.30.tar.gz
[root@localhost]#cd libxml2-2.6.30/
[root@localhost]#./configure --prefix=/usr/local/webserver/lib/libxml
[root@localhost]#make && make install
[root@localhost]#cd ../

tar zxvf freetype-2.3.5.tar.gz
cd freetype-2.3.5/
./configure
make
make install
cd ../


tar zxvf libpng-1.2.20.tar.gz
cd libpng-1.2.20/
./configure
make
make install
cd ../

2、编译安装PHP(FastCGI模式)

tar zxvf jpegsrc.v6b.tar.gz
cd jpeg-6b/
./configure --enable-static --enable-shared
make
make install
make install-lib
cd ../

[root@localhost]#tar zxvf php-5.2.4.tar.gz
[root@localhost]#cd php-5.2.4/
[root@localhost]#./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --enable-ftp --with-config-file-path=/usr/local/php --enable-zip --with-zlib --with-curl --without-iconv --with-iconv=/usr/local/lib --with-libxml-dir=/usr --enable-xml --with-xmlrpc --enable-mbregex-backtrack --with-gettext --with-gd=/usr/lib --enable-gd-native-ttf --with-ttf --enable-gd-jis-conv --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local/php/lib/freetype --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-force-cgi-redirect --enable-dom --enable-safe-mode --enable-discard-path --disable-debug --disable-rpath  --enable-bcmath --enable-shmop --enable-sysvsem --with-ldap --enable-sockets --enable-soap --enable-inline-optimization --enable-mbstring=all --with-ming=/usr --with-pdo-sqlite --enable-pdo --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config

#----If your system was install libxml2, you do not need to install it.----
#tar zxvf libxml2-2.6.30.tar.gz
#cd libxml2-2.6.30/
#./configure
#make
#install
#cd ../

[root@localhost]#cp php.ini-dist /usr/local/php/etc/php.ini
[root@localhost]#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 http://www.cnblogs.com/


tar zxvf mhash-0.9.9.tar.gz
cd mhash-0.9.9/
./configure
make
make install
cd ../

3.修改php.ini文件
  手工修改:查找/usr/local/php/etc/php.ini中的extension_dir = "./"
  修改为extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"
  并在此行后增加以下几行,然后保存:
  extension = "memcache.so"
  extension = "gd.so"

cp /usr/local/lib/libmcrypt.* /usr/lib
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2

4.自动修改:若嫌手工修改麻烦,可执行以下Shell命令,自动完成对php.ini文件的修改:
[root@localhost]sed -i 's#extension_dir = "./"#extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"nextension = "memcache.so"nextension = "gd.so"n#' /usr/local/php/etc/php.ini

tar zxvf mcrypt-2.6.6.tar.gz
cd mcrypt-2.6.6/
./configure
make
make install
cd ../



5.附:编译PHP之后,为PHP添加扩展的方法。(本步骤可选)

  2、编译安装MySQL 5.0.45

[root@localhost]#cd php-5.2.4/pcntl
[root@localhost]#/usr/local/php/bin/phpize
[root@localhost]#./configure --with-php-config=/usr/local/php/bin/php-config
[root@localhost]#make && make install
[root@localhost]#cd ../../../

/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
tar zxvf mysql-5.0.45.tar.gz
cd mysql-5.0.45
./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
chmod w /usr/local/webserver/mysql
chown -R mysql:mysql /usr/local/webserver/mysql
cp support-files/my-medium.cnf /usr/local/webserver/mysql/my.cnf
cd ../

[root@localhost]#cd php-5.2.5/ext/gd/     
[root@localhost]#/usr/local/php/bin/phpize      
[root@localhost]#./configure --with-jpeg-dir --with-png-dir --with-zlib-dir --with-ttf --with-freetype-dir --with-php-config=/usr/local/php/bin/php-config          
[root@localhost]#make -j 50       
[root@localhost]#make install 


利用 Memcached 处理实时数据读写;MySQL是影响性能的最大瓶颈,可以用一台MySQL主库(只写) 多台MySQL辅库(只读)的主辅库集群来解决。另外,访问计数等实时性很强的东西用Memcache做缓存。 
     
[root@localhost]#tar zxvf memcache-2.2.1.tgz     
[root@localhost]#cd memcache-2.2.1/      
[root@localhost]#/usr/local/php/bin/phpize     
[root@localhost]#./configure --with-php-config=/usr/local/php/bin/php-config 
[root@localhost]#make -j 50       
[root@localhost]#make install 
  
安装支持MYSQL PDO驱动

  附:以下为附加步骤,如果你想在这台服务器上运行MySQL数据库,则执行以下两步。如果你只是希望让PHP支持MySQL扩展库,能够连接其他服务器上的MySQL数据库,那么,以下两步无需执行。
  ①、以mysql用户帐号的身份建立数据表:

[root@localhost]#tar xzvf PDO-1[1].0.3.tgz                        
[root@localhost]#cd PDO-1.0.3/                                     
[root@localhost]#/usr/local/php/bin/phpize                          
[root@localhost]#./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql/   
[root@localhost]#make -j 50        
[root@localhost]#make install 

/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(最后的&表示在后台运行)

6.安装lighttpd中附带的spawn-fcgi,用来启动php-cgi

/bin/sh /usr/local/webserver/mysql/bin/mysqld_safe --defaults-file=/usr/local/webserver/mysql/my.cnf &

 注:压缩包中的spawn-fcgi程序为已经编译成二进制的版本。


[root@localhost]#cp spawn-fcgi /usr/local//php/bin
[root@localhost]#chmod x /usr/local/php/bin/spawn-fcgi 

  3、编译安装PHP(FastCGI模式)

7、启动php-cgi进程,监听127.0.0.1的10080端口,进程数为250(如果服务器内存小于3GB,可以只开启25个进程),用户为www:

tar zxvf php-5.2.5.tar.gz
cd php-5.2.5/
./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
sed -i 's#-lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt#& -liconv#' Makefile
make
make install
cp php.ini-dist /usr/local/webserver/php/etc/php.ini
cd ../

/usr/local/php/bin/spawn-fcgi -a 127.0.0.1 -p 10080 -C 250 -u www -f /usr/local/php/bin/php-cgi


8.设定开机启动

  4、编译安装PHP5扩展模块

[root@localhost]#echo "/usr/local/mysql/share/mysql/mysql.server start" >> /etc/rc.local
[root@localhost]#echo "/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf" >> /etc/rc.local
[root@localhost]#echo "/usr/local/php/bin/spawn-fcgi -a 127.0.0.1 -p 10080 -C 250 -u www -f /usr/local/php/bin/php-cgi" >> /etc/rc.local

tar zxvf memcache-2.2.1.tgz
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 php-5.2.5/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 http://www.cnblogs.com/../


  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 /data0/vshare/htdocs
chmod w /data0/vshare/htdocs
chown -R www:www /data0/vshare/htdocs

  7、安装lighttpd中附带的spawn-fcgi,用来启动php-cgi
  注:压缩包中的spawn-fcgi程序为已经编译成二进制的版本。

cp 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.5.33
  1、安装Nginx所需的pcre库:

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

  2、安装Nginx

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

  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

  输入以下内容:

引用

TAG标签:
版权声明:本文由美洲杯赌球发布于计算机教程,转载请注明出处:Varnish nginx php(FastCGI) MYSQL5 MenCache MenCachedb(2)