centos memcache 启动 centos命令行启动

今天给各位分享centos memcache 启动的知识,其中也会对centos命令行启动进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

LAMP平台安装Xcache和Memcached加速网站运行

在CentOS 7系统里搭建好LAMP环境后,就可以安装网站程序了,以最流行了Wordpess为例。为了加快网站的访问速度,除了花钱买更好的硬件设施外。我们可以通过优化网站的程序、主题。为服务器开启缓存功能,为网站提速。我们知道,互联网上缓存为王。

1.安装php加速器Xcache

XCache是一个国人开发的又快又稳定的 PHP opcode缓存器,通过共享编译内存从而降低服务器负载。

由于yum源仓库里面没有,先下载源文件,最新版3.2.0

在tmp目录下:cd/tmp下载:wget

解压缩:tar xvfz xcache-3.2.0.tar.gz

准备安装:cd xcache-3.2.0

安装前,先要准备编译环境:yum-y install php-devel gcc

运行phpize,非常重要:phpize

配置:./configure--enable-xcache

安装:make make install

复制配置文件 cp xcache.ini/etc/php.d(xcache.ini在源程序安装目录)

重新启动http服务:systemctl restart httpd

2.安装memcached

Memcached是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载。它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提供动态、数据库驱动网站的速度。

a.安装

yum-y install memcached

安装memcache关联php

yum-y install php-pecl-memcache

编译安装PHP的memcache扩展

下载 wget

tar xf memcache-3.0.8.tgz

cd memcache-3.0.8

依次执行

phpize

./configure

make make install

b.配置

在php.ini文件中添加memcache扩展

extension=/usr/lib64/php/modules/memcache.so(版本不同目录可能不同)

c.运行

memcached-d-m 128-c 1024-P/tmp/memcached.pid

d.测试

测试memcached是否工作正常,在网站目录下编辑一个文件如memtest.php,放入如下代码:

$memcache= new Memcache;

$memcache-connect('localhost', 11211) or die("Could not connect");

$version=$memcache-getVersion();

echo"Server's version:".$version."

/n";

$tmp_object= new stdClass;

$tmp_object-str_attr='test';

$tmp_object-int_attr= 123;

$memcache-set('key',$tmp_object, false, 10) or die("Failed to save data at the server");

echo"Store data in the cache(data will expire in 10 seconds)

/n";

$get_result=$memcache-get('key');

echo"Data from the cache:

/n";

var_dump($get_result);

?

访问后如果能现实版本号server's version: 1.4…… store date in the cache等信息说明memcached运行正常。

5.整合

Wordpress支持memcached

下载:wget

unzip memcached.2.0.2.zip

cd memcached.2.0.2

复制 object-cache.php到网站根目录 wp-content文件夹内,wordpress会自动调用缓存。

重启服务器:

sytemctl restart memcached

sytemctl restart httpd

3.开启Gzip压缩。

apache2.4版本默认添加了gzip模块,我们要同时开启deflate模块,压缩网页文件,提高服务器浏览速度。

vim/etc/httpd/conf/httpd.conf在最后加入如下几行:

DeflateCompressionLevel 9

AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-httpd-php

AddOutputFilter DEFLATE css js

重新启动http服务:systemctl restart httpd

CentOS下PHP安装memcache扩展问题解决方法分享

系统版本是5.2,把安装memcached的方法记录下先:

复制代码

   

代码如下:

cd~/memcached

   wget-c

   wget-c

   #安装libevent

   tar-zxvf libevent-1.4.10-stable.tar.gz

   cd libevent-1.4.10-stable

   ./configure

   make

   make install

   #安装memcached

   cd..

   tar-zxvf memcached-1.2.8.tar.gz

   cd memcached-1.2.8

   ./configure

   make

   make install

   #如果是64位系统,还需要把libevent的文件复制到/wp-content/lib64/下,用来解决error while loading shared libraries的问题

   cp-R/wp-content/local/lib/libevent*/wp-content/lib64/

好了,开始安装php的扩展,恶梦开始了,本以为直接用yum来安装php-devel.x86_64和php-pecl-memcache.x86_64这两个扩展就可以了,可装了后 phpinfo()里根本找不到memcache扩展,把已经装的这两个扩展remove重来,还是不行,goooooooooooooogle,找到了一篇文章《PHP Pecl Memcached module installation problems》,有救喽,先remove掉php-pecl-memcache.x86_64,然后执行了

