firewall-cmd -permanent -zone=public -add-service=http
firewall-cmd -permanent -zone=public -add-service=https
安装 libevent
[root@localhost ~]# wget https://github.com/libevent/libevent/releases/download/release-2.1.11-stable/libevent-2.1.11-stable.tar.gz
[root@localhost ~]# tar -xzvf libevent-2.1.11-stable.tar.gz
[root@localhost ~]# cd libevent-2.1.11-stable
[root@localhost libevent-2.1.11-stable]# ./configure --prefix=/usr/local/libevent
[root@localhost libevent-2.1.11-stable]# make && make install
安装 memcached
[root@localhost ~]# wget http://www.memcached.org/files/memcached-1.6.1.tar.gz
[root@localhost ~]# tar -xzvf memcached-1.6.1.tar.gz
[root@localhost ~]# cd memcached-1.6.1
[root@localhost memcached-1.6.1]# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent/
[root@localhost memcached-1.6.1]# make && make install
[root@localhost ~]# /usr/local/memcached/bin/memcached -m 32m -p 11211 -d -u root -P /usr/local/memcached/memcached.pid -c 256
[root@localhost ~]# netstat -lntup |grep 11211
tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 125476/memcached
tcp6 0 0 :::11211 :::* LISTEN 125476/memcached
-d
启动守护进程(后台进行)-m
设置memcache使用的内存大小-p
端口默认11211(增加实例,只需要修改端口号即可11212…)-u
以root用户启动进程-c
指定连接数-P
指定pid地址[root@localhost ~]# wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz
[root@localhost ~]# tar -xzvf libmemcached-1.0.18.tar.gz
[root@localhost ~]# cd libmemcached-1.0.18
[root@localhost libmemcached-1.0.18]# ./configure --prefix=/usr/local/libmemcached --with-memcached
[root@localhost libmemcached-1.0.18]# make && make install
yum install php-devel
[root@localhost ~]# which phpize
/usr/bin/phpize
[root@localhost ~]# which php-config
/usr/bin/php-config
[root@localhost ~]# wget http://pecl.php.net/get/memcached-3.1.5.tgz
[root@localhost ~]# tar -xzvf memcached-3.1.5.tgz
[root@localhost ~]# cd memcached-3.1.5
[root@localhost memcached-3.1.5]# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version: 20180731
Zend Module Api No: 20180731
Zend Extension Api No: 320180731
[root@localhost memcached-3.1.5]# ./configure --prefix=/usr/local/phpmemcached --enable-memcached --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached --disable-memcached-sasl
[root@localhost memcached-3.1.5]# make
[root@localhost memcached-3.1.5]# make test
[root@localhost memcached-3.1.5]# make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20180731/
加上模块extension=memcached.so
,看看extension_dir
指定的模块路径下是否有memcached.so
文件
extension_dir
一般是/usr/lib/php/modules/
[root@localhost ~]# mkdir -p /usr/lib/php/modules
[root@localhost ~]# ln -s /usr/lib64/php/modules /usr/lib/php/modules
memcached.so
的记录[root@localhost ~]# vim /usr/local/php/lib/php.ini
extension=memcached.so
[root@localhost ~]# vim /usr/local/nginx/html/test.php
<?php
phpinfo();
?>
[root@localhost ~]# /usr/local/php/sbin/php-fpm
yum install -y telnet
[root@localhost ~]# telnet 192.168.182.11 11211
Trying 192.168.182.11...
Connected to 192.168.182.11.
Escape character is '^]'.
stats
STAT pid 125476
STAT uptime 3514
STAT time 1584515555
STAT version 1.6.1
STAT libevent 2.1.11-stable
STAT pointer_size 64
STAT rusage_user 0.823110
STAT rusage_system 1.728532
STAT max_connections 256
STAT curr_connections 2
STAT total_connections 352
STAT rejected_connections 0
STAT connection_structures 4
STAT response_obj_bytes 2382720
STAT response_obj_total 2040
STAT response_obj_free 2039
STAT response_obj_oom 0
STAT read_buf_bytes 65536
STAT read_buf_bytes_free 49152
STAT read_buf_oom 0
STAT reserved_fds 20
STAT cmd_get 4626
STAT cmd_set 2574
......
Memcached菜鸟教程
/usr/local/bin/memcached: error while loading shared libraries: libevent-2.1.so.7: cannot open shared object file: No such file or directory
解决方法: 创建libevent软连接
[root@localhost ~]# sudo find / -name libevent-2.1.so.7
[root@localhost ~]# /usr/local/lib/libevent-2.1.so.7
[root@localhost ~]# /root/libevent-2.1.11-stable/.libs/libevent-2.1.so.7
[root@localhost ~]# LD_DEBUG=libs /usr/local/bin/memcached -v
4607: find library=libevent-2.1.so.7 [0]; searching
4607: search cache=/etc/ld.so.cache
4607: search path=/lib64/tls/x86_64:/lib64/tls:/lib64/x86_64:/lib64:/usr/lib64/tls/x86_64:/usr/lib64/tls:/usr/lib64/x86_64:/usr/lib64 (system search path)
4607: trying file=/lib64/tls/x86_64/libevent-2.1.so.7
4607: trying file=/lib64/tls/libevent-2.1.so.7
4607: trying file=/lib64/x86_64/libevent-2.1.so.7
4607: trying file=/lib64/libevent-2.1.so.7
4607: trying file=/usr/lib64/tls/x86_64/libevent-2.1.so.7
4607: trying file=/usr/lib64/tls/libevent-2.1.so.7
4607: trying file=/usr/lib64/x86_64/libevent-2.1.so.7
4607: trying file=/usr/lib64/libevent-2.1.so.7
4607:
/usr/local/bin/memcached: error while loading shared libraries: libevent-2.1.so.7: cannot open shared object file: No such file or directory
从Debug信息中就知道程序去哪里找链接库了。我这边程序去 trying file=/usr/lib64/libevent-2.1.so.7
而我的链接库的实际存储位置是 /usr/local/lib/libevent-2.1.so.7
[root@localhost ~]# ln -s /usr/local/lib/libevent-2.1.so.7 /usr/lib64/libevent-2.1.so.7