Memcached 源码安装

一、 Memcached yum安装
(1) 安装 libevent: 轻量级的开源高性能事件通知库

yum   install -y  libevent

(2) 安装Memcached:

  yum  install  -y  memcached 
  systemctl start memcached 
  ps -aux |grep memcached  |grep -v grep 

(3)测试Memcached启动是否连接

   #telnet 192.168.79.28 11211
   Trying 192.168.79.28...
   Connected to 192.168.79.28 (192.168.79.28).
   Escape character is '^]'.

//保存,向 test 中存入数据

set test 0 0 10
test_value
STORED

//取回,取出 test 中保存的数据

get test
VALUE test 0 10
test_value
END
quit
Connection closed by foreign host.

(4)安装Apache
yum install -y httpd
(5)安装MariaDB数据库
yum -y install mariadb-server mariadb
(6)安装PHP
yum -y install php php-mysql php-gd php-pecl-memcache
(7) 设置memcached 与php扩展
php.ini 添加如下一行代码来载入 Memcache 扩展
extension = memcache.so
注意:如果是源码安装的 php,需要修改 extension_dir = “/usr/lib64/php/modules”
(8)设置防火墙
Centos7下的防火墙已经由iptables改为firewall,使用firewall-cmd命令开放80及443端口:
firewall-cmd –permanent –zone=public –add-service=http
firewall-cmd –permanent –zone=public –add-service=https
firewall-cmd –reload
二、 Memcached 源码安装
1.安装libevent
网站:http://libevent.org/
wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
解压: tar -xf libevent-2.0.21-stable.tar.gz
./configure --prefix=/usr/local/libevent
make && make install
2.安装memcached
网站:http://memcached.org/
wget http://www.memcached.org/files/memcached-1.5.4.tar.gz
解压: tar -xf memcached-1.5.4.tar.gz
./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent/
make && make install
2.1 启动 Memcached

 /usr/local/memcached/bin/memcached  -m 32m -p 11211  -d  -u root -P /usr/local/memcached/memcached.pid -c 256
 netstat -lntup |grep 11211 

2.2配置PATH

cat /etc/profile.d/memcached.sh

export PATH=$PATH:/usr/local/memcached/bin
2.3添加用户名:

useradd -u 995 -c “Memcached daemon” -d /run/memcached -s /sbin/nologin -r memcached
chown -R memcached:memcached /usr/local/memcached/

2.4配置启动服务脚本:

   [Unit]
Description=Memcached
Before=httpd.service
After=network.target
[Service]
Type=simple
EnvironmentFile=-/etc/sysconfig/memcached
ExecStart=/usr/local/memcached  -u $USER -p $PORT -m $CACHESIZE -c $MAXCONN $OPTIONS
[Install]
WantedBy=multi-user.target

2.5配置服务脚本

cat /etc/sysconfig/memcached 
PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="64"
OPTIONS=""

3.安装php安装memcached扩展模块(需要安装PHP环境 )
网站:http://pecl.php.net/package/memcache
wget http://pecl.php.net/get/memcache-2.2.7.tgz
解包:tar -zxf memcached-2.2.0.tgz
cd memcache-2.2.7
phpize 备注:phpize 需要php-devel包,并必须进入 memcache-2.2.7 目录 这个命令在编译安装php时会在安装目录下的bin目录下,
查找 php-config which php-config find / -name php-config
./configure --enable-memcache --with-php-config=/usr/bin/php-config

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

make && make install
安装后会提示:/usr/lib64/php/modules/
./configure – enable- - memcache
安装完成后需要在php.ini文件中添加一条extension=memcached.so的记录,然后使用php -m命令可以看到有memcached模块了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值