pecl install memcache

顺利安装上了,打开/etc/php.d/看了下,没有memcache.ini,好吧,手动到/etc/php.ini加上了 extension=memcache.so,好了,重启httpd,刷新 phpinfo(),竟然还没有,我郁闷了。。

回头想想,我好像漏了一个地方没有检查,马上打开/wp-content/lib64/php/modules/查看,果然没有memcache.so,会在哪呢? find-name之,原来躲在/wp-content/local/lib/php/extensions/no-debug-non-zts-20060613/下,复制到/wp-content/lib64/php/modules/再试,久违的 memcache扩展出现了。 T T

Memcached参数说明:

-d选项是启动一个守护进程   -m分配给Memcache使用的内存数量,单位是MB   -u运行Memcache的用户   -l监听的服务器IP地址   -p设置Memcache监听的端口,最好是1024以上的端口   -c最大运行的并发连接数,默认是1024,按照你服务器的负载量来设定   -P设置保存Memcache的pid文件   

启动:

memcached-d-u root-m 128-c 8192

查看状态:

watch“echo stats| nc 127.0.0.1 11211″

状态说明:

uptime:memcached运行的秒数   cmd_get:查询缓存的次数。这两个数据相除一下就能得到平均每秒请求缓存的次数   cmd_set:设置key=value的次数   get_hits:缓存命中的次数。缓存命中率= get_hits/cmd_get* 100%   scurr_items:现在在缓存中的键值对个数   

相关网址:

Libevent:

   Memcached:

   PHP Memcached Extension:

[shell]

[root@~]# pecl install memcache

downloading memcache-2.2.6.tgz...

Starting to download memcache-2.2.6.tgz(35,957 bytes)

..........done: 35,957 bytes

11 source files, building

WARNING: php_bin/opt/php/bin/php appears to have a suffix/bin/php, but config variable php_suffix does not match

running: phpize

Configuring for:

PHP Api Version: 20090626

Zend Module Api No: 20090626

Zend Extension Api No: 220090626

Enable memcache session handler support? [yes]: n

[/shell]

[shell]

running: make INSTALL_ROOT="/var/tmp/pear-build-root/install-memcache-2.2.6" install

Installing shared extensions:/var/tmp/pear-build-root/install-memcache-2.2.6/opt/php/lib/php/extensions/no-debug-non-zts-20090626/

running: find"/var/tmp/pear-build-root/install-memcache-2.2.6"| xargs ls-dils

11370548 4 drwxr-xr-x 3 root root 4096 Jan 6 15:55/var/tmp/pear-build-root/install-memcache-2.2.6

11370602 4 drwxr-xr-x 3 root root 4096 Jan 6 15:55/var/tmp/pear-build-root/install-memcache-2.2.6/opt

11370603 4 drwxr-xr-x 3 root root 4096 Jan 6 15:55/var/tmp/pear-build-root/install-memcache-2.2.6/opt/php

11370604 4 drwxr-xr-x 3 root root 4096 Jan 6 15:55/var/tmp/pear-build-root/install-memcache-2.2.6/opt/php/lib

11370605 4 drwxr-xr-x 3 root root 4096 Jan 6 15:55/var/tmp/pear-build-root/install-memcache-2.2.6/opt/php/lib/php

11370606 4 drwxr-xr-x 3 root root 4096 Jan 6 15:55/var/tmp/pear-build-root/install-memcache-2.2.6/opt/php/lib/php/extensions

11370607 4 drwxr-xr-x 2 root root 4096 Jan 6 15:55/var/tmp/pear-build-root/install-memcache-2.2.6/opt/php/lib/php/extensions/no-debug-non-zts-20090626

11370601 236-rwxr-xr-x 1 root root 235639 Jan 6 15:55/var/tmp/pear-build-root/install-memcache-2.2.6/opt/php/lib/php/extensions/no-debug-non-zts-20090626/memcache.so

Build process completed successfully

Installing'/opt/php/lib/php/extensions/no-debug-non-zts-20090626/memcache.so'

install ok: channel://pecl.php.net/memcache-2.2.6

configuration option"php_ini" is not set to php.ini location

You should add"extension=memcache.so" to php.ini

[/shell]

