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/bin2.3useraddu995cMemcacheddaemond/run/memcacheds/sbin/nologinrmemcachedchownRmemcachedmemcached/usr/local/memcached/2.4[Unit]Description=MemcachedBefore=httpd.serviceAfter=network.target[Service]Type=simpleEnvironmentFile=/etc/sysconfig/memcachedExecStart=/usr/local/memcachedu  USER -p PORTm  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模块了。

猜你喜欢

转载自blog.csdn.net/genglei1022/article/details/78889243