centos7安装redis
方法一:使用命令安装(前提是已经安装了EPEL)。
安装redis:
yum -y install redis
启动/停止/重启 Redis
启动服务:
1
systemctl start redis.service
停止服务:
systemctl stop redis.service
重启服务:
systemctl restart redis.service
检查状态:
[root@idoseek ~]# systemctl status redis.service
redis.service - Redis persistent key-value database
Loaded: loaded (/usr/lib/systemd/system/redis.service; enabled)
Active: active (running) since 二 2014-10-21 21:37:22 EDT; 5h 26min ago
Main PID: 30413 (redis-server)
CGroup: /system.slice/redis.service
└─30413 /usr/bin/redis-server 127.0.0.1:6379
10月 21 21:37:22 idoseek.com systemd[1]: Started Redis persistent key-value database.
随系统启动服务:
[root@idoseek ~]# systemctl enable redis.service
ln -s '/usr/lib/systemd/system/redis.service' '/etc/systemd/system/multi-user.target.wants/redis.service'
关闭随机启动:
[root@idoseek ~]# systemctl disable redis.service
rm '/etc/systemd/system/mult(www.111cn.net)i-user.target.wants/redis.service'
方法二:编译安装
下载安装编译:
# wget http://download.redis.io/releases/redis-2.8.17.tar.gz
# tar xzf redis-2.8.17.tar.gz
# cd redis-2.8.17
# make
# make install
设置配置文件路径:
# mkdir -p /etc/redis && cp redis.conf /etc/redis
修改配置文件:
# vim /etc/redis/redis.conf
修改为: daemonize yes
启动Redis:
# /usr/local/bin/redis-server /etc/redis/redis.conf
#关闭服务
redis-cli shutdown
或者在cli中执行shutdown
redis 127.0.0.1:6379> shutdown
清除缓存
redis-cli flushall
更多文档请参考软件包内的“README”文件。
查看状态 :
# ss -nlp|grep redis
或者
# ps -ef | grep redis
下面介绍为PHP添加redis插件。
从官网下载最新的拓展,地址:http://pecl.php.net/package/redis或者https://github.com/phpredis/phpredis
#wget http://pecl.php.net/get/redis-2.2.5.tgz
#phpize
#./configure --prefix=/opt/redis --enable-redis --with-php-config=/opt/php/bin/php-config
#make && make install
把拓展添加至php.ini,重启php-fpm:
service php-fpm restart
from:http://www.111cn.net/sys/CentOS/85292.htm
错误描述
zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory
zmalloc.h:55:2: error: #error "Newer version of jemalloc required"
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory `/data0/src/redis-2.6.2/src'
make: *** [all] Error 2
原因分析
在README 有这个一段话。
Allocator
---------
Selecting a non-default memory allocator when building Redis is done by setting
the `MALLOC` environment variable. Redis is compiled and linked against libc
malloc by default, with the exception of jemalloc being the default on Linux
systems. This default was picked because jemalloc has proven to have fewer
fragmentation problems than libc malloc.
To force compiling against libc malloc, use:
% make MALLOC=libc
To compile against jemalloc on Mac OS X systems, use:
% make MALLOC=jemalloc
说关于分配器allocator, 如果有MALLOC 这个 环境变量, 会有用这个环境变量的 去建立Redis。
而且libc 并不是默认的 分配器, 默认的是 jemalloc, 因为 jemalloc 被证明 有更少的 fragmentation problems 比libc。
但是如果你又没有jemalloc 而只有 libc 当然 make 出错。 所以加这么一个参数。
解决办法
make MALLOC=libc