欢迎光临
一直在努力

LNMP环境编译

前提:
1. 修改 SSH 连接显示字符集
cat > /etc/sysconfig/i18n<<EOF
LANG=”zh_CN.GB18030″
LANGUAGE=”zh_CN.GB18030:zh_CN.GB2312:zh_CN”
SUPPORTED=”zh_CN.GB18030:zh_CN:zh:en_US.UTF-8:en_US:en”
SYSFONT=”lat0-sun16″
EOF
source /etc/sysconfig/i18n

#Disable SeLinux
sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g’ /etc/selinux/config

2. 设置时区
#Set timezone
rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

yum install -y ntp
ntpdate -u pool.ntp.org
date
加入定时同步

crontab -e
0 0 * * * ntpdate -u pool.ntp.org

3. 配置服务器 yum 国内更新源地址
yum -y install yum-fastestmirror

4. 卸载旧的安装包, 更新软件和安装依赖包
for packages in patch make gcc gcc-c++ gcc-g77 flex bison file libtool libtool-libs autoconf kernel-devel libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2 bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel vim-minimal nano fonts-chinese gettext gettext-devel ncurses-devel gmp-devel pspell-devel unzip libcap wget lsof;
do yum -y install $packages; done

5
cat >>/etc/security/limits.conf<<eof
* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
eof

cat >>/etc/sysctl.conf<<eof
fs.file-max=65535
eof

6

设置开机启动

# vi /etc/rc.local

写入:

ulimit -SHn 65535

编译安装LNMP平台,利用google-perftools 优化nginx的性能和提高mysql的并发链接。
1 #更新安装一些基本的组件库

for packages in patch make gcc gcc-c++ gcc-g77 flex bison file libtool libtool-libs autoconf kernel-devel libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2 bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel vim-minimal nano fonts-chinese gettext gettext-devel ncurses-devel gmp-devel pspell-devel unzip libcap wget lsof;
do yum -y install $packages; done

2 安装nginx

# wget http://nginx.org/download/nginx-1.4.4.tar.gz
# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.31.tar.gz
# wget https://gperftools.googlecode.com/files/gperftools-2.1.tar.gz
# wget http://download.savannah.gnu.org/releases/libunwind/libunwind-1.1.tar.gz

利用 TCMalloc 优化 nginx 性能

针对 64 位操作系统必须安装 libunwind 库

tar zxvf libunwind-1.1.tar.gz
cd libunwind-1.1/
CFLAGS=-fPIC ./configure
make CFLAGS=-fPIC
make CFLAGS=-fPIC install
cd ../

安装 google-perftools 优化

tar zxvf gperftools-2.1.tar.gz
cd gperftools-2.0/
./configure
make && make install
echo “/usr/local/lib” > /etc/ld.so.conf.d/usr_local_lib.conf
/sbin/ldconfig
cd ..

安装 pcre 使 nginx 支持 URL 重写

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

编译安装 nginx

tar zxvf nginx-1.2.7.tar.gz
cd nginx-1.2.7
./configure –prefix=/usr/local/nginx –with-google_perftools_module –user=www –group=www –with-http_stub_status_module –with-http_ssl_module –with-http_gzip_static_module –with-http_flv_module –with-pcre=/root/lnmp0.9-full/pcre-8.31 –with-ipv6
make && make install
cd ../

mkdir /tmp/tcmalloc
chmod 0777 /tmp/tcmalloc

添加用户和组

/usr/sbin/groupadd www
/usr/sbin/useradd -g www www

配置 nginx.conf
mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.old

cat > /usr/local/nginx/conf/nginx.conf<<EOF
user www www;

worker_processes 4;

worker_cpu_affinity 0001 0100 1000 0010;

error_log logs/error.log;

pid logs/nginx.pid;

worker_rlimit_nofile 65535;

google_perftools_profiles /tmp/tcmalloc;

events {

worker_connections 65535;

}

