-
- $ wget http://download.redis.io/releases/redis-2.6.16.tar.gz
- $ tar xzf redis-2.6.16.tar.gz
- $ cd redis-2.6.16
- $ make install
-
复制代码
2.配置
-
- $ mkdir /etc/redis
- $ cp redis.conf /etc/redis/redis.conf
- $ gedit /etc/sysctl.conf$ sysctl -p
-
复制代码
注:sysctl.conf文件尾部加上vm.overcommit_memory=1
3.启动测试
-
- $ /usr/local/bin/redis-server /etc/redis/redis.conf
- $ /usr/local/bin/redis-cli
- $ set test xjx
- $ get test
-
复制代码
4.开机启动
-
-
$ gedit /etc/redis/redis.conf
- 设置daemonize yes
$ gedit /var/run/redis.pid
- 直接保存,主要是创建该文件
gedit /etc/init.d/redis
- 编辑脚本,也可以自己下载或者输入以下内容
- #!/bin/bash
- #
- # redis - this script starts and stops the redis-server daemon
- #
- # chkconfig: - 80 12
- # description: Redis is a persistent key-value database
- # processname: redis-server
- # config: /etc/redis/redis.conf
- # pidfile: /var/run/redis.pid
source /etc/init.d/functions
BIN="/usr/local/bin"
- CONFIG="/etc/redis/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 755 /etc/init.d/redis
复制代码
添加开机启动:
-
- $ chkconfig --add redis
- $ chkconfig --level 345 redis on
- $ chkconfig --list redis
复制代码
之后重启服务器,$ service redis status 查看是否正确配置
接下来介绍phpredis的安装与配置方法。
二、phpredis
1.自行下载解压
https://github.com/nicolasff/phpredis/archive/master.zip
2.安装
-
- $ cd /root/phpredis-master
- $ /usr/local/php/bin/phpize
- $ ./configure --with-php-config=/usr/local/php/bin/php-config
- $ make && make install
-
复制代码
注:路径根据实际情况修改
3.php扩展
$ gedit /usr/local/php/etc/php.ini
加入extension=redis.so,然后重启php-fpm(非nginx)
4.测试
-
- $redis = new Redis();
- $redis->connect('127.0.0.1',6379);
- $redis->set('test','hello world!');
- echo $redis->get('test');
-
复制代码
三、phpredisadmin
http://down.admin5.com/php/75024.html
下载解压至www目录即可,这里提供大家,最好不用官方最新版本,个中原由,你用了就明白啦。
|