How to install memcached on CentOS with memcached PHP extension on CentOS
Published: Wed, 08/29/2012 - 8:46am
Updated: Wed, 06/19/2013 - 12:22am
We'll need the following:
-
memcached ( http://memcached.org/ ) Current Version at time of writing: memcached v1.4.15 date: 2012-9-3
- libevent ( http://libevent.org/ ) Current Version at time of writing: libevent-2.0.21 date: 2012-11-18 **If we're going to build memcached from source, we'll need this
-
pecl/memcached ( http://pecl.php.net/package/memcached ) Current version at time of writing: pecl/memcached 2.1.0 date: 2012-08-07
-
libmemcached ( http://libmemcached.org ; needed by pecl/memcached) Current version at time of writing: libmemcached 1.0.10 date:2012-07-31
** NOTE: we'll be installing this using yum , since doing from source failed for me as it required other dependencies **
-
libmemcached ( http://libmemcached.org ; needed by pecl/memcached) Current version at time of writing: libmemcached 1.0.10 date:2012-07-31
Let's head over to our setup directory--this is where we'll be downloading and installing everything from.
cd /usr/local/src
Fix yum, so it only shows the packages made for our system
vi /etc/yum.conf
Add the following line:
multilib_policy=best
Basically, what this does is, if you're on x86_64 it will only show the x86_64 packages; and vice-versa.
Install memcached using yum
We need to get the latest memcached from yum, however all the regular repos have the oudated version... So we install the PowerStack repository which has the latest version memcached 1.4.14
rpm -Uvh http://powerstack.org/powerstack-release.rpm
yum update
yum install memcached
Install memcached from source
This is an alternative step. Yum way works great--everything is setup for you. However, If you want to do this manually, then continue here:
We'll first need to install libevent. Let's see if it's installed already
whereis libevent
*** Installing via yum will install an older libevent 1.4.13 ***
yum install gcc libevent libevent-devel
OR we can install libevent from source. You can get latest version here: http://libevent.org/ . However, the latest version of libevent may be too new for the latest version of memcached, so if something goes wrong, try a lower version.
wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
tar xvfz libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
./configure
make
make install
#create a symbolic link to libevent since it's not made by default in the location that memcached is expecting it to be
ln -s /usr/local/lib/libevent-2.0.so.5 /lib64/
Now with libevent installed, we can install memcached from source.
wget http://memcached.org/latest
tar -zxvf memcached-1.x.x.tar.gz
cd memcached-1.x.x
./configure
make
make install
If memcached can't start complaing about :
memcached: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory
We need to see where it's looking for the libevent library and crate a symbolic link to it.
LD_DEBUG=libs memcached - v 2>&1 > /dev/null I less
#Example: for me memcached was looking for libevent in /lib64
ln -s /usr/local/lib/libevent-2.0.so.5 /lib64/
Configure memcached
vi /etc/sysconfig/memcached
We set the CACHESIZE. Normally this is pretty low, so we up it to 2048MB
PORT="11211"
USER="memcached"
MAXCONN="2048"
CACHESIZE="2048"
OPTIONS="-l 127.0.0.1"
Next we make sure memcached starts automatically.
chkconfig memcached on
service memcached start
*** If you get an error saying memcached is missing when trying 'chconfig memcached on' do the following (this will likely not happen if you've installed memcached using Yum):
vi /etc/rc.d/init.d/memcached
Paste this:
#!/bin/bash
#
# memcached This shell script takes care of starting and stopping
# standalone memcached.
#
# chkconfig: - 80 12
# description: memcached is a high-performance, distributed memory
# object caching system, generic in nature, but
# intended for use in speeding up dynamic web
# applications by alleviating database load.
# processname: memcached
# config: /etc/memcached.conf
# Source function library.
. /etc/rc.d/init.d/functions
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/bin/memcached
DAEMONBOOTSTRAP=/usr/local/bin/start-memcached
DAEMONCONF=/etc/memcached.conf
NAME=memcached
DESC=memcached
PIDFILE=/var/run/$NAME.pid
[ -x $DAEMON ] || exit 0
[ -x $DAEMONBOOTSTRAP ] || exit 0
RETVAL=0
start() {
echo -n $"Starting $DESC: "
daemon $DAEMONBOOTSTRAP $DAEMONCONF
RETVAL=$?
[ $RETVAL -eq 0 ] && touch $PIDFILE
echo
return $RETVAL
}
stop() {
echo -n $"Shutting down $DESC: "
killproc $NAME
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f $PIDFILE
return $RETVAL
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
start
RETVAL=$?
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit $RETVAL
Now make it executable
chmod 755 /etc/rc.d/init.d/memcached
Create the script
vi /usr/local/bin/start-memcached
chmod 755 /usr/local/bin/start-memcached
#!/usr/bin/perl -w
# start-memcached
# 2003/2004 - Jay Bonci <jaybonci@debian.org>
# This script handles the parsing of the /etc/memcached.conf file
# and was originally created for the Debian distribution.
# Anyone may use this little script under the same terms as
# memcached itself.
use strict;
if ($> != 0 and $< != 0) {
print STDERR "Only root wants to run start-memcached.\n";
exit;
}
my $etcfile = shift || "/etc/memcached.conf";
my $params = [];
my $etchandle;
# This script assumes that memcached is located at /usr/bin/memcached, and
# that the pidfile is writable at /var/run/memcached.pid
my $memcached = "/usr/local/bin/memcached";
my $pidfile = "/var/run/memcached.pid";
# If we don't get a valid logfile parameter in the /etc/memcached.conf file,
# we'll just throw away all of our in-daemon output. We need to re-tie it so
# that non-bash shells will not hang on logout. Thanks to Michael Renner for
# the tip
my $fd_reopened = "/dev/null";
sub handle_logfile {
my ($logfile) = @_;
$fd_reopened = $logfile;
}
sub reopen_logfile {
my ($logfile) = @_;
open *STDERR, ">>$logfile";
open *STDOUT, ">>$logfile";
open *STDIN, ">>/dev/null";
$fd_reopened = $logfile;
}
# This is set up in place here to support other non -[a-z] directives
my $conf_directives = {
"logfile" => \&handle_logfile
};
if (open $etchandle, $etcfile) {
foreach my $line (<$etchandle>) {
$line =~ s/\#.*//go;
$line = join ' ', split ' ', $line;
next unless $line;
next if $line =~ /^\-[dh]/o;
if ($line =~ /^[^\-]/o) {
my ($directive, $arg) = $line =~ /^(.*?)\s+(.*)/;
$conf_directives->{$directive}->($arg);
next;
}
push @$params, $line;
}
}
unshift @$params, "-u root" unless (grep $_ eq '-u', @$params);
$params = join " ", @$params;
if (-e $pidfile) {
open PIDHANDLE, "$pidfile";
my $localpid = <PIDHANDLE>;
close PIDHANDLE;
chomp $localpid;
if (-d "/proc/$localpid") {
print STDERR "memcached is already running.\n";
exit;
} else {
`rm -f $localpid`;
}
}
my $pid = fork();
if ($pid == 0) {
reopen_logfile($fd_reopened);
exec "$memcached $params";
exit(0);
} elsif (open PIDHANDLE,">$pidfile") {
print PIDHANDLE $pid;
close PIDHANDLE;
} else {
print STDERR "Can't write pidfile to $pidfile.\n";
}
Now we try to add it as a service again...
chkconfig memcached on
service memcached start
Cool! we now have the latest version of memcached installed.
Let's check to make sure it's working:
echo stats | nc localhost 11211
This will show something like
STAT pid 10412
STAT uptime 6353
STAT time 1346136470
STAT version 1.4.14
STAT libevent 1.4.13-stable
STAT pointer_size 64
STAT rusage_user 0.000000
STAT rusage_system 0.001999
STAT curr_connections 10
STAT total_connections 14
STAT connection_structures 11
STAT reserved_fds 20
STAT cmd_get 1
STAT cmd_set 0
STAT cmd_flush 0
STAT cmd_touch 0
STAT get_hits 0
STAT get_misses 1
STAT delete_misses 0
STAT delete_hits 0
STAT incr_misses 0
STAT incr_hits 0
STAT decr_misses 0
STAT decr_hits 0
STAT cas_misses 0
STAT cas_hits 0
STAT cas_badval 0
STAT touch_hits 0
STAT touch_misses 0
STAT auth_cmds 0
STAT auth_errors 0
STAT bytes_read 33
STAT bytes_written 2059
STAT limit_maxbytes 536870912
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 4
STAT conn_yields 0
STAT hash_power_level 16
STAT hash_bytes 524288
STAT hash_is_expanding 0
STAT expired_unfetched 0
STAT evicted_unfetched 0
STAT bytes 0
STAT curr_items 0
STAT total_items 0
STAT evictions 0
STAT reclaimed 0
END
Ok it works.
If you get an error saying nc: command not found, then simply do
yum install rc
Install libmemcached
This is needed for pecl/memcached PHP extension. We install the yum repo that has libmemcached and install it with all it's dependencies:
libmemcached
libmemcached-devel
cyrus-sasl-devel
Let's install libmemcached and it's dependencies.
pecl/memcached needs libmemcached 0.39+, and the regular yum repositories probably will install an older version, which won't work
For CentOS 6.x use the following
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm
yum --enablerepo=remi install libmemcached\*
For CentOS 5.x use the following
wget http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
rpm -Uvh remi-release-5*.rpm epel-release-5*.rpm
yum --enablerepo=remi install libmemcached\*
If you want to permantely enable the remi repo, then do the following:
vi /etc/yum.repos.d/remi.repo
Now enable the first/top repo (only) by changing enabled=0 to:
enabled=1
Ok... libmemcached should now be installed, and we can move on to the next step.
Install pecl/memcached
We're almost done... We just now need to install the memcached PHP extension.
wget http://pecl.php.net/get/memcached # this will get the latest version.
tar -zxvf memcached-x.x.x.tgz #fill in whatever version you just download; e.g. memcached-2.1.0.tgz
cd memcached-x.x.x
phpize
./configure
make
make install
Note the extension installation directory, because we will need it in the next step. e.g. /usr/local/lib/php/extensions/no-debug-non-zts-20100525/
locate php.ini # in centos it's located at /usr/local/lib/php.ini
vi /usr/local/lib/php.ini
now add the following line near the bottom of php.ini
extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20100525/"
extension=memcached.so
Example: This is what your php.ini may look like with APC and memcached installed
extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20100525/"
extension = apc.so
apc.enabled=1
apc.shm_size=256M
; or if you have less than 4GB memory try:
; apc.shm_size=128M
apc.ttl = 0
apc.mmap_file_mask=/tmp/apc.XXXXXX
extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20100525/"
extension=memcached.so
Restart Apache.
service httpd restart
Okie dokie... Done! (I think I'm delirious writing this) Let's check to make sure it's working:
php -i | grep memcached
You should see a few lines detailing your setup. Cool! And.... One final step...
Open memcached port 11211 on your firewall
*** UPDATE: You can skip this step for security reasons, and manually add the IPs of your server farm to your firewall if needed. For CSF:
vi /etc/csf/csf.allow
Then add your IPs to the list. **** If you're using a server farm (load balancing) and you have a firewall installed, you'll need to open port 11211 so memcached can share resources across all servers.
vi /etc/sysconfig/iptables
add the below INPUT line:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 11211 -j ACCEPT
Restart iptables
service iptables restart
For CSF use:
vi /etc/csf/csf.conf
under "TCP_IN" and "TCP_OUT" add port: 11211 so it looks something like this:
# Allow incoming TCP ports
TCP_IN = "20,21,22,25,53,80,110,143,443,465,587,993,995,2222,11211"
# Allow outgoing TCP ports
TCP_OUT = "20,21,22,25,53,80,110,113,443,2222,11211"
once done restart CSF
service csf restart
So that's it and that's that...
相关推荐
php memcached扩展,内含安装手册以及源码包,libevent-2.0.22,libmemcached-1.0.18,memcached-1.4.25,memcached-2.2.0,已经在CentOS6.5上进行测试通过。
记录的关于在centos上安装memcached的文档,给有需要的朋友
tomcat+memcached依赖包(centos),包括memcached安装包
Windows8上安装虚拟机VirtualBox,然后新建虚拟电脑,搭建CentOS6.5 + mysql + nginx + php + memcached平台环境,部署网站。文档中记录了部分FAQ。
代码如下:yum -y install memcached#安装完成后执行:memcached -h#出现memcached帮助信息说明安装成功 2. 加入启动服务 代码如下:chkconfig –level 2345 memcached on 3. 配置Memcached 代码如下:vim /etc/...
NULL 博文链接:https://qindongliang.iteye.com/blog/2032975
我的第一个成功的基于 Docker 的映像用于 CentOS 7.0 上的 Memcached 1.4.22,旨在与。 我的 Docker Hub 仓库 Centmin Mod Docker 开发论坛 从 Docker Hub 抓取 docker pull centminmod/docker-centos7-memcached ...
Centos6.0 安装 nginx memcached 文档,简洁的命令
CentOS下Nginx0.8.52-PHP5.3.3-MySQL5.5.6-Memcached1.4.5安装配置优化详解
Vagrant-Sandbox-for-flask-app-with-https:Vagrantfile使用Memcached创建CentOS6 VM,使用SSL和HTTP将Apache重定向到https
今天小编就为大家分享一篇关于CentOS下安装Memcached和PHP Memcached扩展,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
维护者:这是的GIT中回购用于 (不要与任何官方混淆memcached由提供图像memcached上游)。 有关如何使用此Docker映像的完整自述文件以及有关贡献和问题的信息,请参阅。 的是在生成/维护的,尤其是。看到此处合并的...
实现目的:安装部署Memcached服务器 一、防火墙设置 CentOS 7.x默认使用的是firewall作为防火墙,这里改为iptables防火墙。 1、关闭firewall: systemctl stop firewalld.service #停止firewall systemctl disable ...
阿里云服务器centos+apache+php5.3+mysql+Zend Guard Loader+memcached+ftp环境搭建笔记
Linux(Cent OS7.2)下启动停止memcached方法及ps命令使用讲解.docx
Redis 是一个开源、支持网络、基于内存、键值对的 Key-Value 数据库,本篇文章主要介绍了Redis 对比 Memcached 并在 CentOS 下进行安装配置详解,有兴趣的可以了解一下。
自己亲身安装memcached的详细过程,操作系统是CentOS6.2 64位,生产环境。 希望可以帮助到大家。
NULL 博文链接:https://xwv.iteye.com/blog/1721604