/**

 author: 老炮

 date: 2014/5/10

*/

Centos6.4 + PHP5.5.11 + Mysql5.6.16 + Tnginx2.02 + Memcached1.4.17 + Redis2.2


1:准备工作


    1.1 配置网卡 - 确保能上网 (dhcp方式或static方式)


1.1.1 配置ifcfg-eth0文件

[root@localhost log]# vi /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0

TYPE=Ethernet

UUID=e4b2d65f-c9c7-4f51-bfc1-3d06e9f7122e

ONBOOT=yes

NM_CONTROLLED=yes

BOOTPROTO=dhcp

HWADDR=00:0C:29:41:92:54

IPV6INIT=yes

NAME="System eth0"


[root@localhost log]# vi /etc/sysconfig/network-scripts/ifcfg-lo

DEVICE=lo

IPADDR=127.0.0.1

NETMASK=255.0.0.0

NETWORK=127.0.0.0

# If you're having problems with gated making 127.0.0.0/8 a martian,

# you can change this to something else (255.255.255.255, for example)

BROADCAST=127.255.255.255

ONBOOT=yes

NAME=loopback


1.1.2 up eth0网卡

[root@localhost log]# ifconfig eth0 up


1.1.3 重启network服务

[root@localhost log]# service network restart


1.1.4 检查是否ping通过

[root@localhost ~]# ping g.cn


1.1.2 配置ifcfg-eth0文件

step1:Configure eth0 or em1

[root@localhost yum.repos.d]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0

HWADDR=00:1C:42:81:B8:CA

TYPE=Ethernet

UUID=1ada7958-46f9-4b3c-8171-ca6cd4a5e9ca

ONBOOT=yes

NM_CONTROLLED=yes

BOOTPROTO=none

IPV6INIT=no

USERCTL=no

PEERDNS=yes

IPADDR=192.168.1.141

NETMASK=255.255.255.0


step2: Configure Default Gateway

[root@localhost yum.repos.d]# vim /etc/sysconfig/network

NETWORKING=yes

HOSTNAME=141server

GATEWAY=192.168.1.1


step3:Configure DNS Server

[root@localhost yum.repos.d]# vim /etc/resolv.conf 

; generated by /sbin/dhclient-script

nameserver 8.8.8.8

nameserver 192.168.1.1


step4: Restart Network Interface

[root@localhost yum.repos.d]# service network restart

[root@localhost yum.repos.d]# ping centos.org

[root@localhost yum.repos.d]# nslookup centos.org


1.2 CentOS下为yum加入rpmForge源

http://pkgs.repoforge.org/rpmforge-release/

[root@localhost src]# wget -c http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm

[root@localhost src]# rpm -Uvh rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm

安装好后,到/etc/yum.repos.d目录下可以看到多了两个源文件:mirrors-rpmforge  rpmforge.repo

[root@localhost src]# cd /etc/yum.repos.d

[root@localhost yum.repos.d]# ls

CentOS-Base.repo       CentOS-Media.repo  mirrors-rpmforge         mirrors-rpmforge-testing

CentOS-Debuginfo.repo  CentOS-Vault.repo  mirrors-rpmforge-extras  rpmforge.repo


1.3 升级系统和安装相关的程序库

yum -y install yum-fastestmirror

yum -y update

yum -y install patch make gcc gcc-c++ gcc-g77 flex bison

yum -y install libtool libtool-libs kernel-devel autoconf

yum -y install libjpeg libjpeg-devel libpng libpng-devel

yum -y install freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel

yum -y install glib2 glib2-devel bzip2 diff*

yum -y install bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs

yum -y install e2fsprogs-devel krb5 krb5-devel libidn libidn-devel

yum -y install openssl openssl-devel vim-minimal

yum -y install fonts-chinese scim-chewing scim-pinyin scim-tables-chinese

yum -y install libcurl-devel openldap-devel


yum -y groupinstall "Development tools"  