http {

#include deny_ips.conf;

include mime.types;

default_type application/octet-stream;

server_tokens off;

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;

server_names_hash_bucket_size 128;

client_header_buffer_size 32k;

large_client_header_buffers 4 32k;

client_max_body_size 50m;

sendfile on;

tcp_nopush on;

tcp_nodelay on;

keepalive_timeout 60;

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 256k;

fastcgi_intercept_errors on;

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;

include vhost/*.conf;

}
EOF

(ps:
fastcgi_connect_timeout指定连接到后端FastCGI的超时时间。
fastcgi_send_timeout指定向FastCGI传送请求的超时时间,这个值是已经完成两次握手后向FastCGI传送请求的超时时间。
fastcgi_read_timeout指定接收FastCGI应答的超时时间,这个值是已经完成两次握手后接收FastCGI应答的超时时间。
fastcgi_buffer_size用于指定读取FastCGI应答第一部分需要用多大的缓冲区,这个值表示将使用1个64KB的缓冲区读取应答的第一部分(应答头),可以设置为fastcgi_buffers选项指定的缓冲区大小。
fastcgi_buffers指定本地需要用多少和多大的缓冲区来缓冲FastCGI的应答请求。如果一个PHP脚本所产生的页面大小为256KB,那么会为其分配4个64KB的缓冲区来缓存;如果页面大小大于256KB,那么大于256KB的部分会缓存到fastcgi_temp指定的路径中,但是这并不是好方法,因为内存中的数据处理速度要快于硬盘。一般这个值应该为站点中PHP脚本所产生的页面大小的中间值,如果站点大部分脚本所产生的页面大小为256KB,那么可以把这个值设置为“16 16k”、“4 64k”等。
fastcgi_busy_buffers_size的默认值是fastcgi_buffers的两倍。
fastcgi_temp_file_write_size表示在写入缓存文件时使用多大的数据块,默认值是fastcgi_buffers的两倍。
fastcgi_cache表示开启FastCGI缓存并为其指定一个名称。开启缓存非常有用,可以有效降低CPU的负载,并且防止502错误的发生,但是开启缓存也会引起很多问题,要视具体情况而定。
fastcgi_cache_valid、fastcgi用来指定应答代码的缓存时间,实例中的值表示将200和302应答缓存一个小时,将301应答缓存1天,其他应答均缓存1分钟。
)
启动 nginx

ulimit -SHn 65535

/usr/local/nginx/sbin/nginx

验证google-perftools是否已经正常加载 命令:

lsof -n | grep tcmalloc

显示如下:

nginx 2395 nobody 9w REG 8,8 0 1599440 /tmp/tcmalloc.2395

nginx 2396 nobody 11w REG 8,8 0 1599443 /tmp/tcmalloc.2396

nginx 2397 nobody 13w REG 8,8 0 1599441 /tmp/tcmalloc.2397

nginx 2398 nobody 15w REG 8,8 0 1599442 /tmp/tcmalloc.2398

至此,利用TCMalloc优化Nginx的操作完成。

优化 nginx 内核

cat >> /etc/sysctl.conf<<EOF
net.ipv4.tcp_max_tw_buckets = 6000

net.ipv4.ip_local_port_range = 1024 65000

net.ipv4.tcp_tw_recycle = 1

net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_syncookies = 1

net.core.somaxconn = 262144

net.core.netdev_max_backlog = 262144

net.ipv4.tcp_max_orphans = 262144

net.ipv4.tcp_max_syn_backlog = 262144

net.ipv4.tcp_synack_retries = 1

net.ipv4.tcp_syn_retries = 1

net.ipv4.tcp_fin_timeout = 1

net.ipv4.tcp_keepalive_time = 30

EOF

刷新配置

# /sbin/sysctl -p

添加 nginx 的系统服务

vi /etc/init.d/nginx
#!/bin/sh
# Comments to support chkconfig on RedHat Linux
# chkconfig: 2345 65 37
# description: A nginx daemon.

set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC=”nginx daemon”
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
SCRIPTNAME=/etc/init.d/$NAME

# If the daemon file is not found, terminate the script.
test -x $DAEMON || exit 0

d_test() {
$DAEMON -t
}
d_start() {
$DAEMON || echo -n ” already running”
}
d_stop() {
$DAEMON -s quit || echo -n ” not running”
}
d_reload() {
$DAEMON -s reload || echo -n ” could not reload”
}

case “$1″ in
test)
d_test
echo “.”
;;
start)
echo -n “Starting $DESC: $NAME”
d_start
echo “.”
;;
stop)
echo -n “Stopping $DESC: $NAME”
d_stop
echo “.”
;;
reload)
echo -n “Reloading $DESC configuration…”
d_reload
echo “reloaded.”
;;
restart)
echo -n “Restarting $DESC: $NAME”
d_stop
# Sleep for two seconds before starting again, this should give the
# Nginx daemon some time to perform a graceful stop.
sleep 2
d_start
echo “.”
;;
*)
echo “Usage: $SCRIPTNAME {test|start|stop|restart|reload}” >&2
exit 3
;;
esac

exit $?

注册 nginx 服务

chmod +x /etc/init.d/nginx

chkconfig –add nginx

chkconfig –level 2345 nginx on

chkconfig –list nginx
相关 nginx 命令

检测 nginx 配置

# service nginx test

启动

# service nginx start

关闭

# service nginx stop

重启

# service nginx restart

重载配置

# service nginx reload

添加各站点配置目录

cd /usr/local/nginx/conf

mkdir vhost
配置 localhost 站点

cat > vhost/localhost.conf <<EOF
server

{

listen 80;

server_name localhost;

index index.html index.php;

root /var/www/html/;

#limit_conn crawler 20;

location ~ .*\.(php|php5)?$

{

#fastcgi_pass unix:/tmp/php-cgi.sock;

#upload filesize limit

#client_max_body_size 10m;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

include fastcgi.conf;

}

}
EOF

3 安装mysql
wget http://downloads.skysql.com/archives/mysql-5.1/mysql-5.1.72-linux-i686-glibc23.tar.gz
groupadd mysql
useradd -s /sbin/nologin -M -g mysql mysql
cd mysql-5.1.60
./configure –prefix=/usr/local/mysql –with-extra-charsets=complex –enable-thread-safe-client –enable-assembler –with-mysqld-ldflags=-all-static –with-charset=utf8 –enable-thread-safe-client –with-big-tables –with-readline –with-ssl –with-embedded-server –enable-local-infile –with-plugins=innobase
make && make install
chgrp -R mysql /usr/local/mysql/.
cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf
sed -i ‘s/skip-locking/skip-external-locking/g’ /etc/my.cnf
sed -i ‘s:#innodb:innodb:g’ /etc/my.cnf
/usr/local/mysql/bin/mysql_install_db –user=mysql
cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysqld
chmod a+x /etc/init.d/mysqld

cat > /etc/ld.so.conf.d/mysql.conf<<EOF
/usr/local/mysql/lib/mysql
/usr/local/lib
EOF
ldconfig

/usr/local/mysql/bin/mysqladmin -u root password 123456
ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
ln -s /usr/local/mysql/include/mysql /usr/include/mysql

添加并发优化

# vi /usr/local/mysql/bin/mysqld_safe

在 executing mysqld_safe 的下一行,加上:

export LD_PRELOAD=/usr/local/lib/libtcmalloc.so

启动 mysql:

# service mysqld restart

使用lsof命令查看tcmalloc是否起效:

# /usr/sbin/lsof -n | grep tcmalloc

如果发现以下信息,说明tcmalloc已经起效:

mysqld 10847 mysql mem REG 8,5 1203756 20484960 /usr/local/lib/libtcmalloc.so.0.0.0

4 安装php

wget http://cn2.php.net/distributions/php-5.4.21.tar.gz

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz

wget http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz

wget http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?modtime=1194463373&big_mirror=0

wget http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?modtime=1175740843&big_mirror=0

wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick-6.8.0-2.tar.gz

wget http://sourceforge.net/projects/imagemagick/files/old-sources/6.x/6.6/ImageMagick-6.6.9-10.tar.gz

wget http://pecl.php.net/get/imagick-3.1.0RC2.tgz

wget http://pecl.php.net/get/memcache-3.0.7.tgz

wget https://launchpad.net/libmemcached/1.0/1.0.10/+download/libmemcached-1.0.10.tar.gz

wget http://memcached.googlecode.com/files/memcached-1.4.15.tar.gz

wget http://pecl.php.net/get/memcached-2.1.0.tgz

wget https://github.com/eaccelerator/eaccelerator/tarball/master

wget https://github.com/downloads/libevent/libevent/libevent-2.0.20-stable.tar.gz

安装 php 相关的软件
tar zxvf libiconv-1.14.tar.gz

cd libiconv-1.14

./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
tar zxvf mcrypt-2.6.8.tar.gz

cd mcrypt-2.6.8/

/sbin/ldconfig

./configure

make && make install

cd ../

新建扩展配置目录

mkdir -p /usr/local/php/etc/php.d/

开始安装 PHP 5.4.21

tar xvzf php-5.4.21.tar.gz

cd php-5.4.21/

./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-pdo-mysql=/usr/local/mysql/ –with-iconv-dir=/usr/local –enable-fpm –disable-phar –with-fpm-user=www –with-fpm-group=www –with-pcre-regex –with-config-file-scan-dir=/usr/local/php/etc/php.d –with-zlib –with-bz2 –enable-calendar –with-curl –enable-dba –with-libxml-dir –enable-ftp –with-gd –with-jpeg-dir –with-png-dir –with-zlib-dir –with-freetype-dir –enable-gd-native-ttf –enable-gd-jis-conv –with-mhash –enable-mbstring –with-mcrypt –enable-pcntl –enable-xml –disable-rpath –enable-shmop –enable-sockets –enable-zip –enable-bcmath –enable-ipv6 –with-xmlrpc –enable-exif –enable-soap –enable-pdo –with-pdo-mysql –enable-sysvsem –enable-inline-optimization –with-curlwrappers
make ZEND_EXTRA_LIBS=’-liconv’

make test

make install

cp php.ini-production /usr/local/php/etc/php.ini
PATH=/usr/local/php/bin:$PATH

PATH=/usr/local/php/sbin:$PATH

开机启动 php-fpm

cp sapi/fpm/init.d.php-fpm.in /etc/init.d/php-fpm
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
chmod +x /etc/init.d/php-fpm
chkconfig –add php-fpm
chkconfig –level 2345 php-fpm on
chkconfig –list php-fpm
cd ../

关于php-fpm 的操作说明与添加系统服务
相关 php-fpm 命令
启动

# service php-fpm start

关闭

# service php-fpm stop

重启

# service php-fpm restart

重载配置

# service php-fpm reload

安装 PHP 扩展

服务器版 memcached
安装依赖包:

tar zxvf libevent-2.0.20-stable.tar.gz

cd libevent-2.0.20-stable

./configure

make && make install

cd ../

tar xvzf memcached-1.4.15.tar.gz

cd memcached-1.4.15

./configure –enable-64bit –with-libevent=/usr/local/libevent

make && make install

cd ../

检测是否安装成功:

ls -al /usr/local/bin/memcached

mkdir -p /var/run/memcached/

启动 memcached:

/usr/local/bin/memcached -d -m 128 -u root -l 192.168.1.217 -p 11212 -c 256 -P /var/run/memcached/memcached.pid

ps aux|grep memcached

关闭 memcached:

kill `cat /var/run/memcached/memcached.pid`

新建启动和关闭脚本并赋执行权限:

cp scripts/memcached.sysv /etc/init.d/memcached

chmod 755 /etc/init.d/memcached

修改配置:
vi /etc/init.d/memcached

修改:

PORT=11212

USER=root

OPTIONS=””

查找:

daemon memcached -d -p ….

修改为:

daemon /usr/local/bin/memcached -d -p ….

chown $USER /usr/local/bin/memcached

/usr/local/bin/memcached -d -p $PORT -u $USER -m $CACHESIZE -c $MAXCONN -P /var/run/memcache/memcached.pid $OPTIONS

添加到系统服务:

chkconfig –add memcached
chkconfig –level 2345 memcached on
chkconfig –list memcached

测试启动 检测 关闭:

service memcached start
ps aux|grep memcached
service memcached stop
安装php扩展版 memcached

依赖库:

tar zxvf libmemcached-1.0.10.tar.gz

cd libmemcached-1.0.10

./configure –prefix=/usr/local/libmemcached

make && make install

cd ../

安装 memcached

tar vxzf memcached-2.1.0.tgz

cd memcached-2.1.0

/usr/local/php/bin/phpize

./configure –enable-memcached –with-libmemcached-dir=/usr/local/libmemcached –with-php-config=/usr/local/php/bin/php-config

make && make install

cd ..

安装 memcache

tar zxvf memcache-3.0.7.tgz

cd memcache-3.0.7/

/usr/local/php/bin/phpize

./configure –prefix=/usr/local/memcache –enable-memcache –with-php-config=/usr/local/php/bin/php-config –with-zlib-dir

make && make install

cd ../

安装 eaccelerator 给 php 编译加速+缓存

wget https://github.com/eaccelerator/eaccelerator/tarball/master

mv master eaccelerator-eaccelerator-42067ac.tar.gz

tar zxvf eaccelerator-eaccelerator-42067ac.tar.gz

cd eaccelerator-eaccelerator-42067ac/

/usr/local/php/bin/phpize

./configure –enable-eaccelerator=shared –with-php-config=/usr/local/php/bin/php-config

make && make install

cd ../

新建目录:

mkdir /tmp/eaccelerator_cache

chmod 0777 /tmp/eaccelerator_cache

配置扩展

写入:
cat > /usr/local/php/etc/php.d/eaccelerator.ini<<EOF
[eaccelerator]
zend_extension=”/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/eaccelerator.so”
eaccelerator.shm_size=”20″
eaccelerator.cache_dir=”/tmp/eaccelerator_cache1″
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″
EOF


eaccelerator.shm_size=”32″
eAccelerator 可以使用的共享内存的数量 (以兆为单位) . “0″ 是指操作系统的默认值. 默认值是 “0″.可根据服务器的实际情况来调整,16,32,64,128都是可以的。
eaccelerator.cache_dir=”/tmp/eaccelerator_cache”
这个目录是给磁盘缓存使用. eAccelerator 在这里储存预先编译好的代码, 进程数据, 内容以及用户的自定义内容. 同样的数据也能被储存在共享内存中 (这样可以提高访问速度). 默认的设置是 “/tmp/eaccelerator”.
eaccelerator.enable=”1″
开启或关闭 eAccelerator。”1″ 为开启,”0″ 为关闭。默认值为 “1″。
eaccelerator.optimizer=”1″
启或关闭内部优化器,可以提升代码执行速度。”1″ 为开启,”0″ 为关闭。默认值为 “1″。
eaccelerator.check_mtime=”1″
打开或者关闭 PHP 的文件修改检查. “1″ 是指打开, “0″ 是指关闭. 如果您在修改以后重新编译 PHP 的文件,那么您应当设置为 “1″. 默认值是 “1″.
eaccelerator.debug=”0″
开启或关闭调试日志记录。”1″ 为开启,”0″ 为关闭。默认值为 “0″。会将缓存命中得记录写入日志。
eaccelerator.filter=””
判断哪些 PHP 文件必须缓存。您可以指定缓存和不缓存的文件类型(如 “*.php *.phtml”等)
如果参数以 “!” 开头,则匹配这些参数的文件被忽略缓存。默认值为 “”,即,所有 PHP 文件都将被缓存。
eaccelerator.shm_max=”0″
当使用 ” eaccelerator_put() ” 函数时禁止其向共享内存中存储过大的文件。该参数指定允许存储的最大值,单位:字节 (10240, 10K, 1M)。”0″ 为不限制。默认值为 “0″。
eaccelerator.shm_ttl=”0″
当 eAccelerator 获取新脚本的共享内存大小失败时,它将从共享内存中删除所有在最后 “shm_ttl” 秒内没有存取的脚本缓存。默认值为 “0″,即:不从共享内春中删除任何缓存文件。
eaccelerator.shm_prune_period=”0″
当 eAccelerator 获取新脚本的共享内存大小失败时,他将试图从共享内存中删除早于”shm_prune_period” 秒的缓存脚本。默认值为 “0″,即:不从共享内春中删除任何缓存文件。
eaccelerator.shm_only=”0″
允许或禁止将已编译脚本缓存在磁盘上。该选项对 session 数据和内容缓存无效。默认值为 “0″,即:使用磁盘和共享内存进行缓存。
eaccelerator.compress=”1″
允许或禁止压缩内容缓存。默认值为 “1″,即:允许压缩。
eaccelerator.compress_level=”9″
指定内容缓存的压缩等级。默认值为 “9″,为最高等级。
eaccelerator.keys = “disk_only”
eaccelerator.session = “disk_only”
eaccelerator.content = “disk_only”
设置内容缓存的存放的地方,可以设置为:
shm_and_disk 在共享缓存和硬盘(默认值)
shm 默认存在共享内存,如果共享内存已满或大小超过 “eaccelerator.shm_max” 的值,就存到硬盘
shm_only 只存放在共享内存
disk_only 只存放在硬盘
none 不缓存数据
eaccelerator.allowed_admin_path = “/var/www/html/21andy.com/eaccelerator”
这是控制面板的地址
安装包里有个control.php,你把它复制到网站的任意目录,可以用它查看和管理,这个必须指定,否则查看缓存内容的时候会出错

cat > /usr/local/php/etc/php.d/memcache.ini<<EOF
extension = “memcache.so”

memcache.chunk_size = 32768
EOF

cat > /usr/local/php/etc/php.d/memcached.ini<<EOF
extension = “memcached.so”
EOF
修改php配置:
sed -i ‘s/;cgi\.fix_pathinfo=1/cgi\.fix_pathinfo=0/g’ /usr/local/php/etc/php.ini
sed -i ‘s/; extension_dir = “ext”/extension_dir = “\/usr\/local\/php\/lib\/php\/extensions\/no-debug-non-zts-20100525\/”/g’ /usr/local/php/etc/php.ini
sed -i ‘s/allow_url_fopen = On/allow_url_fopen = Off/g’ /usr/local/php/etc/php.ini
sed -i ‘s/;open_basedir =/open_basedir = \/tmp\/:\/var\/www\//g’ /usr/local/php/etc/php.ini
sed -i ‘s/disable_functions =/disable_functions = exec,system,passthru,chroot,scandir,chgrp,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server/g’ /usr/local/php/etc/php.ini
sed -i ‘s/;date\.timezone =/date\.timezone = Asia\/Shanghai/g’ /usr/local/php/etc/php.ini

修改php-fpm配置
查找并修改:

以下为示例数值,按自己服务器实际性能配置:

pm.max_children = 50

pm.start_servers = 20

pm.min_spare_servers = 5

pm.max_spare_servers = 35

pm.max_requests = 10240

rlimit_files = 65535

pm.max_children:静态方式下开启的php-fpm进程数量。
pm.start_servers:动态方式下的起始php-fpm进程数量。
pm.min_spare_servers:动态方式下的最小php-fpm进程数量。
pm.max_spare_servers:动态方式下的最大php-fpm进程数量。

安装 redis和 php扩展
yum install tcl tcl-devel
wget https://redis.googlecode.com/files/redis-2.6.14.tar.gz
tar zxvf redis-2.6.14.tar.gz
cd redis-2.6.14
make
make test
mkdir -p /usr/local/redis/conf
mkdir -p /usr/local/redis/run
mkdir -p /usr/local/redis/db
cp redis.conf /usr/local/redis/conf/
cd src/
cp redis-benchmark redis-check-aof redis-check-dump redis-cli redis-server mkreleasehdr.sh /usr/local/redis/

编辑配置文件
vi /usr/local/redis/conf/redis.conf
daemonize yes
pidfile /usr/local/redis/run/redis.pid
dir /usr/local/redis/db
logfile /var/log/redis.log
cd /usr/local/redis
编辑启动脚本
vi start.sh
#!/bin/bash
/usr/local/redis/redis-server /usr/local/redis/conf/redis.conf

编辑停止脚本
vi stop.sh
#!/bin/bash
kill `cat /usr/local/redis/run/redis.pid`

chmod a+x /usr/local/redis/start.sh /usr/local/redis/stop.sh
chmod a+x /usr/local/redis/start.sh /usr/local/redis/stop.sh
/usr/local/redis/start.sh
netstat -ant |grep 6379
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN
验证
[root@www redis]# ./redis-cli
redis 127.0.0.1:6379> set key value
OK
redis 127.0.0.1:6379> get key
“value”
redis 127.0.0.1:6379>
php扩展的安装:
wget https://github.com/nicolasff/phpredis/archive/master.zip
mv master phpredis-master.zip
unzip phpredis-master.zip
cd phpredis-master

/usr/local/php/bin/phpize
Configuring for:
PHP Api Version: 20100412
Zend Module Api No: 20100525
Zend Extension Api No: 220100525

./configure –with-php-config=/usr/local/php/bin/php-config
make
make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/

cat > /usr/local/php/etc/php.d/redis.ini<<EOF
extension=redis.so
EOF

service php-fpm restart
/etc/init.d/nginx restart

未经允许不得转载:黑少博客 » LNMP环境编译

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

黑少博客

联系我们联系我们