-
使用yum安装软件包memcached - memcached缓存数据库(kv数据库)
- [root@localhost iproute2]# yum install -y memcached
-
memcached配置文件(查看即可,不需要修改) - [root@localhost iproute2]# vim /usr/lib/systemd/system/memcached.service
- 服务配置文件
- [root@localhost iproute2]# vim /etc/sysconfig/memcached
- 环境配置文件
- 1 PORT=“11211”
2 USER=“memcached” 3 MAXCONN=“1024” 4 CACHESIZE=“64” 5 OPTIONS="" - [root@localhost iproute2]# systemctl start memcached
- ss命令和netstat是一样的作用
- [root@localhost iproute2]# ss -antulp | grep 11211
udp UNCONN 0 0 :11211 : users:((“memcached”,pid=25981,fd=28)) udp UNCONN 0 0 [::]:11211 [::]: users:((“memcached”,pid=25981,fd=29)) tcp LISTEN 0 128 :11211 : users:((“memcached”,pid=25981,fd=26)) tcp LISTEN 0 128 [::]:11211 [::]: users:((“memcached”,pid=25981,fd=27)) [root@localhost iproute2]# netstat -antulp | grep 11211 tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 25981/memcached tcp6 0 0 :::11211 ::😗 LISTEN 25981/memcached udp 0 0 0.0.0.0:11211 0.0.0.0:* 25981/memcached udp6 0 0 :::11211 ::😗 25981/memcached - 用yum安装telnet
- [root@localhost iproute2]# yum -y install telnet
- [root@localhost iproute2]# telnet 192.168.2.5 11211
- Trying 192.168.2.5…
Connected to 192.168.2.5. Escape character is ‘^]’. set haha 0 180 3 //存一个key为haha,0代表不压缩,180代表保留180秒,3代表value为3个字节 yyy //value STORED get haha //获取key对应value VALUE haha 0 3 yyy END - 常用命令:
- add myname 0 180 3//新建key,只能新建,如果原来有相同key会报错
- replace myname 0 180 3//替换key,只能替换,如果原来没有这个key会报错
- set myname 0 180 3//设置key,原来没有就新建,有就替换
- get myname 、、//读取key
- append myname 0 180 2//在原有key对应的value值追加值
- delete myname //删除key
- flush_all//清空所有
- quit//退出登录
-
lnmp+memcached -
- 给web1和web2的PHP安装memcached扩展(php-pecl-memcache),否则PHP无法解析连接memcached的指令
- [root@pc207 html]# yum -y install php-pecl-memcache
- [root@pc207 html]# systemctl restart php-fpm
-
- 修改PHP-FPM配置文件,并重启服务
- 注意,因为后端两台web服务器都需要修改配置文件
- 修改/etc/php-fpm.d/www.conf
- 224 php_value[session.save_handler] = files
225 php_value[session.save_path] = /var/lib/php/session 最后两行默认值更改为 php_value[session.save_handler] = memcache php_value[session.save_path] = “tcp://192.168.2.5:11211” 重启php-fpm [root@pc207 html]# systemctl restart php-fpm
|