1.4 PHP需要的库程序

[root@localhost src]# wget -c https://catlnmp.googlecode.com/files/libiconv-1.14.tar.gz

[root@localhost src]# tar xvzf libiconv-1.14.tar.gz

[root@localhost src]# cd libiconv-1.14

[root@localhost src]# ./configure --prefix=/usr/local --libdir=/usr/local/lib64

[root@localhost libiconv-1.14]# make

[root@localhost libiconv-1.14]# make install


[root@localhost src]# wget -c https://catlnmp.googlecode.com/files/libmcrypt-2.5.8.tar.gz

[root@localhost src]# tar xvzf libmcrypt-2.5.8.tar.gz 

[root@localhost src]# cd libmcrypt-2.5.8

[root@localhost libmcrypt-2.5.8]# ./configure --prefix=/usr/local --libdir=/usr/local/lib64

[root@localhost libmcrypt-2.5.8]# make && make install

[root@localhost libmcrypt-2.5.8]# /sbin/ldconfig

[root@localhost libmcrypt-2.5.8]# cd libltdl/

[root@localhost libltdl]# ./configure --enable-ltdl-install --libdir=/usr/local/lib64

[root@localhost libltdl]# make && make install

[root@localhost libltdl]# cd ../../


[root@localhost src]# wget -c http://catlnmp.googlecode.com/files/mhash-0.9.9.9.tar.gz

[root@localhost src]# tar xvzf mhash-0.9.9.9.tar.gz

[root@localhost src]# cd mhash-0.9.9.9

[root@localhost mhash-0.9.9.9]# ./configure --prefix=/usr/local --libdir=/usr/local/lib64

[root@localhost mhash-0.9.9.9]# make && make install


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


[root@localhost src]# wget -c wget http://catlnmp.googlecode.com/files/mcrypt-2.6.8.tar.gz

[root@localhost src]# tar xvzf mcrypt-2.6.8.tar.gz 

[root@localhost src]# cd mcrypt-2.6.8

[root@localhost mcrypt-2.6.8]# /sbin/ldconfig

[root@localhost mcrypt-2.6.8]# LD_LIBRARY_PATH=/usr/local/lib64 ./configure --prefix=/usr/local --libdir=/usr/local/lib64

[root@localhost mcrypt-2.6.8]# make && make install



2:开始安装MySQL


2.1 去除系统自带的MySQL

[root@localhost ~]# yum erase mysql-libs


2.2 安装依赖包

[root@localhost ~]# yum install cmake.x86_64

[root@localhost ~]# yum install ncurses-devel.x86_64

[root@localhost src]# tar zxvf mysql-5.6.16.tar.gz

[root@localhost src]# cd mysql-5.6.16

2.3 编译

[root@localhost mysql-5.6.16]# 

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

-DMYSQL_DATADIR=/usr/local/mysql/data \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DENABLED_LOCAL_INFILE=1 \

-DWITH_EXTRA_CHARSETS=all

[root@localhost mysql-5.6.16]# make

[root@localhost mysql-5.6.16]# make install

2.4 配置环境

[root@localhost mysql-5.6.16]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf

[root@localhost mysql-5.6.16]# vim /etc/my.cnf 

[mysqld]

basedir = /usr/local/mysql

datadir = /usr/local/mysql/data

port = 3306

server_id = 1

socket = /tmp/mysql.sock

explicit_defaults_for_timestamp=true

2.5 添加用户并安装DB

[root@localhost mysql-5.6.16]# groupadd mysql

[root@localhost mysql-5.6.16]# useradd -r -g mysql mysql

[root@localhost ~]# cd /usr/local/

[root@localhost local]# chown -R mysql:mysql mysql

[root@localhost local]# cd mysql/

[root@localhost local]#

scripts/mysql_install_db \

--user=mysql \

--datadir=/usr/local/mysql/data \

--basedir=/usr/local/mysql

