方法一:使用命令安裝(前提是已經安裝了EPEL)。
安裝redis:
yum -y install redis
啓動/中止/重啓 Redis
啓動服務:
1
systemctl start redis.service
中止服務:
systemctl stop redis.service
重啓服務:
php
systemctl restart redis.service
檢查狀態:
html
[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.
隨系統啓動服務:
git
[root@idoseek ~]# systemctl enable redis.service
ln -s '/usr/lib/systemd/system/redis.service' '/etc/systemd/system/multi-user.target.wants/redis.service'
關閉隨機啓動:
github
[root@idoseek ~]# systemctl disable redis.service
rm '/etc/systemd/system/mult(www.111cn.net)i-user.target.wants/redis.service'
方法二:編譯安裝
下載安裝編譯:
redis
# 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
設置配置文件路徑:
vim
# mkdir -p /etc/redis && cp redis.conf /etc/redis
修改配置文件:
緩存
# vim /etc/redis/redis.conf
修改成: daemonize yes
啓動Redis:
php-fpm
# /usr/local/bin/redis-server /etc/redis/redis.conf
#關閉服務
ui
redis-cli shutdown
或者在cli中執行shutdown
.net
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