安装
cd /opt
wget http://download.redis.io/releases/redis-3.0.7.tar.gz
tar -xzf redis-3.0.7.tar.gz
ln -s redis-3.0.7 redis 为了方便目录管理和升级
cd redis
make && make install
可执行文件 /opt/redis/src
redis-server --redis服务器
redis-cli --redis命令行客户端
redis-benchmark --redis性能测试
redis-check-aof --aof文件修复工具
redis-check-dump --RDB文件检查工具
启动方式(3种):
1、最简启动
[root@]# redis-server
连接:
[root@]# redis-cli
:6379> config get *
[root@]# redis-cli -h 127.0.0.1 -p 6379
:6379> set hello world
OK
:6379> get hello
"world"
:6379> ping
PONG
127.0.0.1:6379> exit
[root@]# redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379> del hello
(integer) 1
127.0.0.1:6379> get hello
(nil)
127.0.0.1:6379>
2、动态参数启动:
redis-server --port 6380
[root@centos03ms ~]# ps -ef |grep redis
root 16491 16441 0 22:26 pts/1 00:00:04 redis-server *:6379
root 16688 16542 0 22:29 pts/2 00:00:00 redis-cli
root 17775 16693 0 23:03 pts/7 00:00:00 redis-server *:6380
root 17788 17103 0 23:03 pts/8 00:00:00 grep redis
[root@centos03ms ~]# redis-cli -p 6380
127.0.0.1:6380> ping
PONG
127.0.0.1:6380>
3、配置文件启动:
mkdir config
cp redis.conf ./config/
cd config/
mv redis.conf redis-6381.conf
--过滤掉所有的注释和空格
[root@]# cat redis-6381.conf |grep -v "#"| grep -v "^$">redis-6382.conf
[root@]# rm -rf redis-6381.conf
[root@]# cat redis-6382.conf
daemonize no
pidfile /var/run/redis.pid
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 0
loglevel notice
logfile ""
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir ./
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
[root@]#
先简单编辑如下:
[root@]# cat redis-6382.conf
daemonize yes
port 6382
dir "/opt/redis/data"
logfile "6382.log"
[root@]# pwd
/opt/redis
[root@]# mkdir data
[root@]#
[root@]# redis-server config/redis-6382.conf
[root@]# ps -ef |grep redis|grep 6382
root 7895 1 0 22:28 ? 00:00:00 redis-server *:6382
[root@]#
[root@]# cd data/
[root@]# ls
6382.log
[root@]#
4、验证启动结果
ps -ef |grep redis
netstat -antp |grep redis
redis-cli -h 127.0.0.1 -p 6379 ping