Varnish+nginx+mysql+php 环境搭建(二) 转载(lamppr)

二.) 安装MYSQL
安装mysql-5.0.45.tar.gz, 下面是总体的编译文件
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
允许使用汇编模式(优化性能)

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

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

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

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

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

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

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

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

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

[xxxxx@xxxxx.com]#tar zxvf php-5.2.4.tar.gz
[xxxxx@xxxxx.com]#cd php-5.2.4/
[xxxxx@xxxxx.com]#./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

[xxxxx@xxxxx.com]#cp php.ini-dist /usr/local/php/etc/php.ini
[xxxxx@xxxxx.com]#cd ../

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

4.自动修改:若嫌手工修改麻烦,可执行以下shell命令,自动完成对php.ini文件的修改:
[xxxxx@xxxxx.com]sed -i ’s#extension_dir = “./”#extension_dir = “/usr/local/php/lib/php/extensions/no-debug-non-zts555-55553/”\nextension = “memcache.so”\nextension = “gd.so”\n#’ /usr/local/php/etc/php.ini

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

[xxxxx@xxxxx.com]#cd php-5.2.4/pcntl
[xxxxx@xxxxx.com]#/usr/local/php/bin/phpize
[xxxxx@xxxxx.com]#./configure –with-php-config=/usr/local/php/bin/php-config
[xxxxx@xxxxx.com]#make && make install
[xxxxx@xxxxx.com]#cd http://www.cnblogs.com/../

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

利用 Memcached 处理实时数据读写;MySQL是影响性能的最大瓶颈,可以用一台MySQL主库(只写)+多台MySQL辅库(只读)的主辅库集群来解决。另外,访问计数等实时性很强的东西用Memcache做缓存。

[xxxxx@xxxxx.com]#tar zxvf memcache-2.2.1.tgz
[xxxxx@xxxxx.com]#cd memcache-2.2.1/
[xxxxx@xxxxx.com]#/usr/local/php/bin/phpize
[xxxxx@xxxxx.com]#./configure –with-php-config=/usr/local/php/bin/php-config
[xxxxx@xxxxx.com]#make -j 50
[xxxxx@xxxxx.com]#make install

安装支持MYSQL PDO驱动

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

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

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

[xxxxx@xxxxx.com]#cp spawn-fcgi /usr/local//php/bin
[xxxxx@xxxxx.com]#chmod +x /usr/local/php/bin/spawn-fcgi

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

/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.设定开机启动

[xxxxx@xxxxx.com]#echo “/usr/local/mysql/share/mysql/mysql.server start” >> /etc/rc.local
[xxxxx@xxxxx.com]#echo “/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf” >> /etc/rc.local
[xxxxx@xxxxx.com]#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

原文地址:https://www.cnblogs.com/mashuaimama/p/2441986.html