CentOS 6.5 下安装 Redis 2.8.19,
1)下载Redis
wget http://download.redis.io/redis-stable.tar.gz
或者:http://download.redis.io/releases/ 下载最新版本
- wget http://download.redis.io/releases/redis-2.8.19.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make MALLOC=libc
make test
make install
这3个命令应该没有问题,主要的问题是执行make的时候,出现了异常。
异常一:
make[2]: cc: Command not found
异常原因:没有安装gcc
解决方案:yum install gcc-c++
异常二:
zmalloc.h:51:31: error: jemalloc/jemalloc.h: No such file or directory
异常原因:一些编译依赖或原来编译遗留出现的问题
解决方案:make distclean。清理一下,然后再make。
在make成功以后,需要make test。在make test出现异常。
异常三:
couldn’t execute “tclsh8.5”: no such file or directory
异常原因:没有安装tcl
解决方案:yum install -y tcl。
异常四:运行make test 报了这样的一个错误:
!!! WARNING The following tests failed:
*** [err]: Test replication partial resync: ok psync (diskless: yes, reconnect: 1) in tests/integration/replication-psync.tcl
Expected condition ‘[s -1 sync_partial_ok] > 0’ to be true ([s -1 sync_partial_ok] > 0)
Cleanup: may take some time… OK
make[1]: *** [test] Error 1
make[1]: Leaving directory `/usr/local/src/redis-3.2.1/src’
make: *** [test] Error 2
■ 解决办法:
1,只用单核运行 make test:
taskset -c 1 sudo make test
2,更改 tests/integration/replication-psync.tcl 文件:
vi tests/integration/replication-psync.tcl
把对应报错的那段代码中的 after后面的数字,从100改成 500。我个人觉得,这个参数貌似是等待的毫秒数。
编辑文件tests/integration/replication-psync.tcl
然后找到after 100 把此值修改成200或者300。重新执行make test就可以了
在make成功以后,会在src目录下多出一些可执行文件:redis-server,redis-cli等等。
方便期间用cp命令复制到usr目录下运行。
cp redis-server /usr/local/bin/
cp redis-cli /usr/local/bin/
然后新建目录,存放配置文件
mkdir /etc/redis
mkdir /var/redis
mkdir /var/redis/log
mkdir /var/redis/run
mkdir /var/redis/6379
在redis解压根目录中找到配置文件模板,复制到如下位置。
cd ..
cp redis.conf /etc/redis/6379.conf
通过vim命令修改
daemonize yes
pidfile /var/redis/run/redis_6379.pid
logfile /var/redis/log/redis_6379.log
dir /var/redis/6379
最后运行redis:
$ redis-server /etc/redis/6379.conf
配置自启动:
/etc/init.d/redis-server
#!/bin/sh
#
# redis - this script starts and stops the redis-server daemon
#
# chkconfig: - 85 15
# description: Redis is a persistent key-value database
# processname: redis-server
# config: /etc/redis.conf
# config: /etc/sysconfig/redis
# pidfile: /var/run/redis.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
redis="/usr/local/bin/redis-server"
prog=$(basename $redis)
REDIS_CONF_FILE="/etc/redis.conf"
[ -f /etc/sysconfig/redis ] && . /etc/sysconfig/redis
lockfile=/var/lock/subsys/redis
start() {
[ -x $redis ] || exit 5
[ -f $REDIS_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $redis $REDIS_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
stop
start
}
reload() {
echo -n $"Reloading $prog: "
killproc $redis -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
exit 2
esac
(2)将redis加入自启动服务
sudo chkconfig --add /etc/init.d/redis-server
sudo chkconfig redis-server --level 345 on
使用chkconfig --list查看添加的服务
(4)启动服务
sudo service redis-server start
三、使用
redis-cli
127.0.0.1:6379>
127.0.0.1:6379>
127.0.0.1:6379> keys *
(empty list or set)
Linux下php安装Redis扩展 注意:目录的权限 chomd 777 -R
1、安装redis
下载:https://github.com/nicolasff/phpredis/archive/2.2.4.tar.gz
上传phpredis-2.2.4.tar.gz到/usr/local/src目录
cd /usr/local/src #进入软件包存放目录
tar zxvf phpredis-2.2.4.tar.gz #解压
cd phpredis-2.2.4 #进入安装目录
/usr/local/php/bin/phpize #用phpize生成configure配置文件
./configure –with-php-config=/usr/local/php/bin/php-config #配置
make #编译
make install #安装
安装完成之后,出现下面的安装路径
/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/
2、配置php支持
vi /usr/local/php/etc/php.ini #编辑配置文件,在最后一行添加以下内容
添加
extension=”redis.so”
:wq! #保存退出
3 重启服务
sudo service nginx restart
sudo /etc/init.d/php-fpm restart
hadoop@stormspark:~/workspace/redis2.6.13/src$ make test
You need tcl 8.5 or newer in order to run the Redis test
make: *** [test] Error 1
wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
sudo tar xzvf tcl8.6.1-src.tar.gz -C /usr/local/
cd /usr/local/tcl8.6.1/unix/
sudo ./configure
sudo make
sudo make install
编译安装php7的redis扩展支持
wget -c https://github.com/phpredis/phpredis/archive/php7.zip
unzip php7.zip
cd phpredis-php7
/usr/local/php/bin/phpize
./configure –with-php-config=/usr/local/php/bin/php-config
make
make install
cd ..
/usr/local/php/etc/php.ini
中加入
extension=redis.so
git clone https://github.com/phpredis/phpredis.git
cd phpredis/
/usr/local/php/bin/phpize
./configure –with-php-config=/usr/local/php/bin/php-config
make
make install
cd ..
/usr/local/php/etc/php.ini
中加入
extension=redis.so