標籤:
方法一:使用命令安裝(前提是已經安裝了EPEL)。
安裝redis:
yum -y install redis
啟動/停止/重啟 Redis
啟動服務:
1
systemctl start redis.service
停止服務:
systemctl stop redis.service
重啟服務:
systemctl restart redis.service
檢查狀態:
[[email protected] ~]# 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.
隨系統啟動服務:
[[email protected] ~]# systemctl enable redis.service
ln -s ‘/usr/lib/systemd/system/redis.service‘ ‘/etc/systemd/system/multi-user.target.wants/redis.service‘
關閉隨機啟動:
[[email protected] ~]# 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
錯誤描述
安裝Redis 2.8.18時報錯:
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
centos7安裝redis