2.6 生成MySQL启动脚本并运行,以及mysql做软连接到环境变量

[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld

[root@localhost mysql]# chmod 755 /etc/init.d/mysqld

[root@localhost mysql]# /etc/init.d/mysqld start

[root@localhost mysql]# echo $PATH

/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

[root@localhost mysql]# cd /usr/bin

[root@localhost bin]# ll | grep mysql

[root@localhost bin]# ln -s /usr/local/mysql/bin/mysql ./

[root@localhost bin]# ll | grep mysql

lrwxrwxrwx. 1 root root         26 5月  27 20:26 mysql -> /usr/local/mysql/bin/mysql

2.7 设置root密码以及其他安全相关设置

[root@localhost mysql]# /usr/local/mysql/bin/mysql_secure_installation

root:root

2.8 设置系统启动自行启动MySQL

[root@localhost mysql]# chkconfig --add mysqld

[root@localhost mysql]# chkconfig mysqld on

[root@localhost ~]# chkconfig --list | grep mysql

2.9 开始触碰MySQL

[root@localhost init.d]# /usr/local/mysql/bin/mysql -uroot -p

Enter password: ****

mysql> status

--------------

/usr/local/mysql/bin/mysql  Ver 14.14 Distrib 5.6.16, for Linux (x86_64) using  EditLine wrapper


Connection id: 12

Current database:

Current user: root@localhost

SSL: Not in use

Current pager: stdout

Using outfile: ''

Using delimiter: ;

Server version: 5.6.16 Source distribution

Protocol version: 10

Connection: Localhost via UNIX socket

Server characterset: utf8

Db     characterset: utf8

Client characterset: utf8

Conn.  characterset: utf8

UNIX socket: /tmp/mysql.sock

Uptime: 9 min 6 sec


Threads: 1  Questions: 35  Slow queries: 0  Opens: 70  Flush tables: 1  Open tables: 63  Queries per second avg: 0.064

--------------

mysql> exit;

[root@localhost init.d]#


3:开始安装PHP

3.1 解压等基本操作

[root@localhost src]# tar xvzf php-5.5.11.tar.gz 

[root@localhost src]# cd php-5.5.11


3.2 mysql/lib做软连接,识别成64位

[root@localhost php-5.5.11]# ln -s /usr/local/mysql/lib /usr/local/mysql/lib64


3.3 编译开始

[root@localhost php-5.5.11]# 

./configure --prefix=/usr/local/php \

--with-libdir=lib64 \

--with-config-file-path=/usr/local/php/etc \

--with-mysql=/usr/local/mysql \

--with-mysqli=/usr/local/mysql/bin/mysql_config \

--with-pear=/usr/share/php \

--with-freetype-dir \

--with-jpeg-dir \

--with-png-dir \

--with-zlib \

--with-libxml-dir=/usr \

--enable-xml \

--disable-rpath \

--enable-bcmath \

--enable-shmop \

--enable-sysvsem \

--enable-inline-optimization \

--enable-maintainer-zts \

--enable-opcache \

--with-curl \

--with-iconv-dir=/usr/local/lib64 \

--enable-fpm \

--enable-mbstring \

--with-mcrypt \

--with-gd \

--enable-gd-native-ttf \

--with-mhash \

--enable-pcntl \

--enable-sockets \

--with-xmlrpc \

--enable-zip \

--enable-soap \

--with-bz2 \

--enable-static \

--enable-exif \

--with-pdo-mysql=/usr/local/mysql


3.3.1 error出现解决方法

错误1 : configure: error: Don’t know how to define struct flock on this system, set –enable-opcache=no

解决方法1 

[root@localhost lib]# vim /etc/ld.so.conf.d/local.conf 

[root@localhost lib]# cat /etc/ld.so.conf.d/local.conf 

/usr/local/lib64

[root@localhost lib]# ldconfig -v

解决方法2

[root@localhost lib]# yum groupinstall "Development tools" 

解决方法3

ln -s /usr/local/mysql/lib64/libmysqlclient.so /usr/lib/ 

ln -s /usr/local/mysql/lib64/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18

3.4 make

[root@localhost php-5.5.11]# make


   3.4.1 error出现解决方法

   错误1 :/usr/local/src/php-5.5.11/ext/xmlrpc/libxmlrpc/encodings.c:73: undefined reference to `libiconv_open'

/usr/local/src/php-5.5.11/ext/xmlrpc/libxmlrpc/encodings.c:81: undefined reference to `libiconv'

/usr/local/src/php-5.5.11/ext/xmlrpc/libxmlrpc/encodings.c:101: undefined reference to `libiconv_close'

collect2: ld returned 1 exit status

make: *** [sapi/cli/php] 错误 1

解决方法1:

[root@localhost php-5.5.11]# make clean

[root@localhost php-5.5.11]# vim Makefile

/EXTRA_LIBS

EXTRA_LIBS = ..... -lcrypt -liconv

:wq


解决方法2:

#make ZEND_EXTRA_LIBS='-liconv'

3.5 make install

[root@localhost php-5.5.11]# make install


3.6 拷贝php.ini及修改文件

[root@localhost php-5.5.11]# cp -f php.ini-production /usr/local/php/etc/php.ini

[root@localhost php-5.5.11]# cp /usr/local/php/etc/php.ini /usr/local/php/etc/php.ini.bak

[root@localhost php-5.5.11]# vim /usr/local/php/etc/php.ini 

202: short_open_tag = Off (看老代码风格开启或关闭)

452行: error_reporting = E_ALL & ~E_STRICT

470行: display_errors = On

720行: extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-20121212/"

917: date.timezone = PRC

最后一行: [opcache]

    zend_extension=opcache.so

3.7 php-fpm测试及开始启动

[root@localhost php-5.5.11]# cd /usr/local/php/etc

[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf

[root@localhost etc]# vim php-fpm.conf

      33 error_log = /var/log/php/php-fpm.log

[root@localhost etc]# /usr/local/php/sbin/php-fpm -t

[root@localhost etc]# /usr/local/php/sbin/php-fpm

3.8 php-fpm软重启

[root@localhost etc]# killall -USR2 /usr/local/php/sbin/php-fpm

3.9 执行文件放到环境变量,做软连接

[root@localhost bin]# cd /usr/bin

[root@localhost bin]# ln -s /usr/local/php/bin/php ./

[root@localhost bin]# ln -s /usr/local/php/bin/php-config ./

[root@localhost bin]# ln -s /usr/local/php/bin/phpize ./

[root@localhost bin]# ln /usr/local/php/sbin/php-fpm ./

lrwxrwxrwx.   1 root root          22 5月  28 13:03 php -> /usr/local/php/bin/php

lrwxrwxrwx.   1 root root          29 5月  28 13:04 php-config -> /usr/local/php/bin/php-config

-rwxr-xr-x.   2 root root    32835686 5月  28 00:30 php-fpm

lrwxrwxrwx.   1 root root          25 5月  28 13:05 phpize -> /usr/local/php/bin/phpize


3.10 自动启动PHP服务

[root@localhost fpm]# pwd

/usr/local/src/php-5.5.11/sapi/fpm

[root@localhost fpm]# cat init.d.php-fpm.in | less

[root@localhost fpm]# cp init.d.php-fpm.in /etc/init.d/php-fpm

[root@localhost fpm]# vim /etc/init.d/php-fpm

prefix=/usr/local/php

exec_prefix=${prefix}


php_fpm_BIN=${prefix}/sbin/php-fpm

php_fpm_CONF=${prefix}/etc/php-fpm.conf

php_fpm_PID=/var/run/php-fpm.pid


[root@localhost init.d]# vim /usr/local/php/etc/php-fpm.conf

pid = /var/run/php-fpm.pid

[root@localhost fpm]# chmod 755 /etc/init.d/php-fpm 

[root@localhost fpm]# /etc/init.d/php-fpm stop

[root@localhost fpm]# /etc/init.d/php-fpm start

[root@localhost fpm]# chkconfig --add php-fpm

[root@localhost fpm]# chkconfig php-fpm on

[root@localhost fpm]# service php-fpm restart


4:开始安装TNginx

4.1 指定web目录

[root@localhost src]# groupadd www

[root@localhost src]# useradd -g www www

[root@localhost src]# mkdir -p /www/141.com/

[root@localhost src]# chmod +w /www/141.com/

[root@localhost src]# chown -R www:www /www/141.com/

4.2 安装PCRE

[root@localhost src]# rpm -qa |grep pcre 

pcre-7.8-6.el6.x86_64

[root@localhost src]# cp /lib64/libpcre.so.0 /

[root@localhost src]# rpm -e --nodeps pcre-7.8-6.el6.x86_64

[root@localhost src]# cp /libpcre.so.0 /lib64/


[root@localhost src]# wget -c http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.bz2

[root@localhost src]# tar jxvf pcre-8.35.tar.bz2

[root@localhost src]# cd pcre-8.35

[root@localhost pcre-8.35]# ./configure --prefix=/usr/local --libdir=/usr/local/lib64

[root@localhost pcre-8.35]# make && make install

[root@localhost pcre-8.35]# ln -s /usr/local/lib64/libpcre.so.1 /lib64/


4.3 安装TNginx

4.3.1 解压

[root@localhost src]# tar zxvf tengine-2.0.1.tar.gz

[root@localhost src]# cd tengine-2.0.1

4.3.2 编译及安装

[root@localhost tengine-2.0.1]# ./configure --user=www --group=www --prefix=/usr/local/nginx

[root@localhost tengine-2.0.1]# make && make install

4.3.3 配置nginx文件

[root@localhost tengine-2.0.1]# cd /usr/local/nginx/conf/

[root@localhost conf]# vim nginx.conf

user  www www;

worker_processes  4;

error_log  /var/log/nginx/error.log;

pid        /var/log/nginx/nginx.pid;

gzip  on;

include vhosts/*;

4.3.4 编辑vhost下的conf文件

[root@localhost conf]# mkdir vhosts

[root@localhost conf]# cd vhosts

[root@localhost vhosts]# vim www.141.com.conf

server {

       listen       80;

       server_name www.141.com;

       root    /www/141.com/www/app/;

       index  index.php index.html index.htm;

       access_log /var/log/nginx/www.141.com/access.log;

       error_page  404              /index.php;

       error_page   500 502 503 504  /50x.html;

       charset utf-8;


       location ~* ^.+.(jpg|jpeg|gif|css|png|js|html|htm)$ {

             expires           1d;

             break;

       }


       location ~* ^/(images|javascript|js|css|flash|media|static)/ {

             expires 1d;

       }


       location / {

          if (!-e $request_filename){

              rewrite ^/(.*) /index.php last;

          }

       }


       location ~* ^.+.(php|php5)$ {

           fastcgi_pass   127.0.0.1:9000;

           fastcgi_index  index.php;

           fastcgi_param  SCRIPT_FILENAME  /www/141.com/www/app/$fastcgi_script_name;

           include        fastcgi_params;

       }

   }

4.3.5 开启nginx

[root@localhost app]# /usr/local/nginx/sbin/nginx

4.3.6 做nginx软连接

[root@localhost nginx]# cd /usr/bin/

[root@localhost bin]# ln -s /usr/local/nginx/sbin/nginx ./  

4.3.7 检查是否Nginx+MySQL+PHP联动成功

[root@localhost vhosts]# cd /www/141.com/www/app/

[root@localhost app]# echo "<?php phpinfo()" > index.php 

[root@localhost app]# curl localhost 

4.3.8 浏览上测试联动

客户端机器绑定域名 :192.168.1.141 www.141.com

浏览器无法访问解决方案1

修改服务器防火墙配置-开放80和3306

[root@localhost app]# /etc/init.d/iptables status

[root@localhost app]# vim /etc/sysconfig/iptables

-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

[root@localhost app]# service iptables restart

4.3.9 自动启动Nginx服务

[root@localhost tmp]# vim nginx 

参考lnmp_source_files

[root@localhost tmp]# cp nginx /etc/init.d/nginx

[root@localhost tmp]# chmod 755 /etc/init.d/nginx

[root@localhost tmp]# chkconfig --add nginx

[root@localhost tmp]# chkconfig nginx on

[root@localhost tmp]# service nginx stop

[root@localhost tmp]# service nginx start


5:开始安装Memcached

5.1 安装Memcached Server端

5.1.1 先安装libevent,Memcached需要libevent库的支持

[root@localhost src]# wget -c https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz

[root@localhost src]# tar vxzf libevent-2.0.21-stable.tar.gz 

[root@localhost src]# cd libevent-2.0.21-stable

[root@localhost libevent-2.0.21-stable]# ./configure --prefix=/usr/local --libdir=/usr/local/lib64

[root@localhost libevent-2.0.21-stable]# make

[root@localhost libevent-2.0.21-stable]# make install

5.1.2 Memcached Server端

[root@localhost src]# tar vxzf memcached-1.4.17.tar.gz 

[root@localhost src]# cd memcached-1.4.17

[root@localhost memcached-1.4.17]# ./configure --prefix=/usr/local/memcached --libdir=/usr/local/lib64

[root@localhost memcached-1.4.17]# make && make install

[root@localhost memcached-1.4.17]# /usr/local/memcached/bin/memcached -d -p 11211 -u root -l 127.0.0.1 -m 64 -c 1024 -P /var/run/memcached.pid

停止memcached:kill -9 pid

5.1.2.1 error出现解决方法

[root@localhost memcached-1.4.17]# find / -name libevent-2.0.so.5

[root@localhost memcached-1.4.17]# LD_DEBUG=libs   memcached -v

[root@localhost memcached-1.4.17]# ln -s /usr/local/lib64/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5

5.2 安装Memcached Client端

5.2.1 安装libmemcached,客户端基于libmemcached,需要libmemcached的支持

[root@localhost src]# tar zxvf libmemcached-1.0.18.tar.gz

[root@localhost src]# cd libmemcached-1.0.18

[root@localhost libmemcached-1.0.18]# ./configure --prefix=/usr/local/libmemcached/ --with-libmemcached-dir=/usr/local/libmemcached/

[root@localhost libmemcached-1.0.18]# make && make install

5.2.2 PHP Memcached客户端 

[root@localhost src]# tar zxvf memcached-php-ext-2.2.0.tgz

[root@localhost src]# cd memcached-2.2.0/

[root@localhost memcached-2.2.0]# yum install libmemcache-devel

[root@localhost memcached-2.2.0]# yum install php-devel

[root@localhost memcached-2.2.0]# phpize

[root@localhost memcached-2.2.0]# ./configure --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached/

[root@localhost memcached-2.2.0]# make && make install

[root@localhost memcached-2.2.0]# vim /usr/local/php/etc/php.ini

最后行增加

[memcached]

extension = memcached.so

[root@localhost memcached-2.2.0]# killall -USR2 php-fpm

[root@localhost memcached-2.2.0]# nginx -s reload

5.3 测试Memcached

测试方法1

[root@localhost src]# ps aux | grep memcached

root      1987  0.0  0.1 331120  1220 ?        Ssl  08:36   0:00 /usr/local/memcached/bin/memcached -d -p 11211 -u root -l 127.0.0.1 -m 64 -c 1024 -P /var/run/memcached.pid

root      2076  0.0  0.0 103248   880 pts/3    S+   08:40   0:00 grep memcached

测试方法2 如果不能连接"允许防火墙访问11211端口"

 ~  telnet 192.168.1.141 11211

stats

quit

检测方法2

[root@localhost run]# /usr/local/memcached/bin/memcached -u root -vv

5.4 自动启动Memcached服务

[root@localhost scripts]# pwd

/usr/local/src/memcached-1.4.17/scripts

[root@localhost scripts]# cat memcached.sysv

[root@localhost scripts]# cp memcached.sysv /etc/init.d/memcached

[root@localhost scripts]# chmod 755 /etc/init.d/memcached 

[root@localhost scripts]# vim /etc/init.d/memcached 

[root@localhost scripts]# chkconfig --add memcached

[root@localhost scripts]# chkconfig memcached on

[root@localhost scripts]# service memcached start




6: 开始安装Redis

6.1 编译安装redis

[root@localhost src]# tar xvzf redis-2.8.8.tar.gz 

[root@localhost src]# cd redis-2.8.8

[root@localhost redis-2.8.8]# make

[root@localhost redis-2.8.8]# make test


6.1.1 出现tcl error

make[1]: Entering directory `/usr/local/src/redis-2.8.8/src'

You need tcl 8.5 or newer in order to run the Redis test

make[1]: *** [test] 错误 1

make[1]: Leaving directory `/usr/local/src/redis-2.8.8/src'

make: *** [test] 错误 2

[root@localhost ~]# yum install tcl

[root@localhost redis-2.8.8]# make test

[root@localhost redis-2.8.8]# make PREFIX=/usr/local install

6.2 配置 Redis

[root@localhost redis-2.8.8]# mkdir /etc/redis

[root@localhost redis-2.8.8]# cp redis.conf /etc/redis/redis.conf

daemonize yes

pidfile /var/run/redis.pid

timeout 300

dir /var/lib/redis/

slowlog-max-len 1024

[root@localhost redis-2.8.8]# mkdir /var/lib/redis

6.3 调整系统内核参数

如果内存情况比较紧张的话,需要设定内核参数:

[root@localhost /]# echo 1 > /proc/sys/vm/overcommit_memory


6.4 运行 Redis

[root@localhost /]# redis-server /etc/redis/redis.conf

[root@localhost /]# redis-cli

127.0.0.1:6379> set foo bar

OK

127.0.0.1:6379> get foo

"bar"

127.0.0.1:6379> quit

[root@localhost /]# redis-benchmark (执行redis-benchmark命令时也会将内存数据写入硬盘。)


6.5 关闭redis服务

[root@localhost /]# redis-cli shutdown

如果端口变化可以指定端口:

[root@localhost /]# redis-cli -p 6380 shutdown


6.6 保存/备份

[root@localhost run]# redis-cli save

OK

[root@localhost run]# redis-cli -p 6379 save

OK


6.7 自动启动Redis服务

[root@localhost /]# which redis-server

/usr/local/bin/redis-server

[root@localhost tmp]# vim redis-server

参考lnmp_source_files

[root@localhost tmp]# cp redis-server /etc/init.d/redis

[root@localhost tmp]# chmod 755 /etc/init.d/redis

[root@localhost tmp]# chkconfig --add redis

[root@localhost tmp]# chkconfig --level 345 redis on

[root@localhost tmp]# service redis stop

[root@localhost tmp]# service redis start


6.8 PHP Redis客户端

[root@localhost src]# tar zxvf redis-php-ext-2.2.5.tgz 

[root@localhost src]# cd redis-2.2.5/

[root@localhost redis-2.2.5]# ./configure --with-php-config=/usr/local/php/bin/php-config 

[root@localhost redis-2.2.5]# make && make install

[root@localhost redis-2.2.5]# vim /usr/local/php/etc/php.ini

最后行增加

[redis]

extension = redis.so