centos5 源码安装Nginx + mysql + apache + php的方法

主要依照的是张宴的一篇博文《》,安装的软件是也是从他提供的列表中下载,这里都是tar.gz格式,如果更希望是rpm格式的话,提供一个网址《》这里列出了比较完全的下载包。

我安装的系统:Centos5

1、下载;

我安装的下载来自张宴博文下的地址,下载保存的是home下自己目录的一个文件夹下:

复制代码

   

代码如下:

cd/home/xuxx/software

   wget

   wget

   wget

   wget

   wget

   wget

   wget

   wget

   wget

   wget

   wget

   wget

   wget

   wget

2、准备编译安装环境,需要编译源码用到gc++

建议如果是新安装的系统,使用yum upgrade更新下系统。

复制代码

   

代码如下:

sudo-s

   LANG=C

   yum-y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel

   glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel

   openldap openldap-devel nss_ldap openldap-clients openldap-servers

注意:这里所有的命令是一行的而不能有换行符,如果是copy的时候,注意要去处该换行符

确保安装成功!才能正确使用编译。

3、安装:

一、安装PHP 5.2.8(FastCGI模式)

1、编译安装PHP 5.2.8所需的支持库:

1] libiconv库

复制代码

   

代码如下:

tar zxvf libiconv-1.13.tar.gz

   cd libiconv-1.13/

   ./configure--prefix=/usr/local

   make

   make install

   make clean

   make distclean

   cd../

make clean和make distclean都是删除安装过程中生成的缓存文件。当然如果你不介意放着也可以跳过这两步清理操作。

2]libmcrypt库

复制代码

   

代码如下:

tar zxvf libmcrypt-2.5.8.tar.gz

   cd libmcrypt-2.5.8/

   ./configure

   make

   make install

   make clean

   make distclean

   /sbin/ldconfig

   cd libltdl/

   ./configure--enable-ltdl-install

   make

   make install

   make clean

   make distclean

   cd

3] mhash库

复制代码

   

代码如下:

tar zxvf mhash-0.9.9.9.tar.gz

   cd mhash-0.9.9.9/

   ./configure

   make

   make install

   cd../

4]mcrypt库

注意:因为该库和libmcrypt有依赖性,所以在安装前必须知道libmcrypt,否则的话会出现:

错误

复制代码

   

代码如下:

checking for libmcrypt– version= 2.5.0…

   ***‘libmcrypt-config–version’ returned 2.4.0, but LIBMCRYPT(2.5.8)

   *** was found! If libmcrypt-config was correct, then it is best

   *** to remove the old version of LIBMCRYPT. You may also be able to fix the error

   *** by modifying your LD_LIBRARY_PATH enviroment variable, or by editing

   ***/etc/ld.so.conf. Make sure you have run ldconfig if that is

   *** required on your system.

   *** If libmcrypt-config was wrong, set the environment variable LIBMCRYPT_CONFIG

   *** to point to the correct copy of libmcrypt-config, and remove the file config.cache

   *** before re-running configure

   configure: error:*** libmcrypt was not found

是因为path的问题,所以执行:

复制代码

   

代码如下:

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

然后再安装:

复制代码

   

代码如下:

tar zxvf mcrypt-2.6.8.tar.gz

   cd mcrypt-2.6.8/

   /sbin/ldconfig

   ./configure

   make

   make install

   cd../

二、安装mysql

复制代码

   

代码如下:

/usr/sbin/groupadd mysql

   /usr/sbin/useradd-g mysql xxx

   unzip mysql-5.1.33.zip

   cd mysql-5.1.33/

   ./configure--prefix=/usr/local/webserver/mysql/--enable-assembler--with-extra-charsets=complex--enable-thread-safe-client--with-big-tables

   --with-readline--with-ssl--with-embedded-server--enable-local-infile--with-plugins=innobase

   make

   make install

   make clean

   make distclean

   chmod+w/usr/local/webserver/mysql

   chown-R xxx:mysql/usr/local/webserver/mysql

   cp support-files/my-medium.cnf.sh/usr/local/webserver/mysql/my.cnf

   cd../

注意:这里编译./configure命令是一行的而不能有换行符,如果是copy的时候,注意要去处该换行符

在最后一步拷贝的时候,我安装完在support-files下没有my-medium.cnf而只有my-medium.cnf.sh所以将这个文件拷贝过去。

