您的位置:首页 > 数据库 > Memcache

centos下nginx+postgresql+php+memcached+apc

2016-07-10 18:04 441 查看
具体安装步骤如下:

具体安装软件包:

01
nginx1.0.13
02
'target='_blank'>http://nginx.org/download/nginx-1.0.13.tar.gz[/code]
03
wget
04
05
postgresql9.1.2
06
'target='_blank'>http://ftp.postgresql.org/pub/source/v9.1.2/postgresql-9.1.2.tar.gz[/code]
07
wget
08
09
php5.3.10
10
'target='_blank'>http://cn2.php.net/get/php-5.3.10.tar.gz/from/ar.php.net/mirror[/code]
11
wget
12
13
memcache
1.4.13
14
'target='_blank'>http://code.google.com/p/memcached/downloads/detail?name=memcached-1.4.13.tar.gz&can=2&q=[/code]
15
wget
16
17
memcached
php插件memcache1.5
18
'target='_blank'>http://pecl.php.net/get/memcache-1.5.tgz[/code]
19
wget
20
21
apc
php插件apc3.1.9
22
'target='_blank'>http://pecl.php.net/get/APC-3.1.9.tgz[/code]
23
wget
1.升级系统包

yumupdate

关闭selinux

2.nginx安装:

安装pcre

yuminstallpcre*

解压编译:

1
tar
–zxvfnginx-1.0.13.tar.gz
2
3
cd
nginx-1.0.13
4
5
./configure
--prefix=/usr/
local
/nginx
--with-http_flv_module--with-http_stub_status_module--with-pcre
6
7
make
&&makeinstall
更改配置文件:

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

去掉下面一段的注释:

01
location
~\.php${
02
03
root
html;
04
05
fastcgi_pass
127.0.0.1:9000;
06
07
fastcgi_index
index
.php;
08
09
fastcgi_param
SCRIPT_FILENAME/usr/
local
/nginx/html
$fastcgi_script_name
;
10
11
include
fastcgi_params;
12
13
}
45行添加index.php

做好这两个操作后启动nginx/usr/local/nginx/sbin/nginx

3.postgresql安装

安装readline

yuminstallreadline*

解压编译:

1
tar
–zxvfpostgresql-9.1.2.tar.gz
2
3
cd
postgresql-9.1.2
4
5
./configure
--prefix=/usr/
local
/postgresql
6
7
make
&&makeinstall
postgresql配置:

01
useradd
postgre
02
03
mkdir
/home/postgre/data
04
05
chown
-R
postgre:postgre/usr/
local
/postgresql/
06
07
chown
-R
postgre:postgre/home/postgre
08
09
su
postgre
10
/usr/
local
/postgresql/bin/initdb
--encoding=utf8-D/home/postgre/data
4.php安装

安装所需软件包

01
yum
installjpeg*
02
03
yum
installlibjpeg*
04
05
yum
installlibpng*
06
07
yum
installiconv*
08
09
yum
installlibiconv*
10
11
yum
installfreetype*
12
13
yum
installgd*
解压编译

01
tar
-zxvfphp-5.3.10.tar.gz
02
03
cd
php-5.3.10
04
05
./configure
--prefix=/usr/
local
/php--with-pgsql=/usr/
local
/postgresql
--with-
06
07
gd=/usr
--with-jpeg-dir=/usr--with-png-dir=/usr--with-zlib--enable-mb
08
09
string
--with-freetype-dir--with-iconv--enable-fpm
10
11
make
&&makeinstall
复制php.ini

1
cp
php.ini-production/usr/local/php/lib/php.ini
2
3
cd
/usr/local/php/etc/
4
5
mv
php-fpm.conf.
default
php-fpm.conf
vimphp-fpm.conf

这个配置一般默认就可以启动

启动php-fpm

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

5.memcached安装

安装所需要的软件包:

yuminstalllibevent*

解压编译:

1
tar
-zxvfmemcached-1.4.13.tar.gz
2
3
cd
memcached-1.4.13
4
5
./configure
--prefix=/usr/local/memcached
6
7
make
&&makeinstall
6.memcachedphp插件安装

安装所需要的软件包

yuminstallautoconf

解压编译

1
tar
-zxvfmemcache-1.5.tgz
2
3
cd
memcache-1.5
4
5
/usr/
local
/php/bin/phpize
6
7
./configure
--enable-memcache--with-php-config=/usr/
local
/php/bin/php-config
--with-zlib-dir
1
make
&&makeinstall
配置memcached与php.ini

/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/

vim/usr/local/php/lib/php.ini

查找extension_dir

更改路径为/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/

添加

extension=memcache.so

启动memcached:

/usr/local/memcached/bin/memcached-dm20-uroot-llocalhost-p11211

启动说明:

-d选项是启动一个守护进程,

-m是分配给Memcache使用的内存数量,单位是MB,我这里是10MB,

-u是运行Memcache的用户,我这里是root,

-l是监听的服务器IP地址,如果有多个地址的话,我这里指定了服务器的IP地址192.168.0.200,

-p是设置Memcache监听的端口,我这里设置了12000,最好是1024以上的端口,

-c选项是最大运行的并发连接数,默认是1024,我这里设置了256,按照你服务器的负载量来设定,

-P是设置保存Memcache的pid文件,我这里是保存在/tmp/memcached.pid

7.apc插件的安装

解压编译安装

1
tar
-zxvfAPC-3.1.9.tgz
2
3
cd
APC-3.1.9
4
5
/usr/local/php/bin/phpize
6
7
./configure
--enable-apc--enable-apc-mmap--with-php-config=/usr/local/php/bin/php-config
8
9
make
&&makeinstall
配置php.ini

ls/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/

vim/usr/local/php/lib/php.ini

在extension=memcache.so下面添加extension=apc.so以及

apc.enabled=1

apc.cache_by_default=on

apc.shm_segments=1

apc.shm_size=32

apc.ttl=600

apc.user_ttl=600

apc.num_files_hint=0

apc.write_lock=On

检测是否安装成功

/usr/local/php/bin/php-m|grepapc

装完后reboot

用phpinfo查看是否都已经加载

8.开机自动启动

1
echo
"/usr/local/nginx/sbin/nginx"
>>/etc/rc.
local
2
3
echo
"/usr/local/php/sbin/php-fpm"
>>/etc/rc.
local
4
5
echo
"/usr/local/memcached/bin/memcached
-dm20-uroot-llocalhost-p11211"
>>/etc/rc.
local
9.防火墙设置

vim/etc/sysconfig/iptables

开启11211和80端口

10.测试脚本

Phpinfo

1
<?php
2
3
phpinfo();
4
5
?>
Memcached

01
<?php
02
03
$mem
=
new
Memcache;
04
05
$mem
->connect(
"192.168.10.99"
,11211);
06
07
$mem
->set(
'key'
,
'This
isatest!'
,
0,60);
08
09
$val
=
$mem
->get(
'key'
);
10
11
echo
$val
;
12
13
?>
Apc

安装目录下面直接cpapc.php/usr/local/nginx/html

出处:http://www.centoscn.com/CentosServer/2014/0522/2992.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  memcached nginx php apc linux