#yum install tcl
#cp -r /usr/local/src/redis-3.0.3 /usr/local/redis-3
#cd /usr/local/redis-3
#make && make install
daemonize yes
#cp redis-server /usr/local/bin/
#cp redis-cli /usr/local/bin/
redis启动脚本
#vim /etc/init.d/redis
#
# Init file for redis
#
# chkconfig: - 80 12
# description: redis daemon
#
# processname: redis
# config: /etc/redis.conf
# pidfile: /var/run/redis.pid
source /etc/init.d/functions
#BIN="/usr/local/bin"
BIN="/usr/local/bin"
CONFIG="/usr/local/redis-3/redis.conf"
PIDFILE="/var/run/redis.pid"
### Read configuration
[ -r "$SYSCONFIG" ] && source "$SYSCONFIG"
RETVAL=0
prog="redis-server"
desc="Redis Server"
start() {
if [ -e $PIDFILE ];then
echo "$desc already running...."
exit 1
fi
echo -n $"Starting $desc: "
daemon $BIN/$prog $CONFIG
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
return $RETVAL
}
stop() {
echo -n $"Stop $desc: "
killproc $prog
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog $PIDFILE
return $RETVAL
}
#!/bin/bash
#
# Init file for redis
#
# chkconfig: - 80 12
# description: redis daemon
#
# processname: redis
# config: /etc/redis.conf
# pidfile: /var/run/redis.pid
source /etc/init.d/functions
#BIN="/usr/local/bin"
BIN="/usr/local/bin"
CONFIG="/usr/local/redis-3/redis.conf"
PIDFILE="/var/run/redis.pid"
### Read configuration
[ -r "$SYSCONFIG" ] && source "$SYSCONFIG"
RETVAL=0
prog="redis-server"
desc="Redis Server"
start() {
if [ -e $PIDFILE ];then
echo "$desc already running...."
exit 1
fi
echo -n $"Starting $desc: "
daemon $BIN/$prog $CONFIG
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
return $RETVAL
}
stop() {
echo -n $"Stop $desc: "
killproc $prog
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog $PIDFILE
return $RETVAL
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
condrestart)
[ -e /var/lock/subsys/$prog ] && restart
RETVAL=$?
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|status}"
RETVAL=1
esac
exit $RETVAL
#chmod +x /etc/init.d/redis
启动redis,最好先在配置文件里设置后台运行,否则启动的话是前台运行,会一直占用终端
# /etc/init.d/redis restart
报错(分三部分,三个WARNING)
4347:M 29 Sep 21:31:55.388 # Server started, Redis version 3.0.3
4347:M 29 Sep 21:31:55.388 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
4347:M 29 Sep 21:31:55.388 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
4347:M 29 Sep 21:31:55.388 * The server is now ready to accept connections on port 6379(1)
解决方法
#vim /etc/sysctl.conf
加入
vm.overcommit_memory = 1
或者
#echo "vm.overcommit_memory=1" >> /etc/sysctl.conf
刷新生效
#sysctl -p
(2)
#echo never > /sys/kernel/mm/transparent_hugepage/enabled
#vim /etc/rc.local
加入
echo never > /sys/kernel/mm/transparent_hugepage/enabled
(3)
#echo 511 > /proc/sys/net/core/somaxconn
再启动一次,应该就没问题了
# /etc/init.d/redis restart
测试
# redis-cli
127.0.0.1:6379> set foo bar
OK
127.0.0.1:6379> bar
(error) ERR unknown command 'bar'
127.0.0.1:6379> get foo
"bar"
127.0.0.1:6379> quit
安装php扩展
https://github.com/nicolasff/phpredis/archive/2.2.4.tar.gz
#tar -zxf phpredis-2.2.4.tar.gz
#phpize ./
#./configure --with-php-config=/usr/local/php/bin/php-config
#make && make install
# vim /usr/local/php/etc/php.ini
加入
[redis]
extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/redis.so