mac上redis的安装与配置

安装

上redis官网下载最新redis版本,我下载的是redis-3.0.6.tar.gz
把该文件放到某个目录下进行解压
也可以用命令进行解压

1
tar -zxvf redis-3.0.6.tar.gz

解压之后进入redis-3.0.6
编译

1
make

安装

1
2
cd src
make install

然后会在/usr/local/bin目录下有redis-cli和redis-server命令脚本

启动服务

1
redis-server

进入redis客户端

1
redis-cli

======================= 安装成功

配置–个人习惯

进入到redis的安装目录,找到redis.conf文件(/Users/demondevil/mydatas/redis/redis-3.0.6/redis.conf)
修改daemonize为yes
修改pidfile为/Users/demondevil/mydatas/redis/redis_6379.pid
(默认的路径/var/run/redis.pid只有root用户才有权限,所有启动redis的时候生成不了这个pid文件)
修改logfile为/tmp/logs/redis_6379.log(日志文件)

在/usr/local/bin目录下新建脚本文件redis_6379,内容如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/sh
#Configurations injected by install_server below....

EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/Users/demondevil/mydatas/redis/redis_6379.pid
CONF="/Users/demondevil/mydatas/redis/redis-3.0.6/redis.conf"
REDISPORT="6379"
###############
# SysV Init Information
# chkconfig: - 58 74
# description: redis_6379 is the redis daemon.
### BEGIN INIT INFO
# Provides: redis_6379
# Required-Start: $network $local_fs $remote_fs
# Required-Stop: $network $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Should-Start: $syslog $named
# Should-Stop: $syslog $named
# Short-Description: start and stop redis_6379
# Description: Redis daemon
### END INIT INFO

case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
$EXEC $CONF
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
status)
PID=$(cat $PIDFILE)
if [ ! -x /proc/${PID} ]
then
echo 'Redis is not running'
else
echo "Redis is running ($PID)"
fi
;;
restart)
$0 stop
$0 start
;;
*)
echo "Please use start, stop, restart or status as first argument"
;;
esac

以后redis的启动、关闭、重启、查看状态的命令分别为
redis_6379 start
redis_6379 stop
redis_6379 restart
redis_6379 status

热评文章