@张宴原文:

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

①、以xxx用户帐号的身份建立数据表:

复制代码

   

代码如下:

/usr/local/webserver/mysql/bin/mysql_install_db--basedir=/usr/local/webserver/mysql--datadir=/usr/local/webserver/mysql/data--user=xxx

②、启动MySQL(最后的表示在后台运行)

复制代码

   

代码如下:

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

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

复制代码

   

代码如下:

tar zxvf php-5.2.8.tar.gz

   gzip-cd php-5.2.8-fpm-0.5.10.diff.gz| patch-d php-5.2.8-p1

   cd php-5.2.8/

   ./configure--prefix=/usr/local/webserver/php--with-config-file-path=/usr/local/webserver/php/etc--with-mysql=/usr/local/webserver/mysql

   --with-mysqli=/usr/local/webserver/mysql/bin/mysql_config--with-iconv-dir=/usr/local--with-freetype-dir--with-jpeg-dir--with-png-dir--with-zlib

   --with-libxml-dir=/usr--enable-xml--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-fpm--enable-force-cgi-redirect

   --enable-mbstring--with-mcrypt--with-gd--enable-gd-native-ttf--with-openssl--with-mhash--enable-pcntl--enable-sockets--with-ldap

   --with-ldap-sasl

   make ZEND_EXTRA_LIBS='-liconv'

   make install

   cp php.ini-dist/usr/local/webserver/php/etc/php.ini

   cd../

注意:这里./configure命令是一行的而不能有换行符,如果是copy的时候,注意要去处该换行符

4、编译安装PHP5扩展模块--可选安装

复制代码

   

代码如下:

tar zxvf memcache-2.2.5.tgz

   cd memcache-2.2.5/

   /usr/local/webserver/php/bin/phpize

   ./configure--with-php-config=/usr/local/webserver/php/bin/php-config

   make

   make install

   make clean

   make distclean

   cd../

   tar jxvf eaccelerator-0.9.5.3.tar.bz2

   cd eaccelerator-0.9.5.3/

   /usr/local/webserver/php/bin/phpize

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

   make

   make install

   make clean

   make distclean

   cd../

   tar zxvf PDO_MYSQL-1.0.2.tgz

   cd PDO_MYSQL-1.0.2/

   /usr/local/webserver/php/bin/phpize

   ./configure--with-php-config=/usr/local/webserver/php/bin/php-config--with-pdo-mysql=/usr/local/webserver/mysql

   make

   make install

   make clean

   make distclean

   cd../

   tar zxvf ImageMagick.tar.gz

   cd ImageMagick-6.5.1-2/

   ./configure

   make

   make install

   make clean

   make distclean

   cd../

   tar zxvf imagick-2.2.2.tgz

   cd imagick-2.2.2/

   /usr/local/webserver/php/bin/phpize

   ./configure--with-php-config=/usr/local/webserver/php/bin/php-config

   make

   make install

   make clean

   make distclean

   cd../

5、修改php.ini文件

STRONG手工修改:/STRONG查找/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="pdo_mysql.so"

extension="imagick.so"

再查找output_buffering= Off

修改为output_buffering= On

6、配置eAccelerator加速PHP:

mkdir-p/usr/local/webserver/eaccelerator_cache

vi/usr/local/webserver/php/etc/php.ini

按shift+g键跳到配置文件的最末尾,加上以下配置信息:

复制代码

   

代码如下:

[eaccelerator]

   zend_extension="/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"

   eaccelerator.shm_size="128"

   eaccelerator.cache_dir="/usr/local/webserver/eaccelerator_cache"

   eaccelerator.enable="1"

   eaccelerator.optimizer="1"

   eaccelerator.check_mtime="1"

   eaccelerator.debug="0"

   eaccelerator.filter=""

   eaccelerator.shm_max="0"

   eaccelerator.shm_ttl="300"

   eaccelerator.shm_prune_period="120"

   eaccelerator.shm_only="0"

   eaccelerator.compress="1"

   eaccelerator.compress_level="9"

修改配置文件:

vi/etc/sysctl.conf

kernel.shmmax= 134217728

然后执行以下命令使配置生效:/sbin/sysctl-p

以下的步骤和张宴步骤中一样配置,不再赘诉

阅读剩余
THE END